Statistics
| Revision:

svn-gvsig-desktop / tags / Root_Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / OptimiceStrategy.java @ 1826

History | View | Annotate | Download (4.14 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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 Ib??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 com.iver.cit.gvsig.fmap.operations.strategies;
42

    
43
import com.hardcode.gdbms.engine.data.DataSource;
44

    
45
import com.iver.cit.gvsig.fmap.DriverException;
46
import com.iver.cit.gvsig.fmap.ViewPort;
47
import com.iver.cit.gvsig.fmap.core.IGeometry;
48
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
49
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
50
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
51
import com.iver.cit.gvsig.fmap.layers.FLayer;
52
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
53
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
54
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
55
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
56
import com.iver.cit.gvsig.fmap.operations.Cancellable;
57
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
58
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
59

    
60
import org.apache.log4j.Logger;
61

    
62
import java.awt.Graphics2D;
63
import java.awt.geom.AffineTransform;
64
import java.awt.geom.Rectangle2D;
65
import java.awt.image.BufferedImage;
66

    
67

    
68
/**
69
 * Extiende DefaultStrategy de forma optimizada.
70
 *
71
 * @author Vicente Caballero Navarro
72
 */
73
public class OptimiceStrategy extends DefaultStrategy {
74
        private static Logger logger = Logger.getLogger(OptimiceStrategy.class.getName());
75

    
76
        /**
77
         * Crea una nueva OptimiceStrategy.
78
         *
79
         * @param capa
80
         */
81
        public OptimiceStrategy(FLayer capa) {
82
                super(capa);
83
        }
84

    
85
        /**
86
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
87
         *                 java.awt.Graphics2D, FStyle2D)
88
         */
89
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
90
                Cancellable cancel) throws DriverException {
91
                try {
92
                        VectorialAdapter adapter = ((SingleLayer) getCapa()).getSource();
93
                        DataSource ds = ((AlphanumericData) getCapa()).getRecordset();
94
                        // ShapeInfo shapeinfo = adapter.getShapeInfo();
95
                        logger.debug("adapter.start()");
96
                        adapter.start();
97
                        logger.debug("ds.start()");
98
                        ds.start();
99

    
100
                        VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver();
101
                        int sc;
102
                        long t1 = System.currentTimeMillis();
103
                        Rectangle2D extent = viewPort.getAdjustedExtent();
104
                        AffineTransform at = viewPort.getAffineTransform();
105

    
106
                        sc = adapter.getShapeCount();
107

    
108
                        for (int i = 0; i < sc; i++) {
109
                                if (cancel.isCanceled()) {
110
                                        break;
111
                                }
112

    
113
                                IGeometry geom = adapter.getShape(i);
114
                                VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) getCapa()).getLegend();
115

    
116
                                // TODO Falta rematar esta parte.
117
                                // if (shapeinfo.getBoundingBox(sc).intersects(extent)) {
118
                                        FSymbol symbol = l.getSymbol(i);
119
                                        geom.draw(g, viewPort, symbol);
120
                                // }
121
                        }
122

    
123
                        long t2 = System.currentTimeMillis();
124
                        logger.debug("adapter.stop()");
125
                        adapter.stop();
126
                        logger.debug("ds.stop()");
127
                        ds.stop();
128

    
129
                        System.out.println(t2 - t1);
130
                } catch (DriverIOException e) {
131
                        throw new DriverException(e);
132
                } catch (com.hardcode.gdbms.engine.data.DriverException e) {
133
                        throw new DriverException(e);
134
                }
135
        }
136
}