Statistics
| Revision:

root / trunk / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / WMSLayerNode.java @ 9554

History | View | Annotate | Download (14.7 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 9554 2007-01-08 07:57:34Z jaume $
45
* $Log$
46
* Revision 1.11  2007-01-08 07:57:34  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.10  2006/05/25 15:46:45  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.8  2006/05/25 10:35:09  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.7  2006/05/25 10:28:12  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.6  2006/03/21 16:02:06  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.5  2006/02/28 15:25:14  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.3.2.9  2006/02/20 15:23:08  jaume
65
* Se muestran algunas de las capas de aes
66
*
67
* Revision 1.3.2.8  2006/02/17 12:57:34  jaume
68
* 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
69
*
70
* Revision 1.3.2.7  2006/02/16 10:36:41  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.3.2.6  2006/02/15 11:50:08  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.3.2.5  2006/02/10 13:22:35  jaume
77
* now analyzes dimensions on demand
78
*
79
* Revision 1.3.2.4  2006/02/02 12:12:54  jaume
80
* se muestra el nombre de la capa (adem?s del t?tulo) en los di?logos
81
*
82
* Revision 1.3.2.3  2006/01/31 16:25:24  jaume
83
* correcciones de bugs
84
*
85
* Revision 1.4  2006/01/26 16:07:14  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.3.2.1  2006/01/26 12:59:32  jaume
89
* 0.5
90
*
91
* Revision 1.3  2006/01/24 18:01:17  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.1.2.11  2006/01/23 12:54:45  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.1.2.10  2006/01/20 15:22:46  jaume
98
* *** empty log message ***
99
*
100
* Revision 1.1.2.9  2006/01/17 12:55:40  jaume
101
* *** empty log message ***
102
*
103
* Revision 1.1.2.8  2006/01/05 23:15:53  jaume
104
* *** empty log message ***
105
*
106
* Revision 1.1.2.7  2006/01/04 18:09:02  jaume
107
* Time dimension
108
*
109
* Revision 1.1.2.6  2006/01/03 18:08:40  jaume
110
* *** empty log message ***
111
*
112
* Revision 1.1.2.5  2006/01/02 18:08:01  jaume
113
* Tree de estilos
114
*
115
* Revision 1.1.2.4  2005/12/30 08:56:19  jaume
116
* *** empty log message ***
117
*
118
* Revision 1.1.2.3  2005/12/29 08:26:54  jaume
119
* some gui issues where fixed
120
*
121
* Revision 1.1.2.2  2005/12/26 16:51:40  jaume
122
* Handles STYLES, layer saving does nothing ??
123
*
124
* Revision 1.1.2.1  2005/12/21 15:59:04  jaume
125
* Refatoring maintenance
126
*
127
*
128
*/
129
/**
130
 *
131
 */
132
package com.iver.cit.gvsig.fmap.layers;
133

    
134
import java.awt.Dimension;
135
import java.lang.reflect.Field;
136
import java.util.ArrayList;
137
import java.util.Vector;
138

    
139
import org.gvsig.remoteClient.wms.WMSStyle;
140

    
141
import com.iver.andami.messages.NotificationManager;
142

    
143
/**
144
 * Class defining the node of the layer tree of a common WMS service.
145
 * @author jaume
146
 *
147
 */
148
public class WMSLayerNode {
149
    private String _name;
150
    private String _title;
151
    private Vector srs;
152
    private boolean queryable;
153
    private boolean transparency;
154
    private String lAbstract;
155
    private String latLonBox;
156
    private int selectedStyleIndex = 0;
157
    private ArrayList styles = new ArrayList();
158
    private ArrayList dimensions;
159
    private ArrayList keywords;
160

    
161
    private ArrayList children = new ArrayList();
162
    private WMSLayerNode _parent;
163
        private Dimension fixedSize;
164

    
165
    /**
166
     * @return Returns the name.
167
     */
168
    public String getName() {
169
        return _name;
170
    }
171

    
172
    /**
173
     * @return
174
     */
175
    public ArrayList getChildren() {
176
        return children;
177
    }
178

    
179
    /**
180
     * @param name The name to set.
181
     */
182
    public void setName(String name) {
183
        this._name = name;
184
    }
185

    
186
    /**
187
     * @return Returns the namedStyles.
188
     */
189
    public ArrayList getStyles() {
190
        return styles;
191
    }
192

    
193
    public ArrayList getKeywords(){
194
            return keywords;
195
    }
196
    /**
197
     * @return Returns the queryable.
198
     */
199
    public boolean isQueryable() {
200
        return queryable;
201
    }
202

    
203
    /**
204
     * @param queryable The queryable to set.
205
     */
206
    public void setQueryable(boolean queryable) {
207
        this.queryable = queryable;
208
    }
209
    /**
210
     * @return Returns the srs.
211
     */
212
    public Vector getAllSrs() {
213
        if ((srs.size() == 0) && _parent!=null)
214
            return _parent.getAllSrs();
215
        return srs;
216
    }
217

    
218
    /**
219
     * @param srs The srs to set.
220
     */
221
    public void setSrs(Vector srs) {
222
        this.srs = srs;
223
    }
224

    
225
    /**
226
     * @return Returns the title.
227
     */
228
    public String getTitle() {
229
        return _title;
230
    }
231

    
232
    /**
233
     * @param title The title to set.
234
     */
235
    public void setTitle(String title) {
236
        this._title = title.trim();
237
    }
238

    
239
    /**
240
     * @return Returns the transparency.
241
     */
242
    public boolean isTransparent() {
243
        return transparency;
244
    }
245

    
246
    /**
247
     * @param transparency The transparency to set.
248
     */
249
    public void setTransparency(boolean transparency) {
250
        this.transparency = transparency;
251
    }
252

    
253
    /**
254
     * Sets the list of sons of this layer.
255
     * @param children
256
     */
257
    public void setChildren(ArrayList children) {
258
        this.children = children;
259
    }
260

    
261
    /**
262
     * returns the layer whose this is son of.
263
     * @return
264
     */
265
    public WMSLayerNode getParent(){
266
        return _parent;
267
    }
268
    /**
269
     * @param parentNode
270
     */
271
    public void setParent(WMSLayerNode parentNode) {
272
        this._parent = parentNode;
273
    }
274

    
275
    public ArrayList getDimensions(){
276
        return dimensions;
277
    }
278

    
279
    /**
280
     * Gets the layer abstract.
281
     *
282
     * @return Returns the abstract.
283
     */
284
    public String getAbstract() {
285
        return lAbstract;
286
    }
287

    
288
    /**
289
     * Sets the layer abstract.
290
     *
291
     * @param abstract The abstract to set.
292
     */
293
    public void setAbstract(String _abstract) {
294
        lAbstract = _abstract;
295
    }
296

    
297
    /**
298
     * @param name
299
     * @param units
300
     * @param unitSymbol
301
     * @param dimensionExpression
302
     */
303
    public void addDimension(String name, String units, String unitSymbol, String dimExpression) {
304
            if (dimensions == null)
305
                    dimensions = new ArrayList();
306
            if (name.equalsIgnoreCase("time")) {
307
                    try {
308
                            dimensions.add(new TimeDimension(units, unitSymbol,
309
                                            dimExpression));
310
                    } catch (IllegalArgumentException e) {
311
                            // The TIME class does not yet support this kind of time so it
312
                            // will be treated as a DefaultDimension
313
                            dimensions.add(new DefaultDimension(name.toUpperCase(),
314
                                            units, unitSymbol, dimExpression));
315
                    }
316
            } else if (name.equalsIgnoreCase("sequence")) {
317
                    // TODO Not yet implemented
318
                    return;
319
            } else {
320
                    dimensions.add(new DefaultDimension(name.toUpperCase(), units,
321
                                    unitSymbol, dimExpression));
322
            }
323

    
324
    }
325

    
326
    /**
327
     * Sets the Latitude-Longitude box text to be shown in an user interface layer descriptor.
328
     * @param latLonBox
329
     */
330
    public void setLatLonBox(String _latLonBox) {
331
        latLonBox = _latLonBox;
332
    }
333

    
334
    /**
335
     * Returns the Latitude-Longitude box text to be shown in an user interface layer descriptor.
336
     * @return
337
     */
338
    public String getLatLonBox() {
339
        return latLonBox;
340
    }
341

    
342
    /**
343
     * When a server cannot renderize images but just server them in constant size and
344
     * BBox, the layer must have this value set in order to correctly work.
345
     *
346
     * @param fixedWidth - the constant value for the image width
347
     * @param fixedHeight - the constant value for the image height
348
     */
349
    public void setFixedSize(int fixedWidth, int fixedHeight) {
350
                fixedSize = new Dimension(fixedWidth, fixedHeight);
351
        }
352

    
353
    /**
354
     * Returns the size of this layer (which is constant-sized)
355
     * @return
356
     */
357
        public Dimension getFixedSize() {
358
                return fixedSize;
359
        }
360

    
361
        /**
362
         * Tells whether the layer is constant-sized or not.
363
         * @return boolean
364
         */
365
        public boolean isSizeFixed() {
366
                return fixedSize            != null &&
367
                       fixedSize.getWidth()  > 0    &&
368
                       fixedSize.getHeight() > 0;
369
        }
370

    
371
    /**
372
     *
373
     * @param _name
374
     * @param _title
375
     * @param _abstract
376
     */
377
    public void addStyle(WMSStyle style) {
378
            if (style.getName().equalsIgnoreCase("default"))
379
                    selectedStyleIndex = styles.size();
380
        if (styles==null)
381
            styles = new ArrayList();
382
        styles.add(new FMapWMSStyle(style, this));
383

    
384
    }
385

    
386
    /**
387
     * Returns the style marked as selected or null if none.
388
     * @return FMapWMSStyle
389
     */
390
    public FMapWMSStyle getSelectedStyle() {
391
            if (styles == null || selectedStyleIndex > styles.size()-1 || selectedStyleIndex == -1)
392
                    return null;
393
            return (FMapWMSStyle) styles.get(selectedStyleIndex);
394
    }
395

    
396
    /**
397
     * Marks the style of this layer given by the index as selected
398
     * @param inex of the style
399
     */
400
    public void setSelectedStyleByIndex(int index) {
401
                selectedStyleIndex = index;
402
        }
403

    
404
    /**
405
     * Marks the style of this layer given by its name as selected. If
406
     * this layer has no style with this name, then the layer is marked
407
     * as none selected.
408
     * @param style name
409
     */
410
        public void setSelectedStyleByName(String styName) {
411
                if (styName == null || styName.equals(""))
412
                        setSelectedStyleByIndex(-1);
413
                for (int i = 0; i < styles.size(); i++) {
414
                        FMapWMSStyle sty = (FMapWMSStyle) styles.get(i);
415
                        if (sty.name.equals(styName)) {
416
                                setSelectedStyleByIndex(i);
417
                                return;
418
                        }
419

    
420
                }
421
                setSelectedStyleByIndex(-1);
422
        }
423

    
424
        public void addKeyword(String keyword) {
425
                if (keywords == null)
426
                        keywords = new ArrayList();
427
                keywords.add(keyword);
428
        }
429

    
430
    public String toString(){
431
            String str;
432
            if (getName()==null)
433
                    str = getTitle();
434
            else
435
                    str = "["+getName()+"] "+getTitle();
436
        return str;
437
    }
438

    
439
    /**
440
     * Creates a new instance of WMSLayerNode containing a copy of this,
441
     * but with no children and parent set.
442
     */
443
    public Object clone(){
444
        WMSLayerNode clone       = new WMSLayerNode();
445
        clone._name              = this._name;
446
        clone.queryable          = this.queryable;
447
        clone.srs                = this.srs;
448
        clone._title             = this._title;
449
        clone.transparency       = this.transparency;
450
        clone.styles             = new ArrayList();
451
        clone.lAbstract          = this.lAbstract;
452
        clone.latLonBox          = this.latLonBox;
453
        clone.selectedStyleIndex = this.selectedStyleIndex;
454

    
455
        if (keywords != null) {
456
                clone.keywords = new ArrayList(keywords.size());
457
                for (int i = 0; i < keywords.size(); i++) {
458
                                clone.keywords.add((String) keywords.get(i));
459
                        }
460
        }
461
        if (styles!=null)
462
                for (int i=0; i<styles.size(); i++){
463
                        FMapWMSStyle sty = (FMapWMSStyle) ((FMapWMSStyle) this.styles.get(i)).clone();
464
                        sty.parent = this;
465
                        clone.styles.add(sty);
466
                }
467

    
468
        if (dimensions!=null)
469
                for (int i = 0; i < dimensions.size(); i++) {
470
                        clone.dimensions = new ArrayList();
471
                        clone.dimensions.add((IFMapWMSDimension) this.dimensions.get(i));
472
                }
473

    
474
        return clone;
475
    }
476

    
477

    
478
        /**
479
     * Just a C-struct-like class.
480
     * @author jaume
481
     *
482
     */
483
    public class FMapWMSStyle {
484
            /*
485
             * Please! ensure that the fields are double, int, or Object
486
             * or otherwise add the corresponding entry in the clone() method.
487
             */
488
        public String name;
489
        public String title;
490
        public String styleAbstract;
491
        public String format;
492
        public String type;
493
        public String href;
494
        public WMSLayerNode parent;
495
        public int legendHeight;
496
        public int legendWidth;
497
        /*
498
             * Please! ensure that the fields are double, int, or Object
499
             * or otherwise add the corresponding entry in the clone() method.
500
             */
501

    
502
        /**
503
         * Creates a new instance of FMapWMSStyle
504
         * @param name
505
         * @param title
506
         * @param styleAbstract
507
         * @param parent
508
         */
509
        public FMapWMSStyle(WMSStyle style, WMSLayerNode parent){
510

    
511
            this.name = style.getName();
512
            this.title = style.getTitle();
513
            this.styleAbstract = style.getAbstract();
514
            this.legendWidth = style.getLegendURLWidth();
515
            this.legendHeight = style.getLegendURLHeight();
516
            this.format = style.getLegendURLFormat();
517
            this.href = style.getLegendURLOnlineResourceHRef();
518
            this.type = style.getLegendURLOnlineResourceType();
519
            this.parent = parent;
520
        }
521

    
522
        public FMapWMSStyle() {
523
                        // TODO Auto-generated constructor stub
524
                }
525

    
526
                public String toString(){
527
            return title;
528
        }
529

    
530
        public Object clone() {
531
            FMapWMSStyle clone = new FMapWMSStyle();
532
            Field[] fields = FMapWMSStyle.class.getFields();
533
            for (int i = 0; i < fields.length; i++) {
534
                    try {
535
                            Class clazz = getClass();
536
                            String fieldName = fields[i].getName();
537
                            // int entry
538
                                    if (fields[i].getType().equals(Integer.class)) {
539
                                            clazz.getField(fieldName).
540
                                            setInt(clone, clazz.getField(fieldName)
541
                                                                    .getInt(this));
542
                                    // double entry
543
                                    } else if (fields[i].getType().equals(Double.class)) {
544
                                            clazz.getField(fieldName).
545
                                                setDouble(clone, clazz.getField(fieldName)
546
                                                                .getDouble(this));
547
                                    // any object entry
548
                                    } else {
549
                                            clazz.getField(fieldName).
550
                                                set(clone, clazz.getField(fieldName)
551
                                                                .get(this));
552
                                    }
553
                    } catch (NullPointerException e) {
554
                            NotificationManager.
555
                                        addWarning("Cloning " +
556
                                                        "'"+fields[i].getName()+"' field is null" +
557
                                                                        "(FMapWMSStyle: "+name+")", e);
558
                                } catch (Exception e) {
559
                                        NotificationManager.
560
                                                addWarning("Reflect error when cloning " +
561
                                                                "'"+fields[i].getName()+"' field " +
562
                                                                                "(FMapWMSStyle)", e);
563
                                }
564
                        }
565
            return clone;
566
        }
567
    }
568

    
569
}