Statistics
| Revision:

root / branches / v10 / extensions / extPublish / src / org / gvsig / publish / infoproject / LayerInfo.java @ 19419

History | View | Annotate | Download (7.87 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;
42

    
43
import java.awt.geom.Rectangle2D;
44

    
45
import org.gvsig.publish.PublishLogger;
46
import org.gvsig.publish.infoproject.datasources.DataSourceInfoFactory;
47
import org.gvsig.publish.infoproject.datasources.IRasterDSInfo;
48
import org.gvsig.publish.infoproject.legends.LegendInfoFactory;
49

    
50
import com.iver.cit.gvsig.fmap.DriverException;
51
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
52
import com.iver.cit.gvsig.fmap.layers.FLayer;
53
import com.iver.cit.gvsig.fmap.layers.FLayers;
54
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
55
import com.iver.cit.gvsig.fmap.rendering.Legend;
56
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
57
import com.iver.cit.gvsig.project.documents.view.ProjectView;
58
import com.iver.utiles.XMLEntity;
59
/**
60
 * TODO: When the tree changes I'm creating a new LayerInfo
61
 * Is this correct? 
62
 * 
63
 * @author Jos? Vicente Hig?n (josevicente.higon@iver.es)
64
 *
65
 */
66
public class LayerInfo implements ILayerInfo {
67
        private FLayer layer = null;
68
        private ILayerInfo parent = null;
69
        private LayerInfo[] layers = null;
70
        private ProjectView view=null;
71
        private IViewInfo iview = null;
72
        /**
73
         * Constructor
74
         * @param flayer from gvSIG
75
         * @param view from gvSIG. It contains a set of layers
76
         * @param viewInfo information about the view in which this layer is 
77
         * @param parent information about the parent layer. If it hasn't parent you can use null
78
         * 
79
         * 
80
         * TODO: I must do an exception if the layer is not a FLyrVect or FLyrRaster 
81
         */
82
        public LayerInfo(FLayer flayer, ProjectView view, IViewInfo viewInfo, ILayerInfo parent){
83
                this.parent = parent;
84
                this.iview = viewInfo;
85
                this.layer = flayer;
86
                this.view=view;
87
                if (flayer instanceof FLayers){
88
                        createChilds();        
89
                }
90
        }
91
        private void createChilds(){
92
                //System.err.println("Nuevo grupo: " + layer.getName());
93
                FLayers flayers = (FLayers)layer;
94
                layers = new LayerInfo[flayers.getLayersCount()];
95
                //I start in the second element in order to avoid the flayer itself
96
                for (int i = 0; i< flayers.getLayersCount();i++){
97
                        layers[i] = new LayerInfo(flayers.getLayer(i),view, iview, this);
98
                }
99
        }
100
        /**
101
         * 
102
         * @see org.gvsig.publish.infoproject.ILayerInfo#getDataSource()
103
         */
104
        public IDataSourceInfo getDataSource() {                                
105
                return DataSourceInfoFactory.getInstance(this.layer);                
106
        }
107
        /**
108
         * 
109
         * @see org.gvsig.publish.infoproject.ILayerInfo#getLegend()
110
         */
111
        public ILegendInfo getLegend() {                
112
                return LegendInfoFactory.getInstance(this.layer);
113
        }
114
        /**
115
         * 
116
         * @see org.gvsig.publish.infoproject.ILayerInfo#getMinscale()
117
         */
118
        public double getMinscale() {
119
                return layer.getMinScale();
120
        }
121
        /**
122
         * 
123
         * @see org.gvsig.publish.infoproject.ILayerInfo#getName()
124
         */
125
        public String getName() {                
126
                return this.layer.getName();
127
        }
128
        /**
129
         * 
130
         * @see org.gvsig.publish.infoproject.ILayerInfo#getTitle()
131
         */
132
        public String getTitle() {
133
                return this.layer.getName();
134
        }
135
        /**
136
         * 
137
         * @see org.gvsig.publish.infoproject.ILayerInfo#getChilds()
138
         */
139
        public ILayerInfo[] getChilds() {
140
                // TODO Auto-generated method stub
141
                return layers;
142
        }
143
        /**
144
         * 
145
         * @see java.lang.Object#toString()
146
         */        
147
        public String toString(){
148
                return getName();
149
        }
150
        /**
151
         * 
152
         * @see org.gvsig.publish.infoproject.ILayerInfo#getViewInfo()
153
         */
154
        public IViewInfo getViewInfo() {                
155
                return iview;
156
        }
157
        /**
158
         * 
159
         * @see org.gvsig.publish.infoproject.ILayerInfo#getEPSGString()
160
         */
161
        public String getEPSGString() {
162
                return layer.getProjection().getAbrev();
163
        }
164
        /**
165
         * 
166
         * @see org.gvsig.publish.infoproject.ILayerInfo#getBBox()
167
         */
168
        public Rectangle2D getBBox() {
169
                Rectangle2D extent = null;
170
                try {
171
                        extent = layer.getFullExtent();
172
                } catch (DriverException e) {
173
                        PublishLogger.getLog().error("ERROR LayerInfo: I can't get the extent", e);
174
                } 
175
                return extent;
176
        }
177
        /**
178
         * 
179
         * @see org.gvsig.publish.infoproject.ILayerInfo#getMaxscale()
180
         */
181
        public double getMaxscale() { 
182
                return layer.getMaxScale();
183
        }
184

    
185
        /*
186
         * (non-Javadoc)
187
         * @see org.gvsig.publish.infoProject.ILayerInfo#getOpacityPercent()
188
         */
189
        public int getOpacityPercent() {
190

    
191
                if (layer instanceof FLyrVect){
192
                        FLyrVect v = (FLyrVect)layer;
193
                        FSymbol s = (FSymbol)v.getLegend().getDefaultSymbol();
194
                        int transparency = s.getColor().getAlpha();
195
                        double opacity = transparency * 0.39;
196
                        opacity = Math.ceil(opacity);
197
                        return new Double(opacity).intValue();
198
                }else{
199
                        //I get the transparency from the datasource 
200
                        IDataSourceInfo ds = getDataSource();
201
                        if (ds.getType()== IDataSourceInfo.RASTER_TYPE){
202
                                IRasterDSInfo r = (IRasterDSInfo)ds;
203
                                int transparency =  r.getTransparency();
204
                                double opacity = transparency * 0.39;
205
                                opacity = Math.ceil(opacity);
206
                                opacity = 100 - opacity;
207
                                return new Double(opacity).intValue();
208
                        }else
209
                                return 100;
210
                }
211

    
212
        }
213
        /**
214
         * 
215
         * @see org.gvsig.publish.infoproject.ILayerInfo#getLabeling()
216
         */
217
        public ILabelingInfo getLabeling() {
218
                if (layer instanceof FLyrVect){
219
                        FLyrVect v = (FLyrVect)layer;
220
                        Legend leg = v.getLegend();
221
                        if (leg instanceof VectorialLegend) {
222
                                return new LabelingInfo(v); 
223
                        }
224
                }                
225
                return null;                
226
        }
227
        /**
228
         * 
229
         * @see org.gvsig.publish.infoproject.ILayerInfo#getParent()
230
         */
231
        public ILayerInfo getParent() {
232

    
233
                return this.parent;
234
        }
235
        /**
236
         * 
237
         * @see org.gvsig.publish.infoproject.ILayerInfo#findLayer(java.lang.String)
238
         */
239
        public ILayerInfo findLayer(String layerName) {
240
                if (getName().equals(layerName)){
241
                        return this;
242
                }else{
243
                        //find the layer in its childs
244
                        ILayerInfo[] childs = getChilds();
245
                        if (childs == null){
246
                                return null;
247
                        }
248
                        for (int i = 0; i < childs.length; i++ ){
249
                                ILayerInfo target;
250
                                target = childs[i].findLayer(layerName);
251
                                if (target != null){
252
                                        return target;
253
                                }
254
                        }
255
                }
256
                return null;
257
        }
258

    
259
        /**
260
         * 
261
         * Constants used by ProjectInfoFactory
262
         */
263
        public static final String VERSION="LayerInfo_v1";
264
        public static final String LAYERNAME="layername";
265
        /**
266
         * 
267
         * @see com.iver.utiles.IPersistance#getXMLEntity()
268
         */
269
        public XMLEntity getXMLEntity() {
270
                XMLEntity xml=new XMLEntity();
271
                //put version
272
                xml.putProperty("className", getClassName());
273
                //put properties
274
                xml.putProperty(LAYERNAME, getName());                
275
                return xml;
276
        }
277
        /**
278
         * 
279
         * @see com.iver.utiles.IPersistance#setXMLEntity(com.iver.utiles.XMLEntity)
280
         */
281
        public void setXMLEntity(XMLEntity xml) {
282
                //check version
283
                String classid = xml.getStringProperty("className");
284
                if (!classid.equals(getClassName())){
285
                        return;
286
                }
287
        }
288
        /**
289
         * 
290
         * @see com.iver.utiles.IPersistance#getClassName()
291
         */
292
        public String getClassName() {
293
                return VERSION;
294
        }
295
        /**
296
         * 
297
         * @see org.gvsig.publish.infoproject.ILayerInfo#getSRID()
298
         */
299
        public int getSRID() {
300
                int srid=-1;
301
                if (layer.getProjection() != null){
302
                        String[] components = layer.getProjection().getAbrev().split(":");
303
                        srid = new Integer(components[1]).intValue();
304
                }
305
                return srid;
306
        }
307

    
308

    
309
}