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

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

fix errors with error_prone

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