source: osm/applications/editors/josm/plugins/smed/src/panels/PanelChan.java@ 31659

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

[josm_plugins] fix java 7 warnings / global usage of try-with-resource

File size: 11.0 KB
Line 
1package panels;
2
3import javax.swing.*;
4
5import java.awt.*;
6import java.awt.event.*;
7
8import messages.Messages;
9import smed.SmedAction;
10import seamarks.SeaMark;
11import seamarks.SeaMark.*;
12
13public class PanelChan extends JPanel {
14
15 private SmedAction dlg;
16 public PanelPort panelPort = null;
17 public PanelStbd panelStbd = null;
18 public PanelSaw panelSaw = null;
19 public ButtonGroup catButtons = new ButtonGroup();
20 public JRadioButton portButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PortButton.png")));
21 public JRadioButton stbdButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StbdButton.png")));
22 public JRadioButton prefStbdButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PrefStbdButton.png")));
23 public JRadioButton prefPortButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PrefPortButton.png")));
24 public JRadioButton safeWaterButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SafeWaterButton.png")));
25 private ActionListener alCat = new ActionListener() {
26 public void actionPerformed(java.awt.event.ActionEvent e) {
27 panelPort.setVisible(false);
28 panelStbd.setVisible(false);
29 panelSaw.setVisible(false);
30 SmedAction.panelMain.moreButton.setVisible(false);
31 SmedAction.panelMain.saveButton.setEnabled(false);
32 topmarkButton.setVisible(false);
33 lightButton.setVisible(false);
34 Shp shp = SmedAction.panelMain.mark.getShape();
35 if (portButton.isSelected()) {
36 SmedAction.panelMain.mark.setCategory(Cat.LAM_PORT);
37 if (panelPort.shapes.containsKey(shp)) {
38 panelPort.shapes.get(shp).setSelected(true);
39 } else {
40 panelPort.shapeButtons.clearSelection();
41 SmedAction.panelMain.mark.setShape(Shp.UNKSHP);
42 }
43 panelPort.alShape.actionPerformed(null);
44 panelPort.setVisible(true);
45 portButton.setBorderPainted(true);
46 } else {
47 portButton.setBorderPainted(false);
48 }
49 if (stbdButton.isSelected()) {
50 SmedAction.panelMain.mark.setCategory(Cat.LAM_STBD);
51 if (panelStbd.shapes.containsKey(shp)) {
52 panelStbd.shapes.get(shp).setSelected(true);
53 } else {
54 panelStbd.shapeButtons.clearSelection();
55 SmedAction.panelMain.mark.setShape(Shp.UNKSHP);
56 }
57 panelStbd.alShape.actionPerformed(null);
58 panelStbd.setVisible(true);
59 stbdButton.setBorderPainted(true);
60 } else {
61 stbdButton.setBorderPainted(false);
62 }
63 if (prefStbdButton.isSelected()) {
64 SmedAction.panelMain.mark.setCategory(Cat.LAM_PSTBD);
65 if (panelPort.shapes.containsKey(shp)) {
66 panelPort.shapes.get(shp).setSelected(true);
67 } else {
68 panelPort.shapeButtons.clearSelection();
69 SmedAction.panelMain.mark.setShape(Shp.UNKSHP);
70 }
71 panelPort.alShape.actionPerformed(null);
72 panelPort.setVisible(true);
73 prefStbdButton.setBorderPainted(true);
74 } else {
75 prefStbdButton.setBorderPainted(false);
76 }
77 if (prefPortButton.isSelected()) {
78 SmedAction.panelMain.mark.setCategory(Cat.LAM_PPORT);
79 if (panelStbd.shapes.containsKey(shp)) {
80 panelStbd.shapes.get(shp).setSelected(true);
81 } else {
82 panelStbd.shapeButtons.clearSelection();
83 SmedAction.panelMain.mark.setShape(Shp.UNKSHP);
84 }
85 panelStbd.alShape.actionPerformed(null);
86 panelStbd.setVisible(true);
87 prefPortButton.setBorderPainted(true);
88 } else {
89 prefPortButton.setBorderPainted(false);
90 }
91 if (safeWaterButton.isSelected()) {
92 SmedAction.panelMain.mark.setCategory(Cat.NOCAT);
93 panelSaw.setVisible(true);
94 if (panelSaw.shapes.containsKey(shp)) {
95 panelSaw.shapes.get(shp).setSelected(true);
96 } else {
97 panelSaw.shapeButtons.clearSelection();
98 SmedAction.panelMain.mark.setShape(Shp.UNKSHP);
99 }
100 panelSaw.alShape.actionPerformed(null);
101 panelSaw.setVisible(true);
102 safeWaterButton.setBorderPainted(true);
103 } else {
104 safeWaterButton.setBorderPainted(false);
105 }
106 topmarkButton.setVisible(SmedAction.panelMain.mark.testValid());
107 lightButton.setVisible(SmedAction.panelMain.mark.testValid());
108 SmedAction.panelMain.panelMore.syncPanel();
109 }
110 };
111 public JToggleButton topmarkButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/ChanTopButton.png")));
112 private ActionListener alTop = new ActionListener() {
113 public void actionPerformed(java.awt.event.ActionEvent e) {
114 if (topmarkButton.isSelected()) {
115 if (SeaMark.GrpMAP.get(SmedAction.panelMain.mark.getObject()) == Grp.SAW) {
116 SmedAction.panelMain.mark.setTopmark(Top.SPHERE);
117 SmedAction.panelMain.mark.setTopPattern(Pat.NOPAT);
118 SmedAction.panelMain.mark.setTopColour(Col.RED);
119 } else {
120 switch (dlg.panelMain.mark.getCategory()) {
121 case LAM_PORT:
122 case LAM_PSTBD:
123 dlg.panelMain.mark.setTopmark(Top.CYL);
124 switch (dlg.panelMain.mark.getRegion()) {
125 case A:
126 dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
127 dlg.panelMain.mark.setTopColour(Col.RED);
128 break;
129 case B:
130 dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
131 dlg.panelMain.mark.setTopColour(Col.GREEN);
132 break;
133 case C:
134 if (dlg.panelMain.mark.getCategory() == Cat.LAM_PORT) {
135 dlg.panelMain.mark.setTopPattern(Pat.HSTRP);
136 dlg.panelMain.mark.setTopColour(Col.RED);
137 dlg.panelMain.mark.addTopColour(Col.WHITE);
138 } else {
139 dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
140 dlg.panelMain.mark.setTopColour(Col.RED);
141 }
142 break;
143 }
144 break;
145 case LAM_STBD:
146 case LAM_PPORT:
147 dlg.panelMain.mark.setTopmark(Top.CONE);
148 switch (dlg.panelMain.mark.getRegion()) {
149 case A:
150 dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
151 dlg.panelMain.mark.setTopColour(Col.GREEN);
152 break;
153 case B:
154 dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
155 dlg.panelMain.mark.setTopColour(Col.RED);
156 break;
157 case C:
158 if (dlg.panelMain.mark.getCategory() == Cat.LAM_STBD) {
159 dlg.panelMain.mark.setTopPattern(Pat.HSTRP);
160 dlg.panelMain.mark.setTopColour(Col.GREEN);
161 dlg.panelMain.mark.addTopColour(Col.WHITE);
162 } else {
163 dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
164 dlg.panelMain.mark.setTopColour(Col.GREEN);
165 }
166 break;
167 }
168 break;
169 }
170 }
171 topmarkButton.setBorderPainted(true);
172 } else {
173 dlg.panelMain.mark.setTopmark(Top.NOTOP);
174 dlg.panelMain.mark.setTopPattern(Pat.NOPAT);
175 dlg.panelMain.mark.setTopColour(Col.UNKCOL);
176 topmarkButton.setBorderPainted(false);
177 }
178 dlg.panelMain.panelTop.syncPanel();
179 }
180 };
181 public JToggleButton lightButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/DefLitButton.png")));
182 private ActionListener alLit = new ActionListener() {
183 public void actionPerformed(java.awt.event.ActionEvent e) {
184 if (lightButton.isSelected()) {
185 if (SeaMark.GrpMAP.get(dlg.panelMain.mark.getObject()) == Grp.SAW) {
186 dlg.panelMain.mark.setLightAtt(Att.CHR, 0, "LFl");
187 dlg.panelMain.mark.setLightAtt(Att.COL, 0, Col.WHITE);
188 } else {
189 dlg.panelMain.mark.setLightAtt(Att.CHR, 0, "Fl");
190 switch (dlg.panelMain.mark.getCategory()) {
191 case LAM_PORT:
192 case LAM_PPORT:
193 switch (dlg.panelMain.mark.getRegion()) {
194 case A:
195 case C:
196 dlg.panelMain.mark.setLightAtt(Att.COL, 0, Col.RED);
197 break;
198 case B:
199 dlg.panelMain.mark.setLightAtt(Att.COL, 0, Col.GREEN);
200 break;
201 }
202 break;
203 case LAM_STBD:
204 case LAM_PSTBD:
205 switch (dlg.panelMain.mark.getRegion()) {
206 case A:
207 case C:
208 dlg.panelMain.mark.setLightAtt(Att.COL, 0, Col.GREEN);
209 break;
210 case B:
211 dlg.panelMain.mark.setLightAtt(Att.COL, 0, Col.RED);
212 break;
213 }
214 break;
215 }
216 }
217 lightButton.setBorderPainted(true);
218 } else {
219 dlg.panelMain.mark.clrLight();
220 lightButton.setBorderPainted(false);
221 }
222 dlg.panelMain.panelLit.syncPanel();
223 }
224 };
225
226 public PanelChan(SmedAction dia) {
227 dlg = dia;
228 setLayout(null);
229 panelPort = new PanelPort(dlg);
230 panelPort.setBounds(new Rectangle(55, 0, 70, 160));
231 panelPort.setVisible(false);
232 panelStbd = new PanelStbd(dlg);
233 panelStbd.setBounds(new Rectangle(55, 0, 70, 160));
234 panelStbd.setVisible(false);
235 panelSaw = new PanelSaw(dlg);
236 panelSaw.setBounds(new Rectangle(55, 0, 70, 160));
237 panelSaw.setVisible(false);
238 add(panelPort);
239 add(panelStbd);
240 add(panelSaw);
241 add(getCatButton(portButton, 0, 0, 52, 32, "Port"));
242 add(getCatButton(stbdButton, 0, 32, 52, 32, "Stbd"));
243 add(getCatButton(prefStbdButton, 0, 64, 52, 32, "PrefStbd"));
244 add(getCatButton(prefPortButton, 0, 96, 52, 32, "PrefPort"));
245 add(getCatButton(safeWaterButton, 0, 128, 52, 32, "SafeWater"));
246
247 topmarkButton.setBounds(new Rectangle(130, 0, 34, 32));
248 topmarkButton.setToolTipText(Messages.getString("Topmark"));
249 topmarkButton.setBorder(BorderFactory.createLoweredBevelBorder());
250 topmarkButton.addActionListener(alTop);
251 topmarkButton.setVisible(false);
252 add(topmarkButton);
253 lightButton.setBounds(new Rectangle(130, 32, 34, 32));
254 lightButton.setToolTipText(Messages.getString("Light"));
255 lightButton.setBorder(BorderFactory.createLoweredBevelBorder());
256 lightButton.addActionListener(alLit);
257 lightButton.setVisible(false);
258 add(lightButton);
259 }
260
261 public void syncPanel() {
262 panelPort.setVisible(false);
263 panelStbd.setVisible(false);
264 panelSaw.setVisible(false);
265 if (dlg.panelMain.mark.getCategory() == Cat.LAM_PORT) {
266 panelPort.setVisible(true);
267 portButton.setBorderPainted(true);
268 } else {
269 portButton.setBorderPainted(false);
270 }
271 if (dlg.panelMain.mark.getCategory() == Cat.LAM_PPORT) {
272 panelStbd.setVisible(true);
273 prefPortButton.setBorderPainted(true);
274 } else {
275 prefPortButton.setBorderPainted(false);
276 }
277 if (dlg.panelMain.mark.getCategory() == Cat.LAM_STBD) {
278 panelStbd.setVisible(true);
279 stbdButton.setBorderPainted(true);
280 } else {
281 stbdButton.setBorderPainted(false);
282 }
283 if (dlg.panelMain.mark.getCategory() == Cat.LAM_PSTBD) {
284 panelPort.setVisible(true);
285 prefStbdButton.setBorderPainted(true);
286 } else {
287 prefStbdButton.setBorderPainted(false);
288 }
289 if (SeaMark.GrpMAP.get(dlg.panelMain.mark.getObject()) == Grp.SAW) {
290 panelSaw.setVisible(true);
291 safeWaterButton.setBorderPainted(true);
292 } else {
293 safeWaterButton.setBorderPainted(false);
294 }
295 topmarkButton.setBorderPainted(dlg.panelMain.mark.getTopmark() != Top.NOTOP);
296 topmarkButton.setSelected(dlg.panelMain.mark.getTopmark() != Top.NOTOP);
297 topmarkButton.setVisible(dlg.panelMain.mark.testValid());
298 Boolean lit = (dlg.panelMain.mark.getLightAtt(Att.COL, 0) != Col.UNKCOL) && !((String)dlg.panelMain.mark.getLightAtt(Att.CHR, 0)).isEmpty();
299 lightButton.setBorderPainted(lit);
300 lightButton.setSelected(lit);
301 lightButton.setVisible(dlg.panelMain.mark.testValid());
302 panelPort.syncPanel();
303 panelStbd.syncPanel();
304 panelSaw.syncPanel();
305 dlg.panelMain.mark.testValid();
306 }
307
308 private JRadioButton getCatButton(JRadioButton button, int x, int y, int w, int h, String tip) {
309 button.setBounds(new Rectangle(x, y, w, h));
310 button.setBorder(BorderFactory.createLoweredBevelBorder());
311 button.setToolTipText(Messages.getString(tip));
312 button.addActionListener(alCat);
313 catButtons.add(button);
314 return button;
315 }
316
317}
Note: See TracBrowser for help on using the repository browser.