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

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

checkstyle

File size: 16.1 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.JComboBox;
13import javax.swing.JLabel;
14import javax.swing.JPanel;
15import javax.swing.JRadioButton;
16import javax.swing.JToggleButton;
17import javax.swing.SwingConstants;
18
19import messages.Messages;
20import seamarks.SeaMark;
21import seamarks.SeaMark.Cat;
22import seamarks.SeaMark.Col;
23import seamarks.SeaMark.Ent;
24import seamarks.SeaMark.Obj;
25import seamarks.SeaMark.Pat;
26import seamarks.SeaMark.Shp;
27import seamarks.SeaMark.Top;
28import smed.SmedAction;
29
30public class PanelSpec extends JPanel {
31
32 private SmedAction dlg;
33 public JLabel categoryLabel;
34 public JComboBox<String> categoryBox;
35 public EnumMap<Cat, Integer> categories = new EnumMap<>(Cat.class);
36 private ActionListener alCategoryBox = new ActionListener() {
37 @Override
38 public void actionPerformed(ActionEvent e) {
39 for (Cat cat : categories.keySet()) {
40 int idx = categories.get(cat);
41 if (dlg.node != null && (idx == categoryBox.getSelectedIndex())) {
42 SmedAction.panelMain.mark.setCategory(cat);
43 }
44 }
45 }
46 };
47 public JComboBox<String> mooringBox;
48 public EnumMap<Cat, Integer> moorings = new EnumMap<>(Cat.class);
49 private ActionListener alMooringBox = new ActionListener() {
50 @Override
51 public void actionPerformed(ActionEvent e) {
52 for (Cat cat : moorings.keySet()) {
53 int idx = moorings.get(cat);
54 if (dlg.node != null && (idx == mooringBox.getSelectedIndex())) {
55 SmedAction.panelMain.mark.setCategory(cat);
56 if ((cat == Cat.INB_CALM) || (cat == Cat.INB_SBM)) {
57 SmedAction.panelMain.mark.setObject(Obj.BOYINB);
58 SmedAction.panelMain.mark.setShape(Shp.UNKSHP);
59 } else {
60 SmedAction.panelMain.mark.setObject(Obj.MORFAC);
61 if (cat != Cat.MOR_BUOY) {
62 SmedAction.panelMain.mark.setShape(Shp.UNKSHP);
63 }
64 }
65 }
66 }
67 if (dlg.node != null) {
68 syncPanel();
69 }
70 }
71 };
72 public ButtonGroup shapeButtons = new ButtonGroup();
73 public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
74 public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
75 public JRadioButton canButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CanButton.png")));
76 public JRadioButton coneButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ConeButton.png")));
77 public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
78 public JRadioButton barrelButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BarrelButton.png")));
79 public JRadioButton superButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SuperButton.png")));
80 public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
81 public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
82 public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png")));
83 public JRadioButton stakeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StakeButton.png")));
84 public JRadioButton cairnButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CairnButton.png")));
85 public EnumMap<Shp, JRadioButton> shapes = new EnumMap<>(Shp.class);
86 public EnumMap<Shp, Obj> objects = new EnumMap<>(Shp.class);
87 public ActionListener alShape = new ActionListener() {
88 @Override
89 public void actionPerformed(ActionEvent e) {
90 if ((SmedAction.panelMain.mark.getObject() != Obj.MORFAC) || (SmedAction.panelMain.mark.getCategory() == Cat.MOR_BUOY)) {
91 for (Shp shp : shapes.keySet()) {
92 JRadioButton button = shapes.get(shp);
93 if (button.isSelected()) {
94 SmedAction.panelMain.mark.setShape(shp);
95 if (SeaMark.EntMAP.get(SmedAction.panelMain.mark.getObject()) != Ent.MOORING) {
96 SmedAction.panelMain.mark.setObject(objects.get(shp));
97 if (SmedAction.panelMain.mark.getObjColour(0) == Col.UNKCOL) {
98 SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT);
99 SmedAction.panelMain.mark.setObjColour(Col.YELLOW);
100 }
101 if (button == cairnButton) {
102 SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT);
103 SmedAction.panelMain.mark.setObjColour(Col.UNKCOL);
104 }
105 topmarkButton.setVisible(SmedAction.panelMain.mark.testValid());
106 }
107 button.setBorderPainted(true);
108 } else {
109 button.setBorderPainted(false);
110 }
111 }
112 SmedAction.panelMain.panelMore.syncPanel();
113 }
114 }
115 };
116 public JToggleButton topmarkButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/SpecTopButton.png")));
117 private ActionListener alTop = new ActionListener() {
118 @Override
119 public void actionPerformed(ActionEvent e) {
120 if (topmarkButton.isSelected()) {
121 SmedAction.panelMain.mark.setTopmark(Top.X_SHAPE);
122 SmedAction.panelMain.mark.setTopPattern(Pat.NOPAT);
123 SmedAction.panelMain.mark.setTopColour(Col.YELLOW);
124 topmarkButton.setBorderPainted(true);
125 } else {
126 SmedAction.panelMain.mark.setTopmark(Top.NOTOP);
127 SmedAction.panelMain.mark.setTopPattern(Pat.NOPAT);
128 SmedAction.panelMain.mark.setTopColour(Col.UNKCOL);
129 topmarkButton.setBorderPainted(false);
130 }
131 SmedAction.panelMain.panelTop.syncPanel();
132 }
133 };
134 public JToggleButton noticeButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/NoticeButton.png")));
135 private ActionListener alNotice = new ActionListener() {
136 @Override
137 public void actionPerformed(ActionEvent e) {
138 SmedAction.panelMain.mark.clrMark();
139 if (noticeButton.isSelected()) {
140 SmedAction.panelMain.mark.setObject(Obj.NOTMRK);
141 noticeButton.setBorderPainted(true);
142 } else {
143 SmedAction.panelMain.mark.setObject(Obj.UNKOBJ);
144 noticeButton.setBorderPainted(false);
145 }
146 SmedAction.panelMain.syncPanel();
147 }
148 };
149 public JToggleButton mooringButton = new JToggleButton(new ImageIcon(getClass().getResource("/images/MooringButton.png")));
150 private ActionListener alMooring = new ActionListener() {
151 @Override
152 public void actionPerformed(ActionEvent e) {
153 SmedAction.panelMain.mark.setObject(Obj.UNKOBJ);
154 SmedAction.panelMain.mark.setCategory(Cat.NOCAT);
155 SmedAction.panelMain.mark.setTopmark(Top.NOTOP);
156 if (mooringButton.isSelected()) {
157 SmedAction.panelMain.mark.setObject(Obj.MORFAC);
158 categoryBox.setVisible(false);
159 mooringBox.setVisible(true);
160 pillarButton.setEnabled(false);
161 sparButton.setEnabled(false);
162 beaconButton.setEnabled(false);
163 towerButton.setEnabled(false);
164 stakeButton.setEnabled(false);
165 cairnButton.setEnabled(false);
166 mooringButton.setBorderPainted(true);
167 } else {
168 mooringBox.setVisible(false);
169 categoryBox.setVisible(true);
170 pillarButton.setEnabled(true);
171 sparButton.setEnabled(true);
172 beaconButton.setEnabled(true);
173 towerButton.setEnabled(true);
174 stakeButton.setEnabled(true);
175 cairnButton.setEnabled(true);
176 mooringButton.setBorderPainted(false);
177 }
178 syncPanel();
179 }
180 };
181
182 public PanelSpec(SmedAction dia) {
183 dlg = dia;
184 setLayout(null);
185 add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYSPP));
186 add(getShapeButton(sparButton, 34, 0, 34, 32, "Spar", Shp.SPAR, Obj.BOYSPP));
187 add(getShapeButton(canButton, 68, 0, 34, 32, "Can", Shp.CAN, Obj.BOYSPP));
188 add(getShapeButton(coneButton, 102, 0, 34, 32, "Cone", Shp.CONI, Obj.BOYSPP));
189 add(getShapeButton(sphereButton, 0, 32, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYSPP));
190 add(getShapeButton(barrelButton, 34, 32, 34, 32, "Barrel", Shp.BARREL, Obj.BOYSPP));
191 add(getShapeButton(superButton, 68, 32, 34, 32, "Super", Shp.SUPER, Obj.BOYSPP));
192 add(getShapeButton(floatButton, 102, 32, 34, 32, "Float", Shp.FLOAT, Obj.LITFLT));
193 add(getShapeButton(beaconButton, 0, 64, 34, 32, "Beacon", Shp.BEACON, Obj.BCNSPP));
194 add(getShapeButton(towerButton, 34, 64, 34, 32, "TowerB", Shp.TOWER, Obj.BCNSPP));
195 add(getShapeButton(stakeButton, 68, 64, 34, 32, "Stake", Shp.STAKE, Obj.BCNSPP));
196 add(getShapeButton(cairnButton, 102, 64, 34, 32, "CairnB", Shp.CAIRN, Obj.BCNSPP));
197
198 categoryLabel = new JLabel(Messages.getString("Category"), SwingConstants.CENTER);
199 categoryLabel.setBounds(new Rectangle(5, 125, 160, 18));
200 add(categoryLabel);
201 categoryBox = new JComboBox<>();
202 categoryBox.setBounds(new Rectangle(5, 142, 160, 18));
203 add(categoryBox);
204 categoryBox.setVisible(true);
205 categoryBox.addActionListener(alCategoryBox);
206 addCatItem("", Cat.NOCAT);
207 addCatItem(Messages.getString("UKPurpose"), Cat.SPM_UNKN);
208 addCatItem(Messages.getString("Warning"), Cat.SPM_WARN);
209 addCatItem(Messages.getString("ChanSeparation"), Cat.SPM_CHBF);
210 addCatItem(Messages.getString("Yachting"), Cat.SPM_YCHT);
211 addCatItem(Messages.getString("Cable"), Cat.SPM_CABL);
212 addCatItem(Messages.getString("Outfall"), Cat.SPM_OFAL);
213 addCatItem(Messages.getString("ODAS"), Cat.SPM_ODAS);
214 addCatItem(Messages.getString("RecreationZone"), Cat.SPM_RECN);
215 addCatItem(Messages.getString("Mooring"), Cat.SPM_MOOR);
216 addCatItem(Messages.getString("LANBY"), Cat.SPM_LNBY);
217 addCatItem(Messages.getString("Leading"), Cat.SPM_LDNG);
218 addCatItem(Messages.getString("Notice"), Cat.SPM_NOTC);
219 addCatItem(Messages.getString("TSS"), Cat.SPM_TSS);
220 addCatItem(Messages.getString("FoulGround"), Cat.SPM_FOUL);
221 addCatItem(Messages.getString("Diving"), Cat.SPM_DIVE);
222 addCatItem(Messages.getString("FerryCross"), Cat.SPM_FRRY);
223 addCatItem(Messages.getString("Anchorage"), Cat.SPM_ANCH);
224 mooringBox = new JComboBox<>();
225 mooringBox.setBounds(new Rectangle(5, 142, 160, 18));
226 add(mooringBox);
227 mooringBox.setVisible(false);
228 mooringBox.addActionListener(alMooringBox);
229 addMorItem("", Cat.NOCAT);
230 addMorItem(Messages.getString("Dolphin"), Cat.MOR_DLPN);
231 addMorItem(Messages.getString("DevDolphin"), Cat.MOR_DDPN);
232 addMorItem(Messages.getString("Bollard"), Cat.MOR_BLRD);
233 addMorItem(Messages.getString("Wall"), Cat.MOR_WALL);
234 addMorItem(Messages.getString("Post"), Cat.MOR_POST);
235 addMorItem(Messages.getString("Chain"), Cat.MOR_CHWR);
236 addMorItem(Messages.getString("Rope"), Cat.MOR_ROPE);
237 addMorItem(Messages.getString("Automatic"), Cat.MOR_AUTO);
238 addMorItem(Messages.getString("MooringBuoy"), Cat.MOR_BUOY);
239 addMorItem(Messages.getString("CALM"), Cat.INB_CALM);
240 addMorItem(Messages.getString("SBM"), Cat.INB_SBM);
241
242 topmarkButton.setBounds(new Rectangle(136, 0, 34, 32));
243 topmarkButton.setToolTipText(Messages.getString("Topmark"));
244 topmarkButton.setBorder(BorderFactory.createLoweredBevelBorder());
245 topmarkButton.addActionListener(alTop);
246 add(topmarkButton);
247
248 // noticeButton.setBounds(new Rectangle(136, 32, 34, 32));
249 // noticeButton.setToolTipText(Messages.getString("Notice"));
250 // noticeButton.setBorder(BorderFactory.createLoweredBevelBorder());
251 // noticeButton.addActionListener(alNotice);
252 // add(noticeButton);
253
254 mooringButton.setBounds(new Rectangle(136, 64, 34, 32));
255 mooringButton.setToolTipText(Messages.getString("Mooring"));
256 mooringButton.setBorder(BorderFactory.createLoweredBevelBorder());
257 mooringButton.addActionListener(alMooring);
258 add(mooringButton);
259 }
260
261 public void syncPanel() {
262 if (SeaMark.EntMAP.get(SmedAction.panelMain.mark.getObject()) == Ent.MOORING) {
263 mooringButton.setBorderPainted(true);
264 categoryBox.setVisible(false);
265 mooringBox.setVisible(true);
266 pillarButton.setEnabled(false);
267 sparButton.setEnabled(false);
268 beaconButton.setEnabled(false);
269 towerButton.setEnabled(false);
270 stakeButton.setEnabled(false);
271 cairnButton.setEnabled(false);
272 noticeButton.setEnabled(false);
273 topmarkButton.setVisible(false);
274 for (Cat cat : moorings.keySet()) {
275 int item = moorings.get(cat);
276 if (SmedAction.panelMain.mark.getCategory() == cat) {
277 mooringBox.setSelectedIndex(item);
278 }
279 }
280 } else {
281 mooringButton.setBorderPainted(false);
282 mooringBox.setVisible(false);
283 categoryBox.setVisible(true);
284 pillarButton.setEnabled(true);
285 sparButton.setEnabled(true);
286 beaconButton.setEnabled(true);
287 towerButton.setEnabled(true);
288 stakeButton.setEnabled(true);
289 cairnButton.setEnabled(true);
290 noticeButton.setEnabled(true);
291 topmarkButton.setBorderPainted(SmedAction.panelMain.mark.getTopmark() != Top.NOTOP);
292 topmarkButton.setSelected(SmedAction.panelMain.mark.getTopmark() != Top.NOTOP);
293 topmarkButton.setVisible(SmedAction.panelMain.mark.testValid());
294 for (Cat cat : categories.keySet()) {
295 int item = categories.get(cat);
296 if (SmedAction.panelMain.mark.getCategory() == cat) {
297 categoryBox.setSelectedIndex(item);
298 }
299 }
300 }
301 for (Shp shp : shapes.keySet()) {
302 JRadioButton button = shapes.get(shp);
303 if (SmedAction.panelMain.mark.getShape() == shp) {
304 button.setBorderPainted(true);
305 } else {
306 button.setBorderPainted(false);
307 }
308 }
309 noticeButton.setBorderPainted(false);
310 SmedAction.panelMain.mark.testValid();
311 }
312
313 private void addCatItem(String str, Cat cat) {
314 categories.put(cat, categoryBox.getItemCount());
315 categoryBox.addItem(str);
316 }
317
318 private void addMorItem(String str, Cat cat) {
319 moorings.put(cat, mooringBox.getItemCount());
320 mooringBox.addItem(str);
321 }
322
323 private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
324 button.setBounds(new Rectangle(x, y, w, h));
325 button.setBorder(BorderFactory.createLoweredBevelBorder());
326 button.setToolTipText(Messages.getString(tip));
327 button.addActionListener(alShape);
328 shapeButtons.add(button);
329 shapes.put(shp, button);
330 objects.put(shp, obj);
331 return button;
332 }
333
334}
Note: See TracBrowser for help on using the repository browser.