1 | package panels;
|
---|
2 |
|
---|
3 | import java.awt.Rectangle;
|
---|
4 | import java.awt.event.ActionEvent;
|
---|
5 | import java.awt.event.ActionListener;
|
---|
6 | import java.util.EnumMap;
|
---|
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.Obj;
|
---|
22 | import seamarks.SeaMark.Pat;
|
---|
23 | import seamarks.SeaMark.Shp;
|
---|
24 | import seamarks.SeaMark.Top;
|
---|
25 | import smed.SmedAction;
|
---|
26 |
|
---|
27 | public class PanelHaz extends JPanel {
|
---|
28 |
|
---|
29 | private SmedAction dlg;
|
---|
30 | public ButtonGroup catButtons = new ButtonGroup();
|
---|
31 | public JRadioButton northButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CardNButton.png")));
|
---|
32 | public JRadioButton southButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CardSButton.png")));
|
---|
33 | public JRadioButton eastButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CardEButton.png")));
|
---|
34 | public JRadioButton westButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CardWButton.png")));
|
---|
35 | public JRadioButton isolButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/IsolButton.png")));
|
---|
36 | private ActionListener alCat = new ActionListener() {
|
---|
37 | @Override
|
---|
38 | public void actionPerformed(ActionEvent e) {
|
---|
39 | SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP);
|
---|
40 | if (northButton.isSelected()) {
|
---|
41 | SmedAction.panelMain.mark.setCategory(Cat.CAM_NORTH);
|
---|
42 | SmedAction.panelMain.mark.setObjColour(Col.BLACK);
|
---|
43 | SmedAction.panelMain.mark.addObjColour(Col.YELLOW);
|
---|
44 | northButton.setBorderPainted(true);
|
---|
45 | } else {
|
---|
46 | northButton.setBorderPainted(false);
|
---|
47 | }
|
---|
48 | if (southButton.isSelected()) {
|
---|
49 | SmedAction.panelMain.mark.setCategory(Cat.CAM_SOUTH);
|
---|
50 | SmedAction.panelMain.mark.setObjColour(Col.YELLOW);
|
---|
51 | SmedAction.panelMain.mark.addObjColour(Col.BLACK);
|
---|
52 | southButton.setBorderPainted(true);
|
---|
53 | } else {
|
---|
54 | southButton.setBorderPainted(false);
|
---|
55 | }
|
---|
56 | if (eastButton.isSelected()) {
|
---|
57 | SmedAction.panelMain.mark.setCategory(Cat.CAM_EAST);
|
---|
58 | SmedAction.panelMain.mark.setObjColour(Col.BLACK);
|
---|
59 | SmedAction.panelMain.mark.addObjColour(Col.YELLOW);
|
---|
60 | SmedAction.panelMain.mark.addObjColour(Col.BLACK);
|
---|
61 | eastButton.setBorderPainted(true);
|
---|
62 | } else {
|
---|
63 | eastButton.setBorderPainted(false);
|
---|
64 | }
|
---|
65 | if (westButton.isSelected()) {
|
---|
66 | SmedAction.panelMain.mark.setCategory(Cat.CAM_WEST);
|
---|
67 | SmedAction.panelMain.mark.setObjColour(Col.YELLOW);
|
---|
68 | SmedAction.panelMain.mark.addObjColour(Col.BLACK);
|
---|
69 | SmedAction.panelMain.mark.addObjColour(Col.YELLOW);
|
---|
70 | westButton.setBorderPainted(true);
|
---|
71 | } else {
|
---|
72 | westButton.setBorderPainted(false);
|
---|
73 | }
|
---|
74 | if (isolButton.isSelected()) {
|
---|
75 | SmedAction.panelMain.mark.setCategory(Cat.NOCAT);
|
---|
76 | SmedAction.panelMain.mark.setObjColour(Col.BLACK);
|
---|
77 | SmedAction.panelMain.mark.addObjColour(Col.RED);
|
---|
78 | SmedAction.panelMain.mark.addObjColour(Col.BLACK);
|
---|
79 | isolButton.setBorderPainted(true);
|
---|
80 | } else {
|
---|
81 | isolButton.setBorderPainted(false);
|
---|
82 | }
|
---|
83 | topmarkButton.setVisible(SmedAction.panelMain.mark.testValid());
|
---|
84 | lightButton.setVisible(SmedAction.panelMain.mark.testValid());
|
---|
85 | SmedAction.panelMain.panelMore.syncPanel();
|
---|
86 | }
|
---|
87 | };
|
---|
88 | private ButtonGroup shapeButtons = new ButtonGroup();
|
---|
89 | public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
|
---|
90 | public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
|
---|
91 | public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
|
---|
92 | public JRadioButton canButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CanButton.png")));
|
---|
93 | public JRadioButton coneButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ConeButton.png")));
|
---|
94 | public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
|
---|
95 | public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
|
---|
96 | public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png")));
|
---|
97 | public EnumMap<Shp, JRadioButton> shapes = new EnumMap<>(Shp.class);
|
---|
98 | public EnumMap<Shp, Obj> carObjects = new EnumMap<>(Shp.class);
|
---|
99 | public EnumMap<Shp, Obj> isdObjects = new EnumMap<>(Shp.class);
|
---|
100 | private ActionListener alShape = new ActionListener() {
|
---|
101 | @Override
|
---|
102 | public void actionPerformed(ActionEvent e) {
|
---|
103 | for (Shp shp : shapes.keySet()) {
|
---|
104 | JRadioButton button = shapes.get(shp);
|
---|
105 | if (button.isSelected()) {
|
---|
106 | SmedAction.panelMain.mark.setShape(shp);
|
---|
107 | if (isolButton.isSelected()) {
|
---|
108 | SmedAction.panelMain.mark.setObject(isdObjects.get(shp));
|
---|
109 | } else {
|
---|
110 | SmedAction.panelMain.mark.setObject(carObjects.get(shp));
|
---|
111 | }
|
---|
112 | button.setBorderPainted(true);
|
---|
113 | } else {
|
---|
114 | button.setBorderPainted(false);
|
---|
115 | }
|
---|
116 | }
|
---|
117 | topmarkButton.setVisible(SmedAction.panelMain.mark.testValid());
|
---|
118 | lightButton.setVisible(SmedAction.panelMain.mark.testValid());
|
---|
119 | }
|
---|
120 | };
|
---|
121 | public JToggleButton topmarkButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/HazTopButton.png")));
|
---|
122 | private ActionListener alTop = new ActionListener() {
|
---|
123 | @Override
|
---|
124 | public void actionPerformed(ActionEvent e) {
|
---|
125 | if (topmarkButton.isSelected()) {
|
---|
126 | SmedAction.panelMain.mark.setTopPattern(Pat.NOPAT);
|
---|
127 | SmedAction.panelMain.mark.setTopColour(Col.BLACK);
|
---|
128 | switch (SmedAction.panelMain.mark.getCategory()) {
|
---|
129 | case CAM_NORTH:
|
---|
130 | SmedAction.panelMain.mark.setTopmark(Top.NORTH);
|
---|
131 | break;
|
---|
132 | case CAM_SOUTH:
|
---|
133 | SmedAction.panelMain.mark.setTopmark(Top.SOUTH);
|
---|
134 | break;
|
---|
135 | case CAM_EAST:
|
---|
136 | SmedAction.panelMain.mark.setTopmark(Top.EAST);
|
---|
137 | break;
|
---|
138 | case CAM_WEST:
|
---|
139 | SmedAction.panelMain.mark.setTopmark(Top.WEST);
|
---|
140 | break;
|
---|
141 | default:
|
---|
142 | SmedAction.panelMain.mark.setTopmark(Top.SPHERES2);
|
---|
143 | break;
|
---|
144 | }
|
---|
145 | topmarkButton.setBorderPainted(true);
|
---|
146 | } else {
|
---|
147 | SmedAction.panelMain.mark.setTopmark(Top.NOTOP);
|
---|
148 | SmedAction.panelMain.mark.setTopPattern(Pat.NOPAT);
|
---|
149 | SmedAction.panelMain.mark.setTopColour(Col.UNKCOL);
|
---|
150 | topmarkButton.setBorderPainted(false);
|
---|
151 | }
|
---|
152 | SmedAction.panelMain.panelTop.syncPanel();
|
---|
153 | }
|
---|
154 | };
|
---|
155 | public JToggleButton lightButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/DefLitButton.png")));
|
---|
156 | private ActionListener alLit = new ActionListener() {
|
---|
157 | @Override
|
---|
158 | public void actionPerformed(ActionEvent e) {
|
---|
159 | if (lightButton.isSelected()) {
|
---|
160 | SmedAction.panelMain.mark.setLightAtt(Att.COL, 0, Col.WHITE);
|
---|
161 | switch (SmedAction.panelMain.mark.getCategory()) {
|
---|
162 | case CAM_NORTH:
|
---|
163 | SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, "Q");
|
---|
164 | SmedAction.panelMain.mark.setLightAtt(Att.GRP, 0, "");
|
---|
165 | break;
|
---|
166 | case CAM_SOUTH:
|
---|
167 | SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, "Q+LFl");
|
---|
168 | SmedAction.panelMain.mark.setLightAtt(Att.GRP, 0, "6");
|
---|
169 | break;
|
---|
170 | case CAM_EAST:
|
---|
171 | SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, "Q");
|
---|
172 | SmedAction.panelMain.mark.setLightAtt(Att.GRP, 0, "3");
|
---|
173 | break;
|
---|
174 | case CAM_WEST:
|
---|
175 | SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, "Q");
|
---|
176 | SmedAction.panelMain.mark.setLightAtt(Att.GRP, 0, "9");
|
---|
177 | break;
|
---|
178 | default:
|
---|
179 | SmedAction.panelMain.mark.setLightAtt(Att.CHR, 0, "Fl");
|
---|
180 | SmedAction.panelMain.mark.setLightAtt(Att.GRP, 0, "2");
|
---|
181 | break;
|
---|
182 | }
|
---|
183 | lightButton.setBorderPainted(true);
|
---|
184 | } else {
|
---|
185 | SmedAction.panelMain.mark.clrLight();
|
---|
186 | lightButton.setBorderPainted(false);
|
---|
187 | }
|
---|
188 | SmedAction.panelMain.panelLit.syncPanel();
|
---|
189 | }
|
---|
190 | };
|
---|
191 |
|
---|
192 | public PanelHaz(SmedAction dia) {
|
---|
193 | dlg = dia;
|
---|
194 | setLayout(null);
|
---|
195 | add(getCatButton(northButton, 0, 0, 52, 32, "North"));
|
---|
196 | add(getCatButton(southButton, 0, 32, 52, 32, "South"));
|
---|
197 | add(getCatButton(eastButton, 0, 64, 52, 32, "East"));
|
---|
198 | add(getCatButton(westButton, 0, 96, 52, 32, "West"));
|
---|
199 | add(getCatButton(isolButton, 0, 128, 52, 32, "Isol"));
|
---|
200 |
|
---|
201 | add(getShapeButton(pillarButton, 55, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYCAR, Obj.BOYISD));
|
---|
202 | add(getShapeButton(sparButton, 55, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYCAR, Obj.BOYISD));
|
---|
203 | add(getShapeButton(canButton, 55, 64, 34, 32, "Can", Shp.CAN, Obj.BOYCAR, Obj.BOYISD));
|
---|
204 | add(getShapeButton(coneButton, 55, 96, 34, 32, "Cone", Shp.CONI, Obj.BOYCAR, Obj.BOYISD));
|
---|
205 | add(getShapeButton(sphereButton, 55, 128, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYCAR, Obj.BOYISD));
|
---|
206 | add(getShapeButton(floatButton, 90, 0, 34, 32, "Float", Shp.FLOAT, Obj.LITFLT, Obj.LITFLT));
|
---|
207 | add(getShapeButton(beaconButton, 90, 32, 34, 32, "Beacon", Shp.BEACON, Obj.BCNCAR, Obj.BCNISD));
|
---|
208 | add(getShapeButton(towerButton, 90, 64, 34, 32, "TowerB", Shp.TOWER, Obj.BCNCAR, Obj.BCNISD));
|
---|
209 |
|
---|
210 | topmarkButton.setBounds(new Rectangle(130, 0, 34, 32));
|
---|
211 | topmarkButton.setToolTipText(Messages.getString("Topmark"));
|
---|
212 | topmarkButton.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
213 | topmarkButton.addActionListener(alTop);
|
---|
214 | topmarkButton.setVisible(false);
|
---|
215 | add(topmarkButton);
|
---|
216 | lightButton.setBounds(new Rectangle(130, 32, 34, 32));
|
---|
217 | lightButton.setToolTipText(Messages.getString("Light"));
|
---|
218 | lightButton.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
219 | lightButton.addActionListener(alLit);
|
---|
220 | lightButton.setVisible(false);
|
---|
221 | add(lightButton);
|
---|
222 | }
|
---|
223 |
|
---|
224 | public void syncPanel() {
|
---|
225 | northButton.setBorderPainted(SmedAction.panelMain.mark.getCategory() == Cat.CAM_NORTH);
|
---|
226 | southButton.setBorderPainted(SmedAction.panelMain.mark.getCategory() == Cat.CAM_SOUTH);
|
---|
227 | eastButton.setBorderPainted(SmedAction.panelMain.mark.getCategory() == Cat.CAM_EAST);
|
---|
228 | westButton.setBorderPainted(SmedAction.panelMain.mark.getCategory() == Cat.CAM_WEST);
|
---|
229 | isolButton.setBorderPainted(SeaMark.GrpMAP.get(SmedAction.panelMain.mark.getObject()) == Grp.ISD);
|
---|
230 | for (Shp shp : shapes.keySet()) {
|
---|
231 | JRadioButton button = shapes.get(shp);
|
---|
232 | button.setBorderPainted(SmedAction.panelMain.mark.getShape() == shp);
|
---|
233 | }
|
---|
234 | topmarkButton.setBorderPainted(SmedAction.panelMain.mark.getTopmark() != Top.NOTOP);
|
---|
235 | topmarkButton.setSelected(SmedAction.panelMain.mark.getTopmark() != Top.NOTOP);
|
---|
236 | topmarkButton.setVisible(SmedAction.panelMain.mark.testValid());
|
---|
237 | Boolean lit = (SmedAction.panelMain.mark.getLightAtt(Att.COL, 0) != Col.UNKCOL) && !((String)SmedAction.panelMain.mark.getLightAtt(Att.CHR, 0)).isEmpty();
|
---|
238 | lightButton.setBorderPainted(lit);
|
---|
239 | lightButton.setSelected(lit);
|
---|
240 | lightButton.setVisible(SmedAction.panelMain.mark.testValid());
|
---|
241 | }
|
---|
242 |
|
---|
243 | private JRadioButton getCatButton(JRadioButton button, int x, int y, int w, int h, String tip) {
|
---|
244 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
245 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
246 | button.setToolTipText(Messages.getString(tip));
|
---|
247 | button.addActionListener(alCat);
|
---|
248 | catButtons.add(button);
|
---|
249 | return button;
|
---|
250 | }
|
---|
251 |
|
---|
252 | private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj car, Obj isd) {
|
---|
253 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
254 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
255 | button.setToolTipText(Messages.getString(tip));
|
---|
256 | button.addActionListener(alShape);
|
---|
257 | shapeButtons.add(button);
|
---|
258 | shapes.put(shp, button);
|
---|
259 | carObjects.put(shp, car);
|
---|
260 | isdObjects.put(shp, isd);
|
---|
261 | return button;
|
---|
262 | }
|
---|
263 |
|
---|
264 | }
|
---|