Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 472

History | View | Annotate | Download (9.18 KB)

1 214 fernando
/* Generated by Together */
2
3
package com.iver.cit.gvsig.fmap.layers;
4
5
import java.awt.Graphics2D;
6 303 fernando
import java.awt.geom.Point2D;
7 214 fernando
import java.awt.geom.Rectangle2D;
8
import java.awt.image.BufferedImage;
9 456 fernando
import java.util.ArrayList;
10 214 fernando
import java.util.BitSet;
11 456 fernando
import java.util.Iterator;
12 214 fernando
13 408 fernando
import com.hardcode.driverManager.DriverLoadException;
14
import com.hardcode.gdbms.engine.data.DataSource;
15 470 fjp
import com.hardcode.gdbms.engine.data.DriverException;
16
import com.hardcode.gdbms.engine.data.NoSuchTableException;
17
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
18 214 fernando
import com.iver.cit.gvsig.fmap.ViewPort;
19 305 fjp
import com.iver.cit.gvsig.fmap.core.IGeometry;
20 214 fernando
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
21 244 fernando
import com.iver.cit.gvsig.fmap.operations.Cancellable;
22 228 fernando
import com.iver.cit.gvsig.fmap.operations.QueriedPoint;
23 214 fernando
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
24 231 fernando
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
25
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
26 461 fernando
import com.iver.cit.gvsig.fmap.rendering.Legend;
27
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
28 214 fernando
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
29 321 fernando
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
30 415 fernando
import com.iver.utiles.XMLEntity;
31 214 fernando
32 228 fernando
public class FLyrVect extends FLyrDefault implements LayerOperations, VectorialOperations, CommonOperations {
33 456 fernando
    /** Leyenda de la capa vectorial */
34 321 fernando
    private VectorialLegend legend;
35 214 fernando
36 461 fernando
    public void addSelectionListener(SelectionListener listener) {
37
            selectionSupport.addSelectionListener(listener);
38
    }
39
40
    public void removeSelectionListener(SelectionListener listener) {
41
            selectionSupport.removeSelectionListener(listener);
42
    }
43
44 214 fernando
    /**
45
     * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de una gran cantidad de eventos. Con el fin de no propagar todos estos eventos, se realiza la propagaci?n de manera manual al final de la "r?faga" de eventos
46
     */
47
    public void fireSelectionEvents() {
48 461 fernando
            selectionSupport.fireSelectionEvents();
49
    }
50
51 214 fernando
    public VectorialAdapter getSource() {
52
            return source;
53
    }
54
55
    public void setSource(VectorialAdapter va) {
56
            source = va;
57
    }
58
59 461 fernando
    private SelectionSupport selectionSupport = new SelectionSupport();
60 472 fernando
61
    private LayerChangeSupport layerChangeSupport = new LayerChangeSupport();
62 461 fernando
63 214 fernando
    /**
64
     * @clientCardinality 0..*
65
     */
66
    private VectorialAdapter source;
67
68
        /**
69 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
70 214 fernando
         */
71 228 fernando
        public Rectangle2D getFullExtent() throws DriverIOException {
72 342 fjp
                Rectangle2D rAux;
73
                source.start();
74
                rAux = source.getFullExtent();
75
                source.stop();
76
                return rAux;
77 214 fernando
        }
78
79
        /**
80 470 fjp
         * @throws DriverLoadException
81
         * @throws DriverLoadException
82
         * @throws DriverException
83
         * @throws DriverIOException
84 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
85 214 fernando
         */
86 470 fjp
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverIOException, DriverLoadException, DriverException {
87 230 fernando
                Strategy strategy = StrategyManager.getStrategy(this);
88
89 244 fernando
                strategy.draw(image, g, viewPort, cancel);
90 214 fernando
        }
91
92
        /**
93 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
94 214 fernando
         */
95 228 fernando
        public FLyrVect createLabelLayer(int fieldId) {
96
                return null;
97 214 fernando
        }
98
99
        /**
100 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
101 214 fernando
         */
102 228 fernando
        public void removeLabels() {
103 214 fernando
        }
104
105
        /**
106 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createIndex()
107 214 fernando
         */
108 228 fernando
        public void createIndex() {
109 214 fernando
        }
110
111
        /**
112 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor, com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
113 214 fernando
         */
114 229 vcaballero
        public void process(FeatureVisitor visitor, BitSet subset) {
115 228 fernando
        }
116
117
        /**
118
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
119
         */
120 229 vcaballero
        public void setSelection(BitSet selection) {
121 461 fernando
                selectionSupport.setSelection(selection);
122 228 fernando
        }
123
124
        /**
125
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
126
         */
127
        public boolean isSelected(int index) {
128 461 fernando
                return selectionSupport.isSelected(index);
129 228 fernando
        }
130
131
        /**
132 456 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
133
         */
134
        public BitSet getSelection() {
135 461 fernando
                return selectionSupport.getSelection();
136 456 fernando
        }
137
138
        /**
139 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
140
         */
141
        public void clearSelection() {
142 461 fernando
                selectionSupport.clearSelection();
143 228 fernando
        }
144
145
        /**
146
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint, double)
147
         */
148 303 fernando
        public BitSet queryByPoint(Point2D p, double tolerance) {
149 214 fernando
                return null;
150
        }
151
152
        /**
153 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByRect(java.awt.geom.Rectangle2D)
154 214 fernando
         */
155 229 vcaballero
        public BitSet queryByRect(Rectangle2D rect) {
156 214 fernando
                return null;
157
        }
158
159
        /**
160 305 fjp
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry, int)
161 214 fernando
         */
162 305 fjp
        public BitSet queryByShape(IGeometry g, int relationship) {
163 214 fernando
                return null;
164
        }
165
166
        /**
167 456 fernando
         * @throws DriverIOException
168 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#selectByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint, double)
169 214 fernando
         */
170 456 fernando
        public void selectByPoint(QueriedPoint p, double tolerance) throws DriverIOException {
171
                Strategy s = StrategyManager.getStrategy(this);
172
                this.setSelection(s.queryByPoint(p, tolerance));
173
                fireSelectionEvents();
174 214 fernando
        }
175
176
        /**
177 456 fernando
         * @throws DriverIOException
178 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#selectByRect(java.awt.geom.Rectangle2D)
179 214 fernando
         */
180 456 fernando
        public void selectByRect(Rectangle2D rect) throws DriverIOException {
181
                Strategy s = StrategyManager.getStrategy(this);
182
                this.setSelection(s.queryByRect(rect));
183
                fireSelectionEvents();
184 214 fernando
        }
185
186
        /**
187 305 fjp
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#selectByShape(com.iver.cit.gvsig.fmap.core.IGeometry, int)
188 214 fernando
         */
189 305 fjp
        public void selectByShape(IGeometry g, int relationship) {
190 456 fernando
                fireSelectionEvents();
191 214 fernando
        }
192 228 fernando
193
        /**
194 408 fernando
         * @throws DriverLoadException
195 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
196
         */
197 461 fernando
        public SelectableDataSource getRecordset() throws DriverLoadException {
198 472 fernando
                DataSource ds = source.getRecordset(getName());
199 461 fernando
                SelectableDataSource sds = new SelectableDataSource(ds);
200
                sds.setSelectionSupport(selectionSupport);
201
                return sds;
202 217 fernando
        }
203 214 fernando
204
        /**
205 470 fjp
         * @throws DriverLoadException
206
         * @throws DriverException
207
         * @throws DriverLoadException
208
         * @throws FieldNotFoundException
209 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int, com.iver.cit.gvsig.fmap.rendering.Legend)
210 214 fernando
         */
211 470 fjp
        public void setLegend(VectorialLegend r) throws FieldNotFoundException, DriverException, DriverLoadException {
212 264 fernando
                legend = r;
213 470 fjp
                legend.setDataSource(getRecordset());
214 461 fernando
215 214 fernando
        }
216 303 fernando
217 321 fernando
    public VectorialLegend getLegend() {
218 303 fernando
219
            return legend;
220
    }
221 321 fernando
222
        /**
223
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getLegendInfo()
224
         */
225 458 fjp
        public Legend getLegendInfo() {
226
                return (Legend) legend;
227 321 fernando
        }
228 373 fernando
229
        /**
230
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getShapeType()
231
         */
232
        public int getShapeType() throws DriverIOException {
233
                return source.getShapeType();
234
        }
235 435 vcaballero
236
        /**
237
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
238
         */
239
        public XMLEntity getXMLEntity() {
240 461 fernando
                BitSet selected = selectionSupport.getSelection();
241 435 vcaballero
                XMLEntity xml=super.getXMLEntity();
242
                xml.addChild(legend.getXMLEntity());
243
                if (selected!=null){
244
                xml.putProperty("numBitSet",selected.cardinality());
245
                int n=0;
246
                for (int i=0;i<selected.length();i++){
247
                        if (selected.get(i)){
248
                                xml.putProperty(String.valueOf(n),selected.get(i));
249
                        n++;
250
                        }
251
                }
252
                }
253 442 vcaballero
                if (source instanceof VectorialFileAdapter){
254
                        xml.putProperty("file",((VectorialFileAdapter)source).getFile());
255
                }else if (source instanceof VectorialDBAdapter){
256
257
                }else if (source instanceof WFSAdapter){
258
259
                }
260
261
                xml.putProperty("driverName",getSource().getDriver().getName());
262 435 vcaballero
                return xml;
263
        }
264
265
        /**
266 442 vcaballero
         * @throws ClassNotFoundException
267
         * @throws InstantiationException
268 435 vcaballero
         * @throws IllegalAccessException
269 442 vcaballero
         * @throws DriverIOException
270
         * @throws DriverLoadException
271
         * @throws CancelationException
272
         * @throws DifferentVersionException
273 435 vcaballero
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
274
         */
275 442 vcaballero
        public void setXMLEntity(XMLEntity xml) throws ClassNotFoundException, InstantiationException, IllegalAccessException, DifferentVersionException, CancelationException, DriverLoadException, DriverIOException {
276
                super.setXMLEntity(xml);
277 435 vcaballero
                legend=LegendFactory.createFromXML(xml.getChild(0));
278
                int numBitSet=xml.getIntProperty("numBitSet");
279
                if (numBitSet!=0){
280 461 fernando
                BitSet selected = new BitSet();
281 435 vcaballero
                selected=new BitSet();
282
                for(int i=0;i<numBitSet;i++){
283
                        selected.set(xml.getIntProperty(String.valueOf(i)));
284
                }
285 461 fernando
                selectionSupport.setSelection(selected);
286 435 vcaballero
                }
287
                //TODO source.setDriver(nameDriver);
288 442 vcaballero
289 435 vcaballero
        }
290 472 fernando
        public void addLayerListener(LayerListener listener) {
291
                layerChangeSupport.addLayerListener(listener);
292
        }
293
        public void callLegendChanged(LegendChangedEvent e) {
294
                layerChangeSupport.callLegendChanged(e);
295
        }
296
        public void removeLayerListener(LayerListener listener) {
297
                layerChangeSupport.removeLayerListener(listener);
298
        }
299 214 fernando
}