source: osm/applications/editors/josm/plugins/smed/src/panels/PanelHaz.java@ 33054

Last change on this file since 33054 was 33054, checked in by donvip, 8 years ago

checkstyle

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