source: osm/applications/editors/josm/plugins/smed/src/panels/PanelPort.java@ 33178

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

fix errors with error_prone

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