svn-gvsig-desktop / branches / Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / FirstStrategy.java @ 1848
History | View | Annotate | Download (4.32 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 |
|
59 |
import org.apache.log4j.Logger; |
60 |
|
61 |
import java.awt.Graphics2D; |
62 |
import java.awt.geom.AffineTransform; |
63 |
import java.awt.geom.Rectangle2D; |
64 |
import java.awt.image.BufferedImage; |
65 |
|
66 |
|
67 |
/**
|
68 |
* Estrategia empleada para las capas vectoriales, que dibuja y guarda en un
|
69 |
* fichero el bounding box de cada shape junto con su tipo. No se deber? de
|
70 |
* dibujar dos veces un adaptador con esta estrateg?a
|
71 |
*/
|
72 |
public class FirstStrategy extends DefaultStrategy { |
73 |
private static Logger logger = Logger.getLogger(FirstStrategy.class.getName()); |
74 |
|
75 |
/**
|
76 |
* Crea una nueva FirstStrategy.
|
77 |
*
|
78 |
* @param capa
|
79 |
*/
|
80 |
public FirstStrategy(FLayer capa) {
|
81 |
super(capa);
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* Dibuja metiendo en una estructura de datos para cada geometr?a que se
|
86 |
* dibuja su boundingbox y su tipo
|
87 |
*
|
88 |
* @param image
|
89 |
* @param g Graphics2D
|
90 |
* @param viewPort ViewPort
|
91 |
* @param cancel
|
92 |
*
|
93 |
* @throws DriverException
|
94 |
*/
|
95 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
96 |
Cancellable cancel) throws DriverException {
|
97 |
try {
|
98 |
VectorialAdapter adapter = ((SingleLayer) getCapa()).getSource(); |
99 |
DataSource ds = ((AlphanumericData) getCapa()).getRecordset();
|
100 |
logger.debug("ds.start()");
|
101 |
ds.start(); |
102 |
logger.debug("adapter.start()");
|
103 |
adapter.start(); |
104 |
|
105 |
VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
106 |
int sc;
|
107 |
long t1 = System.currentTimeMillis(); |
108 |
Rectangle2D extent = viewPort.getAdjustedExtent();
|
109 |
AffineTransform at = viewPort.getAffineTransform();
|
110 |
|
111 |
sc = adapter.getShapeCount(); |
112 |
|
113 |
ShapeInfo shapeinfo = StrategyManager.createShapeInfo(adapter); |
114 |
|
115 |
for (int i = 0; i < sc; i++) { |
116 |
if (cancel.isCanceled()) {
|
117 |
break;
|
118 |
} |
119 |
|
120 |
IGeometry geom = adapter.getShape(i); |
121 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) getCapa()).getLegend(); |
122 |
|
123 |
if (geom.intersects(extent)) {
|
124 |
FSymbol symbol = l.getSymbol(i); |
125 |
geom.draw(g, viewPort, symbol); |
126 |
shapeinfo.addShapeInfo(geom.getBounds2D(), |
127 |
geom.getGeometryType()); |
128 |
} |
129 |
} |
130 |
|
131 |
long t2 = System.currentTimeMillis(); |
132 |
logger.debug("adapter.stop()");
|
133 |
adapter.stop(); |
134 |
logger.debug("ds.stop()");
|
135 |
ds.stop(); |
136 |
|
137 |
System.out.println(t2 - t1);
|
138 |
} catch (DriverIOException e) {
|
139 |
throw new DriverException(e); |
140 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
141 |
throw new DriverException(e); |
142 |
} |
143 |
} |
144 |
} |