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

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

code style

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