source: osm/applications/editors/josm/plugins/smed/plugs/oseam/src/oseam/panels/PanelHaz.java@ 26977

Last change on this file since 26977 was 26977, checked in by malcolmh, 13 years ago

save

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