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

Last change on this file since 29894 was 29894, checked in by malcolmh, 11 years ago

clean

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