Changeset 32637 in osm for applications/editors/josm/plugins/indoorhelper/src/views/LevelSelectorView.java
- Timestamp:
- 2016-07-11T22:48:15+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoorhelper/src/views/LevelSelectorView.java
r32122 r32637 21 21 import static org.openstreetmap.josm.tools.I18n.tr; 22 22 23 import java.awt.*; 23 import java.awt.BorderLayout; 24 import java.awt.Container; 25 import java.awt.GridBagConstraints; 26 import java.awt.GridBagLayout; 27 import java.awt.Insets; 24 28 import java.awt.event.ActionListener; 25 29 26 import javax.swing.*; 30 import javax.swing.JButton; 31 import javax.swing.JFrame; 32 import javax.swing.JLabel; 33 import javax.swing.JPanel; 34 import javax.swing.JSpinner; 27 35 import javax.swing.JSpinner.DefaultEditor; 28 import javax.swing.border. *;36 import javax.swing.border.EmptyBorder; 29 37 30 38 /** 31 39 * Class for the pop-up window which provides an level selector to get a user input. 32 40 * In this window the user declares the lowest and the highest level of the building he wants to map. 33 * 41 * 34 42 * @author egru 35 43 * … … 38 46 @SuppressWarnings("serial") 39 47 public class LevelSelectorView extends JFrame { 40 41 private JPanel dialogPane;42 private JPanel contentPanel;43 private JLabel minLabel;44 private JSpinner minSpinner;45 private JLabel maxLabel;46 private JSpinner maxSpinner;47 private JPanel buttonBar;48 private JButton okButton;49 private JButton cancelButton;50 51 public LevelSelectorView() {52 initComponents();53 }54 55 private void initComponents() {56 dialogPane = new JPanel();57 contentPanel = new JPanel();58 minLabel = new JLabel();59 minSpinner = new JSpinner();60 maxLabel = new JLabel();61 maxSpinner = new JSpinner();62 buttonBar = new JPanel();63 okButton = new JButton();64 cancelButton = new JButton();65 66 //======== this ========67 setTitle(tr("Level Selection"));68 Container contentPane = getContentPane();69 contentPane.setLayout(new BorderLayout());70 71 //======== dialogPane ========72 {73 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));74 dialogPane.setLayout(new BorderLayout());75 76 //======== contentPanel ========77 {78 contentPanel.setLayout(new GridBagLayout());79 ((GridBagLayout)contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0};80 ((GridBagLayout)contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0};81 ((GridBagLayout)contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4};82 ((GridBagLayout)contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};83 84 //---- minLabel ----85 minLabel.setText(tr("Lowest Level"));86 contentPanel.add(maxLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,87 GridBagConstraints.CENTER, GridBagConstraints.BOTH,88 new Insets(0, 0, 5, 5), 0, 0));89 JSpinner.DefaultEditor minEditor = (DefaultEditor) maxSpinner.getEditor();90 minEditor.getTextField().setColumns(2);91 maxSpinner.setToolTipText(tr("The lowest level of your building."));92 contentPanel.add(maxSpinner, new GridBagConstraints(2, 0, 2, 1, 0.0, 0.0,93 GridBagConstraints.CENTER, GridBagConstraints.BOTH,94 new Insets(0, 0, 5, 0), 0, 0));95 96 //---- maxLabel ----97 maxLabel.setText(tr("Highest Level"));98 contentPanel.add(minLabel, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0,99 GridBagConstraints.CENTER, GridBagConstraints.BOTH,100 new Insets(0, 0, 5, 5), 0, 0));101 JSpinner.DefaultEditor maxEditor = (DefaultEditor) minSpinner.getEditor();102 maxEditor.getTextField().setColumns(2);103 minSpinner.setToolTipText(tr("The highest level of your building."));104 contentPanel.add(minSpinner, new GridBagConstraints(2, 2, 2, 1, 0.0, 0.0,105 GridBagConstraints.CENTER, GridBagConstraints.BOTH,106 new Insets(0, 0, 5, 0), 0, 0));107 }108 dialogPane.add(contentPanel, BorderLayout.CENTER);109 110 //======== buttonBar ========111 {112 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));113 buttonBar.setLayout(new GridBagLayout());114 ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};115 ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};116 117 //---- okButton ----118 okButton.setText(tr("OK"));119 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,120 GridBagConstraints.CENTER, GridBagConstraints.BOTH,121 new Insets(0, 0, 0, 5), 0, 0));122 123 //---- cancelButton ----124 cancelButton.setText(tr("Cancel"));125 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,126 GridBagConstraints.CENTER, GridBagConstraints.BOTH,127 new Insets(0, 0, 0, 0), 0, 0));128 }129 dialogPane.add(contentPanel, BorderLayout.CENTER);130 131 //======== buttonBar ========132 {133 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));134 buttonBar.setLayout(new GridBagLayout());135 ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};136 ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};137 138 //---- okButton ----139 okButton.setText(tr("OK"));140 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,141 GridBagConstraints.CENTER, GridBagConstraints.BOTH,142 new Insets(0, 0, 0, 5), 0, 0));143 144 //---- cancelButton ----145 cancelButton.setText(tr("Cancel"));146 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,147 GridBagConstraints.CENTER, GridBagConstraints.BOTH,148 new Insets(0, 0, 0, 0), 0, 0));149 }150 dialogPane.add(buttonBar, BorderLayout.SOUTH);151 }152 contentPane.add(dialogPane, BorderLayout.CENTER);153 pack();154 setLocationRelativeTo(getOwner());155 156 }157 158 /**159 * Set the listener for the OK button.160 * 161 * @param l the listener to set162 */163 public void setOkButtonListener(ActionListener l){164 this.okButton.addActionListener(l);165 }166 167 /**168 * Set the listener for the cancel button.169 * 170 * @param l the listener to set171 */172 public void setCancelButtonListener(ActionListener l){173 this.cancelButton.addActionListener(l);174 }175 176 /**177 * Getter for the lowest level.178 * 179 * @return Integer which represents the lowest level of the building.180 */181 public int getMin(){182 return (int) this.minSpinner.getValue();183 }184 185 /**186 * Getter for the highest level.187 * 188 * @return Integer which represents the highest level of the building.189 */190 public int getMax(){191 return (int) this.maxSpinner.getValue();192 }48 49 private JPanel dialogPane; 50 private JPanel contentPanel; 51 private JLabel minLabel; 52 private JSpinner minSpinner; 53 private JLabel maxLabel; 54 private JSpinner maxSpinner; 55 private JPanel buttonBar; 56 private JButton okButton; 57 private JButton cancelButton; 58 59 public LevelSelectorView() { 60 initComponents(); 61 } 62 63 private void initComponents() { 64 dialogPane = new JPanel(); 65 contentPanel = new JPanel(); 66 minLabel = new JLabel(); 67 minSpinner = new JSpinner(); 68 maxLabel = new JLabel(); 69 maxSpinner = new JSpinner(); 70 buttonBar = new JPanel(); 71 okButton = new JButton(); 72 cancelButton = new JButton(); 73 74 //======== this ======== 75 setTitle(tr("Level Selection")); 76 Container contentPane = getContentPane(); 77 contentPane.setLayout(new BorderLayout()); 78 79 //======== dialogPane ======== 80 { 81 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 82 dialogPane.setLayout(new BorderLayout()); 83 84 //======== contentPanel ======== 85 { 86 contentPanel.setLayout(new GridBagLayout()); 87 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; 88 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0}; 89 ((GridBagLayout) contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4}; 90 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 91 92 //---- minLabel ---- 93 minLabel.setText(tr("Lowest Level")); 94 contentPanel.add(maxLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, 95 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 96 new Insets(0, 0, 5, 5), 0, 0)); 97 JSpinner.DefaultEditor minEditor = (DefaultEditor) maxSpinner.getEditor(); 98 minEditor.getTextField().setColumns(2); 99 maxSpinner.setToolTipText(tr("The lowest level of your building.")); 100 contentPanel.add(maxSpinner, new GridBagConstraints(2, 0, 2, 1, 0.0, 0.0, 101 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 102 new Insets(0, 0, 5, 0), 0, 0)); 103 104 //---- maxLabel ---- 105 maxLabel.setText(tr("Highest Level")); 106 contentPanel.add(minLabel, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0, 107 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 108 new Insets(0, 0, 5, 5), 0, 0)); 109 JSpinner.DefaultEditor maxEditor = (DefaultEditor) minSpinner.getEditor(); 110 maxEditor.getTextField().setColumns(2); 111 minSpinner.setToolTipText(tr("The highest level of your building.")); 112 contentPanel.add(minSpinner, new GridBagConstraints(2, 2, 2, 1, 0.0, 0.0, 113 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 114 new Insets(0, 0, 5, 0), 0, 0)); 115 } 116 dialogPane.add(contentPanel, BorderLayout.CENTER); 117 118 //======== buttonBar ======== 119 { 120 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 121 buttonBar.setLayout(new GridBagLayout()); 122 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 123 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 124 125 //---- okButton ---- 126 okButton.setText(tr("OK")); 127 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 128 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 129 new Insets(0, 0, 0, 5), 0, 0)); 130 131 //---- cancelButton ---- 132 cancelButton.setText(tr("Cancel")); 133 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 134 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 135 new Insets(0, 0, 0, 0), 0, 0)); 136 } 137 dialogPane.add(contentPanel, BorderLayout.CENTER); 138 139 //======== buttonBar ======== 140 { 141 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 142 buttonBar.setLayout(new GridBagLayout()); 143 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 144 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 145 146 //---- okButton ---- 147 okButton.setText(tr("OK")); 148 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 149 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 150 new Insets(0, 0, 0, 5), 0, 0)); 151 152 //---- cancelButton ---- 153 cancelButton.setText(tr("Cancel")); 154 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 155 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 156 new Insets(0, 0, 0, 0), 0, 0)); 157 } 158 dialogPane.add(buttonBar, BorderLayout.SOUTH); 159 } 160 contentPane.add(dialogPane, BorderLayout.CENTER); 161 pack(); 162 setLocationRelativeTo(getOwner()); 163 164 } 165 166 /** 167 * Set the listener for the OK button. 168 * 169 * @param l the listener to set 170 */ 171 public void setOkButtonListener(ActionListener l) { 172 this.okButton.addActionListener(l); 173 } 174 175 /** 176 * Set the listener for the cancel button. 177 * 178 * @param l the listener to set 179 */ 180 public void setCancelButtonListener(ActionListener l) { 181 this.cancelButton.addActionListener(l); 182 } 183 184 /** 185 * Getter for the lowest level. 186 * 187 * @return Integer which represents the lowest level of the building. 188 */ 189 public int getMin() { 190 return (int) this.minSpinner.getValue(); 191 } 192 193 /** 194 * Getter for the highest level. 195 * 196 * @return Integer which represents the highest level of the building. 197 */ 198 public int getMax() { 199 return (int) this.maxSpinner.getValue(); 200 } 193 201 }
Note:
See TracChangeset
for help on using the changeset viewer.
