Changeset 33974 in osm for applications/editors/josm/plugins/indoorhelper/src/views/LevelSelectorView.java
- Timestamp:
- 2018-01-04T11:05:03+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoorhelper/src/views/LevelSelectorView.java
r32637 r33974 1 /*2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps.3 * Copyright (C) 2016 Erik Gruschka4 *5 * This program is free software: you can redistribute it and/or modify6 * it under the terms of the GNU General Public License as published by7 * the Free Software Foundation, either version 3 of the License, or8 * (at your option) any later version.9 *10 * This program is distributed in the hope that it will be useful,11 * but WITHOUT ANY WARRANTY; without even the implied warranty of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU General Public License for more details.14 *15 * You should have received a copy of the GNU General Public License16 * along with this program. If not, see <http://www.gnu.org/licenses/>.17 */18 19 1 package views; 20 2 … … 22 4 23 5 import java.awt.BorderLayout; 24 import java.awt.Container;25 6 import java.awt.GridBagConstraints; 26 7 import java.awt.GridBagLayout; 27 8 import java.awt.Insets; 28 9 import java.awt.event.ActionListener; 10 import java.awt.event.FocusEvent; 11 import java.awt.event.FocusListener; 12 import java.awt.event.WindowListener; 29 13 30 14 import javax.swing.JButton; … … 32 16 import javax.swing.JLabel; 33 17 import javax.swing.JPanel; 34 import javax.swing.JSpinner;35 import javax.swing.JSpinner.DefaultEditor;36 18 import javax.swing.border.EmptyBorder; 37 19 20 import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField; 21 38 22 /** 39 * Class for the pop-up window which provides an level selector to get a user input. 40 * In this window the user declares the lowest and the highest level of the building he wants to map. 23 * This is the level selector toolbox of the indoorhelper plug-in. 41 24 * 42 * @author egru25 * @author rebsc 43 26 * 44 27 */ 45 46 @SuppressWarnings("serial")47 28 public class LevelSelectorView extends JFrame { 48 29 49 private JPanel dialogPane; 30 private static final long serialVersionUID = 1L; 31 private JPanel dialogPane; 50 32 private JPanel contentPanel; 51 private JLabel minLabel; 52 private JSpinner minSpinner; 53 private JLabel maxLabel; 54 private JSpinner maxSpinner; 33 private JPanel infoBar; 55 34 private JPanel buttonBar; 56 35 private JButton okButton; 57 36 private JButton cancelButton; 37 private JLabel label1; 38 private JLabel label2; 39 private DisableShortcutsOnFocusGainedTextField field; 58 40 59 41 public LevelSelectorView() { … … 64 46 dialogPane = new JPanel(); 65 47 contentPanel = new JPanel(); 66 minLabel = new JLabel(); 67 minSpinner = new JSpinner(); 68 maxLabel = new JLabel(); 69 maxSpinner = new JSpinner(); 48 infoBar = new JPanel(); 70 49 buttonBar = new JPanel(); 71 50 okButton = new JButton(); 72 51 cancelButton = new JButton(); 52 label1 = new JLabel(); 53 label2 = new JLabel(); 54 field = new DisableShortcutsOnFocusGainedTextField(); 73 55 74 56 //======== this ======== 75 setTitle(tr(" Level Selection"));76 Container contentPane = getContentPane(); 57 setTitle(tr("Add a new level")); 58 java.awt.Container contentPane = getContentPane(); 77 59 contentPane.setLayout(new BorderLayout()); 78 60 … … 82 64 dialogPane.setLayout(new BorderLayout()); 83 65 66 67 //======== infoBar ======== 68 { 69 70 //---- Label1 ---- 71 label1.setText(tr("<html> Please insert the new level number you want to add.<br> " 72 + " <i>Info</i>: <br> If the OK button got pressed you will switch to the drawing action.<br>" 73 + "To finish the new object please press the spacebar. The new level<br>will be tagged automatically. </html>")); 74 infoBar.add(label1); 75 } 76 dialogPane.add(infoBar,BorderLayout.NORTH); 77 78 84 79 //======== contentPanel ======== 85 80 { 86 81 contentPanel.setLayout(new GridBagLayout()); 87 82 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; 88 83 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0}; … … 90 85 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 91 86 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 87 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)); 88 //---- Label2 ---- 89 label2.setText(tr("level number:")); 90 contentPanel.add(label2,new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, 91 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 92 new Insets(5, 5, 5, 30), 0, 0)); 93 94 //---- Field ---- 95 field.setToolTipText(tr("Example: '2' or '3'")); 96 field.addFocusListener(new FocusListener() { 97 98 @Override 99 public void focusLost(FocusEvent e) {} 100 101 @Override 102 public void focusGained(FocusEvent e) { 103 field.selectAll(); 104 } 105 }); 106 contentPanel.add(field, new GridBagConstraints(3, 0, 2, 1, 0.0, 0.0, 107 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 108 new Insets(5, 0, 5, 200), 0, 0)); 109 115 110 } 116 111 dialogPane.add(contentPanel, BorderLayout.CENTER); … … 126 121 okButton.setText(tr("OK")); 127 122 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)); 123 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 124 new Insets(0, 0, 0, 5), 0, 0)); 130 125 131 //---- cancelButton ----132 126 //---- Button ---- 127 cancelButton.setText(tr("Cancel")); 133 128 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)); 129 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 130 new Insets(0, 0, 0, 0), 0, 0)); 157 131 } 158 132 dialogPane.add(buttonBar, BorderLayout.SOUTH); … … 164 138 } 165 139 140 /************************************************* 141 * GETTER 142 * 143 */ 166 144 /** 145 * Getter for the level number field. 146 * 147 * @return the {@link String} 148 */ 149 public String getLevelNumber() { 150 return this.field.getText(); 151 } 152 153 /************************************************* 154 * SELECTOR VIEW LISTENER 155 * 156 */ 157 158 /** 167 159 * Set the listener for the OK button. 168 160 * … … 173 165 } 174 166 175 176 * Set the listener for the cancel button.167 /** 168 * Set the listener for the Cancel button. 177 169 * 178 170 * @param l the listener to set … … 183 175 184 176 /** 185 * Getter forthe lowest level.177 * Set the listener for window {@Link LevelSelectorView} 186 178 * 187 * @ return Integer which represents the lowest level of the building.179 * @param l the listener to set 188 180 */ 189 public int getMin() {190 return (int) this.minSpinner.getValue();181 public void setSelectorWindowListener(WindowListener l) { 182 this.addWindowListener(l); 191 183 } 192 184 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 } 185 /** 186 * 187 * 188 * 189 * 190 * 191 * 192 * 193 * 194 */ 201 195 }
Note:
See TracChangeset
for help on using the changeset viewer.