Statistics
| Revision:

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

History | View | Annotate | Download (6.21 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
        public IDataSourceInfo getDataSource() {                                
102
                return DataSourceInfoFactory.getInstance(this.layer);                
103
        }
104

    
105
        public Object getLegend() {                
106
                return LegendInfoFactory.getInstance(this.layer);
107
        }
108

    
109
        public double getMinscale() {
110
                return layer.getMinScale();
111
        }
112

    
113
        public String getName() {                
114
                return this.layer.getName();
115
        }
116

    
117
        public String getTitle() {
118
                return this.layer.getName();
119
        }
120
        
121
        public ILayerInfo[] getChilds() {
122
                // TODO Auto-generated method stub
123
                return layers;
124
        }
125
        public String toString(){
126
                return getName();
127
        }
128

    
129
        public IViewInfo getViewInfo() {                
130
                return iview;
131
        }
132

    
133
        public String getCRS() {
134
                return layer.getProjection().getAbrev();
135
        }
136

    
137
        public Rectangle2D getBBox() {
138
                Rectangle2D extent = null;
139
                try {
140
                        extent = layer.getFullExtent();
141
                } catch (DriverException e) {
142
                        PublishLogger.getLog().error("ERROR LayerInfo: I can't get the extent", e);
143
                } 
144
                return extent;
145
        }
146

    
147
        public double getMaxscale() { 
148
                return layer.getMaxScale();
149
        }
150
        public XMLEntity getXMLEntity() {
151
                XMLEntity xml=new XMLEntity();
152
                //I put the name of the interface because RemoteResource musn't know LayerInfo, only ILayerInfo !!
153
                xml.putProperty("className", ILayerInfo.class.getName());
154
                xml.putProperty("layerName", ((FLayer) layer)
155
                                .getName());
156
                xml.putProperty("viewName", view.getName());
157
                return xml;
158
        }
159

    
160
        public void setXMLEntity(XMLEntity xml) {
161
                //At the moment .. nothing 
162
                
163
        }
164

    
165
/*
166
 * (non-Javadoc)
167
 * @see org.gvsig.publish.infoProject.ILayerInfo#getOpacityPercent()
168
 */
169
        public int getOpacityPercent() {
170
                
171
                if (layer instanceof FLyrVect){
172
                        FLyrVect v = (FLyrVect)layer;
173
                        FSymbol s = (FSymbol)v.getLegend().getDefaultSymbol();
174
                        int transparency = s.getColor().getAlpha();
175
                        double opacity = transparency * 0.39;
176
                        opacity = Math.ceil(opacity);
177
                        return new Double(opacity).intValue();
178
                }else{
179
                        //I get the transparency from the datasource 
180
                        IDataSourceInfo ds = getDataSource();
181
                        if (ds.getDataType()== IDataSourceInfo.RASTER_DATA){
182
                                IRasterDSInfo r = (IRasterDSInfo)ds;
183
                                int transparency =  r.getTransparency();
184
                                double opacity = transparency * 0.39;
185
                                opacity = Math.ceil(opacity);
186
                                opacity = 100 - opacity;
187
                                return new Double(opacity).intValue();
188
                        }else
189
                                return 100;
190
                }
191
                
192
        }
193

    
194
        public ILabelingInfo getLabeling() {
195
                if (layer instanceof FLyrVect){
196
                        FLyrVect v = (FLyrVect)layer;
197
                        Legend leg = v.getLegend();
198
                        if (leg instanceof VectorialLegend) {
199
                                return new LabelingInfo(v); 
200
                        }
201
                }                
202
                return null;                
203
        }
204
        /**
205
         * @return information about the parent layer
206
         */
207
        public ILayerInfo getParent() {
208
 
209
                return this.parent;
210
        }
211
        public ILayerInfo findLayer(String layerName) {
212
                if (getName().equals(layerName)){
213
                        return this;
214
                }else{
215
                        //find the layer in its childs
216
                        ILayerInfo[] childs = getChilds();
217
                        if (childs == null){
218
                                return null;
219
                        }
220
                        for (int i = 0; i < childs.length; i++ ){
221
                                ILayerInfo target;
222
                                target = childs[i].findLayer(layerName);
223
                                if (target != null){
224
                                        return target;
225
                                }
226
                        }
227
                }
228
                return null;
229
        }
230

    
231

    
232
        
233
}