Statistics
| Revision:

root / trunk / extensions / extPublish / src / org / gvsig / publish / infoproject / gvsig19 / LayerInfo.java @ 29308

History | View | Annotate | Download (8.91 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 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 Iba?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
package org.gvsig.publish.infoproject.gvsig19;
42

    
43
import java.awt.geom.Rectangle2D;
44

    
45
import org.gvsig.exceptions.DriverException;
46
import org.gvsig.publish.PublishLogger;
47
import org.gvsig.publish.infoproject.IDataSourceInfo;
48
import org.gvsig.publish.infoproject.ILabelingInfo;
49
import org.gvsig.publish.infoproject.ILayerInfo;
50
import org.gvsig.publish.infoproject.ILegendInfo;
51
import org.gvsig.publish.infoproject.IViewInfo;
52
import org.gvsig.publish.infoproject.datasources.IRasterDSInfo;
53
import org.gvsig.publish.infoproject.factory.DataSourceInfoFactory;
54
import org.gvsig.publish.infoproject.factory.LegendInfoFactory;
55

    
56
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
57

    
58

    
59
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
60
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
61
import com.iver.cit.gvsig.fmap.layers.FLayer;
62
import com.iver.cit.gvsig.fmap.layers.FLayers;
63
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
64
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
65
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy;
66

    
67
import com.iver.cit.gvsig.project.documents.view.ProjectView;
68
import com.iver.utiles.XMLEntity;
69
/**
70
 * TODO: When the tree changes I'm creating a new LayerInfo
71
 * Is this correct? 
72
 * 
73
 * @author Jos? Vicente Hig?n (josevicente.higon@iver.es)
74
 *
75
 */
76
public class LayerInfo implements ILayerInfo {
77
        private FLayer layer = null;
78
        private ProjectView view=null;
79
        private ILayerInfo parent = null;
80
        private ILayerInfo[] childs = null;        
81
        private IViewInfo iview = null;
82
        
83
        /**
84
         * Constructor
85
         * @param flayer from gvSIG
86
         * @param view from gvSIG. It contains a set of layers
87
         * @param viewInfo information about the view in which this layer is 
88
         * @param parent information about the parent layer. If it hasn't parent you can use null
89
         * 
90
         * 
91
         * TODO: I must do an exception if the layer is not a FLyrVect or FLyrRaster 
92
         */
93
        public LayerInfo(FLayer flayer, ProjectView view, IViewInfo viewInfo, LayerInfo parent){
94
                this.parent = parent;
95
                this.iview = viewInfo;
96
                this.layer = flayer;
97
                this.view=view;
98
                if (flayer instanceof FLayers){
99
                        createChilds();        
100
                }
101
        }
102
        private void createChilds(){                
103
                FLayers flayers = (FLayers)layer;
104
                childs = new ILayerInfo[flayers.getLayersCount()];
105
                //I start in the second element in order to avoid the flayer itself????
106
                int j = flayers.getLayersCount() -1;
107
                for (int i = 0; i< flayers.getLayersCount();i++){
108
                        childs[j] = new LayerInfo(flayers.getLayer(i),view, iview, this);
109
                        j--;
110
                }
111
        }
112
        /**
113
         * 
114
         * @see org.gvsig.publish.infoproject.ILayerInfo#getDataSource()
115
         */
116
        public IDataSourceInfo getDataSource() {                                
117
                return DataSourceInfoFactory.getInstance(this.layer);                
118
        }
119
        /**
120
         * 
121
         * @see org.gvsig.publish.infoproject.ILayerInfo#getLegend()
122
         */
123
        public ILegendInfo getLegend() {                
124
                return LegendInfoFactory.getInstance(this.layer);
125
        }
126
        /**
127
         * 
128
         * @see org.gvsig.publish.infoproject.ILayerInfo#getMinscale()
129
         */
130
        public double getMinscale() {
131
                return layer.getMinScale();
132
        }
133
        /**
134
         * 
135
         * @see org.gvsig.publish.infoproject.ILayerInfo#getName()
136
         */
137
        public String getName() {                
138
                return this.layer.getName();
139
        }
140
        /**
141
         * 
142
         * @see org.gvsig.publish.infoproject.ILayerInfo#getTitle()
143
         */
144
        public String getTitle() {
145
                return this.layer.getName();
146
        }
147
        /**
148
         * 
149
         * @see org.gvsig.publish.infoproject.ILayerInfo#getChilds()
150
         */
151
        public ILayerInfo[] getChilds() {
152
                
153
                return childs;
154
        }
155
        /*
156
         * (non-Javadoc)
157
         * @see org.gvsig.publish.infoproject.ILayerInfo#setChilds(org.gvsig.publish.infoproject.ILayerInfo[])
158
         */
159
        public void setChilds(ILayerInfo[] childs){
160
                if (childs !=null){
161
                        this.childs =  childs;
162
                        for (int i=0; i< this.childs.length; i++){
163
                                childs[i].setParent(this);
164
                        }
165
                }else{
166
                        this.childs = null;
167
                }
168
                
169
        }
170
        /**
171
         * 
172
         * @see java.lang.Object#toString()
173
         */        
174
        public String toString(){
175
                return getName();
176
        }
177
        /**
178
         * 
179
         * @see org.gvsig.publish.infoproject.ILayerInfo#getViewInfo()
180
         */
181
        public IViewInfo getViewInfo() {                
182
                return iview;
183
        }
184
        /**
185
         * 
186
         * @see org.gvsig.publish.infoproject.ILayerInfo#getEPSGString()
187
         */
188
        public String getEPSGString() {
189
                return layer.getProjection().getAbrev();
190
        }
191
        /**
192
         * 
193
         * @see org.gvsig.publish.infoproject.ILayerInfo#getBBox()
194
         */
195
        public Rectangle2D getBBox() {
196
                Rectangle2D extent = null;
197
                try {
198
                        extent = layer.getFullExtent();
199
                } catch (ExpansionFileReadException e) {
200
                        PublishLogger.getLog().error("ERROR LayerInfo: I can't get the extent", e);
201
                } catch (ReadDriverException e) {
202
                        PublishLogger.getLog().error("ERROR LayerInfo: I can't get the extent", e);
203
                } 
204
                return extent;
205
        }
206
        /**
207
         * 
208
         * @see org.gvsig.publish.infoproject.ILayerInfo#getMaxscale()
209
         */
210
        public double getMaxscale() { 
211
                return layer.getMaxScale();
212
        }
213

    
214
        /*
215
         * (non-Javadoc)
216
         * @see org.gvsig.publish.infoProject.ILayerInfo#getOpacityPercent()
217
         */
218
        public int getOpacityPercent() {
219
        
220
                if (layer instanceof FLyrDefault){
221
                        FLyrDefault lyr = (FLyrDefault)layer;                        
222
                        int transparency= lyr.getTransparency();
223
                        double opacity = transparency * 0.39;
224
                        opacity = Math.ceil(opacity);
225
                        return new Double(opacity).intValue();
226
                }else{
227
                        throw new NotImplementedException();
228
                }
229

    
230
        }
231
        /*
232
         * (non-Javadoc)
233
         * @see org.gvsig.publish.infoproject.ILayerInfo#getLabeling()
234
         */
235
        public ILabelingInfo getLabeling() {
236
                if (layer instanceof FLyrVect){
237
                        FLyrVect v = (FLyrVect)layer;
238
                        ILabelingStrategy lab = v.getLabelingStrategy();
239
                                return new LabelingInfo(lab); 
240
                }else{
241
                        throw new NotImplementedException();
242
                }                
243
        }
244
        /**
245
         * 
246
         * @see org.gvsig.publish.infoproject.ILayerInfo#getParent()
247
         */
248
        public ILayerInfo getParent() {
249
                return this.parent;
250
        }
251
        /*
252
         * (non-Javadoc)
253
         * @see org.gvsig.publish.infoproject.ILayerInfo#setParent(org.gvsig.publish.infoproject.ILayerInfo)
254
         */
255
        public void setParent(ILayerInfo parent){
256
                this.parent = parent;
257
        }
258
        /**
259
         * 
260
         * @see org.gvsig.publish.infoproject.ILayerInfo#findLayer(java.lang.String)
261
         */
262
        public ILayerInfo findLayer(String layerName) {
263
                if (getName().equals(layerName)){
264
                        return this;
265
                }else{
266
                        //find the layer in its childs
267
                        ILayerInfo[] childs = getChilds();
268
                        if (childs == null){
269
                                return null;
270
                        }
271
                        for (int i = 0; i < childs.length; i++ ){
272
                                ILayerInfo target;
273
                                target = childs[i].findLayer(layerName);
274
                                if (target != null){
275
                                        return target;
276
                                }
277
                        }
278
                }
279
                return null;
280
        }
281

    
282
/*
283
 * (non-Javadoc)
284
 * @see com.iver.utiles.IPersistance#getXMLEntity()
285
 */
286
        public XMLEntity getXMLEntity() {                
287
                XMLEntity xml=new XMLEntity();
288
                //put version and className
289
                xml.setName(getClassName());
290
                xml.putProperty("version", getVersion());
291
                
292
                //put properties
293
                xml.putProperty("layername", getName());
294
                return xml;
295
        }
296
        /*
297
         * (non-Javadoc)
298
         * @see com.iver.utiles.IPersistance#setXMLEntity(com.iver.utiles.XMLEntity)
299
         */
300
        public void setXMLEntity(XMLEntity xml) {
301
                //check version
302
                int version = xml.getIntProperty("version");                
303
                if (version!= getVersion()){
304
                        PublishLogger.getLog().error("ERROR: " + getClassName() + ": the version doesn't match!");
305
                        return;
306
                }        
307
        }
308
        /**
309
         * 
310
         * @see org.gvsig.publish.infoproject.ILayerInfo#getSRID()
311
         */
312
        public int getSRID() {
313
                int srid=-1;
314
                if (layer.getProjection() != null){
315
                        String[] components = layer.getProjection().getAbrev().split(":");
316
                        srid = new Integer(components[1]).intValue();
317
                }
318
                return srid;
319
        }
320
        /*
321
         * (non-Javadoc)
322
         * @see org.gvsig.publish.infoproject.ILayerInfo#getPathString()
323
         */
324
        public String getPathString() {
325
                if (parent == null){
326
                        return "/";
327
                }else{
328
                        return parent.getPathString() +  parent.getTitle() + "/";
329
                }
330
        }
331
        /*
332
         * (non-Javadoc)
333
         * @see org.gvsig.publish.IPublishPersistence#getVersion()
334
         */
335
        public int getVersion() {                
336
                return 1;
337
        }
338
        /*
339
         * (non-Javadoc)
340
         * @see com.iver.utiles.IPersistance#getClassName()
341
         */
342
        public String getClassName() {
343
                return "LayerInfo";
344
        }
345

    
346

    
347
}