source: osm/applications/editors/josm/plugins/smed/src/panels/PanelMore.java@ 32767

Last change on this file since 32767 was 32767, checked in by donvip, 8 years ago

code style

File size: 16.5 KB
Line 
1package panels;
2
3import java.awt.Rectangle;
4import java.awt.event.ActionEvent;
5import java.awt.event.ActionListener;
6import java.awt.event.FocusAdapter;
7import java.awt.event.FocusEvent;
8import java.awt.event.FocusListener;
9import java.util.EnumMap;
10
11import javax.swing.BorderFactory;
12import javax.swing.ButtonGroup;
13import javax.swing.ImageIcon;
14import javax.swing.JComboBox;
15import javax.swing.JLabel;
16import javax.swing.JPanel;
17import javax.swing.JRadioButton;
18import javax.swing.JTextField;
19import javax.swing.SwingConstants;
20
21import messages.Messages;
22import seamarks.SeaMark.Cns;
23import seamarks.SeaMark.Col;
24import seamarks.SeaMark.Con;
25import seamarks.SeaMark.Ent;
26import seamarks.SeaMark.Pat;
27import seamarks.SeaMark.Reg;
28import seamarks.SeaMark.Sts;
29import smed.SmedAction;
30
31public class PanelMore extends JPanel {
32
33 private SmedAction dlg;
34 public JLabel infoLabel;
35 public JTextField infoBox;
36 private FocusListener flInfo = new FocusAdapter() {
37 @Override
38 public void focusLost(FocusEvent e) {
39 SmedAction.panelMain.mark.setInfo(infoBox.getText());
40 }
41 };
42 public JLabel sourceLabel;
43 public JTextField sourceBox;
44 private FocusListener flSource = new FocusAdapter() {
45 @Override
46 public void focusLost(FocusEvent e) {
47 SmedAction.panelMain.mark.setSource(sourceBox.getText());
48 }
49 };
50 public JLabel elevLabel;
51 public JTextField elevBox;
52 private FocusListener flElev = new FocusAdapter() {
53 @Override
54 public void focusLost(FocusEvent e) {
55 SmedAction.panelMain.mark.setElevation(elevBox.getText());
56 }
57 };
58 public JLabel heightLabel;
59 public JTextField heightBox;
60 private FocusListener flHeight = new FocusAdapter() {
61 @Override
62 public void focusLost(FocusEvent e) {
63 SmedAction.panelMain.mark.setObjectHeight(heightBox.getText());
64 }
65 };
66 public JLabel statusLabel;
67 public JComboBox<String> statusBox;
68 public EnumMap<Sts, Integer> statuses = new EnumMap<>(Sts.class);
69 private ActionListener alStatus = new ActionListener() {
70 @Override
71 public void actionPerformed(ActionEvent e) {
72 for (Sts sts : statuses.keySet()) {
73 int idx = statuses.get(sts);
74 if (SmedAction.panelMain.mark != null && (idx == statusBox.getSelectedIndex())) {
75 SmedAction.panelMain.mark.setStatus(sts);
76 }
77 }
78 }
79 };
80 public JLabel constrLabel;
81 public JComboBox<String> constrBox;
82 public EnumMap<Cns, Integer> constructions = new EnumMap<>(Cns.class);
83 private ActionListener alConstr = new ActionListener() {
84 @Override
85 public void actionPerformed(ActionEvent e) {
86 for (Cns cns : constructions.keySet()) {
87 int idx = constructions.get(cns);
88 if (SmedAction.panelMain.mark != null && (idx == constrBox.getSelectedIndex())) {
89 SmedAction.panelMain.mark.setConstr(cns);
90 }
91 }
92 }
93 };
94 public JLabel conLabel;
95 public JComboBox<String> conBox;
96 public EnumMap<Con, Integer> conspicuities = new EnumMap<>(Con.class);
97 private ActionListener alCon = new ActionListener() {
98 @Override
99 public void actionPerformed(ActionEvent e) {
100 for (Con con : conspicuities.keySet()) {
101 int idx = conspicuities.get(con);
102 if (SmedAction.panelMain.mark != null && (idx == conBox.getSelectedIndex())) {
103 SmedAction.panelMain.mark.setConsp(con);
104 }
105 }
106 }
107 };
108 public JLabel reflLabel;
109 public JComboBox<String> reflBox;
110 public EnumMap<Con, Integer> reflectivities = new EnumMap<>(Con.class);
111 private ActionListener alRefl = new ActionListener() {
112 @Override
113 public void actionPerformed(ActionEvent e) {
114 for (Con con : reflectivities.keySet()) {
115 int idx = reflectivities.get(con);
116 if (SmedAction.panelMain.mark != null && (idx == reflBox.getSelectedIndex())) {
117 SmedAction.panelMain.mark.setRefl(con);
118 }
119 }
120 }
121 };
122 public PanelPat panelPat;
123 private ButtonGroup regionButtons = new ButtonGroup();
124 public JRadioButton regionAButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RegionAButton.png")));
125 public JRadioButton regionBButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RegionBButton.png")));
126 public JRadioButton regionCButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RegionCButton.png")));
127 private ActionListener alRegion = new ActionListener() {
128 @Override
129 public void actionPerformed(ActionEvent e) {
130 if (regionAButton.isSelected()) {
131 SmedAction.panelMain.mark.setRegion(Reg.A);
132 switch (dlg.panelMain.mark.getCategory()) {
133 case LAM_PORT:
134 dlg.panelMain.mark.setObjColour(Col.RED);
135 dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
136 break;
137 case LAM_PPORT:
138 dlg.panelMain.mark.setObjColour(Col.RED);
139 dlg.panelMain.mark.addObjColour(Col.GREEN);
140 dlg.panelMain.mark.addObjColour(Col.RED);
141 dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
142 break;
143 case LAM_STBD:
144 dlg.panelMain.mark.setObjColour(Col.GREEN);
145 dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
146 break;
147 case LAM_PSTBD:
148 dlg.panelMain.mark.setObjColour(Col.GREEN);
149 dlg.panelMain.mark.addObjColour(Col.RED);
150 dlg.panelMain.mark.addObjColour(Col.GREEN);
151 dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
152 break;
153 }
154 regionAButton.setBorderPainted(true);
155 } else {
156 regionAButton.setBorderPainted(false);
157 }
158 if (regionBButton.isSelected()) {
159 dlg.panelMain.mark.setRegion(Reg.B);
160 switch (dlg.panelMain.mark.getCategory()) {
161 case LAM_PORT:
162 dlg.panelMain.mark.setObjColour(Col.GREEN);
163 dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
164 break;
165 case LAM_PPORT:
166 dlg.panelMain.mark.setObjColour(Col.GREEN);
167 dlg.panelMain.mark.addObjColour(Col.RED);
168 dlg.panelMain.mark.addObjColour(Col.GREEN);
169 dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
170 break;
171 case LAM_STBD:
172 dlg.panelMain.mark.setObjColour(Col.RED);
173 dlg.panelMain.mark.setObjPattern(Pat.NOPAT);
174 break;
175 case LAM_PSTBD:
176 dlg.panelMain.mark.setObjColour(Col.RED);
177 dlg.panelMain.mark.addObjColour(Col.GREEN);
178 dlg.panelMain.mark.addObjColour(Col.RED);
179 dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
180 break;
181 }
182 regionBButton.setBorderPainted(true);
183 } else {
184 regionBButton.setBorderPainted(false);
185 }
186 if (regionCButton.isSelected()) {
187 dlg.panelMain.mark.setRegion(Reg.C);
188 dlg.panelMain.mark.setObjPattern(Pat.HSTRP);
189 switch (dlg.panelMain.mark.getCategory()) {
190 case LAM_PORT:
191 dlg.panelMain.mark.setObjColour(Col.RED);
192 dlg.panelMain.mark.addObjColour(Col.WHITE);
193 dlg.panelMain.mark.addObjColour(Col.RED);
194 dlg.panelMain.mark.addObjColour(Col.WHITE);
195 break;
196 case LAM_PPORT:
197 case LAM_PSTBD:
198 dlg.panelMain.mark.setObjColour(Col.RED);
199 dlg.panelMain.mark.addObjColour(Col.GREEN);
200 dlg.panelMain.mark.addObjColour(Col.RED);
201 dlg.panelMain.mark.addObjColour(Col.GREEN);
202 break;
203 case LAM_STBD:
204 dlg.panelMain.mark.setObjColour(Col.GREEN);
205 dlg.panelMain.mark.addObjColour(Col.WHITE);
206 dlg.panelMain.mark.addObjColour(Col.GREEN);
207 dlg.panelMain.mark.addObjColour(Col.WHITE);
208 break;
209 }
210 regionCButton.setBorderPainted(true);
211 } else {
212 regionCButton.setBorderPainted(false);
213 }
214 panelPat.syncPanel();
215 }
216 };
217
218 public PanelMore(SmedAction dia) {
219 dlg = dia;
220 setLayout(null);
221 panelPat = new PanelPat(dlg, Ent.BODY);
222 panelPat.setBounds(new Rectangle(0, 0, 110, 160));
223 add(panelPat);
224 add(getRegionButton(regionAButton, 110, 0, 34, 30, "RegionA"));
225 add(getRegionButton(regionBButton, 110, 32, 34, 30, "RegionB"));
226 add(getRegionButton(regionCButton, 110, 64, 34, 30, "RegionC"));
227
228 elevLabel = new JLabel(Messages.getString("Elevation"), SwingConstants.CENTER);
229 elevLabel.setBounds(new Rectangle(140, 0, 90, 20));
230 add(elevLabel);
231 elevBox = new JTextField();
232 elevBox.setBounds(new Rectangle(160, 20, 50, 20));
233 elevBox.setHorizontalAlignment(SwingConstants.CENTER);
234 add(elevBox);
235 elevBox.addFocusListener(flElev);
236
237 heightLabel = new JLabel(Messages.getString("Height"), SwingConstants.CENTER);
238 heightLabel.setBounds(new Rectangle(140, 40, 90, 20));
239 add(heightLabel);
240 heightBox = new JTextField();
241 heightBox.setBounds(new Rectangle(160, 60, 50, 20));
242 heightBox.setHorizontalAlignment(SwingConstants.CENTER);
243 add(heightBox);
244 heightBox.addFocusListener(flHeight);
245
246 sourceLabel = new JLabel(Messages.getString("Source"), SwingConstants.CENTER);
247 sourceLabel.setBounds(new Rectangle(110, 80, 130, 20));
248 add(sourceLabel);
249 sourceBox = new JTextField();
250 sourceBox.setBounds(new Rectangle(110, 100, 130, 20));
251 sourceBox.setHorizontalAlignment(SwingConstants.CENTER);
252 add(sourceBox);
253 sourceBox.addFocusListener(flSource);
254
255 infoLabel = new JLabel(Messages.getString("Information"), SwingConstants.CENTER);
256 infoLabel.setBounds(new Rectangle(110, 120, 130, 20));
257 add(infoLabel);
258 infoBox = new JTextField();
259 infoBox.setBounds(new Rectangle(110, 140, 130, 20));
260 infoBox.setHorizontalAlignment(SwingConstants.CENTER);
261 add(infoBox);
262 infoBox.addFocusListener(flInfo);
263
264 statusLabel = new JLabel(Messages.getString("Status"), SwingConstants.CENTER);
265 statusLabel.setBounds(new Rectangle(250, 0, 100, 20));
266 add(statusLabel);
267 statusBox = new JComboBox<>();
268 statusBox.setBounds(new Rectangle(250, 20, 100, 20));
269 addStsItem("", Sts.UNKSTS);
270 addStsItem(Messages.getString("Permanent"), Sts.PERM);
271 addStsItem(Messages.getString("Occasional"), Sts.OCC);
272 addStsItem(Messages.getString("Recommended"), Sts.REC);
273 addStsItem(Messages.getString("NotInUse"), Sts.NIU);
274 addStsItem(Messages.getString("Intermittent"), Sts.INT);
275 addStsItem(Messages.getString("Reserved"), Sts.RESV);
276 addStsItem(Messages.getString("Temporary"), Sts.TEMP);
277 addStsItem(Messages.getString("Private"), Sts.PRIV);
278 addStsItem(Messages.getString("Mandatory"), Sts.MAND);
279 addStsItem(Messages.getString("Destroyed"), Sts.DEST);
280 addStsItem(Messages.getString("Extinguished"), Sts.EXT);
281 addStsItem(Messages.getString("Illuminated"), Sts.ILLUM);
282 addStsItem(Messages.getString("Historic"), Sts.HIST);
283 addStsItem(Messages.getString("Public"), Sts.PUB);
284 addStsItem(Messages.getString("Synchronized"), Sts.SYNC);
285 addStsItem(Messages.getString("Watched"), Sts.WATCH);
286 addStsItem(Messages.getString("UnWatched"), Sts.UNWAT);
287 addStsItem(Messages.getString("Doubtful"), Sts.DOUBT);
288 add(statusBox);
289 statusBox.addActionListener(alStatus);
290
291 constrLabel = new JLabel(Messages.getString("Construction"), SwingConstants.CENTER);
292 constrLabel.setBounds(new Rectangle(250, 40, 100, 20));
293 add(constrLabel);
294 constrBox = new JComboBox<>();
295 constrBox.setBounds(new Rectangle(250, 60, 100, 20));
296 addCnsItem("", Cns.UNKCNS);
297 addCnsItem(Messages.getString("Masonry"), Cns.BRICK);
298 addCnsItem(Messages.getString("Concreted"), Cns.CONC);
299 addCnsItem(Messages.getString("Boulders"), Cns.BOULD);
300 addCnsItem(Messages.getString("HardSurfaced"), Cns.HSURF);
301 addCnsItem(Messages.getString("Unsurfaced"), Cns.USURF);
302 addCnsItem(Messages.getString("Wooden"), Cns.WOOD);
303 addCnsItem(Messages.getString("Metal"), Cns.METAL);
304 addCnsItem(Messages.getString("GRP"), Cns.GLAS);
305 addCnsItem(Messages.getString("Painted"), Cns.PAINT);
306 add(constrBox);
307 constrBox.addActionListener(alConstr);
308
309 conLabel = new JLabel(Messages.getString("Conspicuity"), SwingConstants.CENTER);
310 conLabel.setBounds(new Rectangle(250, 80, 100, 20));
311 add(conLabel);
312 conBox = new JComboBox<>();
313 conBox.setBounds(new Rectangle(250, 100, 100, 20));
314 addConItem("", Con.UNKCON);
315 addConItem(Messages.getString("Conspicuous"), Con.CONSP);
316 addConItem(Messages.getString("NotConspicuous"), Con.NCONS);
317 add(conBox);
318 conBox.addActionListener(alCon);
319
320 reflLabel = new JLabel(Messages.getString("Reflectivity"), SwingConstants.CENTER);
321 reflLabel.setBounds(new Rectangle(250, 120, 100, 20));
322 add(reflLabel);
323 reflBox = new JComboBox<>();
324 reflBox.setBounds(new Rectangle(250, 140, 100, 20));
325 addReflItem("", Con.UNKCON);
326 addReflItem(Messages.getString("Conspicuous"), Con.CONSP);
327 addReflItem(Messages.getString("NotConspicuous"), Con.NCONS);
328 addReflItem(Messages.getString("Reflector"), Con.REFL);
329 add(reflBox);
330 reflBox.addActionListener(alRefl);
331
332 }
333
334 public void syncPanel() {
335 panelPat.syncPanel();
336 regionAButton.setBorderPainted(dlg.panelMain.mark.getRegion() == Reg.A);
337 regionBButton.setBorderPainted(dlg.panelMain.mark.getRegion() == Reg.B);
338 regionCButton.setBorderPainted(dlg.panelMain.mark.getRegion() == Reg.C);
339 elevBox.setText(dlg.panelMain.mark.getElevation());
340 heightBox.setText(dlg.panelMain.mark.getObjectHeight());
341 sourceBox.setText(dlg.panelMain.mark.getSource());
342 infoBox.setText(dlg.panelMain.mark.getInfo());
343 for (Sts sts : statuses.keySet()) {
344 int item = statuses.get(sts);
345 if (dlg.panelMain.mark.getStatus() == sts) {
346 statusBox.setSelectedIndex(item);
347 }
348 }
349 for (Cns cns : constructions.keySet()) {
350 int item = constructions.get(cns);
351 if (dlg.panelMain.mark.getConstr() == cns) {
352 constrBox.setSelectedIndex(item);
353 }
354 }
355 for (Con con : conspicuities.keySet()) {
356 int item = conspicuities.get(con);
357 if (dlg.panelMain.mark.getConsp() == con) {
358 conBox.setSelectedIndex(item);
359 }
360 }
361 for (Con con : reflectivities.keySet()) {
362 int item = reflectivities.get(con);
363 if (dlg.panelMain.mark.getRefl() == con) {
364 reflBox.setSelectedIndex(item);
365 }
366 }
367 }
368
369 private void addStsItem(String str, Sts sts) {
370 statuses.put(sts, statusBox.getItemCount());
371 statusBox.addItem(str);
372 }
373
374 private void addCnsItem(String str, Cns cns) {
375 constructions.put(cns, constrBox.getItemCount());
376 constrBox.addItem(str);
377 }
378
379 private void addConItem(String str, Con con) {
380 conspicuities.put(con, conBox.getItemCount());
381 conBox.addItem(str);
382 }
383
384 private void addReflItem(String str, Con con) {
385 reflectivities.put(con, reflBox.getItemCount());
386 reflBox.addItem(str);
387 }
388
389 private JRadioButton getRegionButton(JRadioButton button, int x, int y, int w, int h, String tip) {
390 button.setBounds(new Rectangle(x, y, w, h));
391 button.setBorder(BorderFactory.createLoweredBevelBorder());
392 button.setToolTipText(Messages.getString(tip));
393 button.addActionListener(alRegion);
394 regionButtons.add(button);
395 return button;
396 }
397}
Note: See TracBrowser for help on using the repository browser.