source: osm/applications/editors/josm/plugins/toms/src/toms/seamarks/buoys/BuoySaw.java@ 25542

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

'Bug fix release'

File size: 8.6 KB
Line 
1//License: GPL. For details, see LICENSE file.
2// Copyright (c) 2009 / 2010 by Werner Koenig & Malcolm Herring
3
4package toms.seamarks.buoys;
5
6import java.util.Map;
7
8import javax.swing.ImageIcon;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.command.ChangePropertyCommand;
12import org.openstreetmap.josm.data.osm.Node;
13
14import toms.Messages;
15import toms.dialogs.SmpDialogAction;
16import toms.seamarks.SeaMark;
17
18public class BuoySaw extends Buoy {
19 public BuoySaw(SmpDialogAction dia, Node node) {
20 super(dia);
21
22 String str;
23 Map<String, String> keys;
24 keys = node.getKeys();
25 setNode(node);
26
27 resetMask();
28 dlg.cbM01TypeOfMark.setSelectedIndex(SAFE_WATER);
29
30 dlg.cbM01StyleOfMark.removeAllItems();
31 dlg.cbM01StyleOfMark.addItem(Messages.getString("SmpDialogAction.212")); //$NON-NLS-1$
32 dlg.cbM01StyleOfMark.addItem(Messages.getString("Buoy.01")); //$NON-NLS-1$
33 dlg.cbM01StyleOfMark.addItem(Messages.getString("Buoy.04")); //$NON-NLS-1$
34 dlg.cbM01StyleOfMark.addItem(Messages.getString("Buoy.08")); //$NON-NLS-1$
35 dlg.cbM01StyleOfMark.addItem(Messages.getString("Buoy.05")); //$NON-NLS-1$
36 dlg.cbM01StyleOfMark.addItem(Messages.getString("Buoy.07")); //$NON-NLS-1$
37 dlg.cbM01StyleOfMark.setVisible(true);
38 dlg.lM01StyleOfMark.setVisible(true);
39
40 setBuoyIndex(SAFE_WATER);
41 setColour(SeaMark.RED_WHITE);
42 setLightColour("W"); //$NON-NLS-1$
43 setRegion(Main.pref.get("tomsplugin.IALA").equals("B")); //$NON-NLS-1$ //$NON-NLS-2$
44
45 if (keys.containsKey("name")) //$NON-NLS-1$
46 setName(keys.get("name")); //$NON-NLS-1$
47
48 if (keys.containsKey("seamark:name")) //$NON-NLS-1$
49 setName(keys.get("seamark:name")); //$NON-NLS-1$
50
51 if (keys.containsKey("seamark:longname")) //$NON-NLS-1$
52 setLongname(keys.get("seamark:longname")); //$NON-NLS-1$
53
54 if (keys.containsKey("seamark:fixme")) //$NON-NLS-1$
55 setFixme(keys.get("seamark:fixme")); //$NON-NLS-1$
56
57 if (keys.containsKey("seamark:buoy_safe_water:name")) //$NON-NLS-1$
58 setName(keys.get("seamark:buoy_safe_water:name")); //$NON-NLS-1$
59 else if (keys.containsKey("seamark:beacon_safe_water:name")) //$NON-NLS-1$
60 setName(keys.get("seamark:beacon_safe_water:name")); //$NON-NLS-1$
61 else if (keys.containsKey("seamark:light_float:name")) //$NON-NLS-1$
62 setName(keys.get("seamark:light_float:name")); //$NON-NLS-1$
63
64 if (keys.containsKey("seamark:buoy_safe_water:shape")) { //$NON-NLS-1$
65 str = keys.get("seamark:buoy_safe_water:shape"); //$NON-NLS-1$
66
67 if (str.equals("pillar")) //$NON-NLS-1$
68 setStyleIndex(SAFE_PILLAR);
69 else if (str.equals("spar")) //$NON-NLS-1$
70 setStyleIndex(SAFE_SPAR);
71 else if (str.equals("sphere")) //$NON-NLS-1$
72 setStyleIndex(SAFE_SPHERE);
73 } else if ((keys.containsKey("seamark:type")) //$NON-NLS-1$
74 && (keys.get("seamark:type").equals("light_float"))) { //$NON-NLS-1$ //$NON-NLS-2$
75 setStyleIndex(SAFE_FLOAT);
76 } else if ((keys.containsKey("seamark:type")) //$NON-NLS-1$
77 && (keys.get("seamark:type").equals("beacon_safe_water"))) { //$NON-NLS-1$ //$NON-NLS-2$
78 setStyleIndex(SAFE_BEACON);
79 }
80
81 if (getStyleIndex() >= dlg.cbM01StyleOfMark.getItemCount())
82 setStyleIndex(0);
83
84 if (keys.containsKey("seamark:topmark:shape") //$NON-NLS-1$
85 || keys.containsKey("seamark:topmark:colour")) { //$NON-NLS-1$
86 setTopMark(true);
87 }
88
89 refreshLights();
90 parseLights(keys);
91 parseFogRadar(keys);
92
93 dlg.cbM01StyleOfMark.setSelectedIndex(getStyleIndex());
94 dlg.tfM01Name.setText(getName());
95 dlg.cM01TopMark.setSelected(hasTopMark());
96 }
97
98 public void refreshLights() {
99 dlg.cbM01Kennung.removeAllItems();
100 dlg.cbM01Kennung.addItem(Messages.getString("SmpDialogAction.212")); //$NON-NLS-1$
101 dlg.cbM01Kennung.addItem("Iso"); //$NON-NLS-1$
102 dlg.cbM01Kennung.addItem("Oc"); //$NON-NLS-1$
103 dlg.cbM01Kennung.addItem("LFl"); //$NON-NLS-1$
104 dlg.cbM01Kennung.addItem("Mo"); //$NON-NLS-1$
105 dlg.cbM01Kennung.setSelectedIndex(0);
106 }
107
108 public boolean isValid() {
109 return (getBuoyIndex() > 0) && (getStyleIndex() > 0);
110 }
111
112 public void setLightColour() {
113 super.setLightColour("W"); //$NON-NLS-1$
114 }
115
116 public void paintSign() {
117 if (dlg.paintlock)
118 return;
119 super.paintSign();
120
121 dlg.sM01StatusBar.setText(getErrMsg());
122
123 if (isValid()) {
124 dlg.tfM01Name.setEnabled(true);
125 dlg.tfM01Name.setText(getName());
126 dlg.cM01TopMark.setEnabled(true);
127 dlg.cM01TopMark.setVisible(true);
128 dlg.cM01Radar.setVisible(true);
129 dlg.cM01Racon.setVisible(true);
130 dlg.cM01Fog.setVisible(true);
131 dlg.cM01Fired.setVisible(true);
132 dlg.cM01Fired.setEnabled(true);
133 if (!isSectored()) {
134 dlg.cbM01Colour.setVisible(false);
135 dlg.lM01Colour.setVisible(false);
136 }
137 dlg.rbM01Fired1.setVisible(false);
138 dlg.rbM01FiredN.setVisible(false);
139 dlg.lM01Height.setVisible(false);
140 dlg.tfM01Height.setVisible(false);
141 dlg.lM01Range.setVisible(false);
142 dlg.tfM01Range.setVisible(false);
143
144 if (isFired()) {
145 switch (getStyleIndex()) {
146 case SAFE_FLOAT:
147 case SAFE_BEACON:
148 dlg.lM01Height.setVisible(true);
149 dlg.tfM01Height.setVisible(true);
150 dlg.lM01Range.setVisible(true);
151 dlg.tfM01Range.setVisible(true);
152 break;
153 default:
154 }
155 }
156
157 String image = "/images/Safe_Water"; //$NON-NLS-1$
158
159 switch (getStyleIndex()) {
160 case SAFE_PILLAR:
161 image += "_Pillar"; //$NON-NLS-1$
162 break;
163 case SAFE_SPAR:
164 image += "_Spar"; //$NON-NLS-1$
165 break;
166 case SAFE_SPHERE:
167 image += "_Sphere"; //$NON-NLS-1$
168 break;
169 case SAFE_BEACON:
170 image += "_Beacon"; //$NON-NLS-1$
171 break;
172 case SAFE_FLOAT:
173 image += "_Float"; //$NON-NLS-1$
174 break;
175 default:
176 }
177
178 if (!image.equals("/images/Safe_Water")) { //$NON-NLS-1$
179 image += ".png"; //$NON-NLS-1$
180 dlg.lM01Icon.setIcon(new ImageIcon(getClass().getResource(image)));
181 if (hasTopMark()) {
182 image = "";
183 switch (getStyleIndex()) {
184 case SAFE_PILLAR:
185 case SAFE_SPAR:
186 image = "/images/Top_Sphere_Red_Buoy.png"; //$NON-NLS-1$
187 break;
188 case SAFE_SPHERE:
189 image = "/images/Top_Sphere_Red_Buoy_Small.png"; //$NON-NLS-1$
190 break;
191 case SAFE_BEACON:
192 image = "/images/Top_Sphere_Red_Beacon.png"; //$NON-NLS-1$
193 break;
194 case SAFE_FLOAT:
195 image = "/images/Top_Sphere_Red_Float.png"; //$NON-NLS-1$
196 break;
197 }
198 if (!image.isEmpty())
199 dlg.lM06Icon.setIcon(new ImageIcon(getClass().getResource(image)));
200 }
201 } else
202 dlg.lM01Icon.setIcon(null);
203 }
204 }
205
206 public void saveSign() {
207 Node node = getNode();
208
209 if (node == null) {
210 return;
211 }
212
213 switch (getStyleIndex()) {
214 case SAFE_PILLAR:
215 super.saveSign("buoy_safe_water"); //$NON-NLS-1$
216 Main.main.undoRedo.add(new ChangePropertyCommand(node,
217 "seamark:buoy_safe_water:shape", "pillar")); //$NON-NLS-1$ //$NON-NLS-2$
218 break;
219 case SAFE_SPAR:
220 super.saveSign("buoy_safe_water"); //$NON-NLS-1$
221 Main.main.undoRedo.add(new ChangePropertyCommand(node,
222 "seamark:buoy_safe_water:shape", "spar")); //$NON-NLS-1$ //$NON-NLS-2$
223 break;
224 case SAFE_SPHERE:
225 super.saveSign("buoy_safe_water"); //$NON-NLS-1$
226 Main.main.undoRedo.add(new ChangePropertyCommand(node,
227 "seamark:buoy_safe_water:shape", "sphere")); //$NON-NLS-1$ //$NON-NLS-2$
228 break;
229 case SAFE_BEACON:
230 super.saveSign("beacon_safe_water"); //$NON-NLS-1$
231 break;
232 case SAFE_FLOAT:
233 super.saveSign("light_float"); //$NON-NLS-1$
234 break;
235 default:
236 }
237
238 switch (getStyleIndex()) {
239 case SAFE_PILLAR:
240 case SAFE_SPAR:
241 case SAFE_SPHERE:
242 Main.main.undoRedo.add(new ChangePropertyCommand(node,
243 "seamark:buoy_safe_water:colour_pattern", "vertical stripes")); //$NON-NLS-1$ //$NON-NLS-2$
244 Main.main.undoRedo.add(new ChangePropertyCommand(node,
245 "seamark:buoy_safe_water:colour", "red;white")); //$NON-NLS-1$ //$NON-NLS-2$
246 break;
247 case SAFE_BEACON:
248 Main.main.undoRedo.add(new ChangePropertyCommand(node,
249 "seamark:beacon_safe_water:colour_pattern", "vertical stripes")); //$NON-NLS-1$ //$NON-NLS-2$
250 Main.main.undoRedo.add(new ChangePropertyCommand(node,
251 "seamark:beacon_safe_water:colour", "red;white")); //$NON-NLS-1$ //$NON-NLS-2$
252 break;
253 case SAFE_FLOAT:
254 Main.main.undoRedo.add(new ChangePropertyCommand(node,
255 "seamark:light_float:colour_pattern", "vertical stripes")); //$NON-NLS-1$ //$NON-NLS-2$
256 Main.main.undoRedo.add(new ChangePropertyCommand(node,
257 "seamark:light_float:colour", "red;white")); //$NON-NLS-1$ //$NON-NLS-2$
258 break;
259 default:
260 }
261 saveTopMarkData("sphere", "red"); //$NON-NLS-1$ //$NON-NLS-2$
262 saveLightData(); //$NON-NLS-1$
263 saveRadarFogData();
264 }
265}
Note: See TracBrowser for help on using the repository browser.