source: osm/applications/editors/josm/plugins/smed/src/panels/PanelStbd.java@ 32542

Last change on this file since 32542 was 30738, checked in by donvip, 10 years ago

[josm_plugins] fix java 7 warnings / global usage of try-with-resource

File size: 5.2 KB
Line 
1package panels;
2
3import java.awt.*;
4import java.awt.event.*;
5import javax.swing.*;
6
7import java.util.*;
8
9import messages.Messages;
10import smed.SmedAction;
11import seamarks.SeaMark.*;
12
13public class PanelStbd extends JPanel {
14
15 private SmedAction dlg;
16 public ButtonGroup shapeButtons = new ButtonGroup();
17 public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
18 public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
19 public JRadioButton coneButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ConeButton.png")));
20 public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
21 public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
22 public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
23 public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png")));
24 public JRadioButton perchButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PerchSButton.png")));
25 public JRadioButton stakeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StakeButton.png")));
26 public EnumMap<Shp, JRadioButton> shapes = new EnumMap<>(Shp.class);
27 public EnumMap<Shp, Obj> objects = new EnumMap<>(Shp.class);
28 public ActionListener alShape = new ActionListener() {
29 public void actionPerformed(java.awt.event.ActionEvent e) {
30 for (Shp shp : shapes.keySet()) {
31 JRadioButton button = shapes.get(shp);
32 if (button.isSelected()) {
33 SmedAction.panelMain.mark.setShape(shp);
34 SmedAction.panelMain.mark.setObject(objects.get(shp));
35 button.setBorderPainted(true);
36 } else
37 button.setBorderPainted(false);
38 }
39 if (SmedAction.panelMain.mark.testValid()) {
40 SmedAction.panelMain.panelChan.topmarkButton.setVisible(true);
41 SmedAction.panelMain.panelChan.lightButton.setVisible(true);
42 if (SmedAction.panelMain.mark.getCategory() == Cat.LAM_STBD) {
43 switch (SmedAction.panelMain.mark.getRegion()) {
44 case A:
45 SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT);
46 SmedAction.panelMain.mark.setObjColour(Col.GREEN);
47 break;
48 case B:
49 SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT);
50 SmedAction.panelMain.mark.setObjColour(Col.RED);
51 break;
52 case C:
53 SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP);
54 SmedAction.panelMain.mark.setObjColour(Col.GREEN);
55 SmedAction.panelMain.mark.addObjColour(Col.WHITE);
56 SmedAction.panelMain.mark.addObjColour(Col.GREEN);
57 SmedAction.panelMain.mark.addObjColour(Col.WHITE);
58 break;
59 }
60 } else {
61 SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP);
62 switch (SmedAction.panelMain.mark.getRegion()) {
63 case A:
64 SmedAction.panelMain.mark.setObjColour(Col.GREEN);
65 SmedAction.panelMain.mark.addObjColour(Col.RED);
66 SmedAction.panelMain.mark.addObjColour(Col.GREEN);
67 break;
68 case B:
69 SmedAction.panelMain.mark.setObjColour(Col.RED);
70 SmedAction.panelMain.mark.addObjColour(Col.GREEN);
71 SmedAction.panelMain.mark.addObjColour(Col.RED);
72 break;
73 case C:
74 SmedAction.panelMain.mark.setObjColour(Col.RED);
75 SmedAction.panelMain.mark.addObjColour(Col.GREEN);
76 SmedAction.panelMain.mark.addObjColour(Col.RED);
77 SmedAction.panelMain.mark.addObjColour(Col.GREEN);
78 break;
79 }
80 }
81 SmedAction.panelMain.panelMore.syncPanel();
82 } else {
83 SmedAction.panelMain.panelChan.topmarkButton.setVisible(false);
84 SmedAction.panelMain.panelChan.lightButton.setVisible(false);
85 }
86 }
87 };
88
89 public PanelStbd(SmedAction dia) {
90 dlg = dia;
91 setLayout(null);
92 add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYLAT));
93 add(getShapeButton(sparButton, 0, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYLAT));
94 add(getShapeButton(coneButton, 0, 64, 34, 32, "Cone", Shp.CONI, Obj.BOYLAT));
95 add(getShapeButton(sphereButton, 0, 96, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYLAT));
96 add(getShapeButton(floatButton, 0, 128, 34, 32, "Float", Shp.FLOAT, Obj.FLTLAT));
97 add(getShapeButton(beaconButton, 35, 0, 34, 32, "Beacon", Shp.BEACON, Obj.BCNLAT));
98 add(getShapeButton(towerButton, 35, 32, 34, 32, "TowerB", Shp.TOWER, Obj.BCNLAT));
99 add(getShapeButton(perchButton, 35, 64, 34, 32, "Perch", Shp.PERCH, Obj.BCNLAT));
100 add(getShapeButton(stakeButton, 35, 96, 34, 32, "Stake", Shp.STAKE, Obj.BCNLAT));
101 }
102
103 public void syncPanel() {
104 for (Shp shp : shapes.keySet()) {
105 JRadioButton button = shapes.get(shp);
106 if (SmedAction.panelMain.mark.getShape() == shp) {
107 button.setBorderPainted(true);
108 } else
109 button.setBorderPainted(false);
110 }
111 }
112
113 private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
114 button.setBounds(new Rectangle(x, y, w, h));
115 button.setBorder(BorderFactory.createLoweredBevelBorder());
116 button.setToolTipText(Messages.getString(tip));
117 button.addActionListener(alShape);
118 shapeButtons.add(button);
119 shapes.put(shp, button);
120 objects.put(shp, obj);
121 return button;
122 }
123
124}
Note: See TracBrowser for help on using the repository browser.