Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / FMap.java @ 350

History | View | Annotate | Download (10.8 KB)

1
/* Generated by Together */
2
package com.iver.cit.gvsig.fmap;
3

    
4
import java.awt.Graphics2D;
5
import java.awt.Toolkit;
6
import java.awt.geom.Point2D;
7
import java.awt.geom.Rectangle2D;
8
import java.awt.image.BufferedImage;
9

    
10
import org.cresques.cts.ICoordTrans;
11
import org.cresques.cts.IProjection;
12
import org.cresques.geo.Projected;
13

    
14
import com.iver.cit.gvsig.fmap.core.IGeometry;
15
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
16
import com.iver.cit.gvsig.fmap.layers.CancelationException;
17
import com.iver.cit.gvsig.fmap.layers.FLayer;
18
import com.iver.cit.gvsig.fmap.layers.FLayers;
19
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
20
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent;
21
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener;
22
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent;
23
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
24
import com.iver.cit.gvsig.fmap.operations.Cancellable;
25
import com.iver.cit.gvsig.fmap.operations.selection.Record;
26
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
27
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
28

    
29

    
30
/**
31
 * DOCUMENT ME!
32
 *
33
 * @author Fernando Gonz?lez Cort?s
34
 */
35
public class FMap implements Projected {
36
    public static final double[] CHANGEM = {
37
            1000, 1, 0.01, 0.001, 1609.344, 0.9144, 0.3048, 0.0254
38
        };
39

    
40
        /** DOCUMENT ME! */
41
        public static final double[] CHANGE = {
42
            100000, 100, 1, 0.1, 160934.4, 91.44, 30.48, 2.54
43
        };
44
        
45
        public static final int EQUALS = 0;
46
        public static final int DISJOINT = 1;
47
        public static final int INTERSECTS = 2;
48
        public static final int TOUCHES = 3;
49
        public static final int CROSSES = 4;
50
        public static final int WITHIN = 5;
51
        public static final int CONTAINS = 6;
52
        public static final int OVERLAPS = 7;
53
        private FLayers layers = new FLayers();
54
        private ViewPort viewPort;
55

    
56
        public FMap(ViewPort vp){
57
                this.viewPort = vp;
58
                layers.addLayerCollectionListener(new LayerListener());
59
        }
60
        
61
        /**
62
         * DOCUMENT ME!
63
         *
64
         * @return DOCUMENT ME!
65
         */
66
        public FLayers getLayers() {
67
                return layers;
68
        }
69

    
70
        /**
71
         * Dibuja en la imagen que se pasa como par?metro el contenido de las capas
72
         * visibles del mapa y teniendo en cuenta los datos del ViewPort contenido
73
         * en este FMap
74
         *
75
         * @param b DOCUMENT ME!
76
         */
77
        public void drawLabels(BufferedImage b) {
78
        }
79

    
80
        /**
81
         * DOCUMENT ME!
82
         *
83
         * @param g DOCUMENT ME!
84
         */
85
        public void print(Graphics2D g) {
86
        }
87

    
88
        /**
89
         * Crea un nuevo FMap con la informaci?n del ViewPort que se pasa como
90
         * par?metro.
91
         *
92
         * @param vp DOCUMENT ME!
93
         *
94
         * @return DOCUMENT ME!
95
         */
96
        public FMap createNewFMap(ViewPort vp) {
97
                FMap ret = new FMap(vp);
98
                ret.layers = this.layers;
99

    
100
                return ret;
101
        }
102

    
103
        /**
104
         * Crea un nuevo FMap totalmente desligado, se replican las capas y el
105
         * ViewPort
106
         *
107
         * @return DOCUMENT ME!
108
         */
109
        public FMap cloneFMap() {
110
                return createXMLEntity(getXMLEntity());
111
        }
112

    
113
        /**
114
         * DOCUMENT ME!
115
         *
116
         * @return DOCUMENT ME!
117
         */
118
        public XMLEntity getXMLEntity() {
119
                return new XMLEntity();
120
        }
121

    
122
        /**
123
         * DOCUMENT ME!
124
         *
125
         * @param xe DOCUMENT ME!
126
         *
127
         * @return DOCUMENT ME!
128
         */
129
        public FMap createXMLEntity(XMLEntity xe) {
130
                // TODO Implementar bien
131
                return new FMap(null);
132
        }
133
        
134
        /**
135
         * A?ade la capa que se pasa como par?metro al nodo que se pasa como
136
         * parametro y lanza ProjectionMismatchException si no est?n todas las
137
         * capas de este FMap en la misma proyecci?n. Lanza un
138
         * ChildNotAllowedException si la capa no es un FLayers y no permite hijos
139
         *
140
         * @param parent DOCUMENT ME!
141
         * @param layer DOCUMENT ME!
142
         *
143
         * @throws ProjectionMismatchException DOCUMENT ME!
144
         * @throws ChildrenNotAllowedException DOCUMENT ME!
145
         */
146
/*        public void addLayer(LayerPath parent, FLayer layer)
147
                throws ProjectionMismatchException, ChildrenNotAllowedException {
148
                layers.addLayer(parent, layer);
149
        }
150
        public void removeLayer(LayerPath parent)throws ChildrenNotAllowedException{
151
                layers.removeLayer(parent);
152
        }
153
        */
154
        /**
155
         * A?ade una capa al grupo de capas que se sit?a por encima de todas las
156
         * otras capas
157
         *
158
         * @param vectorial DOCUMENT ME!
159
         */
160
        public void addToTrackLayer(FLyrVect vectorial) {
161
        }
162
        
163
    public long getScaleView() {
164
        Toolkit kit = Toolkit.getDefaultToolkit();
165
        double dpi = kit.getScreenResolution();
166
        IProjection proj = viewPort.getProjection();
167

    
168
        double w = ((viewPort.getImageSize().getWidth() / dpi) * 2.54);
169

    
170
        if (viewPort.getAdjustedExtent() == null) {
171
            return 0;
172
        }
173

    
174
        
175
        if (proj == null)
176
                return (long) (viewPort.getAdjustedExtent().getWidth() / w * CHANGE[getViewPort()
177
                                                               .getMapUnits()]);
178
        return (long) proj.getScale(viewPort.getAdjustedExtent().getMinX(), viewPort.getAdjustedExtent().getMaxX(), viewPort.getImageSize().getWidth(), dpi);
179
    }
180

    
181
        /**
182
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#setVectorial(com.iver.cit.gvsig.fmap.VectorialAdapter)
183
         */
184
        public void setVectorial(VectorialAdapter v) {
185
        }
186

    
187
        /**
188
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor, VectorialSubSet)
189
         */
190
        public void process(FeatureVisitor visitor) {
191
        }
192

    
193
        /**
194
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#processSelected(com.iver.cit.gvsig.fmap.FeatureVisitor)
195
         */
196
        public void processSelected(FeatureVisitor visitor) {
197
        }
198

    
199
        /**
200
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#select(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor, VectorialSubSet)
201
         */
202
        public void select(FeatureVisitor visitor) {
203
        }
204

    
205
        /**
206
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectFromSelection()
207
         */
208
        public void selectFromSelection() {
209
        }
210

    
211
        /**
212
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
213
         */
214
        public void createIndex() {
215
        }
216

    
217
        /**
218
         * @see org.cresques.geo.Projected#getProjection()
219
         */
220
        public IProjection getProjection() {
221
                return null;
222
        }
223

    
224
        /**
225
         * @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
226
         */
227
        public void reProject(ICoordTrans arg0) {
228
        }
229

    
230
        /**
231
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByPoint(java.awt.geom.Point2D,
232
         *                 double)
233
         */
234
        public void selectByPoint(Point2D p, double tolerance) {
235
        }
236

    
237
        /**
238
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByRect(java.awt.geom.Rectangle2D)
239
         */
240
        public void selectByRect(Rectangle2D rect) {
241
        }
242

    
243
        /**
244
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
245
         *                 int)
246
         */
247
        public void selectByShape(IGeometry g, int relationship) {
248
        }
249

    
250
        /**
251
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(java.awt.geom.Point2D,
252
         *                 double)
253
         */
254
        public Record[] queryByPoint(Point2D p, double tolerance) {
255
                return null;
256
        }
257

    
258
        /**
259
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
260
         */
261
        public Record[] queryByRect(Rectangle2D rect) {
262
                return null;
263
        }
264

    
265
        /**
266
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
267
         *                 int)
268
         */
269
        public Record[] queryByShape(IGeometry g, int relationship) {
270
                return null;
271
        }
272

    
273
        /**
274
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
275
         */
276
        public Rectangle2D getSelectionBounds() {
277
                return null;
278
        }
279

    
280
        /**
281
         * DOCUMENT ME!
282
         *
283
         * @param image DOCUMENT ME!
284
         * @param g DOCUMENT ME!
285
         * @param viewPort DOCUMENT ME!
286
         *
287
         * @throws DriverIOException
288
         *
289
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
290
         *                 java.awt.Graphics2D, FStyle2D)
291
         */
292
        public void draw(BufferedImage image, Graphics2D g, Cancellable cancel)
293
                throws DriverIOException {
294
                if (viewPort.getExtent() == null) return;
295
                
296
                layers.draw(image, g, viewPort, cancel);
297
        }
298

    
299
        /**
300
         * DOCUMENT ME!
301
         *
302
         * @param image DOCUMENT ME!
303
         * @param g DOCUMENT ME!
304
         * @param viewPort DOCUMENT ME!
305
         *
306
         * @throws DriverIOException
307
         *
308
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
309
         *                 java.awt.Graphics2D, FStyle2D)
310
         */
311
        public void draw(BufferedImage image, Graphics2D g)
312
                throws DriverIOException {
313
                layers.draw(image, g, viewPort, new Cancellable() {
314
                        /**
315
                         * @see com.iver.cit.gvsig.fmap.operations.Cancellable#isCanceled()
316
                         */
317
                        public boolean isCanceled() {
318
                                return false;
319
                        }
320
                });
321
        }
322

    
323
        /**
324
         * @return Returns the viewPort.
325
         */
326
        public ViewPort getViewPort() {
327
                return viewPort;
328
        }
329
        /**
330
         * @param viewPort The viewPort to set.
331
         */
332
        public void setViewPort(ViewPort viewPort) {
333
                this.viewPort = viewPort;
334
        }
335

    
336
        public class LayerListener implements LayerCollectionListener{
337

    
338
                /**
339
                 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
340
                 */
341
                public void layerAdded(LayerCollectionEvent e) {
342
                        // Si es la primera capa, fijamos su extent al ViewPort
343
                        if (getLayers().getLayerCount() == 1)
344
                        {
345
                                FLayer lyr = e.getAffectedLayer();
346
                                try {
347
                                        getViewPort().setExtent(lyr.getFullExtent());
348
                                } catch (DriverIOException e1) {
349
                                }
350
                        }
351
                }
352

    
353
                /**
354
                 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
355
                 */
356
                public void layerMoved(LayerPositionEvent e) {
357
                }
358

    
359
                /**
360
                 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
361
                 */
362
                public void layerRemoved(LayerCollectionEvent e) {
363
                }
364

    
365
                /**
366
                 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
367
                 */
368
                public void layerAdding(LayerCollectionEvent e) throws CancelationException {
369
                }
370

    
371
                /**
372
                 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
373
                 */
374
                public void layerMoving(LayerPositionEvent e) throws CancelationException {
375
                }
376

    
377
                /**
378
                 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
379
                 */
380
                public void layerRemoving(LayerCollectionEvent e) throws CancelationException {
381
                }
382

    
383
                /**
384
                 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
385
                 */
386
                public void activationChanged(LayerCollectionEvent e) throws CancelationException {
387
                }
388

    
389
                /**
390
                 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
391
                 */
392
                public void visibilityChanged(LayerCollectionEvent e) throws CancelationException {
393
                }
394
                
395
        }
396
        
397
        /**
398
         * M?todo de conveniencia. Recorre las capas y te da el fullExtent
399
         * @return fullExtent de todas las capas.
400
         * @throws DriverIOException
401
         */
402
        public Rectangle2D getFullExtent() throws DriverIOException
403
        {
404
                return layers.getFullExtent();
405
        }
406
}