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