Statistics
| Revision:

svn-gvsig-desktop / tags / Root_MULTITHREADING_DEVELOPMENT / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / WMSLayerNode.java @ 5232

History | View | Annotate | Download (12.1 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
*
44
* $Id: WMSLayerNode.java 4503 2006-03-21 16:02:06Z jaume $
45
* $Log$
46
* Revision 1.6  2006-03-21 16:02:06  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.5  2006/02/28 15:25:14  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.3.2.9  2006/02/20 15:23:08  jaume
53
* Se muestran algunas de las capas de aes
54
*
55
* Revision 1.3.2.8  2006/02/17 12:57:34  jaume
56
* oculta/eXconde los nombres de las capas y adem?s corrige el error de selecci?n de varios styles si hay alguna capa seleccionada repetida
57
*
58
* Revision 1.3.2.7  2006/02/16 10:36:41  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.3.2.6  2006/02/15 11:50:08  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.3.2.5  2006/02/10 13:22:35  jaume
65
* now analyzes dimensions on demand
66
*
67
* Revision 1.3.2.4  2006/02/02 12:12:54  jaume
68
* se muestra el nombre de la capa (adem?s del t?tulo) en los di?logos
69
*
70
* Revision 1.3.2.3  2006/01/31 16:25:24  jaume
71
* correcciones de bugs
72
*
73
* Revision 1.4  2006/01/26 16:07:14  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.3.2.1  2006/01/26 12:59:32  jaume
77
* 0.5
78
*
79
* Revision 1.3  2006/01/24 18:01:17  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.1.2.11  2006/01/23 12:54:45  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.1.2.10  2006/01/20 15:22:46  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.1.2.9  2006/01/17 12:55:40  jaume
89
* *** empty log message ***
90
*
91
* Revision 1.1.2.8  2006/01/05 23:15:53  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.1.2.7  2006/01/04 18:09:02  jaume
95
* Time dimension
96
*
97
* Revision 1.1.2.6  2006/01/03 18:08:40  jaume
98
* *** empty log message ***
99
*
100
* Revision 1.1.2.5  2006/01/02 18:08:01  jaume
101
* Tree de estilos
102
*
103
* Revision 1.1.2.4  2005/12/30 08:56:19  jaume
104
* *** empty log message ***
105
*
106
* Revision 1.1.2.3  2005/12/29 08:26:54  jaume
107
* some gui issues where fixed
108
*
109
* Revision 1.1.2.2  2005/12/26 16:51:40  jaume
110
* Handles STYLES, layer saving does nothing ??
111
*
112
* Revision 1.1.2.1  2005/12/21 15:59:04  jaume
113
* Refatoring maintenance
114
*
115
*
116
*/
117
/**
118
 * 
119
 */
120
package com.iver.cit.gvsig.fmap.layers;
121

    
122
import java.awt.Dimension;
123
import java.util.ArrayList;
124
import java.util.Vector;
125

    
126
/**
127
 * Class defining the node of the layer tree of a common WMS service.
128
 * @author jaume
129
 *
130
 */
131
public class WMSLayerNode {
132
    private String _name;
133
    private String _title;
134
    private Vector srs;
135
    private boolean queryable;
136
    private boolean transparency;
137
    private String lAbstract;
138
    private String latLonBox;
139
    private int selectedStyleIndex = 0;
140
    private ArrayList styles = new ArrayList();
141
    private ArrayList dimensions;
142
    
143
    private ArrayList children = new ArrayList();
144
    private WMSLayerNode _parent;
145
        private Dimension fixedSize;
146
        
147
    /**
148
     * @return Returns the name.
149
     */
150
    public String getName() {
151
        return _name;
152
    }
153
    
154
    /**
155
     * @return
156
     */
157
    public ArrayList getChildren() {
158
        return children;
159
    }
160
    
161
    /**
162
     * @param name The name to set.
163
     */
164
    public void setName(String name) {
165
        this._name = name;
166
    }
167
    
168
    /**
169
     * @return Returns the namedStyles.
170
     */
171
    public ArrayList getStyles() {
172
        return styles;
173
    }
174
    
175
    /**
176
     * @return Returns the queryable.
177
     */
178
    public boolean isQueryable() {
179
        return queryable;
180
    }
181
    
182
    /**
183
     * @param queryable The queryable to set.
184
     */
185
    public void setQueryable(boolean queryable) {
186
        this.queryable = queryable;
187
    }
188
    /**
189
     * @return Returns the srs.
190
     */
191
    public Vector getAllSrs() {
192
        if ((srs.size() == 0) && _parent!=null)
193
            return _parent.getAllSrs();
194
        return srs;
195
    }
196
    
197
    /**
198
     * @param srs The srs to set.
199
     */
200
    public void setSrs(Vector srs) {
201
        this.srs = srs;
202
    }
203
    
204
    /**
205
     * @return Returns the title.
206
     */
207
    public String getTitle() {
208
        return _title;
209
    }
210
    
211
    /**
212
     * @param title The title to set.
213
     */
214
    public void setTitle(String title) {
215
        this._title = title.trim();
216
    }
217
    
218
    /**
219
     * @return Returns the transparency.
220
     */
221
    public boolean isTransparent() {
222
        return transparency;
223
    }
224
    
225
    /**
226
     * @param transparency The transparency to set.
227
     */
228
    public void setTransparency(boolean transparency) {
229
        this.transparency = transparency;
230
    }
231
    
232
    /**
233
     * Sets the list of sons of this layer.
234
     * @param children
235
     */
236
    public void setChildren(ArrayList children) {
237
        this.children = children;
238
    }
239
    
240
    /**
241
     * returns the layer whose this is son of. 
242
     * @return
243
     */
244
    public WMSLayerNode getParent(){
245
        return _parent;
246
    }
247
    /**
248
     * @param parentNode
249
     */
250
    public void setParent(WMSLayerNode parentNode) {
251
        this._parent = parentNode;
252
    }
253
    
254
    public ArrayList getDimensions(){
255
        return dimensions;
256
    }
257
    
258
    /**
259
     * Gets the layer abstract.
260
     *  
261
     * @return Returns the abstract.
262
     */
263
    public String getAbstract() {
264
        return lAbstract;
265
    }
266
    
267
    /**
268
     * Sets the layer abstract.
269
     * 
270
     * @param abstract The abstract to set.
271
     */
272
    public void setAbstract(String _abstract) {
273
        lAbstract = _abstract;
274
    }
275

    
276
    /**
277
     * @param name
278
     * @param units
279
     * @param unitSymbol
280
     * @param dimensionExpression
281
     */
282
    public void addDimension(String name, String units, String unitSymbol, String dimExpression) {
283
            if (dimensions == null)
284
                    dimensions = new ArrayList();
285
            if (name.equalsIgnoreCase("time")) {
286
                    try {
287
                            dimensions.add(new TimeDimension(units, unitSymbol,
288
                                            dimExpression));
289
                    } catch (IllegalArgumentException e) {
290
                            // The TIME class does not yet support this kind of time so it
291
                            // will be treated as a DefaultDimension
292
                            dimensions.add(new DefaultDimension(name.toUpperCase(),
293
                                            units, unitSymbol, dimExpression));
294
                    }
295
            } else if (name.equalsIgnoreCase("sequence")) {
296
                    // TODO Not yet implemented
297
                    return;
298
            } else {
299
                    dimensions.add(new DefaultDimension(name.toUpperCase(), units,
300
                                    unitSymbol, dimExpression));
301
            }
302
            
303
    }
304

    
305
    /**
306
     * Sets the Latitude-Longitude box text to be shown in an user interface layer descriptor.
307
     * @param latLonBox
308
     */
309
    public void setLatLonBox(String _latLonBox) {
310
        latLonBox = _latLonBox;
311
    }
312
    
313
    /**
314
     * Returns the Latitude-Longitude box text to be shown in an user interface layer descriptor.
315
     * @return
316
     */
317
    public String getLatLonBox() {
318
        return latLonBox;
319
    }
320

    
321
    /**
322
     * When a server cannot renderize images but just server them in constant size and
323
     * BBox, the layer must have this value set in order to correctly work.
324
     * 
325
     * @param fixedWidth - the constant value for the image width
326
     * @param fixedHeight - the constant value for the image height
327
     */
328
    public void setFixedSize(int fixedWidth, int fixedHeight) {
329
                fixedSize = new Dimension(fixedWidth, fixedHeight);
330
        }
331

    
332
    /**
333
     * Returns the size of this layer (which is constant-sized)
334
     * @return
335
     */
336
        public Dimension getFixedSize() {
337
                return fixedSize;
338
        }
339

    
340
        /**
341
         * Tells whether the layer is constant-sized or not.
342
         * @return boolean
343
         */
344
        public boolean isSizeFixed() {
345
                return fixedSize            != null &&
346
                       fixedSize.getWidth()  > 0    &&
347
                       fixedSize.getHeight() > 0;
348
        }
349
        
350
    /**
351
     * 
352
     * @param _name
353
     * @param _title
354
     * @param _abstract
355
     */
356
    public void addStyle(String name, String title, String _abstract) {
357
            if (name.equalsIgnoreCase("default"))
358
                    selectedStyleIndex = styles.size();
359
        if (styles==null)
360
            styles = new ArrayList();
361
        styles.add(new FMapWMSStyle(name, title, _abstract, this));
362
        
363
    }
364
    
365
    /**
366
     * Returns the style marked as selected or null if none.
367
     * @return FMapWMSStyle
368
     */
369
    public FMapWMSStyle getSelectedStyle() {
370
            if (styles == null || selectedStyleIndex > styles.size()-1 || selectedStyleIndex == -1)
371
                    return null;
372
            return (FMapWMSStyle) styles.get(selectedStyleIndex);
373
    }
374
    
375
    /**
376
     * Marks the style of this layer given by the index as selected
377
     * @param inex of the style
378
     */
379
    public void setSelectedStyleByIndex(int index) {
380
                selectedStyleIndex = index;
381
        }
382

    
383
    /**
384
     * Marks the style of this layer given by its name as selected. If
385
     * this layer has no style with this name, then the layer is marked
386
     * as none selected.
387
     * @param style name
388
     */
389
        public void setSelectedStyleByName(String styName) {
390
                if (styName == null || styName.equals(""))
391
                        setSelectedStyleByIndex(-1);
392
                for (int i = 0; i < styles.size(); i++) {
393
                        FMapWMSStyle sty = (FMapWMSStyle) styles.get(i);
394
                        if (sty.name.equals(styName)) {
395
                                setSelectedStyleByIndex(i);
396
                                return;
397
                        }
398
                        
399
                }
400
                setSelectedStyleByIndex(-1);
401
        }
402
    
403
    public String toString(){
404
            String str;
405
            if (getName()==null)
406
                    str = getTitle();
407
            else
408
                    str = "["+getName()+"] "+getTitle();
409
        return str;
410
    }
411
    
412
    /**
413
     * Creates a new instance of WMSLayerNode containing a copy of this, 
414
     * but with no children and parent set.
415
     */
416
    public Object clone(){
417
        WMSLayerNode clone       = new WMSLayerNode();
418
        clone._name              = this._name;
419
        clone.queryable          = this.queryable;
420
        clone.srs                = this.srs;
421
        clone._title             = this._title;
422
        clone.transparency       = this.transparency;
423
        clone.styles             = new ArrayList();
424
        clone.lAbstract          = this.lAbstract;
425
        clone.latLonBox          = this.latLonBox;
426
        clone.selectedStyleIndex = this.selectedStyleIndex;
427
        
428
        if (styles!=null)
429
                for (int i=0; i<styles.size(); i++){
430
                        FMapWMSStyle sty = (FMapWMSStyle) ((FMapWMSStyle) this.styles.get(i)).clone();
431
                        sty.parent = this;
432
                        clone.styles.add(sty);
433
                }
434
        
435
        if (dimensions!=null)
436
                for (int i = 0; i < dimensions.size(); i++) {
437
                        clone.dimensions = new ArrayList();
438
                        clone.dimensions.add((IFMapWMSDimension) this.dimensions.get(i));
439
                }
440
        
441
        return clone;
442
    }
443

    
444
        
445
        /**
446
     * Just a C-struct-like class.
447
     * @author jaume
448
     *
449
     */
450
    public class FMapWMSStyle {
451
        public String name;
452
        public String title;
453
        public String styleAbstract;
454
        public WMSLayerNode parent;
455
        
456
        /**
457
         * Creates a new instance of FMapWMSStyle
458
         * @param name
459
         * @param title
460
         * @param styleAbstract
461
         * @param parent
462
         */
463
        public FMapWMSStyle(String name, String title, String styleAbstract, WMSLayerNode parent){
464
            this.name = name;
465
            this.title = title;
466
            this.styleAbstract = styleAbstract;
467
            this.parent = parent;
468
        }
469
        
470
        public String toString(){
471
            return title;
472
        }
473
        
474
        public Object clone() {
475
            FMapWMSStyle clone = new FMapWMSStyle(this.name, this.title, this.styleAbstract, this.parent);
476
            return clone;
477
        }
478
    }
479
}