Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / datastruct / WMSLayerNode.java @ 239

History | View | Annotate | Download (11 KB)

1
/* 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.impl.datastruct;
23

    
24
import java.awt.Dimension;
25
import java.util.ArrayList;
26
import java.util.Vector;
27

    
28
import org.gvsig.fmap.dal.coverage.datastruct.RemoteStyle;
29
import org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode;
30
import org.gvsig.fmap.dal.coverage.store.remote.RemoteTimeDimension;
31
import org.gvsig.raster.util.DefaultDimension;
32
import org.gvsig.raster.util.TimeDimension;
33

    
34
/**
35
 * Class defining the node of the layer tree of a common WMS service.
36
 * @author jaume
37
 */
38
@SuppressWarnings("unchecked")
39
public class WMSLayerNode implements RemoteLayerNode {
40
    private String                         _name              = null;
41
    private String                         _title             = null;
42
        private Vector                         srs                = null;
43
    private boolean                        queryable;
44
    private boolean                        transparency;
45
    private String                         lAbstract          = null;
46
    private String                         latLonBox          = null;
47
    private int                            selectedStyleIndex = 0;
48
    private ArrayList<RemoteStyle>         styles             = new ArrayList<RemoteStyle>();
49
    private ArrayList<RemoteTimeDimension> dimensions         = null;
50
    private ArrayList<String>              keywords           = null;
51
    private ArrayList                      children           = new ArrayList();
52
    private RemoteLayerNode                _parent            = null;
53
        private Dimension                      fixedSize          = null;
54

    
55
    /*
56
     * (non-Javadoc)
57
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getName()
58
     */
59
    public String getName() {
60
        return _name;
61
    }
62

    
63
    /*
64
     * (non-Javadoc)
65
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getChildren()
66
     */
67
    public ArrayList getChildren() {
68
        return children;
69
    }
70

    
71
    /**
72
     * @param name The name to set.
73
     */
74
    public void setName(String name) {
75
        this._name = name;
76
    }
77

    
78
    /**
79
     * @return Returns the namedStyles.
80
     */
81
    public ArrayList<RemoteStyle> getStyles() {
82
        return styles;
83
    }
84

    
85
    public ArrayList<String> getKeywords(){
86
            return keywords;
87
    }
88
   
89
    /*
90
     * (non-Javadoc)
91
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#isQueryable()
92
     */
93
    public boolean isQueryable() {
94
        return queryable;
95
    }
96

    
97
    /**
98
     * @param queryable The queryable to set.
99
     */
100
    public void setQueryable(boolean queryable) {
101
        this.queryable = queryable;
102
    }
103
    
104
    /*
105
     * (non-Javadoc)
106
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getAllSrs()
107
     */
108
    public Vector getAllSrs() {
109
        if ((srs.size() == 0) && _parent!=null)
110
            return _parent.getAllSrs();
111
        return srs;
112
    }
113

    
114
    /**
115
     * @param srs The srs to set.
116
     */
117
    public void setSrs(Vector srs) {
118
        this.srs = srs;
119
    }
120

    
121
    /*
122
     * (non-Javadoc)
123
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getTitle()
124
     */
125
    public String getTitle() {
126
        return _title;
127
    }
128

    
129
    /*
130
     * (non-Javadoc)
131
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setTitle(java.lang.String)
132
     */
133
    public void setTitle(String title) {
134
        this._title = title.trim();
135
    }
136

    
137
   /*
138
    * (non-Javadoc)
139
    * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#isTransparent()
140
    */
141
    public boolean isTransparent() {
142
        return transparency;
143
    }
144

    
145
    /**
146
     * @param transparency The transparency to set.
147
     */
148
    public void setTransparency(boolean transparency) {
149
        this.transparency = transparency;
150
    }
151

    
152
    /**
153
     * Sets the list of sons of this layer.
154
     * @param children
155
     */
156
    public void setChildren(ArrayList children) {
157
        this.children = children;
158
    }
159

    
160
    /*
161
     * (non-Javadoc)
162
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getParent()
163
     */
164
    public RemoteLayerNode getParent() {
165
        return _parent;
166
    }
167
    
168
    /*
169
     * (non-Javadoc)
170
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setParent(org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode)
171
     */
172
    public void setParent(RemoteLayerNode parentNode) {
173
        this._parent = parentNode;
174
    }
175

    
176
    /*
177
     * (non-Javadoc)
178
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getDimensions()
179
     */
180
    public ArrayList<RemoteTimeDimension> getDimensions() {
181
        return dimensions;
182
    }
183

    
184
    /**
185
     * Gets the layer abstract.
186
     *
187
     * @return Returns the abstract.
188
     */
189
    public String getAbstract() {
190
        return lAbstract;
191
    }
192

    
193
    /**
194
     * Sets the layer abstract.
195
     *
196
     * @param abstract The abstract to set.
197
     */
198
    public void setAbstract(String _abstract) {
199
        lAbstract = _abstract;
200
    }
201

    
202
    /**
203
     * @param name
204
     * @param units
205
     * @param unitSymbol
206
     * @param dimensionExpression
207
     */
208
    public void addDimension(String name, String units, String unitSymbol, String dimExpression) {
209
            if (dimensions == null)
210
                    dimensions = new ArrayList<RemoteTimeDimension>();
211
            if (name.equalsIgnoreCase("time")) {
212
                    try {
213
                            dimensions.add(new TimeDimension(units, unitSymbol,
214
                                            dimExpression));
215
                    } catch (IllegalArgumentException e) {
216
                            // The TIME class does not yet support this kind of time so it
217
                            // will be treated as a DefaultDimension
218
                            dimensions.add(new DefaultDimension(name.toUpperCase(),
219
                                            units, unitSymbol, dimExpression));
220
                    }
221
            } else if (name.equalsIgnoreCase("sequence")) {
222
                    // TODO Not yet implemented
223
                    return;
224
            } else {
225
                    dimensions.add(new DefaultDimension(name.toUpperCase(), units,
226
                                    unitSymbol, dimExpression));
227
            }
228

    
229
    }
230

    
231
    /*
232
     * (non-Javadoc)
233
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setLatLonBox(java.lang.String)
234
     */
235
    public void setLatLonBox(String _latLonBox) {
236
        latLonBox = _latLonBox;
237
    }
238

    
239
    /*
240
     * (non-Javadoc)
241
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getLatLonBox()
242
     */
243
    public String getLatLonBox() {
244
        return latLonBox;
245
    }
246

    
247
    /**
248
     * When a server cannot renderize images but just server them in constant size and
249
     * BBox, the layer must have this value set in order to correctly work.
250
     *
251
     * @param fixedWidth - the constant value for the image width
252
     * @param fixedHeight - the constant value for the image height
253
     */
254
    public void setFixedSize(int fixedWidth, int fixedHeight) {
255
                fixedSize = new Dimension(fixedWidth, fixedHeight);
256
        }
257

    
258
   /*
259
    * (non-Javadoc)
260
    * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getFixedSize()
261
    */
262
        public Dimension getFixedSize() {
263
                return fixedSize;
264
        }
265

    
266
        /*
267
         * (non-Javadoc)
268
         * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#isSizeFixed()
269
         */
270
        public boolean isSizeFixed() {
271
                return fixedSize            != null &&
272
                       fixedSize.getWidth()  > 0    &&
273
                       fixedSize.getHeight() > 0;
274
        }
275

    
276
    /**
277
     *
278
     * @param _name
279
     * @param _title
280
     * @param _abstract
281
     */
282
    public void addStyle(org.gvsig.remoteclient.wms.WMSStyle style) {
283
            if (style.getName().equalsIgnoreCase("default"))
284
                    selectedStyleIndex = styles.size();
285
        if (styles==null)
286
            styles = new ArrayList<RemoteStyle>();
287
        styles.add(new DefaultWMSStyle(style, this));
288

    
289
    }
290

    
291
    /*
292
     * (non-Javadoc)
293
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#getSelectedStyle()
294
     */
295
    public RemoteStyle getSelectedStyle() {
296
            if (styles == null || selectedStyleIndex > styles.size() - 1 || selectedStyleIndex == -1)
297
                    return null;
298
            return (RemoteStyle) styles.get(selectedStyleIndex);
299
    }
300

    
301
    /*
302
     * (non-Javadoc)
303
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setSelectedStyleByIndex(int)
304
     */
305
    public void setSelectedStyleByIndex(int index) {
306
                selectedStyleIndex = index;
307
        }
308

    
309
    /*
310
     * (non-Javadoc)
311
     * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteLayerNode#setSelectedStyleByName(java.lang.String)
312
     */
313
        public void setSelectedStyleByName(String styName) {
314
                if (styName == null || styName.equals(""))
315
                        setSelectedStyleByIndex(-1);
316
                for (int i = 0; i < styles.size(); i++) {
317
                        DefaultWMSStyle sty = (DefaultWMSStyle) styles.get(i);
318
                        if (sty.name.equals(styName)) {
319
                                setSelectedStyleByIndex(i);
320
                                return;
321
                        }
322

    
323
                }
324
                setSelectedStyleByIndex(-1);
325
        }
326

    
327
        public void addKeyword(String keyword) {
328
                if (keywords == null)
329
                        keywords = new ArrayList<String>();
330
                keywords.add(keyword);
331
        }
332

    
333
    public String toString(){
334
            String str;
335
            if (getName()==null)
336
                    str = getTitle();
337
            else
338
                    str = "["+getName()+"] "+getTitle();
339
        return str;
340
    }
341

    
342
    /*
343
     * (non-Javadoc)
344
     * @see java.lang.Object#clone()
345
     */
346
    public Object clone() throws CloneNotSupportedException {
347
        WMSLayerNode clone       = new WMSLayerNode();
348
        clone._name              = this._name;
349
        clone.queryable          = this.queryable;
350
        clone.srs                = this.srs;
351
        clone._title             = this._title;
352
        clone.transparency       = this.transparency;
353
        clone.styles             = new ArrayList<RemoteStyle>();
354
        clone.lAbstract          = this.lAbstract;
355
        clone.latLonBox          = this.latLonBox;
356
        clone.selectedStyleIndex = this.selectedStyleIndex;
357

    
358
        if (keywords != null) {
359
                clone.keywords = new ArrayList<String>(keywords.size());
360
                for (int i = 0; i < keywords.size(); i++) {
361
                                clone.keywords.add((String) keywords.get(i));
362
                        }
363
        }
364
        if (styles != null)
365
                for (int i=0; i<styles.size(); i++){
366
                        RemoteStyle sty = (RemoteStyle) ((DefaultWMSStyle) this.styles.get(i)).clone();
367
                        ((DefaultWMSStyle)sty).parent = this;
368
                        clone.styles.add(sty);
369
                }
370

    
371
        if (dimensions!=null)
372
                for (int i = 0; i < dimensions.size(); i++) {
373
                        clone.dimensions = new ArrayList<RemoteTimeDimension>();
374
                        clone.dimensions.add((RemoteTimeDimension) this.dimensions.get(i));
375
                }
376

    
377
        return clone;
378
    }
379

    
380
}