source: osm/applications/editors/josm/plugins/smed/src/panels/PanelLit.java@ 33054

Last change on this file since 33054 was 33054, checked in by donvip, 9 years ago

checkstyle

File size: 16.4 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.Att;
24import seamarks.SeaMark.Ent;
25import seamarks.SeaMark.Exh;
26import seamarks.SeaMark.Lit;
27import seamarks.SeaMark.Vis;
28import smed.SmedAction;
29
30public class PanelLit extends JPanel {
31
32 private SmedAction dlg;
33 public PanelSectors panelSector;
34 public PanelCol panelCol;
35 public PanelChr panelChr;
36 public JLabel groupLabel;
37 public JTextField groupBox;
38 private FocusListener flGroup = new FocusAdapter() {
39 @Override
40 public void focusLost(FocusEvent e) {
41 SmedAction.panelMain.mark.setLightAtt(Att.GRP, 0, groupBox.getText());
42 }
43 };
44 public JLabel periodLabel;
45 public JTextField periodBox;
46 private FocusListener flPeriod = new FocusAdapter() {
47 @Override
48 public void focusLost(FocusEvent e) {
49 SmedAction.panelMain.mark.setLightAtt(Att.PER, 0, periodBox.getText());
50 }
51 };
52 public JLabel sequenceLabel;
53 public JTextField sequenceBox;
54 private FocusListener flSequence = new FocusAdapter() {
55 @Override
56 public void focusLost(FocusEvent e) {
57 SmedAction.panelMain.mark.setLightAtt(Att.SEQ, 0, sequenceBox.getText());
58 }
59 };
60 public JLabel visibilityLabel;
61 public JComboBox<String> visibilityBox;
62 public EnumMap<Vis, Integer> visibilities = new EnumMap<>(Vis.class);
63 private ActionListener alVisibility = new ActionListener() {
64 @Override
65 public void actionPerformed(ActionEvent e) {
66 for (Vis vis : visibilities.keySet()) {
67 int idx = visibilities.get(vis);
68 if (idx == visibilityBox.getSelectedIndex()) {
69 SmedAction.panelMain.mark.setLightAtt(Att.VIS, 0, vis);
70 }
71 }
72 }
73 };
74 public JLabel heightLabel;
75 public JTextField heightBox;
76 private FocusListener flHeight = new FocusAdapter() {
77 @Override
78 public void focusLost(FocusEvent e) {
79 SmedAction.panelMain.mark.setLightAtt(Att.HGT, 0, heightBox.getText());
80 }
81 };
82 public JLabel rangeLabel;
83 public JTextField rangeBox;
84 private FocusListener flRange = new FocusAdapter() {
85 @Override
86 public void focusLost(FocusEvent e) {
87 SmedAction.panelMain.mark.setLightAtt(Att.RNG, 0, rangeBox.getText());
88 }
89 };
90 public JLabel orientationLabel;
91 public JTextField orientationBox;
92 private FocusListener flOrientation = new FocusAdapter() {
93 @Override
94 public void focusLost(FocusEvent e) {
95 SmedAction.panelMain.mark.setLightAtt(Att.ORT, 0, orientationBox.getText());
96 }
97 };
98 public JLabel multipleLabel;
99 public JTextField multipleBox;
100 private FocusListener flMultiple = new FocusAdapter() {
101 @Override
102 public void focusLost(FocusEvent e) {
103 SmedAction.panelMain.mark.setLightAtt(Att.MLT, 0, multipleBox.getText());
104 }
105 };
106 public JLabel categoryLabel;
107 public JComboBox<String> categoryBox;
108 public EnumMap<Lit, Integer> categories = new EnumMap<>(Lit.class);
109 private ActionListener alCategory = new ActionListener() {
110 @Override
111 public void actionPerformed(ActionEvent e) {
112 for (Lit lit : categories.keySet()) {
113 int idx = categories.get(lit);
114 if (idx == categoryBox.getSelectedIndex()) {
115 SmedAction.panelMain.mark.setLightAtt(Att.LIT, 0, lit);
116 }
117 }
118 if (SmedAction.panelMain.mark.getLightAtt(Att.LIT, 0) == Lit.DIR) {
119 SmedAction.panelMain.mark.setLightAtt(Att.MLT, 0, "");
120 multipleBox.setText("");
121 orientationLabel.setVisible(true);
122 orientationBox.setVisible(true);
123 multipleLabel.setVisible(false);
124 multipleBox.setVisible(false);
125 } else if ((SmedAction.panelMain.mark.getLightAtt(Att.LIT, 0) == Lit.VERT)
126 || (SmedAction.panelMain.mark.getLightAtt(Att.LIT, 0) == Lit.HORIZ)) {
127 SmedAction.panelMain.mark.setLightAtt(Att.ORT, 0, "");
128 orientationBox.setText("");
129 orientationLabel.setVisible(false);
130 orientationBox.setVisible(false);
131 multipleLabel.setVisible(true);
132 multipleBox.setVisible(true);
133 } else {
134 SmedAction.panelMain.mark.setLightAtt(Att.MLT, 0, "");
135 multipleBox.setText("");
136 SmedAction.panelMain.mark.setLightAtt(Att.ORT, 0, "");
137 orientationBox.setText("");
138 orientationLabel.setVisible(false);
139 orientationBox.setVisible(false);
140 multipleLabel.setVisible(false);
141 multipleBox.setVisible(false);
142 }
143 }
144 };
145 public JLabel exhibitionLabel;
146 public JComboBox<String> exhibitionBox;
147 public EnumMap<Exh, Integer> exhibitions = new EnumMap<>(Exh.class);
148 private ActionListener alExhibition = new ActionListener() {
149 @Override
150 public void actionPerformed(ActionEvent e) {
151 for (Exh exh : exhibitions.keySet()) {
152 int idx = exhibitions.get(exh);
153 if (idx == exhibitionBox.getSelectedIndex()) {
154 SmedAction.panelMain.mark.setLightAtt(Att.EXH, 0, exh);
155 }
156 }
157 }
158 };
159 private ButtonGroup typeButtons;
160 public JRadioButton singleButton;
161 public JRadioButton sectorButton;
162 private ActionListener alType = new ActionListener() {
163 @Override
164 public void actionPerformed(ActionEvent e) {
165 singleButton.setBorderPainted(singleButton.isSelected());
166 sectorButton.setBorderPainted(sectorButton.isSelected());
167 if (sectorButton.isSelected()) {
168 panelSector.setVisible(true);
169 } else {
170 panelSector.setVisible(false);
171 while (SmedAction.panelMain.mark.getSectorCount() > 1) {
172 SmedAction.panelMain.mark.delLight(1);
173 }
174 }
175 }
176 };
177
178 public PanelLit(SmedAction dia) {
179 dlg = dia;
180 setLayout(null);
181 panelCol = new PanelCol(dlg, Ent.LIGHT);
182 panelCol.setBounds(new Rectangle(0, 0, 34, 160));
183 panelChr = new PanelChr(dlg);
184 panelChr.setBounds(new Rectangle(34, 0, 88, 160));
185 add(panelChr);
186 add(panelCol);
187 panelSector = new PanelSectors(dlg);
188 panelSector.setVisible(false);
189
190 typeButtons = new ButtonGroup();
191 singleButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SingleButton.png")));
192 add(getTypeButton(singleButton, 280, 125, 34, 30, "Single"));
193 sectorButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SectorButton.png")));
194 add(getTypeButton(sectorButton, 315, 125, 34, 30, "Sectored"));
195
196 groupLabel = new JLabel(Messages.getString("Group"), SwingConstants.CENTER);
197 groupLabel.setBounds(new Rectangle(123, 0, 65, 20));
198 add(groupLabel);
199 groupBox = new JTextField();
200 groupBox.setBounds(new Rectangle(135, 20, 40, 20));
201 groupBox.setHorizontalAlignment(SwingConstants.CENTER);
202 add(groupBox);
203 groupBox.addFocusListener(flGroup);
204
205 periodLabel = new JLabel(Messages.getString("Period"), SwingConstants.CENTER);
206 periodLabel.setBounds(new Rectangle(123, 40, 65, 20));
207 add(periodLabel);
208 periodBox = new JTextField();
209 periodBox.setBounds(new Rectangle(135, 60, 40, 20));
210 periodBox.setHorizontalAlignment(SwingConstants.CENTER);
211 add(periodBox);
212 periodBox.addFocusListener(flPeriod);
213
214 heightLabel = new JLabel(Messages.getString("Height"), SwingConstants.CENTER);
215 heightLabel.setBounds(new Rectangle(123, 80, 65, 20));
216 add(heightLabel);
217 heightBox = new JTextField();
218 heightBox.setBounds(new Rectangle(135, 100, 40, 20));
219 heightBox.setHorizontalAlignment(SwingConstants.CENTER);
220 add(heightBox);
221 heightBox.addFocusListener(flHeight);
222
223 rangeLabel = new JLabel(Messages.getString("Range"), SwingConstants.CENTER);
224 rangeLabel.setBounds(new Rectangle(123, 120, 65, 20));
225 add(rangeLabel);
226 rangeBox = new JTextField();
227 rangeBox.setBounds(new Rectangle(135, 140, 40, 20));
228 rangeBox.setHorizontalAlignment(SwingConstants.CENTER);
229 add(rangeBox);
230 rangeBox.addFocusListener(flRange);
231
232 sequenceLabel = new JLabel(Messages.getString("Sequence"), SwingConstants.CENTER);
233 sequenceLabel.setBounds(new Rectangle(188, 120, 80, 20));
234 add(sequenceLabel);
235 sequenceBox = new JTextField();
236 sequenceBox.setBounds(new Rectangle(183, 140, 90, 20));
237 sequenceBox.setHorizontalAlignment(SwingConstants.CENTER);
238 add(sequenceBox);
239 sequenceBox.addFocusListener(flSequence);
240
241 categoryLabel = new JLabel(Messages.getString("Category"), SwingConstants.CENTER);
242 categoryLabel.setBounds(new Rectangle(185, 0, 165, 20));
243 add(categoryLabel);
244 categoryBox = new JComboBox<>();
245 categoryBox.setBounds(new Rectangle(185, 20, 165, 20));
246 add(categoryBox);
247 addCatItem("", Lit.UNKLIT);
248 addCatItem(Messages.getString("VertDisp"), Lit.VERT);
249 addCatItem(Messages.getString("HorizDisp"), Lit.HORIZ);
250 addCatItem(Messages.getString("Directional"), Lit.DIR);
251 addCatItem(Messages.getString("Upper"), Lit.UPPER);
252 addCatItem(Messages.getString("Lower"), Lit.LOWER);
253 addCatItem(Messages.getString("Rear"), Lit.REAR);
254 addCatItem(Messages.getString("Front"), Lit.FRONT);
255 addCatItem(Messages.getString("Aero"), Lit.AERO);
256 addCatItem(Messages.getString("AirObstruction"), Lit.AIROBS);
257 addCatItem(Messages.getString("FogDetector"), Lit.FOGDET);
258 addCatItem(Messages.getString("Floodlight"), Lit.FLOOD);
259 addCatItem(Messages.getString("Striplight"), Lit.STRIP);
260 addCatItem(Messages.getString("Subsidiary"), Lit.SUBS);
261 addCatItem(Messages.getString("Spotlight"), Lit.SPOT);
262 addCatItem(Messages.getString("MoireEffect"), Lit.MOIRE);
263 addCatItem(Messages.getString("Emergency"), Lit.EMERG);
264 addCatItem(Messages.getString("Bearing"), Lit.BEAR);
265 categoryBox.addActionListener(alCategory);
266
267 visibilityLabel = new JLabel(Messages.getString("Visibility"), SwingConstants.CENTER);
268 visibilityLabel.setBounds(new Rectangle(185, 40, 165, 20));
269 add(visibilityLabel);
270 visibilityBox = new JComboBox<>();
271 visibilityBox.setBounds(new Rectangle(185, 60, 165, 20));
272 add(visibilityBox);
273 addVisibItem("", Vis.UNKVIS);
274 addVisibItem(Messages.getString("Intensified"), Vis.INTEN);
275 addVisibItem(Messages.getString("Unintensified"), Vis.UNINTEN);
276 addVisibItem(Messages.getString("PartiallyObscured"), Vis.PARTOBS);
277 visibilityBox.addActionListener(alVisibility);
278
279 exhibitionLabel = new JLabel(Messages.getString("Exhibition"), SwingConstants.CENTER);
280 exhibitionLabel.setBounds(new Rectangle(280, 80, 70, 20));
281 add(exhibitionLabel);
282 exhibitionBox = new JComboBox<>();
283 exhibitionBox.setBounds(new Rectangle(280, 100, 70, 20));
284 add(exhibitionBox);
285 addExhibItem("", Exh.UNKEXH);
286 addExhibItem(Messages.getString("24h"), Exh.H24);
287 addExhibItem(Messages.getString("Day"), Exh.DAY);
288 addExhibItem(Messages.getString("Night"), Exh.NIGHT);
289 addExhibItem(Messages.getString("Fog"), Exh.FOG);
290 exhibitionBox.addActionListener(alExhibition);
291
292 orientationLabel = new JLabel(Messages.getString("Orientation"), SwingConstants.CENTER);
293 orientationLabel.setBounds(new Rectangle(188, 80, 80, 20));
294 orientationLabel.setVisible(false);
295 add(orientationLabel);
296 orientationBox = new JTextField();
297 orientationBox.setBounds(new Rectangle(208, 100, 40, 20));
298 orientationBox.setHorizontalAlignment(SwingConstants.CENTER);
299 orientationBox.setVisible(false);
300 add(orientationBox);
301 orientationBox.addFocusListener(flOrientation);
302
303 multipleLabel = new JLabel(Messages.getString("Multiplicity"), SwingConstants.CENTER);
304 multipleLabel.setBounds(new Rectangle(188, 80, 80, 20));
305 multipleLabel.setVisible(false);
306 add(multipleLabel);
307 multipleBox = new JTextField();
308 multipleBox.setBounds(new Rectangle(208, 100, 40, 20));
309 multipleBox.setHorizontalAlignment(SwingConstants.CENTER);
310 multipleBox.setVisible(false);
311 add(multipleBox);
312 multipleBox.addFocusListener(flMultiple);
313 }
314
315 public void syncPanel() {
316 orientationLabel.setVisible(false);
317 orientationBox.setVisible(false);
318 multipleLabel.setVisible(false);
319 multipleBox.setVisible(false);
320 groupBox.setText((String) SmedAction.panelMain.mark.getLightAtt(Att.GRP, 0));
321 periodBox.setText((String) SmedAction.panelMain.mark.getLightAtt(Att.PER, 0));
322 sequenceBox.setText((String) SmedAction.panelMain.mark.getLightAtt(Att.SEQ, 0));
323 heightBox.setText((String) SmedAction.panelMain.mark.getLightAtt(Att.HGT, 0));
324 rangeBox.setText((String) SmedAction.panelMain.mark.getLightAtt(Att.RNG, 0));
325 orientationBox.setText((String) SmedAction.panelMain.mark.getLightAtt(Att.ORT, 0));
326 orientationBox.setVisible(SmedAction.panelMain.mark.getLightAtt(Att.LIT, 0) == Lit.DIR);
327 multipleBox.setText((String) SmedAction.panelMain.mark.getLightAtt(Att.MLT, 0));
328 multipleBox.setVisible((SmedAction.panelMain.mark.getLightAtt(Att.LIT, 0) == Lit.VERT)
329 || (SmedAction.panelMain.mark.getLightAtt(Att.LIT, 0) == Lit.HORIZ));
330 for (Vis vis : visibilities.keySet()) {
331 int item = visibilities.get(vis);
332 if (SmedAction.panelMain.mark.getLightAtt(Att.VIS, 0) == vis) {
333 visibilityBox.setSelectedIndex(item);
334 }
335 }
336 for (Lit lit : categories.keySet()) {
337 int item = categories.get(lit);
338 if (SmedAction.panelMain.mark.getLightAtt(Att.LIT, 0) == lit) {
339 categoryBox.setSelectedIndex(item);
340 }
341 }
342 for (Exh exh : exhibitions.keySet()) {
343 int item = exhibitions.get(exh);
344 if (SmedAction.panelMain.mark.getLightAtt(Att.EXH, 0) == exh) {
345 exhibitionBox.setSelectedIndex(item);
346 }
347 }
348 if (SmedAction.panelMain.mark.isSectored()) {
349 singleButton.setBorderPainted(false);
350 sectorButton.setBorderPainted(true);
351 if (isVisible()) {
352 panelSector.setVisible(true);
353 }
354 } else {
355 singleButton.setBorderPainted(true);
356 sectorButton.setBorderPainted(false);
357 panelSector.setVisible(false);
358 while (SmedAction.panelMain.mark.getSectorCount() > 1) {
359 SmedAction.panelMain.mark.delLight(SmedAction.panelMain.mark.getSectorCount() - 1);
360 }
361 }
362 panelCol.syncPanel();
363 panelChr.syncPanel();
364 panelSector.syncPanel();
365 }
366
367 private void addCatItem(String str, Lit lit) {
368 categories.put(lit, categoryBox.getItemCount());
369 categoryBox.addItem(str);
370 }
371
372 private void addVisibItem(String str, Vis vis) {
373 visibilities.put(vis, visibilityBox.getItemCount());
374 visibilityBox.addItem(str);
375 }
376
377 private void addExhibItem(String str, Exh exh) {
378 exhibitions.put(exh, exhibitionBox.getItemCount());
379 exhibitionBox.addItem(str);
380 }
381
382 private JRadioButton getTypeButton(JRadioButton button, int x, int y, int w, int h, String tip) {
383 button.setBounds(new Rectangle(x, y, w, h));
384 button.setBorder(BorderFactory.createLoweredBevelBorder());
385 button.setToolTipText(Messages.getString(tip));
386 button.addActionListener(alType);
387 typeButtons.add(button);
388 return button;
389 }
390
391}
Note: See TracBrowser for help on using the repository browser.