gvsig-raster / org.gvsig.raster.wms / branches / org.gvsig.raster.wms_dataaccess_refactoring / org.gvsig.raster.wms.io / src / main / java / org / gvsig / raster / wms / io / WMSLayerNode.java @ 2378
History | View | Annotate | Download (12.8 KB)
1 | 470 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.raster.wms.io; |
||
23 | |||
24 | import java.awt.Dimension; |
||
25 | import java.util.ArrayList; |
||
26 | 763 | nbrodin | import java.util.List; |
27 | 470 | nbrodin | |
28 | import org.gvsig.raster.wms.io.time.DefaultDimension; |
||
29 | import org.gvsig.raster.wms.io.time.RemoteTimeDimension; |
||
30 | import org.gvsig.raster.wms.io.time.TimeDimension; |
||
31 | 763 | nbrodin | import org.gvsig.tools.ToolsLocator; |
32 | import org.gvsig.tools.dynobject.DynStruct; |
||
33 | import org.gvsig.tools.persistence.PersistenceManager; |
||
34 | import org.gvsig.tools.persistence.Persistent; |
||
35 | import org.gvsig.tools.persistence.PersistentState; |
||
36 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
37 | 470 | nbrodin | |
38 | /**
|
||
39 | * Class defining the node of the layer tree of a common WMS service.
|
||
40 | * @author jaume
|
||
41 | */
|
||
42 | @SuppressWarnings("unchecked") |
||
43 | 763 | nbrodin | public class WMSLayerNode implements Persistent { |
44 | 470 | nbrodin | private String _name = null; |
45 | private String _title = null; |
||
46 | 2378 | nbrodin | private List<String> srs = null; |
47 | 470 | nbrodin | private boolean queryable; |
48 | private boolean transparency; |
||
49 | private String lAbstract = null; |
||
50 | private String latLonBox = null; |
||
51 | private int selectedStyleIndex = 0; |
||
52 | 2378 | nbrodin | private List<RemoteWMSStyle> styles = new ArrayList<RemoteWMSStyle>(); |
53 | private List<RemoteTimeDimension> dimensions = null; |
||
54 | private List<String> keywords = null; |
||
55 | private List<WMSLayerNode> children = new ArrayList<WMSLayerNode>(); |
||
56 | 470 | nbrodin | private WMSLayerNode _parent = null; |
57 | private Dimension fixedSize = null; |
||
58 | 763 | nbrodin | |
59 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
60 | this._name = state.getString("_name"); |
||
61 | this._title = state.getString("_title"); |
||
62 | 2378 | nbrodin | this.srs = state.getList("srs"); |
63 | 763 | nbrodin | this.queryable = state.getBoolean("queryable"); |
64 | this.transparency = state.getBoolean("transparency"); |
||
65 | this.lAbstract = state.getString("lAbstract"); |
||
66 | this.latLonBox = state.getString("latLonBox"); |
||
67 | 766 | nbrodin | this.selectedStyleIndex = state.getInt("selectedStyleIndex"); |
68 | 2378 | nbrodin | this.styles = state.getList("styles"); |
69 | this.dimensions = state.getList("dimensions"); |
||
70 | this.keywords = state.getList("keywords"); |
||
71 | this.children = state.getList("children"); |
||
72 | 763 | nbrodin | this._parent = (WMSLayerNode)state.get("_parent"); |
73 | this.fixedSize = (Dimension)state.get("fixedSize"); |
||
74 | } |
||
75 | |||
76 | public void saveToState(PersistentState state) throws PersistenceException { |
||
77 | state.set("_name", _name);
|
||
78 | state.set("_title", _title);
|
||
79 | state.set("srs", srs);
|
||
80 | state.set("queryable", queryable);
|
||
81 | state.set("transparency", transparency);
|
||
82 | state.set("lAbstract", lAbstract);
|
||
83 | state.set("latLonBox", latLonBox);
|
||
84 | state.set("selectedStyleIndex", selectedStyleIndex);
|
||
85 | state.set("styles", styles);
|
||
86 | state.set("dimensions", dimensions);
|
||
87 | state.set("keywords", keywords);
|
||
88 | state.set("children", children);
|
||
89 | state.set("_parent", _parent);
|
||
90 | state.set("fixedSize", fixedSize);
|
||
91 | } |
||
92 | |||
93 | public static void registerPersistent() { |
||
94 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
95 | DynStruct definition = manager.getDefinition("WMSLayerNode_Persistent");
|
||
96 | if( definition == null ) { |
||
97 | definition = manager.addDefinition( |
||
98 | WMSLayerNode.class, |
||
99 | "WMSLayerNode_Persistent",
|
||
100 | "WMSLayerNode Persistence",
|
||
101 | null,
|
||
102 | null
|
||
103 | ); |
||
104 | } |
||
105 | 470 | nbrodin | |
106 | 763 | nbrodin | definition.addDynFieldString("_name").setMandatory(false); |
107 | definition.addDynFieldString("_title").setMandatory(false); |
||
108 | definition.addDynFieldList("srs").setClassOfItems(String.class).setMandatory(false); |
||
109 | definition.addDynFieldBoolean("queryable").setMandatory(false); |
||
110 | definition.addDynFieldBoolean("transparency").setMandatory(false); |
||
111 | definition.addDynFieldString("lAbstract").setMandatory(false); |
||
112 | definition.addDynFieldString("latLonBox").setMandatory(false); |
||
113 | definition.addDynFieldInt("selectedStyleIndex").setMandatory(false); |
||
114 | definition.addDynFieldList("styles").setClassOfItems(RemoteWMSStyle.class).setMandatory(false); |
||
115 | definition.addDynFieldList("dimensions").setClassOfItems(RemoteTimeDimension.class).setMandatory(false); |
||
116 | definition.addDynFieldList("keywords").setClassOfItems(String.class).setMandatory(false); |
||
117 | definition.addDynFieldList("children").setClassOfItems(WMSLayerNode.class).setMandatory(false); |
||
118 | definition.addDynFieldObject("_parent").setClassOfValue(WMSLayerNode.class).setMandatory(false); |
||
119 | definition.addDynFieldObject("fixedSize").setClassOfValue(Dimension.class).setMandatory(false); |
||
120 | } |
||
121 | |||
122 | 470 | nbrodin | /**
|
123 | * @return Returns the name.
|
||
124 | */
|
||
125 | public String getName() { |
||
126 | return _name;
|
||
127 | } |
||
128 | |||
129 | 2378 | nbrodin | public List<WMSLayerNode> getChildren() { |
130 | 470 | nbrodin | return children;
|
131 | } |
||
132 | |||
133 | /**
|
||
134 | * @param name The name to set.
|
||
135 | */
|
||
136 | public void setName(String name) { |
||
137 | this._name = name;
|
||
138 | } |
||
139 | |||
140 | /**
|
||
141 | * @return Returns the namedStyles.
|
||
142 | */
|
||
143 | 2378 | nbrodin | public List<RemoteWMSStyle> getStyles() { |
144 | 470 | nbrodin | return styles;
|
145 | } |
||
146 | |||
147 | 2378 | nbrodin | public List<String> getKeywords() { |
148 | 470 | nbrodin | return keywords;
|
149 | } |
||
150 | |||
151 | /**
|
||
152 | * @return Returns the queryable.
|
||
153 | */
|
||
154 | public boolean isQueryable() { |
||
155 | return queryable;
|
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * @param queryable The queryable to set.
|
||
160 | */
|
||
161 | public void setQueryable(boolean queryable) { |
||
162 | this.queryable = queryable;
|
||
163 | } |
||
164 | |||
165 | /**
|
||
166 | * @return Returns the srs.
|
||
167 | */
|
||
168 | 2378 | nbrodin | public List<String> getAllSrs() { |
169 | 470 | nbrodin | if ((srs.size() == 0) && _parent!=null) |
170 | return _parent.getAllSrs();
|
||
171 | return srs;
|
||
172 | } |
||
173 | |||
174 | /**
|
||
175 | * @param srs The srs to set.
|
||
176 | */
|
||
177 | 2378 | nbrodin | public void setSrs(List<String> srs) { |
178 | 470 | nbrodin | this.srs = srs;
|
179 | } |
||
180 | |||
181 | /**
|
||
182 | * @return Returns the title.
|
||
183 | */
|
||
184 | public String getTitle() { |
||
185 | return _title;
|
||
186 | } |
||
187 | |||
188 | public void setTitle(String title) { |
||
189 | this._title = title.trim();
|
||
190 | } |
||
191 | |||
192 | /**
|
||
193 | * @return Returns the transparency.
|
||
194 | */
|
||
195 | public boolean isTransparent() { |
||
196 | return transparency;
|
||
197 | } |
||
198 | |||
199 | /**
|
||
200 | * @param transparency The transparency to set.
|
||
201 | */
|
||
202 | public void setTransparency(boolean transparency) { |
||
203 | this.transparency = transparency;
|
||
204 | } |
||
205 | |||
206 | /**
|
||
207 | * Sets the list of sons of this layer.
|
||
208 | * @param children
|
||
209 | */
|
||
210 | 2378 | nbrodin | public void setChildren(List<WMSLayerNode> children) { |
211 | 470 | nbrodin | this.children = children;
|
212 | } |
||
213 | |||
214 | public WMSLayerNode getParent() {
|
||
215 | return _parent;
|
||
216 | } |
||
217 | |||
218 | public void setParent(WMSLayerNode parentNode) { |
||
219 | this._parent = parentNode;
|
||
220 | } |
||
221 | |||
222 | 2378 | nbrodin | public List<RemoteTimeDimension> getDimensions() { |
223 | 470 | nbrodin | return dimensions;
|
224 | } |
||
225 | |||
226 | /**
|
||
227 | * Gets the layer abstract.
|
||
228 | *
|
||
229 | * @return Returns the abstract.
|
||
230 | */
|
||
231 | public String getAbstract() { |
||
232 | return lAbstract;
|
||
233 | } |
||
234 | |||
235 | /**
|
||
236 | * Sets the layer abstract.
|
||
237 | *
|
||
238 | * @param abstract The abstract to set.
|
||
239 | */
|
||
240 | public void setAbstract(String _abstract) { |
||
241 | lAbstract = _abstract; |
||
242 | } |
||
243 | |||
244 | /**
|
||
245 | * @param name
|
||
246 | * @param units
|
||
247 | * @param unitSymbol
|
||
248 | * @param dimensionExpression
|
||
249 | */
|
||
250 | public void addDimension(String name, String units, String unitSymbol, String dimExpression) { |
||
251 | if (dimensions == null) |
||
252 | dimensions = new ArrayList<RemoteTimeDimension>(); |
||
253 | if (name.equalsIgnoreCase("time")) { |
||
254 | try {
|
||
255 | dimensions.add(new TimeDimension(units, unitSymbol,
|
||
256 | dimExpression)); |
||
257 | } catch (IllegalArgumentException e) { |
||
258 | // The TIME class does not yet support this kind of time so it
|
||
259 | // will be treated as a DefaultDimension
|
||
260 | dimensions.add(new DefaultDimension(name.toUpperCase(),
|
||
261 | units, unitSymbol, dimExpression)); |
||
262 | } |
||
263 | } else if (name.equalsIgnoreCase("sequence")) { |
||
264 | // TODO Not yet implemented
|
||
265 | return;
|
||
266 | } else {
|
||
267 | dimensions.add(new DefaultDimension(name.toUpperCase(), units,
|
||
268 | unitSymbol, dimExpression)); |
||
269 | } |
||
270 | |||
271 | } |
||
272 | |||
273 | |||
274 | public void setLatLonBox(String _latLonBox) { |
||
275 | latLonBox = _latLonBox; |
||
276 | } |
||
277 | |||
278 | public String getLatLonBox() { |
||
279 | return latLonBox;
|
||
280 | } |
||
281 | |||
282 | /**
|
||
283 | * When a server cannot renderize images but just server them in constant size and
|
||
284 | * BBox, the layer must have this value set in order to correctly work.
|
||
285 | *
|
||
286 | * @param fixedWidth - the constant value for the image width
|
||
287 | * @param fixedHeight - the constant value for the image height
|
||
288 | */
|
||
289 | public void setFixedSize(int fixedWidth, int fixedHeight) { |
||
290 | fixedSize = new Dimension(fixedWidth, fixedHeight); |
||
291 | } |
||
292 | |||
293 | /*
|
||
294 | * (non-Javadoc)
|
||
295 | * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getFixedSize()
|
||
296 | */
|
||
297 | public Dimension getFixedSize() { |
||
298 | return fixedSize;
|
||
299 | } |
||
300 | |||
301 | /*
|
||
302 | * (non-Javadoc)
|
||
303 | * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#isSizeFixed()
|
||
304 | */
|
||
305 | public boolean isSizeFixed() { |
||
306 | return fixedSize != null && |
||
307 | fixedSize.getWidth() > 0 &&
|
||
308 | fixedSize.getHeight() > 0;
|
||
309 | } |
||
310 | |||
311 | /**
|
||
312 | *
|
||
313 | * @param _name
|
||
314 | * @param _title
|
||
315 | * @param _abstract
|
||
316 | */
|
||
317 | public void addStyle(org.gvsig.remoteclient.wms.WMSStyle style) { |
||
318 | if (style.getName().equalsIgnoreCase("default")) |
||
319 | selectedStyleIndex = styles.size(); |
||
320 | if (styles == null) |
||
321 | styles = new ArrayList<RemoteWMSStyle>(); |
||
322 | styles.add(new RemoteWMSStyle(style, this)); |
||
323 | |||
324 | } |
||
325 | |||
326 | /*
|
||
327 | * (non-Javadoc)
|
||
328 | * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getSelectedStyle()
|
||
329 | */
|
||
330 | public RemoteWMSStyle getSelectedStyle() {
|
||
331 | if (styles == null || selectedStyleIndex > styles.size() - 1 || selectedStyleIndex == -1) |
||
332 | return null; |
||
333 | return (RemoteWMSStyle) styles.get(selectedStyleIndex);
|
||
334 | } |
||
335 | |||
336 | /*
|
||
337 | * (non-Javadoc)
|
||
338 | * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setSelectedStyleByIndex(int)
|
||
339 | */
|
||
340 | public void setSelectedStyleByIndex(int index) { |
||
341 | selectedStyleIndex = index; |
||
342 | } |
||
343 | |||
344 | /*
|
||
345 | * (non-Javadoc)
|
||
346 | * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setSelectedStyleByName(java.lang.String)
|
||
347 | */
|
||
348 | public void setSelectedStyleByName(String styName) { |
||
349 | if (styName == null || styName.equals("")) |
||
350 | setSelectedStyleByIndex(-1);
|
||
351 | for (int i = 0; i < styles.size(); i++) { |
||
352 | RemoteWMSStyle sty = (RemoteWMSStyle) styles.get(i); |
||
353 | if (sty.name.equals(styName)) {
|
||
354 | setSelectedStyleByIndex(i); |
||
355 | return;
|
||
356 | } |
||
357 | |||
358 | } |
||
359 | setSelectedStyleByIndex(-1);
|
||
360 | } |
||
361 | |||
362 | public void addKeyword(String keyword) { |
||
363 | if (keywords == null) |
||
364 | keywords = new ArrayList<String>(); |
||
365 | keywords.add(keyword); |
||
366 | } |
||
367 | |||
368 | public String toString(){ |
||
369 | String str;
|
||
370 | if (getName()==null) |
||
371 | str = getTitle(); |
||
372 | else
|
||
373 | str = "["+getName()+"] "+getTitle(); |
||
374 | return str;
|
||
375 | } |
||
376 | |||
377 | /*
|
||
378 | * (non-Javadoc)
|
||
379 | * @see java.lang.Object#clone()
|
||
380 | */
|
||
381 | public Object clone() throws CloneNotSupportedException { |
||
382 | WMSLayerNode clone = new WMSLayerNode();
|
||
383 | clone._name = this._name;
|
||
384 | clone.queryable = this.queryable;
|
||
385 | clone.srs = this.srs;
|
||
386 | clone._title = this._title;
|
||
387 | clone.transparency = this.transparency;
|
||
388 | clone.styles = new ArrayList<RemoteWMSStyle>(); |
||
389 | clone.lAbstract = this.lAbstract;
|
||
390 | clone.latLonBox = this.latLonBox;
|
||
391 | clone.selectedStyleIndex = this.selectedStyleIndex;
|
||
392 | |||
393 | if (keywords != null) { |
||
394 | clone.keywords = new ArrayList<String>(keywords.size()); |
||
395 | for (int i = 0; i < keywords.size(); i++) { |
||
396 | clone.keywords.add((String) keywords.get(i));
|
||
397 | } |
||
398 | } |
||
399 | if (styles != null) |
||
400 | for (int i=0; i<styles.size(); i++){ |
||
401 | RemoteWMSStyle sty = (RemoteWMSStyle) this.styles.get(i).clone();
|
||
402 | ((RemoteWMSStyle)sty).parent = this;
|
||
403 | clone.styles.add(sty); |
||
404 | } |
||
405 | |||
406 | if (dimensions!=null) |
||
407 | for (int i = 0; i < dimensions.size(); i++) { |
||
408 | clone.dimensions = new ArrayList<RemoteTimeDimension>(); |
||
409 | clone.dimensions.add((RemoteTimeDimension) this.dimensions.get(i));
|
||
410 | } |
||
411 | |||
412 | return clone;
|
||
413 | } |
||
414 | |||
415 | } |