1 | package oseam.panels;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.*;
|
---|
6 | import java.awt.event.*;
|
---|
7 | import javax.swing.*;
|
---|
8 |
|
---|
9 | import oseam.Messages;
|
---|
10 | import oseam.dialogs.OSeaMAction;
|
---|
11 | import oseam.seamarks.SeaMark.*;
|
---|
12 |
|
---|
13 | public class PanelMain extends JPanel {
|
---|
14 |
|
---|
15 | private OSeaMAction dlg;
|
---|
16 | public JLabel shapeIcon = null;
|
---|
17 | public JLabel lightIcon = null;
|
---|
18 | public JLabel topIcon = null;
|
---|
19 | public JLabel radarIcon = null;
|
---|
20 | public JLabel fogIcon = null;
|
---|
21 | public JLabel nameLabel = null;
|
---|
22 | public JTextField nameBox = null;
|
---|
23 | private JButton saveButton = null;
|
---|
24 | private ActionListener alSave = null;
|
---|
25 | public JButton moreButton = null;
|
---|
26 | private ActionListener alMore = null;
|
---|
27 | public ButtonGroup typeButtons = null;
|
---|
28 | public JRadioButton chanButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ChanButton.png")));
|
---|
29 | public JRadioButton hazButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/HazButton.png")));
|
---|
30 | public JRadioButton specButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SpecButton.png")));
|
---|
31 | public JRadioButton lightsButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/LightsButton.png")));
|
---|
32 | private ActionListener alType = null;
|
---|
33 | private ButtonGroup miscButtons = null;
|
---|
34 | public JRadioButton topButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TopButton.png")));
|
---|
35 | public JRadioButton fogButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogButton.png")));
|
---|
36 | public JRadioButton radButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/RadarButton.png")));
|
---|
37 | public JRadioButton litButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/LitButton.png")));
|
---|
38 | private ActionListener alMisc = null;
|
---|
39 | private ActionListener alName = null;
|
---|
40 | public PanelChan panelChan = null;
|
---|
41 | public PanelHaz panelHaz = null;
|
---|
42 | public PanelSpec panelSpec = null;
|
---|
43 | public PanelLights panelLights = null;
|
---|
44 | public PanelMore panelMore = null;
|
---|
45 | public PanelTop panelTop = null;
|
---|
46 | public PanelFog panelFog = null;
|
---|
47 | public PanelRadar panelRadar = null;
|
---|
48 | public PanelLit panelLit = null;
|
---|
49 |
|
---|
50 | public PanelMain(OSeaMAction dia) {
|
---|
51 |
|
---|
52 | dlg = dia;
|
---|
53 | panelChan = new PanelChan(dlg);
|
---|
54 | panelChan.setBounds(new Rectangle(65, 0, 180, 160));
|
---|
55 | panelChan.setVisible(false);
|
---|
56 | panelHaz = new PanelHaz(dlg);
|
---|
57 | panelHaz.setBounds(new Rectangle(65, 0, 180, 160));
|
---|
58 | panelHaz.setVisible(false);
|
---|
59 | panelSpec = new PanelSpec(dlg);
|
---|
60 | panelSpec.setBounds(new Rectangle(65, 0, 180, 160));
|
---|
61 | panelSpec.setVisible(false);
|
---|
62 | panelLights = new PanelLights(dlg);
|
---|
63 | panelLights.setBounds(new Rectangle(65, 0, 180, 160));
|
---|
64 | panelLights.setVisible(false);
|
---|
65 | panelMore = new PanelMore(dlg);
|
---|
66 | panelMore.setBounds(new Rectangle(40, 165, 360, 160));
|
---|
67 | panelMore.setVisible(false);
|
---|
68 | panelTop = new PanelTop(dlg);
|
---|
69 | panelTop.setBounds(new Rectangle(40, 165, 360, 160));
|
---|
70 | panelTop.setVisible(false);
|
---|
71 | panelFog = new PanelFog(dlg);
|
---|
72 | panelFog.setBounds(new Rectangle(40, 165, 360, 160));
|
---|
73 | panelFog.setVisible(false);
|
---|
74 | panelRadar = new PanelRadar(dlg);
|
---|
75 | panelRadar.setBounds(new Rectangle(40, 165, 360, 160));
|
---|
76 | panelRadar.setVisible(false);
|
---|
77 | panelLit = new PanelLit(dlg);
|
---|
78 | panelLit.setBounds(new Rectangle(40, 165, 360, 160));
|
---|
79 | panelLit.setVisible(false);
|
---|
80 |
|
---|
81 | shapeIcon = new JLabel();
|
---|
82 | shapeIcon.setBounds(new Rectangle(235, 0, 150, 185));
|
---|
83 | this.add(shapeIcon, null);
|
---|
84 | lightIcon = new JLabel();
|
---|
85 | lightIcon.setBounds(new Rectangle(235, 0, 150, 185));
|
---|
86 | this.add(lightIcon, null);
|
---|
87 | topIcon = new JLabel();
|
---|
88 | topIcon.setBounds(new Rectangle(235, 0, 150, 185));
|
---|
89 | this.add(topIcon, null);
|
---|
90 | radarIcon = new JLabel();
|
---|
91 | radarIcon.setBounds(new Rectangle(235, 0, 150, 185));
|
---|
92 | this.add(radarIcon, null);
|
---|
93 | fogIcon = new JLabel();
|
---|
94 | fogIcon.setBounds(new Rectangle(235, 0, 150, 185));
|
---|
95 | this.add(fogIcon, null);
|
---|
96 |
|
---|
97 | this.add(getButton(chanButton, 0, 0, 62, 40, "Chan"), null);
|
---|
98 | this.add(getButton(hazButton, 0, 40, 62, 40, "Haz"), null);
|
---|
99 | this.add(getButton(specButton, 0, 80, 62, 40, "Spec"), null);
|
---|
100 | this.add(getButton(lightsButton, 0, 120, 62, 40, "Lights"), null);
|
---|
101 | this.add(panelChan, null);
|
---|
102 | this.add(panelHaz, null);
|
---|
103 | this.add(panelSpec, null);
|
---|
104 | this.add(panelLights, null);
|
---|
105 | this.add(panelMore, null);
|
---|
106 | this.add(panelTop, null);
|
---|
107 | this.add(panelFog, null);
|
---|
108 | this.add(panelRadar, null);
|
---|
109 | this.add(panelLit, null);
|
---|
110 | typeButtons = new ButtonGroup();
|
---|
111 | typeButtons.add(chanButton);
|
---|
112 | typeButtons.add(hazButton);
|
---|
113 | typeButtons.add(specButton);
|
---|
114 | typeButtons.add(lightsButton);
|
---|
115 | alType = new ActionListener() {
|
---|
116 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
117 | if (dlg.node == null) {
|
---|
118 | typeButtons.clearSelection();
|
---|
119 | }
|
---|
120 | if (chanButton.isSelected()) {
|
---|
121 | chanButton.setBorderPainted(true);
|
---|
122 | panelChan.setVisible(true);
|
---|
123 | } else {
|
---|
124 | chanButton.setBorderPainted(false);
|
---|
125 | panelChan.setVisible(false);
|
---|
126 | panelChan.clearSelections();
|
---|
127 | }
|
---|
128 | if (hazButton.isSelected()) {
|
---|
129 | hazButton.setBorderPainted(true);
|
---|
130 | panelHaz.setVisible(true);
|
---|
131 | } else {
|
---|
132 | hazButton.setBorderPainted(false);
|
---|
133 | panelHaz.setVisible(false);
|
---|
134 | panelHaz.clearSelections();
|
---|
135 | }
|
---|
136 | if (specButton.isSelected()) {
|
---|
137 | if (dlg.mark != null) {
|
---|
138 | if (dlg.mark.getObject() == Obj.UNKNOWN) {
|
---|
139 | panelSpec.clearSelections();
|
---|
140 | panelSpec.panelCol.yellowButton.doClick();
|
---|
141 | } else {
|
---|
142 | panelSpec.panelCol.colours.get(dlg.mark.getColour(Ent.BODY, 0)).doClick();
|
---|
143 | }
|
---|
144 | if (panelSpec.shapes.containsKey(dlg.mark.getShape())) {
|
---|
145 | panelSpec.shapes.get(dlg.mark.getShape()).doClick();
|
---|
146 | } else {
|
---|
147 | panelSpec.shapeButtons.clearSelection();
|
---|
148 | panelSpec.alShape.actionPerformed(null);
|
---|
149 | }
|
---|
150 | }
|
---|
151 | specButton.setBorderPainted(true);
|
---|
152 | panelSpec.setVisible(true);
|
---|
153 | } else {
|
---|
154 | specButton.setBorderPainted(false);
|
---|
155 | panelSpec.setVisible(false);
|
---|
156 | panelSpec.clearSelections();
|
---|
157 | }
|
---|
158 | if (lightsButton.isSelected()) {
|
---|
159 | if (dlg.mark != null) {
|
---|
160 | if (dlg.mark.getObject() == Obj.UNKNOWN) {
|
---|
161 | panelLights.clearSelections();
|
---|
162 | } else {
|
---|
163 | panelLights.objects.get(dlg.mark.getObject()).doClick();
|
---|
164 | }
|
---|
165 | }
|
---|
166 | lightsButton.setBorderPainted(true);
|
---|
167 | panelLights.setVisible(true);
|
---|
168 | } else {
|
---|
169 | lightsButton.setBorderPainted(false);
|
---|
170 | panelLights.setVisible(false);
|
---|
171 | panelLights.clearSelections();
|
---|
172 | }
|
---|
173 | }
|
---|
174 | };
|
---|
175 | chanButton.addActionListener(alType);
|
---|
176 | hazButton.addActionListener(alType);
|
---|
177 | specButton.addActionListener(alType);
|
---|
178 | lightsButton.addActionListener(alType);
|
---|
179 |
|
---|
180 | this.add(getButton(topButton, 0, 165, 34, 32, "Topmarks"), null);
|
---|
181 | this.add(getButton(fogButton, 0, 205, 34, 32, "FogSignals"), null);
|
---|
182 | this.add(getButton(radButton, 0, 245, 34, 32, "Radar"), null);
|
---|
183 | this.add(getButton(litButton, 0, 285, 34, 32, "Lit"), null);
|
---|
184 | miscButtons = new ButtonGroup();
|
---|
185 | miscButtons.add(topButton);
|
---|
186 | miscButtons.add(fogButton);
|
---|
187 | miscButtons.add(radButton);
|
---|
188 | miscButtons.add(litButton);
|
---|
189 | alMisc = new ActionListener() {
|
---|
190 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
191 | if (dlg.mark == null) {
|
---|
192 | miscButtons.clearSelection();
|
---|
193 | }
|
---|
194 | if (topButton.isSelected()) {
|
---|
195 | moreButton.setText("v v v");
|
---|
196 | panelMore.setVisible(false);
|
---|
197 | topButton.setBorderPainted(true);
|
---|
198 | panelTop.setVisible(true);
|
---|
199 | } else {
|
---|
200 | topButton.setBorderPainted(false);
|
---|
201 | panelTop.setVisible(false);
|
---|
202 | }
|
---|
203 | if (fogButton.isSelected()) {
|
---|
204 | moreButton.setText("v v v");
|
---|
205 | panelMore.setVisible(false);
|
---|
206 | fogButton.setBorderPainted(true);
|
---|
207 | panelFog.setVisible(true);
|
---|
208 | } else {
|
---|
209 | fogButton.setBorderPainted(false);
|
---|
210 | panelFog.setVisible(false);
|
---|
211 | }
|
---|
212 | if (radButton.isSelected()) {
|
---|
213 | moreButton.setText("v v v");
|
---|
214 | panelMore.setVisible(false);
|
---|
215 | radButton.setBorderPainted(true);
|
---|
216 | panelRadar.setVisible(true);
|
---|
217 | } else {
|
---|
218 | radButton.setBorderPainted(false);
|
---|
219 | panelRadar.setVisible(false);
|
---|
220 | }
|
---|
221 | if (litButton.isSelected()) {
|
---|
222 | moreButton.setText("v v v");
|
---|
223 | panelMore.setVisible(false);
|
---|
224 | litButton.setBorderPainted(true);
|
---|
225 | panelLit.setVisible(true);
|
---|
226 | } else {
|
---|
227 | litButton.setBorderPainted(false);
|
---|
228 | panelLit.setVisible(false);
|
---|
229 | }
|
---|
230 | }
|
---|
231 | };
|
---|
232 | topButton.addActionListener(alMisc);
|
---|
233 | fogButton.addActionListener(alMisc);
|
---|
234 | radButton.addActionListener(alMisc);
|
---|
235 | litButton.addActionListener(alMisc);
|
---|
236 |
|
---|
237 | nameLabel = new JLabel();
|
---|
238 | nameLabel.setBounds(new Rectangle(5, 329, 60, 20));
|
---|
239 | nameLabel.setText(tr("Name:"));
|
---|
240 | this.add(nameLabel, null);
|
---|
241 | nameBox = new JTextField();
|
---|
242 | nameBox.setBounds(new Rectangle(60, 330, 200, 20));
|
---|
243 | this.add(nameBox, null);
|
---|
244 | alName = new ActionListener() {
|
---|
245 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
246 | if (dlg.mark == null)
|
---|
247 | return;
|
---|
248 | else
|
---|
249 | dlg.mark.setName(nameBox.getText());
|
---|
250 | }
|
---|
251 | };
|
---|
252 | nameBox.addActionListener(alName);
|
---|
253 |
|
---|
254 | saveButton = new JButton();
|
---|
255 | saveButton.setBounds(new Rectangle(285, 330, 100, 20));
|
---|
256 | saveButton.setText(tr("Save"));
|
---|
257 | this.add(saveButton, null);
|
---|
258 | alSave = new ActionListener() {
|
---|
259 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
260 | if (dlg.mark != null) {
|
---|
261 | dlg.mark.saveSign(dlg.node);
|
---|
262 | }
|
---|
263 | }
|
---|
264 | };
|
---|
265 | saveButton.addActionListener(alSave);
|
---|
266 |
|
---|
267 | moreButton = new JButton();
|
---|
268 | moreButton.setBounds(new Rectangle(350, 145, 40, 15));
|
---|
269 | moreButton.setMargin(new Insets(0, 0, 0, 0));
|
---|
270 | moreButton.setText("v v v");
|
---|
271 | this.add(moreButton, null);
|
---|
272 | alMore = new ActionListener() {
|
---|
273 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
274 | if (panelMore.isVisible()) {
|
---|
275 | moreButton.setText("v v v");
|
---|
276 | panelMore.setVisible(false);
|
---|
277 | if (topButton.isSelected())
|
---|
278 | panelTop.setVisible(true);
|
---|
279 | if (radButton.isSelected())
|
---|
280 | panelRadar.setVisible(true);
|
---|
281 | if (fogButton.isSelected())
|
---|
282 | panelFog.setVisible(true);
|
---|
283 | if (litButton.isSelected())
|
---|
284 | panelLit.setVisible(true);
|
---|
285 | } else {
|
---|
286 | panelMore.setVisible(true);
|
---|
287 | moreButton.setText("^ ^ ^");
|
---|
288 | if (topButton.isSelected())
|
---|
289 | panelTop.setVisible(false);
|
---|
290 | if (radButton.isSelected())
|
---|
291 | panelRadar.setVisible(false);
|
---|
292 | if (fogButton.isSelected())
|
---|
293 | panelFog.setVisible(false);
|
---|
294 | if (litButton.isSelected())
|
---|
295 | panelLit.setVisible(false);
|
---|
296 | }
|
---|
297 | }
|
---|
298 | };
|
---|
299 | moreButton.addActionListener(alMore);
|
---|
300 |
|
---|
301 | this.clearSelections();
|
---|
302 |
|
---|
303 | }
|
---|
304 |
|
---|
305 | public void clearSelections() {
|
---|
306 | typeButtons.clearSelection();
|
---|
307 | moreButton.setVisible(false);
|
---|
308 | alType.actionPerformed(null);
|
---|
309 | nameBox.setText("");
|
---|
310 | clearType();
|
---|
311 | }
|
---|
312 |
|
---|
313 | public void clearType() {
|
---|
314 | topButton.setEnabled(false);
|
---|
315 | fogButton.setEnabled(false);
|
---|
316 | radButton.setEnabled(false);
|
---|
317 | litButton.setEnabled(false);
|
---|
318 | miscButtons.clearSelection();
|
---|
319 | alMisc.actionPerformed(null);
|
---|
320 | panelChan.clearSelections();
|
---|
321 | panelHaz.clearSelections();
|
---|
322 | panelSpec.clearSelections();
|
---|
323 | panelLights.clearSelections();
|
---|
324 | panelTop.clearSelections();
|
---|
325 | panelFog.clearSelections();
|
---|
326 | panelRadar.clearSelections();
|
---|
327 | panelLit.clearSelections();
|
---|
328 | shapeIcon.setIcon(null);
|
---|
329 | lightIcon.setIcon(null);
|
---|
330 | topIcon.setIcon(null);
|
---|
331 | radarIcon.setIcon(null);
|
---|
332 | fogIcon.setIcon(null);
|
---|
333 | }
|
---|
334 |
|
---|
335 | private JRadioButton getButton(JRadioButton button, int x, int y, int w, int h, String tip) {
|
---|
336 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
337 | button.setBorder(BorderFactory.createLineBorder(Color.magenta, 2));
|
---|
338 | button.setToolTipText(Messages.getString(tip));
|
---|
339 | return button;
|
---|
340 | }
|
---|
341 |
|
---|
342 | }
|
---|