source: osm/applications/editors/josm/plugins/indoorhelper/src/views/DialogPanel.java@ 34179

Last change on this file since 34179 was 34005, checked in by donvip, 7 years ago

code cleanup

File size: 9.0 KB
Line 
1/*
2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps.
3 * Copyright (C) 2016 Erik Gruschka
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (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 of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package views;
20
21import static org.openstreetmap.josm.tools.I18n.tr;
22
23import java.awt.BorderLayout;
24import java.awt.GridBagConstraints;
25import java.awt.GridBagLayout;
26import java.awt.Insets;
27import java.awt.event.FocusEvent;
28import java.awt.event.FocusListener;
29
30import javax.swing.DefaultComboBoxModel;
31import javax.swing.JButton;
32import javax.swing.JLabel;
33import javax.swing.JPanel;
34import javax.swing.JSeparator;
35import javax.swing.JToggleButton;
36import javax.swing.border.EmptyBorder;
37
38import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
39import org.openstreetmap.josm.gui.widgets.JosmComboBox;
40
41import model.TagCatalog;
42import model.TagCatalog.IndoorObject;
43
44@SuppressWarnings("serial")
45public class DialogPanel extends JPanel {
46 private JPanel contentPanel;
47 private JToggleButton powerButton;
48 private JLabel levelLabel;
49 private JosmComboBox<String> levelBox;
50 private JLabel levelTagLabel;
51 private DisableShortcutsOnFocusGainedTextField levelTagField;
52 private JLabel objectLabel;
53 private JosmComboBox<TagCatalog.IndoorObject> objectBox;
54 private JLabel nameLabel;
55 private DisableShortcutsOnFocusGainedTextField nameField;
56 private JLabel refLabel;
57 private DisableShortcutsOnFocusGainedTextField refField;
58 private JPanel buttonBar;
59 private JButton applyButton;
60 private JSeparator separator1;
61 private JSeparator separator2;
62
63 /**
64 * Create the panel.
65 */
66 public DialogPanel() {
67 contentPanel = new JPanel();
68 powerButton = new JToggleButton();
69 levelLabel = new JLabel();
70 levelBox = new JosmComboBox<>();
71 levelTagLabel = new JLabel();
72 levelTagField = new DisableShortcutsOnFocusGainedTextField();
73 objectLabel = new JLabel();
74 objectBox = new JosmComboBox<>();
75 objectBox.setModel(new DefaultComboBoxModel<>(TagCatalog.IndoorObject.values()));
76 nameLabel = new JLabel();
77 nameField = new DisableShortcutsOnFocusGainedTextField();
78 refLabel = new JLabel();
79 refField = new DisableShortcutsOnFocusGainedTextField();
80 buttonBar = new JPanel();
81 applyButton = new JButton();
82 separator1 = new JSeparator();
83 separator2 = new JSeparator();
84
85 //======== this ========
86 //Container contentPane = this.get;
87 //contentPane.setLayout(new BorderLayout());
88
89 //======== dialogPane ========
90
91 this.setBorder(new EmptyBorder(12, 12, 12, 12));
92 this.setLayout(new BorderLayout());
93
94 //======== contentPanel ========
95
96 contentPanel.setLayout(new GridBagLayout());
97 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
99 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0};
100 ((GridBagLayout) contentPanel.getLayout()).columnWeights = new double[] {
101 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
102 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
103 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
104
105 //---- powerButton ----
106 powerButton.setText(tr("POWER"));
107 powerButton.setToolTipText(tr("Activates the plug-in"));
108 contentPanel.add(powerButton, new GridBagConstraints(8, 0, 4, 1, 0.0, 0.0,
109 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
110 new Insets(0, 0, 5, 5), 0, 0));
111 contentPanel.add(separator1, new GridBagConstraints(1, 1, 12, 1, 0.0, 0.0,
112 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
113 new Insets(0, 0, 5, 5), 0, 0));
114
115 //---- levelLabel ----
116 levelLabel.setText(tr("Working Level"));
117 contentPanel.add(levelLabel, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0,
118 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
119 new Insets(0, 0, 5, 5), 0, 0));
120
121 //---- levelBox ----
122 levelBox.setEnabled(false);
123 levelBox.setEditable(false);
124 levelBox.setToolTipText(tr("Selects the working level."));
125 contentPanel.add(levelBox, new GridBagConstraints(3, 2, 3, 1, 0.0, 0.0,
126 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
127 new Insets(0, 0, 5, 5), 0, 0));
128
129 //---- levelTagLabel ----
130 levelTagLabel.setText(tr("Level Name"));
131 contentPanel.add(levelTagLabel, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0,
132 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
133 new Insets(0, 0, 5, 5), 0, 0));
134
135 //---- levelTagField ----
136 levelTagField.setEnabled(false);
137 levelTagField.setColumns(6);
138 levelTagField.setToolTipText(tr("Optional name-tag for a level."));
139 contentPanel.add(levelTagField, new GridBagConstraints(8, 2, 5, 1, 0.0, 0.0,
140 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
141 new Insets(0, 0, 5, 5), 0, 0));
142 contentPanel.add(separator2, new GridBagConstraints(1, 3, 12, 1, 0.0, 0.0,
143 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
144 new Insets(0, 0, 5, 5), 0, 0));
145
146 //---- objectLabel ----
147 objectLabel.setText(tr("Object"));
148 contentPanel.add(objectLabel, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0,
149 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
150 new Insets(0, 0, 5, 5), 0, 0));
151
152 //---- objectBox ----
153 objectBox.setEnabled(false);
154 objectBox.setPrototypeDisplayValue(IndoorObject.CONCRETE_WALL);
155 objectBox.setToolTipText(tr("The object preset you want to tag."));
156 contentPanel.add(objectBox, new GridBagConstraints(3, 4, 3, 1, 0.0, 0.0,
157 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
158 new Insets(0, 0, 5, 5), 0, 0));
159
160 //---- nameLabel ----
161 nameLabel.setText(tr("Name"));
162 contentPanel.add(nameLabel, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0,
163 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
164 new Insets(0, 0, 5, 5), 0, 0));
165
166 //---- nameField ----
167 nameField.setEnabled(false);
168 nameField.addFocusListener(new FocusListener() {
169
170 @Override
171 public void focusLost(FocusEvent e) {}
172
173 @Override
174 public void focusGained(FocusEvent e) {
175 nameField.selectAll();
176 }
177 });
178 nameField.setToolTipText(tr("Sets the name tag when the room-object is selected."));
179 contentPanel.add(nameField, new GridBagConstraints(3, 5, 3, 1, 0.0, 0.0,
180 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
181 new Insets(0, 0, 5, 5), 0, 0));
182
183 //---- refLabel ----
184 refLabel.setText(tr("Reference"));
185 contentPanel.add(refLabel, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0,
186 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
187 new Insets(0, 0, 0, 5), 0, 0));
188
189 //---- refField ----
190 refField.setEnabled(false);
191 refField.addFocusListener(new FocusListener() {
192
193 @Override
194 public void focusLost(FocusEvent e) {}
195
196 @Override
197 public void focusGained(FocusEvent e) {
198 refField.selectAll();
199 }
200 });
201 refField.setToolTipText(tr("Sets the ref tag when the room-object is selected."));
202 contentPanel.add(refField, new GridBagConstraints(3, 6, 3, 1, 0.0, 0.0,
203 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
204 new Insets(0, 0, 0, 5), 0, 0));
205
206 this.add(contentPanel, BorderLayout.CENTER);
207
208 //======== buttonBar ========
209
210 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
211 buttonBar.setLayout(new GridBagLayout());
212 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 80};
213 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0};
214
215 //---- applyButton ----
216 applyButton.setText(tr("Apply Tags"));
217 applyButton.setEnabled(false);
218 buttonBar.add(applyButton, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
219 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
220 new Insets(0, 0, 0, 0), 0, 0));
221
222 this.add(buttonBar, BorderLayout.SOUTH);
223 }
224}
Note: See TracBrowser for help on using the repository browser.