source: osm/applications/editors/josm/plugins/smed1/src/panels/PanelLit.java@ 29036

Last change on this file since 29036 was 29036, checked in by malcolmh, 12 years ago

initial

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