svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 28953
History | View | Annotate | Download (68.5 KB)
1 | 1100 | fjp | /* 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 | 214 | fernando | package com.iver.cit.gvsig.fmap.layers; |
42 | |||
43 | 1828 | fernando | import java.awt.Graphics2D; |
44 | 5048 | ldiaz | import java.awt.Point; |
45 | 14409 | vcaballero | import java.awt.geom.AffineTransform; |
46 | 1828 | fernando | import java.awt.geom.Point2D; |
47 | import java.awt.geom.Rectangle2D; |
||
48 | import java.awt.image.BufferedImage; |
||
49 | 4977 | azabala | import java.io.File; |
50 | 13558 | evercher | import java.net.URI; |
51 | 11704 | jaume | import java.util.ArrayList; |
52 | 1828 | fernando | |
53 | 9010 | caballero | import javax.print.attribute.PrintRequestAttributeSet; |
54 | 12657 | jaume | import javax.print.attribute.standard.PrintQuality; |
55 | 9010 | caballero | |
56 | 1828 | fernando | import org.apache.log4j.Logger; |
57 | import org.cresques.cts.ICoordTrans; |
||
58 | 27619 | vcaballero | import org.gvsig.exceptions.BaseException; |
59 | 1828 | fernando | |
60 | 10627 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
61 | 22465 | vcaballero | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
62 | 1828 | fernando | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
63 | 10627 | caballero | import com.hardcode.gdbms.engine.data.driver.DriverException; |
64 | 470 | fjp | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
65 | 10627 | caballero | import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
66 | import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
||
67 | import com.iver.cit.gvsig.exceptions.layers.ReloadLayerException; |
||
68 | 27619 | vcaballero | import com.iver.cit.gvsig.exceptions.layers.ReprojectLayerException; |
69 | 10627 | caballero | import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException; |
70 | import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
||
71 | import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
||
72 | 12657 | jaume | import com.iver.cit.gvsig.fmap.MapContext; |
73 | 13928 | jaume | import com.iver.cit.gvsig.fmap.MapControl; |
74 | 214 | fernando | import com.iver.cit.gvsig.fmap.ViewPort; |
75 | 12466 | jaume | import com.iver.cit.gvsig.fmap.core.CartographicSupport; |
76 | 12349 | jaume | import com.iver.cit.gvsig.fmap.core.FPoint2D; |
77 | 12466 | jaume | import com.iver.cit.gvsig.fmap.core.FShape; |
78 | 11704 | jaume | import com.iver.cit.gvsig.fmap.core.IFeature; |
79 | 757 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
80 | 10679 | jaume | import com.iver.cit.gvsig.fmap.core.ILabelable; |
81 | 24160 | jmvivo | import com.iver.cit.gvsig.fmap.core.IRow; |
82 | 11807 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol; |
83 | 11704 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
84 | 14481 | vcaballero | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
85 | 2978 | fjp | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
86 | 11704 | jaume | import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
87 | 11971 | caballero | import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
88 | 3301 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
89 | 6534 | jmvivo | import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
90 | 24160 | jmvivo | import com.iver.cit.gvsig.fmap.edition.AfterFieldEditEvent; |
91 | import com.iver.cit.gvsig.fmap.edition.AfterRowEditEvent; |
||
92 | 4256 | caballero | import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter; |
93 | 24160 | jmvivo | import com.iver.cit.gvsig.fmap.edition.BeforeFieldEditEvent; |
94 | import com.iver.cit.gvsig.fmap.edition.BeforeRowEditEvent; |
||
95 | 5184 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
96 | 24160 | jmvivo | import com.iver.cit.gvsig.fmap.edition.IEditionListener; |
97 | 6856 | fjp | import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
98 | import com.iver.cit.gvsig.fmap.edition.IWriteable; |
||
99 | import com.iver.cit.gvsig.fmap.edition.IWriter; |
||
100 | 3981 | caballero | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
101 | 4159 | fjp | import com.iver.cit.gvsig.fmap.edition.VectorialEditableDBAdapter; |
102 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
103 | import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
||
104 | 5048 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
105 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
106 | import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
||
107 | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
||
108 | 5057 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialXMLItem; |
109 | 5201 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
110 | 214 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
111 | 231 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
112 | import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
||
113 | 13884 | jaume | import com.iver.cit.gvsig.fmap.rendering.IClassifiedVectorLegend; |
114 | 11558 | jaume | import com.iver.cit.gvsig.fmap.rendering.ILegend; |
115 | 13884 | jaume | import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
116 | 25033 | jmvivo | import com.iver.cit.gvsig.fmap.rendering.LegendClearEvent; |
117 | import com.iver.cit.gvsig.fmap.rendering.LegendContentsChangedListener; |
||
118 | 214 | fernando | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
119 | 3035 | fjp | import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
120 | 25033 | jmvivo | import com.iver.cit.gvsig.fmap.rendering.SymbolLegendEvent; |
121 | 11807 | jaume | import com.iver.cit.gvsig.fmap.rendering.ZSort; |
122 | 18621 | jdominguez | import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy; |
123 | import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy; |
||
124 | 25452 | vcaballero | import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
125 | 18621 | jdominguez | import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory; |
126 | 4977 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.IPersistentSpatialIndex; |
127 | import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex; |
||
128 | 5414 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeGt2; |
129 | 4977 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
130 | import com.iver.cit.gvsig.fmap.spatialindex.SpatialIndexException; |
||
131 | import com.iver.utiles.FileUtils; |
||
132 | 13913 | jaume | import com.iver.utiles.IPersistence; |
133 | 10679 | jaume | import com.iver.utiles.NotExistInXMLEntity; |
134 | 2672 | fjp | import com.iver.utiles.PostProcessSupport; |
135 | 415 | fernando | import com.iver.utiles.XMLEntity; |
136 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
137 | import com.iver.utiles.swing.threads.CancellableMonitorable; |
||
138 | 214 | fernando | |
139 | 562 | fernando | /**
|
140 | 1034 | vcaballero | * Capa b?sica Vectorial.
|
141 | 5184 | caballero | *
|
142 | 562 | fernando | * @author Fernando Gonz?lez Cort?s
|
143 | */
|
||
144 | 885 | fjp | |
145 | 5152 | fjp | // TODO Cuando no sea para pruebas debe no ser public
|
146 | 10679 | jaume | public class FLyrVect extends FLyrDefault implements ILabelable, |
147 | 12349 | jaume | ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData, |
148 | 25033 | jmvivo | AlphanumericData, InfoByPoint, SelectionListener, IEditionListener, LegendContentsChangedListener { |
149 | 12349 | jaume | private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
150 | 16254 | vcaballero | /**
|
151 | * @deprecated Don?t use Strategy, you should be use iterators.
|
||
152 | */
|
||
153 | 24376 | vcaballero | // public static boolean forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD = true;
|
154 | 16254 | vcaballero | /**
|
155 | * @deprecated Don?t use Strategy, you should be use iterators.
|
||
156 | */
|
||
157 | 24376 | vcaballero | // private boolean useStrategy=false;
|
158 | 14409 | vcaballero | |
159 | 12349 | jaume | /** Leyenda de la capa vectorial */
|
160 | 13884 | jaume | private IVectorLegend legend;
|
161 | 12349 | jaume | private int typeShape = -1; |
162 | private ReadableVectorial source;
|
||
163 | private SelectableDataSource sds;
|
||
164 | private SelectionSupport selectionSupport = new SelectionSupport(); |
||
165 | private SpatialCache spatialCache = new SpatialCache(); |
||
166 | private boolean spatialCacheEnabled = false; |
||
167 | 3940 | caballero | |
168 | 12349 | jaume | /**
|
169 | * An implementation of gvSIG spatial index
|
||
170 | */
|
||
171 | protected ISpatialIndex spatialIndex = null; |
||
172 | private boolean bHasJoin = false; |
||
173 | private XMLEntity orgXMLEntity = null; |
||
174 | private XMLEntity loadSelection = null; |
||
175 | 13884 | jaume | private IVectorLegend loadLegend = null; |
176 | 461 | fernando | |
177 | 13558 | evercher | //Lo a?ado. Caracter?sticas de HyperEnlace (LINK)
|
178 | private FLyrVectLinkProperties linkProperties=new FLyrVectLinkProperties(); |
||
179 | //private ArrayList linkProperties=null;
|
||
180 | |||
181 | 12349 | jaume | /**
|
182 | * Devuelve el VectorialAdapater de la capa.
|
||
183 | *
|
||
184 | * @return VectorialAdapter.
|
||
185 | */
|
||
186 | public ReadableVectorial getSource() {
|
||
187 | if (!this.isAvailable()) return null; |
||
188 | return source;
|
||
189 | } |
||
190 | 5115 | caballero | |
191 | 12349 | jaume | /**
|
192 | * If we use a persistent spatial index associated with this layer, and the
|
||
193 | * index is not intrisic to the layer (for example spatial databases) this
|
||
194 | * method looks for existent spatial index, and loads it.
|
||
195 | *
|
||
196 | */
|
||
197 | private void loadSpatialIndex() { |
||
198 | //FIXME: Al abrir el indice en fichero...
|
||
199 | //?C?mo lo liberamos? un metodo Layer.shutdown()
|
||
200 | 5484 | caballero | |
201 | |||
202 | 12349 | jaume | ReadableVectorial source = getSource(); |
203 | //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
|
||
204 | //PUES SON VECTORIALFILEADAPTER
|
||
205 | if (!(source instanceof VectorialFileAdapter)) { |
||
206 | // we are not interested in db adapters
|
||
207 | return;
|
||
208 | } |
||
209 | VectorialDriver driver = source.getDriver(); |
||
210 | if (!(driver instanceof BoundedShapes)) { |
||
211 | // we dont spatially index layers that are not bounded
|
||
212 | return;
|
||
213 | } |
||
214 | File file = ((VectorialFileAdapter) source).getFile();
|
||
215 | String fileName = file.getAbsolutePath();
|
||
216 | File sptFile = new File(fileName + ".qix"); |
||
217 | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
||
218 | // before to exit, look for it in temp path
|
||
219 | String tempPath = System.getProperty("java.io.tmpdir"); |
||
220 | fileName = tempPath + File.separator + sptFile.getName();
|
||
221 | sptFile = new File(fileName); |
||
222 | // it doesnt exists, must to create
|
||
223 | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
||
224 | return;
|
||
225 | }// if
|
||
226 | }// if
|
||
227 | 5484 | caballero | |
228 | 12349 | jaume | try {
|
229 | source.start(); |
||
230 | spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
|
||
231 | "NM", source.getFullExtent(), source.getShapeCount(), false); |
||
232 | source.setSpatialIndex(spatialIndex); |
||
233 | } catch (SpatialIndexException e) {
|
||
234 | spatialIndex = null;
|
||
235 | e.printStackTrace(); |
||
236 | return;
|
||
237 | } catch (ReadDriverException e) {
|
||
238 | spatialIndex = null;
|
||
239 | e.printStackTrace(); |
||
240 | return;
|
||
241 | } |
||
242 | 5484 | caballero | |
243 | 12349 | jaume | } |
244 | 5115 | caballero | |
245 | 12349 | jaume | /**
|
246 | * Checks if it has associated an external spatial index
|
||
247 | * (an spatial index file).
|
||
248 | *
|
||
249 | * It looks for it in main file path, or in temp system path.
|
||
250 | * If main file is rivers.shp, it looks for a file called
|
||
251 | * rivers.shp.qix.
|
||
252 | 5484 | caballero | |
253 | 12349 | jaume | * @return
|
254 | */
|
||
255 | public boolean isExternallySpatiallyIndexed() { |
||
256 | /*
|
||
257 | * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
|
||
258 | * con el que se trabaje (ahora mismo considera la extension .qix,
|
||
259 | * pero esto depender? del tipo de ?ndice)
|
||
260 | * */
|
||
261 | ReadableVectorial source = getSource(); |
||
262 | if (!(source instanceof VectorialFileAdapter)) { |
||
263 | // we are not interested in db adapters.
|
||
264 | // think in non spatial dbs, like HSQLDB
|
||
265 | return false; |
||
266 | } |
||
267 | File file = ((VectorialFileAdapter) source).getFile();
|
||
268 | String fileName = file.getAbsolutePath();
|
||
269 | File sptFile = new File(fileName + ".qix"); |
||
270 | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
||
271 | // before to exit, look for it in temp path
|
||
272 | // it doesnt exists, must to create
|
||
273 | String tempPath = System.getProperty("java.io.tmpdir"); |
||
274 | fileName = tempPath + File.separator + sptFile.getName();
|
||
275 | sptFile = new File(fileName); |
||
276 | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
||
277 | return false; |
||
278 | }// if
|
||
279 | }// if
|
||
280 | return true; |
||
281 | } |
||
282 | 472 | fernando | |
283 | 12349 | jaume | /**
|
284 | * Inserta el VectorialAdapter a la capa.
|
||
285 | *
|
||
286 | * @param va
|
||
287 | * VectorialAdapter.
|
||
288 | */
|
||
289 | public void setSource(ReadableVectorial rv) { |
||
290 | source = rv; |
||
291 | // azabala: we check if this layer could have a file spatial index
|
||
292 | // and load it if it exists
|
||
293 | 16542 | vcaballero | loadSpatialIndex(); |
294 | 12349 | jaume | } |
295 | 214 | fernando | |
296 | 12349 | jaume | public Rectangle2D getFullExtent() throws ReadDriverException, ExpansionFileReadException { |
297 | Rectangle2D rAux;
|
||
298 | source.start(); |
||
299 | rAux = (Rectangle2D)source.getFullExtent().clone();
|
||
300 | source.stop(); |
||
301 | 885 | fjp | |
302 | 12349 | jaume | // Si existe reproyecci?n, reproyectar el extent
|
303 | ICoordTrans ct = getCoordTrans(); |
||
304 | 27619 | vcaballero | try{
|
305 | if (ct != null) { |
||
306 | Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
||
307 | Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
||
308 | pt1 = ct.convert(pt1, null);
|
||
309 | pt2 = ct.convert(pt2, null);
|
||
310 | rAux = new Rectangle2D.Double(); |
||
311 | rAux.setFrameFromDiagonal(pt1, pt2); |
||
312 | } |
||
313 | }catch (IllegalStateException e) { |
||
314 | this.setAvailable(false); |
||
315 | this.addError(new ReprojectLayerException(getName(), e)); |
||
316 | } |
||
317 | 12349 | jaume | //Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
|
318 | if (rAux.getWidth()==0 && rAux.getHeight()==0) { |
||
319 | rAux=new Rectangle2D.Double(0,0,100,100); |
||
320 | } |
||
321 | 6476 | caballero | |
322 | 12349 | jaume | return rAux;
|
323 | } |
||
324 | 214 | fernando | |
325 | 12466 | jaume | /**
|
326 | * Draws using IFeatureIterator. This method will replace the old draw(...) one.
|
||
327 | * @autor jaume dominguez faus - jaume.dominguez@iver.es
|
||
328 | * @param image
|
||
329 | * @param g
|
||
330 | * @param viewPort
|
||
331 | * @param cancel
|
||
332 | * @param scale
|
||
333 | * @throws ReadDriverException
|
||
334 | */
|
||
335 | 18621 | jdominguez | private void _draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
336 | 12349 | jaume | Cancellable cancel, double scale) throws ReadDriverException { |
337 | 14369 | jdominguez | boolean bDrawShapes = true; |
338 | if (legend instanceof SingleSymbolLegend) { |
||
339 | bDrawShapes = legend.getDefaultSymbol().isShapeVisible(); |
||
340 | } |
||
341 | 14452 | vcaballero | Point2D offset = viewPort.getOffset();
|
342 | 14369 | jdominguez | double dpi = MapContext.getScreenDPI();
|
343 | 12657 | jaume | |
344 | 15601 | vcaballero | |
345 | |||
346 | 14369 | jdominguez | if (bDrawShapes) {
|
347 | 15601 | vcaballero | boolean cacheFeatures = isSpatialCacheEnabled();
|
348 | SpatialCache cache = null;
|
||
349 | 25953 | vcaballero | if (cacheFeatures) {
|
350 | getSpatialCache().clearAll(); |
||
351 | cache = getSpatialCache(); |
||
352 | } |
||
353 | 11704 | jaume | |
354 | 14369 | jdominguez | try {
|
355 | ArrayList<String> fieldList = new ArrayList<String>(); |
||
356 | 11704 | jaume | |
357 | 14369 | jdominguez | // fields from legend
|
358 | String[] aux = null; |
||
359 | 13445 | caballero | |
360 | 14369 | jdominguez | if (legend instanceof IClassifiedVectorLegend) { |
361 | aux = ((IClassifiedVectorLegend) legend).getClassifyingFieldNames(); |
||
362 | 25274 | vcaballero | if (aux!=null) |
363 | for (int i = 0; i < aux.length; i++) { |
||
364 | fieldList.add(aux[i]); |
||
365 | } |
||
366 | 14369 | jdominguez | } |
367 | |||
368 | 18621 | jdominguez | // Get the iterator over the visible features
|
369 | IFeatureIterator it = getSource().getFeatureIterator( |
||
370 | viewPort.getAdjustedExtent(), |
||
371 | fieldList.toArray(new String[fieldList.size()]), |
||
372 | viewPort.getProjection(), |
||
373 | true);
|
||
374 | 23731 | vcaballero | |
375 | 14369 | jdominguez | ZSort zSort = ((IVectorLegend) getLegend()).getZSort(); |
376 | 23731 | vcaballero | |
377 | 18621 | jdominguez | boolean bSymbolLevelError = false; |
378 | 23731 | vcaballero | |
379 | 14369 | jdominguez | // if layer has map levels it will use a ZSort
|
380 | boolean useZSort = zSort != null && zSort.isUsingZSort(); |
||
381 | 12075 | jaume | |
382 | 14369 | jdominguez | // -- visual FX stuff
|
383 | long time = System.currentTimeMillis(); |
||
384 | BufferedImage virtualBim;
|
||
385 | Graphics2D virtualGraphics;
|
||
386 | 11853 | jaume | |
387 | 14369 | jdominguez | // render temporary map each screenRefreshRate milliseconds;
|
388 | int screenRefreshDelay = (int) ((1D/MapControl.getDrawFrameRate())*3*1000); |
||
389 | BufferedImage[] imageLevels = null; |
||
390 | Graphics2D[] graphics = null; |
||
391 | if (useZSort) {
|
||
392 | imageLevels = new BufferedImage[zSort.getLevelCount()]; |
||
393 | graphics = new Graphics2D[imageLevels.length]; |
||
394 | for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
||
395 | imageLevels[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
||
396 | graphics[i] = imageLevels[i].createGraphics(); |
||
397 | 14409 | vcaballero | graphics[i].setTransform(g.getTransform()); |
398 | 20704 | vcaballero | graphics[i].setRenderingHints(g.getRenderingHints()); |
399 | 14369 | jdominguez | } |
400 | } |
||
401 | // -- end visual FX stuff
|
||
402 | 12466 | jaume | |
403 | 23731 | vcaballero | |
404 | 14369 | jdominguez | // Iteration over each feature
|
405 | while ( !cancel.isCanceled() && it.hasNext()) {
|
||
406 | IFeature feat = it.next(); |
||
407 | IGeometry geom = feat.getGeometry(); |
||
408 | 11853 | jaume | |
409 | 15601 | vcaballero | if (cacheFeatures) {
|
410 | if (cache.getMaxFeatures() >= cache.size()) {
|
||
411 | 25953 | vcaballero | // already reprojected
|
412 | cache.insert(geom.getBounds2D(), geom); |
||
413 | } |
||
414 | 15601 | vcaballero | } |
415 | |||
416 | 14369 | jdominguez | // retrieve the symbol associated to such feature
|
417 | ISymbol sym = legend.getSymbolByFeature(feat); |
||
418 | |||
419 | 18621 | jdominguez | if (sym == null) continue; |
420 | 23731 | vcaballero | |
421 | 14573 | vcaballero | //C?digo para poder acceder a los ?ndices para ver si est? seleccionado un Feature
|
422 | ReadableVectorial rv=getSource(); |
||
423 | int selectionIndex=-1; |
||
424 | if (rv instanceof ISpatialDB){ |
||
425 | 22465 | vcaballero | selectionIndex = ((ISpatialDB)rv).getRowIndexByFID(feat); |
426 | 14573 | vcaballero | }else{
|
427 | 22465 | vcaballero | selectionIndex = Integer.parseInt(feat.getID());
|
428 | 14369 | jdominguez | } |
429 | 14573 | vcaballero | if (selectionIndex!=-1) { |
430 | if (selectionSupport.isSelected(selectionIndex)) {
|
||
431 | 25953 | vcaballero | sym = sym.getSymbolForSelection(); |
432 | } |
||
433 | } |
||
434 | 14369 | jdominguez | |
435 | // Check if this symbol is sized with CartographicSupport
|
||
436 | CartographicSupport csSym = null;
|
||
437 | int symbolType = sym.getSymbolType();
|
||
438 | boolean bDrawCartographicSupport = false; |
||
439 | |||
440 | if ( symbolType == FShape.POINT
|
||
441 | 12466 | jaume | || symbolType == FShape.LINE |
442 | || sym instanceof CartographicSupport) {
|
||
443 | 11807 | jaume | |
444 | 18621 | jdominguez | // patch
|
445 | 25953 | vcaballero | if (!sym.getClass().equals(FSymbol.class)) {
|
446 | csSym = (CartographicSupport) sym; |
||
447 | bDrawCartographicSupport = (csSym.getUnit() != -1);
|
||
448 | } |
||
449 | 14369 | jdominguez | } |
450 | 11853 | jaume | |
451 | 14369 | jdominguez | int x = -1; |
452 | int y = -1; |
||
453 | int[] xyCoords = new int[2]; |
||
454 | 11853 | jaume | |
455 | 14369 | jdominguez | // Check if size is a pixel
|
456 | boolean onePoint = bDrawCartographicSupport ?
|
||
457 | 14409 | vcaballero | isOnePoint(g.getTransform(), viewPort, MapContext.getScreenDPI(), csSym, geom, xyCoords) : |
458 | 25953 | vcaballero | isOnePoint(g.getTransform(), viewPort, geom, xyCoords); |
459 | 12466 | jaume | |
460 | 25953 | vcaballero | // Avoid out of bounds exceptions
|
461 | if (onePoint) {
|
||
462 | x = xyCoords[0];
|
||
463 | y = xyCoords[1];
|
||
464 | if (x<0 || y<0 || x>= viewPort.getImageWidth() || y>=viewPort.getImageHeight()) continue; |
||
465 | } |
||
466 | 13445 | caballero | |
467 | 25953 | vcaballero | if (useZSort) {
|
468 | // Check if this symbol is a multilayer
|
||
469 | 26366 | vcaballero | int[] symLevels = zSort.getLevels(sym); |
470 | 25953 | vcaballero | if (sym instanceof IMultiLayerSymbol) { |
471 | // if so, treat each of its layers as a single symbol
|
||
472 | // in its corresponding map level
|
||
473 | IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
||
474 | for (int i = 0; !cancel.isCanceled() && i < mlSym.getLayerCount(); i++) { |
||
475 | ISymbol mySym = mlSym.getLayer(i); |
||
476 | 26366 | vcaballero | int symbolLevel = 0; |
477 | if (symLevels != null) { |
||
478 | symbolLevel = symLevels[i]; |
||
479 | } else {
|
||
480 | 25953 | vcaballero | /* an error occured when managing symbol levels.
|
481 | * some of the legend changed events regarding the
|
||
482 | * symbols did not finish satisfactory and the legend
|
||
483 | * is now inconsistent. For this drawing, it will finish
|
||
484 | * as it was at the bottom (level 0) but, when done, the
|
||
485 | * ZSort will be reset to avoid app crashes. This is
|
||
486 | * a bug that has to be fixed.
|
||
487 | */
|
||
488 | bSymbolLevelError = true;
|
||
489 | } |
||
490 | 23731 | vcaballero | |
491 | 25953 | vcaballero | if (onePoint) {
|
492 | if (x<0 || y<0 || x>= imageLevels[symbolLevel].getWidth() || y>=imageLevels[symbolLevel].getHeight()) continue; |
||
493 | imageLevels[symbolLevel].setRGB(x, y, mySym.getOnePointRgb()); |
||
494 | } else {
|
||
495 | if (!bDrawCartographicSupport) {
|
||
496 | geom.drawInts(graphics[symbolLevel], viewPort, mySym, cancel); |
||
497 | } else {
|
||
498 | geom.drawInts(graphics[symbolLevel], viewPort, dpi, (CartographicSupport) mySym, cancel); |
||
499 | } |
||
500 | } |
||
501 | } |
||
502 | } else {
|
||
503 | // else, just draw the symbol in its level
|
||
504 | 26366 | vcaballero | int symbolLevel = 0; |
505 | if (symLevels != null) { |
||
506 | |||
507 | symbolLevel=symLevels[0];
|
||
508 | } else {
|
||
509 | /* If symLevels == null
|
||
510 | * an error occured when managing symbol levels.
|
||
511 | 25953 | vcaballero | * some of the legend changed events regarding the
|
512 | * symbols did not finish satisfactory and the legend
|
||
513 | * is now inconsistent. For this drawing, it will finish
|
||
514 | * as it was at the bottom (level 0). This is
|
||
515 | * a bug that has to be fixed.
|
||
516 | */
|
||
517 | // bSymbolLevelError = true;
|
||
518 | } |
||
519 | 214 | fernando | |
520 | 25953 | vcaballero | if (!bDrawCartographicSupport) {
|
521 | geom.drawInts(graphics[symbolLevel], viewPort, sym, cancel); |
||
522 | } else {
|
||
523 | geom.drawInts(graphics[symbolLevel], viewPort, dpi, (CartographicSupport) csSym, cancel); |
||
524 | } |
||
525 | } |
||
526 | 6246 | caballero | |
527 | 25953 | vcaballero | // -- visual FX stuff
|
528 | // Cuando el offset!=0 se est? dibujando sobre el Layout y por tanto no tiene que ejecutar el siguiente c?digo.
|
||
529 | if (offset.getX()==0 && offset.getY()==0) |
||
530 | if ((System.currentTimeMillis() - time) > screenRefreshDelay) { |
||
531 | virtualBim = new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_ARGB); |
||
532 | virtualGraphics = virtualBim.createGraphics(); |
||
533 | virtualGraphics.drawImage(image,0,0, null); |
||
534 | for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
||
535 | virtualGraphics.drawImage(imageLevels[i],0,0, null); |
||
536 | } |
||
537 | g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
||
538 | g.drawImage(virtualBim, 0, 0, null); |
||
539 | time = System.currentTimeMillis();
|
||
540 | } |
||
541 | // -- end visual FX stuff
|
||
542 | |||
543 | } else {
|
||
544 | // no ZSort, so there is only a map level, symbols are
|
||
545 | // just drawn.
|
||
546 | if (onePoint) {
|
||
547 | if (x<0 || y<0 || x>= image.getWidth() || y>=image.getHeight()) continue; |
||
548 | image.setRGB(x, y, sym.getOnePointRgb()); |
||
549 | } else {
|
||
550 | if (!bDrawCartographicSupport) {
|
||
551 | geom.drawInts(g, viewPort, sym, cancel); |
||
552 | } else {
|
||
553 | geom.drawInts(g, viewPort, dpi, csSym, cancel); |
||
554 | } |
||
555 | } |
||
556 | } |
||
557 | 14369 | jdominguez | } |
558 | 650 | vcaballero | |
559 | 14369 | jdominguez | if (useZSort) {
|
560 | g.drawImage(image, 0, 0, null); |
||
561 | 25953 | vcaballero | g.translate(offset.getX(), offset.getY()); |
562 | 20704 | vcaballero | for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
563 | 14369 | jdominguez | g.drawImage(imageLevels[i],0,0, null); |
564 | imageLevels[i] = null;
|
||
565 | graphics[i] = null;
|
||
566 | 12349 | jaume | } |
567 | 25953 | vcaballero | g.translate(-offset.getX(), -offset.getY()); |
568 | 14369 | jdominguez | imageLevels = null;
|
569 | graphics = null;
|
||
570 | } |
||
571 | it.closeIterator(); |
||
572 | 23731 | vcaballero | |
573 | 18621 | jdominguez | if (bSymbolLevelError) {
|
574 | ((IVectorLegend) getLegend()).setZSort(null);
|
||
575 | } |
||
576 | 23731 | vcaballero | |
577 | 14369 | jdominguez | } catch (ReadDriverException e) {
|
578 | this.setVisible(false); |
||
579 | this.setActive(false); |
||
580 | throw e;
|
||
581 | 14409 | vcaballero | } |
582 | 23731 | vcaballero | |
583 | |||
584 | 14369 | jdominguez | } |
585 | 12349 | jaume | } |
586 | 11807 | jaume | |
587 | 14409 | vcaballero | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
588 | 12349 | jaume | Cancellable cancel, double scale) throws ReadDriverException { |
589 | 16254 | vcaballero | // forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD = true;
|
590 | 24271 | vcaballero | // if (!isUseStrategy()) {
|
591 | 12349 | jaume | _draw(image, g, viewPort, cancel, scale); |
592 | 24271 | vcaballero | // } else {
|
593 | //// moved up to FLayers
|
||
594 | //// if (isWithinScale(scale)) {
|
||
595 | //
|
||
596 | //
|
||
597 | // // Las que solo tienen etiquetado sin pintar el shape,
|
||
598 | // // no pasamos por ellas
|
||
599 | // boolean bDrawShapes = true;
|
||
600 | // if (legend instanceof SingleSymbolLegend) {
|
||
601 | // if (legend.getDefaultSymbol().isShapeVisible() == false)
|
||
602 | // bDrawShapes = false;
|
||
603 | // }
|
||
604 | // if (bDrawShapes) {
|
||
605 | // Strategy strategy = StrategyManager.getStrategy(this);
|
||
606 | // try {
|
||
607 | // prepareDrawing(image, g, viewPort);
|
||
608 | // strategy.draw(image, g, viewPort, cancel);
|
||
609 | // } catch (ReadDriverException e) {
|
||
610 | // this.setVisible(false);
|
||
611 | // this.setActive(false);
|
||
612 | // throw e;
|
||
613 | // }
|
||
614 | // }
|
||
615 | // if (getVirtualLayers() != null) {
|
||
616 | // getVirtualLayers().draw(image, g, viewPort, cancel, scale);
|
||
617 | // }
|
||
618 | //// }
|
||
619 | // }
|
||
620 | 12349 | jaume | } |
621 | 5484 | caballero | |
622 | 12349 | jaume | /**
|
623 | * Se llama antes de empezar a pintar.
|
||
624 | * Es ?til para preparar la cache a emplear, las leyendas, etc.
|
||
625 | * @param image
|
||
626 | * @param g
|
||
627 | * @param viewPort
|
||
628 | */
|
||
629 | private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
||
630 | |||
631 | } |
||
632 | |||
633 | public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
634 | 12657 | jaume | double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
635 | // TEST METHOD
|
||
636 | |||
637 | 23731 | vcaballero | |
638 | 18621 | jdominguez | /* SVN */
|
639 | 23731 | vcaballero | |
640 | 18621 | jdominguez | /* boolean bDrawShapes = true;
|
641 | 12657 | jaume | if (legend instanceof SingleSymbolLegend) {
|
642 | bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
|
||
643 | }
|
||
644 | |||
645 | |||
646 | if (bDrawShapes) {
|
||
647 | double dpi = 72;
|
||
648 | |||
649 | PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
|
||
650 | if (resolution.equals(PrintQuality.NORMAL)){
|
||
651 | dpi = 300;
|
||
652 | } else if (resolution.equals(PrintQuality.HIGH)){
|
||
653 | dpi = 600;
|
||
654 | } else if (resolution.equals(PrintQuality.DRAFT)){
|
||
655 | dpi = 72;
|
||
656 | }
|
||
657 | |||
658 | |||
659 | try {
|
||
660 | prepareDrawing(null, g, viewPort);
|
||
661 | 13884 | jaume | ArrayList<String> fieldList = new ArrayList<String>();
|
662 | String[] aux;
|
||
663 | 14409 | vcaballero | |
664 | 12657 | jaume | // fields from legend
|
665 | 13884 | jaume | if (legend instanceof IClassifiedVectorLegend) {
|
666 | aux = ((IClassifiedVectorLegend) legend).
|
||
667 | getClassifyingFieldNames();
|
||
668 | for (int i = 0; i < aux.length; i++) {
|
||
669 | fieldList.add(aux[i]);
|
||
670 | }
|
||
671 | 12657 | jaume | }
|
672 | |||
673 | // fields from labeling
|
||
674 | if (isLabeled()) {
|
||
675 | aux = getLabelingStrategy().getUsedFields();
|
||
676 | for (int i = 0; i < aux.length; i++) {
|
||
677 | fieldList.add(aux[i]);
|
||
678 | }
|
||
679 | }
|
||
680 | |||
681 | 13884 | jaume | ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
|
682 | 12657 | jaume | |
683 | // if layer has map levels it will use a ZSort
|
||
684 | boolean useZSort = zSort != null && zSort.isUsingZSort();
|
||
685 | |||
686 | |||
687 | int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
|
||
688 | for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
|
||
689 | // Get the iterator over the visible features
|
||
690 | IFeatureIterator it = getSource().getFeatureIterator(
|
||
691 | viewPort.getAdjustedExtent(),
|
||
692 | 13884 | jaume | fieldList.toArray(new String[fieldList.size()]),
|
693 | 12657 | jaume | viewPort.getProjection(),
|
694 | true);
|
||
695 | |||
696 | // Iteration over each feature
|
||
697 | while ( !cancel.isCanceled() && it.hasNext()) {
|
||
698 | IFeature feat = it.next();
|
||
699 | IGeometry geom = feat.getGeometry();
|
||
700 | |||
701 | // retreive the symbol associated to such feature
|
||
702 | ISymbol sym = legend.getSymbolByFeature(feat);
|
||
703 | 14409 | vcaballero | |
704 | 14369 | jdominguez | if (useZSort) {
|
705 | // Check if this symbol is a multilayer
|
||
706 | if (sym instanceof IMultiLayerSymbol) {
|
||
707 | // if so, get the layer corresponding to the current
|
||
708 | // level. If none, continue to next iteration
|
||
709 | IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
|
||
710 | for (int i = 0; i < mlSym.getLayerCount(); i++) {
|
||
711 | ISymbol mySym = mlSym.getLayer(i);
|
||
712 | if (zSort.getSymbolLevel(mySym) == mapPass) {
|
||
713 | sym = mySym;
|
||
714 | break;
|
||
715 | }
|
||
716 | System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
|
||
717 | }
|
||
718 | 14409 | vcaballero | |
719 | 14369 | jdominguez | if (sym == null) {
|
720 | continue;
|
||
721 | }
|
||
722 | } else {
|
||
723 | // else, just draw the symbol in its level
|
||
724 | if (zSort.getSymbolLevel(sym) != mapPass) {
|
||
725 | System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
|
||
726 | continue;
|
||
727 | }
|
||
728 | }
|
||
729 | }
|
||
730 | 12657 | jaume | |
731 | // Check if this symbol is sized with CartographicSupport
|
||
732 | CartographicSupport csSym = null;
|
||
733 | int symbolType = sym.getSymbolType();
|
||
734 | boolean bDrawCartographicSupport = false;
|
||
735 | |||
736 | if ( symbolType == FShape.POINT
|
||
737 | || symbolType == FShape.LINE
|
||
738 | || sym instanceof CartographicSupport) {
|
||
739 | |||
740 | csSym = (CartographicSupport) sym;
|
||
741 | bDrawCartographicSupport = (csSym.getUnit() != -1);
|
||
742 | }
|
||
743 | 14409 | vcaballero | |
744 | 14369 | jdominguez | System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription());
|
745 | 12657 | jaume | |
746 | if (!bDrawCartographicSupport) {
|
||
747 | 13952 | jaume | geom.drawInts(g, viewPort, sym, null);
|
748 | 12657 | jaume | } else {
|
749 | geom.drawInts(g, viewPort, dpi, (CartographicSupport) csSym);
|
||
750 | }
|
||
751 | |||
752 | }
|
||
753 | it.closeIterator();
|
||
754 | }
|
||
755 | } catch (ReadDriverException e) {
|
||
756 | this.setVisible(false);
|
||
757 | this.setActive(false);
|
||
758 | throw e;
|
||
759 | 14409 | vcaballero | }
|
760 | 18621 | jdominguez | */
|
761 | 23731 | vcaballero | |
762 | |||
763 | 18621 | jdominguez | // TEST METHOD
|
764 | boolean bDrawShapes = true; |
||
765 | if (legend instanceof SingleSymbolLegend) { |
||
766 | bDrawShapes = legend.getDefaultSymbol().isShapeVisible(); |
||
767 | 12657 | jaume | } |
768 | 18621 | jdominguez | |
769 | |||
770 | if (bDrawShapes) {
|
||
771 | |||
772 | try {
|
||
773 | double dpi = 72; |
||
774 | |||
775 | PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class); |
||
776 | if (resolution.equals(PrintQuality.NORMAL)){ |
||
777 | dpi = 300;
|
||
778 | } else if (resolution.equals(PrintQuality.HIGH)){ |
||
779 | dpi = 600;
|
||
780 | } else if (resolution.equals(PrintQuality.DRAFT)){ |
||
781 | dpi = 72;
|
||
782 | } |
||
783 | ArrayList<String> fieldList = new ArrayList<String>(); |
||
784 | String[] aux; |
||
785 | |||
786 | // fields from legend
|
||
787 | if (legend instanceof IClassifiedVectorLegend) { |
||
788 | aux = ((IClassifiedVectorLegend) legend). |
||
789 | getClassifyingFieldNames(); |
||
790 | for (int i = 0; i < aux.length; i++) { |
||
791 | fieldList.add(aux[i]); |
||
792 | } |
||
793 | } |
||
794 | //
|
||
795 | // // fields from labeling
|
||
796 | // if (isLabeled()) {
|
||
797 | // aux = getLabelingStrategy().getUsedFields();
|
||
798 | // for (int i = 0; i < aux.length; i++) {
|
||
799 | // fieldList.add(aux[i]);
|
||
800 | // }
|
||
801 | // }
|
||
802 | |||
803 | ZSort zSort = ((IVectorLegend) getLegend()).getZSort(); |
||
804 | |||
805 | // if layer has map levels it will use a ZSort
|
||
806 | boolean useZSort = zSort != null && zSort.isUsingZSort(); |
||
807 | |||
808 | |||
809 | int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1; |
||
810 | for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) { |
||
811 | // Get the iterator over the visible features
|
||
812 | IFeatureIterator it = getSource().getFeatureIterator( |
||
813 | viewPort.getAdjustedExtent(), |
||
814 | fieldList.toArray(new String[fieldList.size()]), |
||
815 | viewPort.getProjection(), |
||
816 | true);
|
||
817 | |||
818 | // Iteration over each feature
|
||
819 | while ( !cancel.isCanceled() && it.hasNext()) {
|
||
820 | IFeature feat = it.next(); |
||
821 | IGeometry geom = feat.getGeometry(); |
||
822 | |||
823 | // retreive the symbol associated to such feature
|
||
824 | ISymbol sym = legend.getSymbolByFeature(feat); |
||
825 | 27621 | vcaballero | if (sym == null) { |
826 | continue;
|
||
827 | } |
||
828 | 18621 | jdominguez | if (useZSort) {
|
829 | 26366 | vcaballero | int[] symLevels = zSort.getLevels(sym); |
830 | if(symLevels != null){ |
||
831 | // Check if this symbol is a multilayer
|
||
832 | if (sym instanceof IMultiLayerSymbol) { |
||
833 | // if so, get the layer corresponding to the current
|
||
834 | // level. If none, continue to next iteration
|
||
835 | IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
||
836 | for (int i = 0; i < mlSym.getLayerCount(); i++) { |
||
837 | ISymbol mySym = mlSym.getLayer(i); |
||
838 | if (symLevels[i] == mapPass) {
|
||
839 | sym = mySym; |
||
840 | break;
|
||
841 | } |
||
842 | System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")"); |
||
843 | } |
||
844 | } else {
|
||
845 | // else, just draw the symbol in its level
|
||
846 | if (symLevels[0] != mapPass) { |
||
847 | System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")"); |
||
848 | continue;
|
||
849 | } |
||
850 | } |
||
851 | } |
||
852 | 18621 | jdominguez | } |
853 | |||
854 | // Check if this symbol is sized with CartographicSupport
|
||
855 | CartographicSupport csSym = null;
|
||
856 | int symbolType = sym.getSymbolType();
|
||
857 | |||
858 | if ( symbolType == FShape.POINT
|
||
859 | || symbolType == FShape.LINE |
||
860 | || sym instanceof CartographicSupport) {
|
||
861 | |||
862 | csSym = (CartographicSupport) sym; |
||
863 | } |
||
864 | |||
865 | 26902 | vcaballero | // System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription());
|
866 | 18621 | jdominguez | |
867 | 28417 | vcaballero | if (csSym == null) { |
868 | geom.drawInts(g, viewPort, sym, null);
|
||
869 | } else {
|
||
870 | 18621 | jdominguez | geom.drawInts(g, viewPort, dpi, (CartographicSupport) csSym, cancel); |
871 | 28417 | vcaballero | } |
872 | 18621 | jdominguez | |
873 | } |
||
874 | it.closeIterator(); |
||
875 | } |
||
876 | } catch (ReadDriverException e) {
|
||
877 | this.setVisible(false); |
||
878 | this.setActive(false); |
||
879 | throw e;
|
||
880 | } |
||
881 | } |
||
882 | 12349 | jaume | } |
883 | |||
884 | 12657 | jaume | |
885 | 12349 | jaume | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
886 | double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
||
887 | 24271 | vcaballero | // if (forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD) {
|
888 | 12657 | jaume | _print(g, viewPort, cancel, scale, properties); |
889 | 24271 | vcaballero | // } else {
|
890 | //// moved up to Flayers
|
||
891 | //// if (isVisible() && isWithinScale(scale)) {
|
||
892 | // Strategy strategy = StrategyManager.getStrategy(this);
|
||
893 | //
|
||
894 | // strategy.print(g, viewPort, cancel, properties);
|
||
895 | // ILabelingStrategy labeling;
|
||
896 | // if ( (labeling = getLabelingStrategy() ) != null) {
|
||
897 | // // contains labels
|
||
898 | // labeling.print(g, viewPort, cancel, properties);
|
||
899 | // }
|
||
900 | //// }
|
||
901 | // }
|
||
902 | 12349 | jaume | } |
903 | |||
904 | public void deleteSpatialIndex() { |
||
905 | //must we delete possible spatial indexes files?
|
||
906 | spatialIndex = null;
|
||
907 | } |
||
908 | |||
909 | 5414 | azabala | /**
|
910 | * <p>
|
||
911 | * Creates an spatial index associated to this layer.
|
||
912 | * The spatial index will used
|
||
913 | * the native projection of the layer, so if the layer is reprojected, it will
|
||
914 | * be ignored.
|
||
915 | * </p>
|
||
916 | * @param cancelMonitor instance of CancellableMonitorable that allows
|
||
917 | * to monitor progress of spatial index creation, and cancel the process
|
||
918 | 5484 | caballero | */
|
919 | 5414 | azabala | public void createSpatialIndex(CancellableMonitorable cancelMonitor){ |
920 | 12349 | jaume | // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
921 | 5414 | azabala | // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
922 | // para que acepten recorrer sin geometria, solo con rectangulos.
|
||
923 | 5484 | caballero | |
924 | 12349 | jaume | //If this vectorial layer is based in a spatial database, the spatial
|
925 | //index is already implicit. We only will index file drivers
|
||
926 | ReadableVectorial va = getSource(); |
||
927 | //We must think in non spatial databases, like HSQLDB
|
||
928 | if(!(va instanceof VectorialFileAdapter)){ |
||
929 | return;
|
||
930 | } |
||
931 | if (!(va.getDriver() instanceof BoundedShapes)) { |
||
932 | return;
|
||
933 | } |
||
934 | File file = ((VectorialFileAdapter) va).getFile();
|
||
935 | String fileName = file.getAbsolutePath();
|
||
936 | ISpatialIndex localCopy = null;
|
||
937 | try {
|
||
938 | va.start(); |
||
939 | localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(), |
||
940 | va.getShapeCount(), true);
|
||
941 | 5484 | caballero | |
942 | 12349 | jaume | } catch (SpatialIndexException e1) {
|
943 | // Probably we dont have writing permissions
|
||
944 | String directoryName = System.getProperty("java.io.tmpdir"); |
||
945 | File newFile = new File(directoryName + |
||
946 | File.separator +
|
||
947 | file.getName()); |
||
948 | String newFileName = newFile.getName();
|
||
949 | try {
|
||
950 | localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(), |
||
951 | va.getShapeCount(), true);
|
||
952 | } catch (SpatialIndexException e) {
|
||
953 | // if we cant build a file based spatial index, we'll build
|
||
954 | // a pure memory spatial index
|
||
955 | localCopy = new QuadtreeJts();
|
||
956 | } catch (ReadDriverException e) {
|
||
957 | localCopy = new QuadtreeJts();
|
||
958 | } |
||
959 | 5115 | caballero | |
960 | 12787 | jaume | } catch(Exception e){ |
961 | 12349 | jaume | e.printStackTrace(); |
962 | }//try
|
||
963 | 5414 | azabala | BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
964 | try {
|
||
965 | for (int i=0; i < va.getShapeCount(); i++) |
||
966 | { |
||
967 | 12349 | jaume | if(cancelMonitor != null){ |
968 | if(cancelMonitor.isCanceled())
|
||
969 | return;
|
||
970 | cancelMonitor.reportStep(); |
||
971 | } |
||
972 | 5414 | azabala | Rectangle2D r = shapeBounds.getShapeBounds(i);
|
973 | 5916 | azabala | if(r != null) |
974 | 12349 | jaume | localCopy.insert(r, i); |
975 | 5414 | azabala | } // for
|
976 | va.stop(); |
||
977 | if(localCopy instanceof IPersistentSpatialIndex) |
||
978 | 12349 | jaume | ((IPersistentSpatialIndex) localCopy).flush(); |
979 | 5414 | azabala | spatialIndex = localCopy; |
980 | 11286 | azabala | //vectorial adapter needs a reference to the spatial index, to solve
|
981 | //request for feature iteration based in spatial queries
|
||
982 | source.setSpatialIndex(spatialIndex); |
||
983 | 10627 | caballero | } catch (ReadDriverException e) {
|
984 | 12349 | jaume | // TODO Auto-generated catch block
|
985 | e.printStackTrace(); |
||
986 | } |
||
987 | 5414 | azabala | } |
988 | 5484 | caballero | |
989 | 12349 | jaume | public void createSpatialIndex() { |
990 | createSpatialIndex(null);
|
||
991 | } |
||
992 | 214 | fernando | |
993 | 12349 | jaume | public void process(FeatureVisitor visitor, FBitSet subset) |
994 | throws ReadDriverException, ExpansionFileReadException, VisitorException {
|
||
995 | Strategy s = StrategyManager.getStrategy(this);
|
||
996 | s.process(visitor, subset); |
||
997 | } |
||
998 | 228 | fernando | |
999 | 12349 | jaume | public void process(FeatureVisitor visitor) throws ReadDriverException, VisitorException { |
1000 | Strategy s = StrategyManager.getStrategy(this);
|
||
1001 | s.process(visitor); |
||
1002 | } |
||
1003 | 4223 | caballero | |
1004 | 12349 | jaume | public void process(FeatureVisitor visitor, Rectangle2D rect) |
1005 | throws ReadDriverException, ExpansionFileReadException, VisitorException {
|
||
1006 | Strategy s = StrategyManager.getStrategy(this);
|
||
1007 | s.process(visitor, rect); |
||
1008 | } |
||
1009 | 562 | fernando | |
1010 | 12349 | jaume | public FBitSet queryByRect(Rectangle2D rect) throws ReadDriverException, VisitorException { |
1011 | Strategy s = StrategyManager.getStrategy(this);
|
||
1012 | 562 | fernando | |
1013 | 12349 | jaume | return s.queryByRect(rect);
|
1014 | } |
||
1015 | 214 | fernando | |
1016 | 12349 | jaume | public FBitSet queryByPoint(Point2D p, double tolerance) |
1017 | throws ReadDriverException, VisitorException {
|
||
1018 | Strategy s = StrategyManager.getStrategy(this);
|
||
1019 | return s.queryByPoint(p, tolerance);
|
||
1020 | } |
||
1021 | 3940 | caballero | |
1022 | 12349 | jaume | public FBitSet queryByShape(IGeometry g, int relationship) |
1023 | throws ReadDriverException, VisitorException {
|
||
1024 | Strategy s = StrategyManager.getStrategy(this);
|
||
1025 | return s.queryByShape(g, relationship);
|
||
1026 | } |
||
1027 | 5048 | ldiaz | |
1028 | 12349 | jaume | public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException { |
1029 | Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p); |
||
1030 | FBitSet bs = queryByPoint(pReal, tolerance); |
||
1031 | VectorialXMLItem[] item = new VectorialXMLItem[1]; |
||
1032 | item[0] = new VectorialXMLItem(bs, this); |
||
1033 | 5115 | caballero | |
1034 | 12349 | jaume | return item;
|
1035 | } |
||
1036 | 5152 | fjp | |
1037 | 13884 | jaume | public void setLegend(IVectorLegend r) throws LegendLayerException { |
1038 | 24160 | jmvivo | if (this.legend == r){ |
1039 | return;
|
||
1040 | } |
||
1041 | if (this.legend != null && this.legend.equals(r)){ |
||
1042 | return;
|
||
1043 | } |
||
1044 | 13884 | jaume | IVectorLegend oldLegend = legend; |
1045 | 12349 | jaume | legend = r; |
1046 | try {
|
||
1047 | legend.setDataSource(getRecordset()); |
||
1048 | } catch (FieldNotFoundException e1) {
|
||
1049 | throw new LegendLayerException(getName(),e1); |
||
1050 | } catch (ReadDriverException e1) {
|
||
1051 | throw new LegendLayerException(getName(),e1); |
||
1052 | 24160 | jmvivo | } finally{
|
1053 | this.updateDrawVersion();
|
||
1054 | 12349 | jaume | } |
1055 | 25033 | jmvivo | if (oldLegend != null){ |
1056 | oldLegend.removeLegendListener(this);
|
||
1057 | } |
||
1058 | if (legend != null){ |
||
1059 | legend.addLegendListener(this);
|
||
1060 | } |
||
1061 | 12349 | jaume | LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
1062 | oldLegend, legend); |
||
1063 | 28761 | vcaballero | e.setLayer(this);
|
1064 | 12349 | jaume | callLegendChanged(e); |
1065 | } |
||
1066 | 303 | fernando | |
1067 | 12349 | jaume | /**
|
1068 | * Devuelve la Leyenda de la capa.
|
||
1069 | *
|
||
1070 | * @return Leyenda.
|
||
1071 | */
|
||
1072 | public ILegend getLegend() {
|
||
1073 | return legend;
|
||
1074 | } |
||
1075 | 373 | fernando | |
1076 | 12349 | jaume | /**
|
1077 | * Devuelve el tipo de shape que contiene la capa.
|
||
1078 | *
|
||
1079 | * @return tipo de shape.
|
||
1080 | *
|
||
1081 | * @throws DriverException
|
||
1082 | */
|
||
1083 | public int getShapeType() throws ReadDriverException { |
||
1084 | if (typeShape == -1) { |
||
1085 | getSource().start(); |
||
1086 | typeShape = getSource().getShapeType(); |
||
1087 | getSource().stop(); |
||
1088 | } |
||
1089 | 562 | fernando | |
1090 | 12349 | jaume | return typeShape;
|
1091 | } |
||
1092 | 435 | vcaballero | |
1093 | 12349 | jaume | public XMLEntity getXMLEntity() throws XMLException { |
1094 | if (!this.isAvailable() && this.orgXMLEntity != null) { |
||
1095 | return this.orgXMLEntity; |
||
1096 | } |
||
1097 | XMLEntity xml = super.getXMLEntity();
|
||
1098 | if (getLegend()!=null) |
||
1099 | xml.addChild(getLegend().getXMLEntity()); |
||
1100 | try {
|
||
1101 | if (getRecordset()!=null) |
||
1102 | xml.addChild(getRecordset().getSelectionSupport().getXMLEntity()); |
||
1103 | } catch (ReadDriverException e1) {
|
||
1104 | e1.printStackTrace(); |
||
1105 | throw new XMLException(e1); |
||
1106 | } |
||
1107 | // Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
|
||
1108 | ReadableVectorial rv=getSource(); |
||
1109 | xml.putProperty("type", "vectorial"); |
||
1110 | if (source instanceof VectorialEditableAdapter) { |
||
1111 | setSource(((VectorialEditableAdapter) source).getOriginalAdapter()); |
||
1112 | } |
||
1113 | if (source instanceof VectorialFileAdapter) { |
||
1114 | xml.putProperty("type", "vectorial"); |
||
1115 | xml.putProperty("file", ((VectorialFileAdapter) source)
|
||
1116 | .getFile()); |
||
1117 | try {
|
||
1118 | xml.putProperty("recordset-name", source.getRecordset()
|
||
1119 | .getName()); |
||
1120 | } catch (ReadDriverException e) {
|
||
1121 | throw new XMLException(e); |
||
1122 | } catch (RuntimeException e) { |
||
1123 | e.printStackTrace(); |
||
1124 | } |
||
1125 | } else if (source instanceof VectorialDBAdapter) { |
||
1126 | xml.putProperty("type", "vectorial"); |
||
1127 | 3940 | caballero | |
1128 | 12349 | jaume | IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) source |
1129 | .getDriver(); |
||
1130 | 3940 | caballero | |
1131 | 12349 | jaume | // Guardamos el nombre del driver para poder recuperarlo
|
1132 | // con el DriverManager de Fernando.
|
||
1133 | xml.putProperty("db", dbDriver.getName());
|
||
1134 | try {
|
||
1135 | xml.putProperty("recordset-name", source.getRecordset()
|
||
1136 | .getName()); |
||
1137 | } catch (ReadDriverException e) {
|
||
1138 | throw new XMLException(e); |
||
1139 | } catch (RuntimeException e) { |
||
1140 | e.printStackTrace(); |
||
1141 | } |
||
1142 | xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos
|
||
1143 | // metido la leyenda y el
|
||
1144 | // selection support
|
||
1145 | } else if (source instanceof VectorialAdapter) { |
||
1146 | // Se supone que hemos hecho algo gen?rico.
|
||
1147 | xml.putProperty("type", "vectorial"); |
||
1148 | 3940 | caballero | |
1149 | 12349 | jaume | VectorialDriver driver = source.getDriver(); |
1150 | 3940 | caballero | |
1151 | 12349 | jaume | // Guardamos el nombre del driver para poder recuperarlo
|
1152 | // con el DriverManager de Fernando.
|
||
1153 | xml.putProperty("other", driver.getName());
|
||
1154 | // try {
|
||
1155 | try {
|
||
1156 | xml.putProperty("recordset-name", source.getRecordset()
|
||
1157 | .getName()); |
||
1158 | } catch (ReadDriverException e) {
|
||
1159 | throw new XMLException(e); |
||
1160 | } catch (RuntimeException e) { |
||
1161 | e.printStackTrace(); |
||
1162 | } |
||
1163 | 13913 | jaume | if (driver instanceof IPersistence) { |
1164 | 12349 | jaume | // xml.putProperty("className", driver.getClass().getName());
|
1165 | 13913 | jaume | IPersistence persist = (IPersistence) driver; |
1166 | 12349 | jaume | xml.addChild(persist.getXMLEntity()); // Tercer child. Antes
|
1167 | // hemos metido la
|
||
1168 | // leyenda y el
|
||
1169 | // selection support
|
||
1170 | } |
||
1171 | } |
||
1172 | if (rv!=null) |
||
1173 | setSource(rv); |
||
1174 | xml.putProperty("driverName", source.getDriver().getName());
|
||
1175 | if (bHasJoin)
|
||
1176 | xml.putProperty("hasJoin", "true"); |
||
1177 | 3940 | caballero | |
1178 | 12349 | jaume | // properties from ILabelable
|
1179 | xml.putProperty("isLabeled", isLabeled);
|
||
1180 | if (strategy != null) { |
||
1181 | XMLEntity strategyXML = strategy.getXMLEntity(); |
||
1182 | strategyXML.putProperty("Strategy", strategy.getClassName());
|
||
1183 | xml.addChild(strategy.getXMLEntity()); |
||
1184 | } |
||
1185 | 13558 | evercher | xml.addChild(getLinkProperties().getXMLEntity()); |
1186 | 12349 | jaume | return xml;
|
1187 | } |
||
1188 | 435 | vcaballero | |
1189 | 12349 | jaume | /**
|
1190 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
1191 | */
|
||
1192 | public void setXMLEntity03(XMLEntity xml) throws XMLException { |
||
1193 | 3940 | caballero | |
1194 | 12349 | jaume | super.setXMLEntity(xml);
|
1195 | legend = LegendFactory.createFromXML03(xml.getChild(0));
|
||
1196 | 2183 | fernando | |
1197 | 12349 | jaume | try {
|
1198 | setLegend(legend); |
||
1199 | } catch (LegendLayerException e) {
|
||
1200 | throw new XMLException(e); |
||
1201 | } |
||
1202 | 2183 | fernando | |
1203 | 12349 | jaume | try {
|
1204 | getRecordset().getSelectionSupport() |
||
1205 | .setXMLEntity03(xml.getChild(1));
|
||
1206 | } catch (ReadDriverException e) {
|
||
1207 | e.printStackTrace(); |
||
1208 | } |
||
1209 | } |
||
1210 | 2183 | fernando | |
1211 | 12349 | jaume | /*
|
1212 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
1213 | */
|
||
1214 | public void setXMLEntity(XMLEntity xml) throws XMLException { |
||
1215 | try {
|
||
1216 | 18621 | jdominguez | super.setXMLEntity(xml);
|
1217 | XMLEntity legendXML = xml.getChild(0);
|
||
1218 | IVectorLegend leg = LegendFactory.createFromXML(legendXML); |
||
1219 | 28544 | vcaballero | |
1220 | 18621 | jdominguez | /* end patch */
|
1221 | try {
|
||
1222 | getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
||
1223 | // JMVIVO: Esto sirve para algo????
|
||
1224 | 22465 | vcaballero | /*
|
1225 | * Jaume: si, para restaurar el selectable datasource cuando se
|
||
1226 | * clona la capa, cuando se carga de un proyecto. Si no esta ya
|
||
1227 | * no se puede ni hacer consultas sql, ni hacer selecciones,
|
||
1228 | * ni usar la mayor parte de las herramientas.
|
||
1229 | 23731 | vcaballero | *
|
1230 | 22465 | vcaballero | * Lo vuelvo a poner.
|
1231 | */
|
||
1232 | |||
1233 | 18621 | jdominguez | String recordsetName = xml.getStringProperty("recordset-name"); |
1234 | 6476 | caballero | |
1235 | 24271 | vcaballero | // SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
1236 | // .getDataSourceFactory().createRandomDataSource(
|
||
1237 | // recordsetName, DataSourceFactory.AUTOMATIC_OPENING));
|
||
1238 | |||
1239 | 22764 | vcaballero | LayerFactory.getDataSourceFactory().changeDataSourceName( |
1240 | getSource().getRecordset().getName(), recordsetName); |
||
1241 | 22465 | vcaballero | SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
1242 | .getDataSourceFactory().createRandomDataSource( |
||
1243 | recordsetName, DataSourceFactory.AUTOMATIC_OPENING)); |
||
1244 | 24271 | vcaballero | |
1245 | 18621 | jdominguez | } catch (NoSuchTableException e1) {
|
1246 | this.setAvailable(false); |
||
1247 | throw new XMLException(e1); |
||
1248 | } catch (ReadDriverException e1) {
|
||
1249 | this.setAvailable(false); |
||
1250 | throw new XMLException(e1); |
||
1251 | } |
||
1252 | // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
||
1253 | // el final
|
||
1254 | // de la lectura del proyecto
|
||
1255 | if (xml.contains("hasJoin")) { |
||
1256 | setIsJoined(true);
|
||
1257 | PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
||
1258 | } else {
|
||
1259 | try {
|
||
1260 | setLegend(leg); |
||
1261 | } catch (LegendLayerException e) {
|
||
1262 | throw new XMLException(e); |
||
1263 | } |
||
1264 | } |
||
1265 | 17117 | vcaballero | |
1266 | 26865 | vcaballero | //Por compatibilidad con proyectos anteriores a la 1.0
|
1267 | boolean containsIsLabeled = xml.contains("isLabeled"); |
||
1268 | if (containsIsLabeled){
|
||
1269 | isLabeled = xml.getBooleanProperty("isLabeled");
|
||
1270 | } |
||
1271 | 18621 | jdominguez | // set properties for ILabelable
|
1272 | 25452 | vcaballero | XMLEntity labelingXML = xml.firstChild("labelingStrategy", "labelingStrategy"); |
1273 | 18621 | jdominguez | if (labelingXML!= null) { |
1274 | 26865 | vcaballero | if(!containsIsLabeled){
|
1275 | isLabeled = true;
|
||
1276 | } |
||
1277 | 18621 | jdominguez | try {
|
1278 | this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this); |
||
1279 | } catch (NotExistInXMLEntity neXMLEX) {
|
||
1280 | // no strategy was set, just continue;
|
||
1281 | logger.warn("Reached what should be unreachable code");
|
||
1282 | } |
||
1283 | 28953 | vcaballero | } else if (legendXML.contains("labelFieldName")|| legendXML.contains("labelfield")) { |
1284 | 28544 | vcaballero | /* (jaume) begin patch;
|
1285 | * for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
||
1286 | * no longer managed by the Legend but by the ILabelingStrategy. The
|
||
1287 | * following allows restoring older projects' labelings.
|
||
1288 | */
|
||
1289 | 28953 | vcaballero | String labelTextField = null; |
1290 | if (legendXML.contains("labelFieldName")){ |
||
1291 | labelTextField = legendXML.getStringProperty("labelFieldName");
|
||
1292 | if (labelTextField != null) { |
||
1293 | AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
||
1294 | labeling.setLayer(this);
|
||
1295 | labeling.setUsesFixedSize(true);
|
||
1296 | labeling.setFixedSize(10);
|
||
1297 | labeling.setTextField(labelTextField); |
||
1298 | labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
|
||
1299 | labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
|
||
1300 | this.setLabelingStrategy(labeling);
|
||
1301 | this.setIsLabeled(true); |
||
1302 | } |
||
1303 | }else{
|
||
1304 | labelTextField = legendXML.getStringProperty("labelfield");
|
||
1305 | if (labelTextField != null) { |
||
1306 | AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
||
1307 | labeling.setLayer(this);
|
||
1308 | labeling.setUsesFixedSize(true);
|
||
1309 | labeling.setFixedSize(10);
|
||
1310 | labeling.setTextField(labelTextField); |
||
1311 | labeling.setHeightField(legendXML.getStringProperty("labelFieldHeight"));
|
||
1312 | labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
|
||
1313 | this.setLabelingStrategy(labeling);
|
||
1314 | this.setIsLabeled(true); |
||
1315 | } |
||
1316 | } |
||
1317 | |||
1318 | }else if(!containsIsLabeled){ |
||
1319 | isLabeled = false;
|
||
1320 | 18621 | jdominguez | } |
1321 | 10910 | jaume | |
1322 | 28176 | vcaballero | // compatibility with hyperlink from 1.9 alpha version... do we really need to be compatible with alpha versions??
|
1323 | 28134 | vcaballero | XMLEntity xmlLinkProperties=xml.firstChild("typeChild", "linkProperties"); |
1324 | 18621 | jdominguez | if (xmlLinkProperties != null){ |
1325 | 28134 | vcaballero | try {
|
1326 | String fieldName=xmlLinkProperties.getStringProperty("fieldName"); |
||
1327 | 28571 | vcaballero | xmlLinkProperties.remove("fieldName");
|
1328 | 28134 | vcaballero | String extName = xmlLinkProperties.getStringProperty("extName"); |
1329 | 28571 | vcaballero | xmlLinkProperties.remove("extName");
|
1330 | 28134 | vcaballero | int typeLink = xmlLinkProperties.getIntProperty("typeLink"); |
1331 | 28571 | vcaballero | xmlLinkProperties.remove("typeLink");
|
1332 | 28134 | vcaballero | if (fieldName!=null) { |
1333 | setProperty("legacy.hyperlink.selectedField", fieldName);
|
||
1334 | setProperty("legacy.hyperlink.type", new Integer(typeLink)); |
||
1335 | if (extName!=null) { |
||
1336 | setProperty("legacy.hyperlink.extension", extName);
|
||
1337 | } |
||
1338 | } |
||
1339 | } |
||
1340 | catch (NotExistInXMLEntity ex) {
|
||
1341 | logger.warn("Error getting old hyperlink configuration", ex);
|
||
1342 | } |
||
1343 | 18621 | jdominguez | } |
1344 | 6476 | caballero | |
1345 | 18621 | jdominguez | } catch (XMLException e) {
|
1346 | this.setAvailable(false); |
||
1347 | this.orgXMLEntity = xml;
|
||
1348 | } catch (Exception e) { |
||
1349 | e.printStackTrace(); |
||
1350 | this.setAvailable(false); |
||
1351 | this.orgXMLEntity = xml;
|
||
1352 | 13558 | evercher | |
1353 | 18621 | jdominguez | } |
1354 | 10910 | jaume | |
1355 | 3940 | caballero | |
1356 | 12349 | jaume | } |
1357 | 562 | fernando | |
1358 | 12349 | jaume | public void setXMLEntityNew(XMLEntity xml) throws XMLException { |
1359 | try {
|
||
1360 | super.setXMLEntity(xml);
|
||
1361 | 6768 | jmvivo | |
1362 | 12349 | jaume | XMLEntity legendXML = xml.getChild(0);
|
1363 | 13884 | jaume | IVectorLegend leg = LegendFactory.createFromXML(legendXML); |
1364 | 12349 | jaume | /* (jaume) begin patch;
|
1365 | * for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
||
1366 | * no longer managed by the Legend but by the ILabelingStrategy. The
|
||
1367 | * following allows restoring older projects' labelings.
|
||
1368 | */
|
||
1369 | if (legendXML.contains("labelFieldHeight")) { |
||
1370 | 18621 | jdominguez | AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
1371 | 12349 | jaume | labeling.setLayer(this);
|
1372 | labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
|
||
1373 | labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
|
||
1374 | this.setLabelingStrategy(labeling);
|
||
1375 | this.setIsLabeled(true); |
||
1376 | } |
||
1377 | /* end patch */
|
||
1378 | try {
|
||
1379 | getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
||
1380 | 9010 | caballero | |
1381 | 12349 | jaume | this.setLoadSelection(xml.getChild(1)); |
1382 | } catch (ReadDriverException e1) {
|
||
1383 | this.setAvailable(false); |
||
1384 | throw new XMLException(e1); |
||
1385 | } |
||
1386 | // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
||
1387 | // el final
|
||
1388 | // de la lectura del proyecto
|
||
1389 | if (xml.contains("hasJoin")) { |
||
1390 | setIsJoined(true);
|
||
1391 | PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
||
1392 | } else {
|
||
1393 | this.setLoadLegend(leg);
|
||
1394 | } |
||
1395 | 6768 | jmvivo | |
1396 | 12349 | jaume | } catch (XMLException e) {
|
1397 | this.setAvailable(false); |
||
1398 | this.orgXMLEntity = xml;
|
||
1399 | } catch (Exception e) { |
||
1400 | this.setAvailable(false); |
||
1401 | this.orgXMLEntity = xml;
|
||
1402 | } |
||
1403 | 6768 | jmvivo | |
1404 | |||
1405 | 12349 | jaume | } |
1406 | 9010 | caballero | |
1407 | 562 | fernando | |
1408 | 12349 | jaume | /**
|
1409 | * Sobreimplementaci?n del m?todo toString para que las bases de datos
|
||
1410 | * identifiquen la capa.
|
||
1411 | *
|
||
1412 | * @return DOCUMENT ME!
|
||
1413 | */
|
||
1414 | public String toString() { |
||
1415 | /*
|
||
1416 | * Se usa internamente para que la parte de datos identifique de forma
|
||
1417 | * un?voca las tablas
|
||
1418 | */
|
||
1419 | String ret = super.toString(); |
||
1420 | 911 | fernando | |
1421 | 12349 | jaume | return "layer" + ret.substring(ret.indexOf('@') + 1); |
1422 | } |
||
1423 | 2672 | fjp | |
1424 | 12349 | jaume | public boolean isJoined() { |
1425 | return bHasJoin;
|
||
1426 | } |
||
1427 | 5115 | caballero | |
1428 | 12349 | jaume | /**
|
1429 | * Returns if a layer is spatially indexed
|
||
1430 | *
|
||
1431 | * @return if this layer has the ability to proces spatial queries without
|
||
1432 | * secuential scans.
|
||
1433 | */
|
||
1434 | public boolean isSpatiallyIndexed() { |
||
1435 | ReadableVectorial source = getSource(); |
||
1436 | if (source instanceof ISpatialDB) |
||
1437 | return true; |
||
1438 | 6246 | caballero | |
1439 | 5794 | azabala | //FIXME azabala
|
1440 | /*
|
||
1441 | * Esto es muy dudoso, y puede cambiar.
|
||
1442 | * Estoy diciendo que las que no son fichero o no son
|
||
1443 | * BoundedShapes estan indexadas. Esto es mentira, pero
|
||
1444 | * as? quien pregunte no querr? generar el indice.
|
||
1445 | * Esta por ver si interesa generar el indice para capas
|
||
1446 | * HSQLDB, WFS, etc.
|
||
1447 | 6246 | caballero | */
|
1448 | 12349 | jaume | if(!(source instanceof VectorialFileAdapter)){ |
1449 | return true; |
||
1450 | } |
||
1451 | if (!(source.getDriver() instanceof BoundedShapes)) { |
||
1452 | return true; |
||
1453 | } |
||
1454 | 6246 | caballero | |
1455 | 12349 | jaume | if (getISpatialIndex() != null) |
1456 | return true; |
||
1457 | return false; |
||
1458 | } |
||
1459 | 2672 | fjp | |
1460 | 12349 | jaume | public void setIsJoined(boolean hasJoin) { |
1461 | bHasJoin = hasJoin; |
||
1462 | } |
||
1463 | 2978 | fjp | |
1464 | 12349 | jaume | /**
|
1465 | * @return Returns the spatialIndex.
|
||
1466 | */
|
||
1467 | public ISpatialIndex getISpatialIndex() {
|
||
1468 | return spatialIndex;
|
||
1469 | } |
||
1470 | /**
|
||
1471 | * Sets the spatial index. This could be useful if, for some
|
||
1472 | * reasons, you want to work with a distinct spatial index
|
||
1473 | * (for example, a spatial index which could makes nearest
|
||
1474 | * neighbour querys)
|
||
1475 | * @param spatialIndex
|
||
1476 | */
|
||
1477 | public void setISpatialIndex(ISpatialIndex spatialIndex){ |
||
1478 | this.spatialIndex = spatialIndex;
|
||
1479 | } |
||
1480 | 3366 | caballero | |
1481 | 12349 | jaume | public SelectableDataSource getRecordset() throws ReadDriverException { |
1482 | if (!this.isAvailable()) return null; |
||
1483 | if (sds == null) { |
||
1484 | 10910 | jaume | |
1485 | 12349 | jaume | SelectableDataSource ds = source.getRecordset(); |
1486 | 4455 | fjp | |
1487 | 12349 | jaume | if (ds == null) { |
1488 | return null; |
||
1489 | } |
||
1490 | 4455 | fjp | |
1491 | 12349 | jaume | sds = ds; |
1492 | sds.setSelectionSupport(selectionSupport); |
||
1493 | 24160 | jmvivo | selectionSupport.addSelectionListener(this);
|
1494 | 4523 | caballero | |
1495 | 12349 | jaume | } |
1496 | return sds;
|
||
1497 | } |
||
1498 | 11704 | jaume | |
1499 | 12349 | jaume | public void setEditing(boolean b) throws StartEditionLayerException { |
1500 | super.setEditing(b);
|
||
1501 | try {
|
||
1502 | if (b) {
|
||
1503 | VectorialEditableAdapter vea = null;
|
||
1504 | // TODO: Qu? pasa si hay m?s tipos de adapters?
|
||
1505 | // FJP: Se podr?a pasar como argumento el
|
||
1506 | // VectorialEditableAdapter
|
||
1507 | // que se quiera usar para evitar meter c?digo aqu? de este
|
||
1508 | // estilo.
|
||
1509 | if (getSource() instanceof VectorialDBAdapter) { |
||
1510 | vea = new VectorialEditableDBAdapter();
|
||
1511 | } else if (this instanceof FLyrAnnotation) { |
||
1512 | vea = new AnnotationEditableAdapter(
|
||
1513 | (FLyrAnnotation) this);
|
||
1514 | } else {
|
||
1515 | vea = new VectorialEditableAdapter();
|
||
1516 | } |
||
1517 | 24160 | jmvivo | vea.addEditionListener(this);
|
1518 | 12349 | jaume | vea.setOriginalVectorialAdapter(getSource()); |
1519 | 11286 | azabala | // azo: implementations of readablevectorial need
|
1520 | 12349 | jaume | //references of projection and spatial index
|
1521 | vea.setProjection(getProjection()); |
||
1522 | vea.setSpatialIndex(spatialIndex); |
||
1523 | 11704 | jaume | |
1524 | |||
1525 | 12349 | jaume | // /vea.setSpatialIndex(getSpatialIndex());
|
1526 | // /vea.setFullExtent(getFullExtent());
|
||
1527 | 12783 | caballero | vea.setCoordTrans(getCoordTrans()); |
1528 | 12349 | jaume | vea.startEdition(EditionEvent.GRAPHIC); |
1529 | setSource(vea); |
||
1530 | getRecordset().setSelectionSupport( |
||
1531 | vea.getOriginalAdapter().getRecordset() |
||
1532 | .getSelectionSupport()); |
||
1533 | 5152 | fjp | |
1534 | 12349 | jaume | } else {
|
1535 | VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource(); |
||
1536 | 24160 | jmvivo | vea.removeEditionListener(this);
|
1537 | 12349 | jaume | setSource(vea.getOriginalAdapter()); |
1538 | } |
||
1539 | // Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
||
1540 | // recordset
|
||
1541 | setRecordset(getSource().getRecordset()); |
||
1542 | 13884 | jaume | if (getLegend() instanceof IVectorLegend) { |
1543 | IVectorLegend ley = (IVectorLegend) getLegend(); |
||
1544 | 12349 | jaume | ley.setDataSource(getSource().getRecordset()); |
1545 | // Esto lo pongo para evitar que al dibujar sobre un
|
||
1546 | // dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
||
1547 | // de la leyenda de textos "dibujar solo textos".
|
||
1548 | 10910 | jaume | //jaume
|
1549 | // if (!(getSource().getDriver() instanceof IndexedShpDriver)){
|
||
1550 | // FSymbol symbol=new FSymbol(getShapeType());
|
||
1551 | // symbol.setFontSizeInPixels(false);
|
||
1552 | // symbol.setFont(new Font("SansSerif", Font.PLAIN, 9));
|
||
1553 | // Color color=symbol.getColor();
|
||
1554 | // int alpha=symbol.getColor().getAlpha();
|
||
1555 | // if (alpha>250) {
|
||
1556 | // symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),100));
|
||
1557 | // }
|
||
1558 | // ley.setDefaultSymbol(symbol);
|
||
1559 | // }
|
||
1560 | //jaume//
|
||
1561 | 12349 | jaume | ley.useDefaultSymbol(true);
|
1562 | } |
||
1563 | } catch (ReadDriverException e) {
|
||
1564 | throw new StartEditionLayerException(getName(),e); |
||
1565 | } catch (FieldNotFoundException e) {
|
||
1566 | throw new StartEditionLayerException(getName(),e); |
||
1567 | } catch (StartWriterVisitorException e) {
|
||
1568 | throw new StartEditionLayerException(getName(),e); |
||
1569 | } |
||
1570 | 4223 | caballero | |
1571 | 12349 | jaume | setSpatialCacheEnabled(b); |
1572 | callEditionChanged(LayerEvent |
||
1573 | .createEditionChangedEvent(this, "edition")); |
||
1574 | 5152 | fjp | |
1575 | 12349 | jaume | } |
1576 | 4147 | fjp | |
1577 | 12349 | jaume | /**
|
1578 | * Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
||
1579 | * forma, podr?s poner leyendas basadas en el nuevo recordset
|
||
1580 | *
|
||
1581 | * @param newSds
|
||
1582 | */
|
||
1583 | public void setRecordset(SelectableDataSource newSds) { |
||
1584 | 24160 | jmvivo | // TODO: Deberiamos hacer comprobaciones del cambio
|
1585 | 12349 | jaume | sds = newSds; |
1586 | sds.setSelectionSupport(selectionSupport); |
||
1587 | 24160 | jmvivo | selectionSupport.addSelectionListener(this);
|
1588 | this.updateDrawVersion();
|
||
1589 | 12349 | jaume | } |
1590 | 3366 | caballero | |
1591 | 12349 | jaume | public void clearSpatialCache() |
1592 | { |
||
1593 | spatialCache.clearAll(); |
||
1594 | } |
||
1595 | 5223 | fjp | |
1596 | 12349 | jaume | public boolean isSpatialCacheEnabled() { |
1597 | return spatialCacheEnabled;
|
||
1598 | } |
||
1599 | 5223 | fjp | |
1600 | 12349 | jaume | public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
1601 | this.spatialCacheEnabled = spatialCacheEnabled;
|
||
1602 | } |
||
1603 | 5223 | fjp | |
1604 | 12349 | jaume | public SpatialCache getSpatialCache() {
|
1605 | return spatialCache;
|
||
1606 | } |
||
1607 | 5226 | fjp | |
1608 | 12349 | jaume | /**
|
1609 | * Siempre es un numero mayor de 1000
|
||
1610 | * @param maxFeatures
|
||
1611 | */
|
||
1612 | public void setMaxFeaturesInEditionCache(int maxFeatures) { |
||
1613 | if (maxFeatures > spatialCache.maxFeatures)
|
||
1614 | spatialCache.setMaxFeatures(maxFeatures); |
||
1615 | 6246 | caballero | |
1616 | 12349 | jaume | } |
1617 | 6246 | caballero | |
1618 | 12349 | jaume | /**
|
1619 | * This method returns a boolean that is used by the FPopMenu
|
||
1620 | * to make visible the properties menu or not. It is visible by
|
||
1621 | * default, and if a later don't have to show this menu only
|
||
1622 | * has to override this method.
|
||
1623 | * @return
|
||
1624 | * If the properties menu is visible (or not)
|
||
1625 | */
|
||
1626 | public boolean isPropertiesMenuVisible(){ |
||
1627 | return true; |
||
1628 | } |
||
1629 | 9010 | caballero | |
1630 | 12349 | jaume | public void reload() throws ReloadLayerException { |
1631 | this.setAvailable(true); |
||
1632 | super.reload();
|
||
1633 | 24160 | jmvivo | this.updateDrawVersion();
|
1634 | 12349 | jaume | try {
|
1635 | this.source.getDriver().reload();
|
||
1636 | if (this.getLegend() == null) { |
||
1637 | if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
||
1638 | WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
||
1639 | 13884 | jaume | this.setLegend((IVectorLegend) aux.getDefaultLegend());
|
1640 | 12349 | jaume | this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
|
1641 | } else {
|
||
1642 | this.setLegend(LegendFactory.createSingleSymbolLegend(
|
||
1643 | this.getShapeType()));
|
||
1644 | } |
||
1645 | } |
||
1646 | 9010 | caballero | |
1647 | 12349 | jaume | } catch (LegendLayerException e) {
|
1648 | this.setAvailable(false); |
||
1649 | throw new ReloadLayerException(getName(),e); |
||
1650 | } catch (ReadDriverException e) {
|
||
1651 | this.setAvailable(false); |
||
1652 | throw new ReloadLayerException(getName(),e); |
||
1653 | } |
||
1654 | 9010 | caballero | |
1655 | 12349 | jaume | } |
1656 | 9010 | caballero | |
1657 | 12349 | jaume | protected void setLoadSelection(XMLEntity xml) { |
1658 | this.loadSelection = xml;
|
||
1659 | } |
||
1660 | 5793 | fjp | |
1661 | 13884 | jaume | protected void setLoadLegend(IVectorLegend legend) { |
1662 | 12349 | jaume | this.loadLegend = legend;
|
1663 | } |
||
1664 | 6534 | jmvivo | |
1665 | 12349 | jaume | protected void putLoadSelection() throws XMLException { |
1666 | if (this.loadSelection == null) return; |
||
1667 | try {
|
||
1668 | this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection); |
||
1669 | } catch (ReadDriverException e) {
|
||
1670 | throw new XMLException(e); |
||
1671 | } |
||
1672 | this.loadSelection = null; |
||
1673 | 9010 | caballero | |
1674 | 12349 | jaume | } |
1675 | protected void putLoadLegend() throws LegendLayerException { |
||
1676 | if (this.loadLegend == null) return; |
||
1677 | this.setLegend(this.loadLegend); |
||
1678 | this.loadLegend = null; |
||
1679 | } |
||
1680 | 6761 | jmvivo | |
1681 | 12349 | jaume | protected void cleanLoadOptions() { |
1682 | this.loadLegend = null; |
||
1683 | this.loadSelection = null; |
||
1684 | } |
||
1685 | 6761 | jmvivo | |
1686 | 12349 | jaume | public boolean isWritable() { |
1687 | VectorialDriver drv = getSource().getDriver(); |
||
1688 | if (!drv.isWritable())
|
||
1689 | return false; |
||
1690 | if (drv instanceof IWriteable) |
||
1691 | { |
||
1692 | IWriter writer = ((IWriteable)drv).getWriter(); |
||
1693 | if (writer != null) |
||
1694 | { |
||
1695 | if (writer instanceof ISpatialWriter) |
||
1696 | return true; |
||
1697 | } |
||
1698 | } |
||
1699 | return false; |
||
1700 | 6856 | fjp | |
1701 | 12349 | jaume | } |
1702 | 6856 | fjp | |
1703 | 12349 | jaume | public FLayer cloneLayer() throws Exception { |
1704 | FLyrVect clonedLayer = new FLyrVect();
|
||
1705 | clonedLayer.setSource(getSource()); |
||
1706 | 13445 | caballero | if (isJoined()) {
|
1707 | clonedLayer.setIsJoined(true);
|
||
1708 | clonedLayer.setRecordset(getRecordset()); |
||
1709 | } |
||
1710 | 12349 | jaume | clonedLayer.setVisible(isVisible()); |
1711 | clonedLayer.setISpatialIndex(getISpatialIndex()); |
||
1712 | clonedLayer.setName(getName()); |
||
1713 | clonedLayer.setCoordTrans(getCoordTrans()); |
||
1714 | 10627 | caballero | |
1715 | 13884 | jaume | clonedLayer.setLegend((IVectorLegend)getLegend().cloneLegend()); |
1716 | 10679 | jaume | |
1717 | 12349 | jaume | clonedLayer.setIsLabeled(isLabeled()); |
1718 | 27235 | vcaballero | ILabelingStrategy labelingStrategy=getLabelingStrategy(); |
1719 | if (labelingStrategy!=null) |
||
1720 | clonedLayer.setLabelingStrategy(labelingStrategy); |
||
1721 | 10679 | jaume | |
1722 | 12349 | jaume | return clonedLayer;
|
1723 | } |
||
1724 | 9923 | fjp | |
1725 | 12657 | jaume | |
1726 | 14409 | vcaballero | private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, double dpi, CartographicSupport csSym, IGeometry geom, int[] xyCoords) { |
1727 | 23731 | vcaballero | return isOnePoint(graphicsTransform, viewPort, geom, xyCoords) && csSym.getCartographicSize(viewPort, dpi, (FShape)geom.getInternalShape()) <= 1; |
1728 | 12466 | jaume | } |
1729 | |||
1730 | 14409 | vcaballero | private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, IGeometry geom, int[] xyCoords) { |
1731 | 12466 | jaume | boolean onePoint = false; |
1732 | 20704 | vcaballero | int type=geom.getGeometryType() % FShape.Z;
|
1733 | 25766 | jpiera | if (type!=FShape.POINT && type!=FShape.MULTIPOINT && type!=FShape.NULL) {
|
1734 | 12466 | jaume | |
1735 | Rectangle2D geomBounds = geom.getBounds2D();
|
||
1736 | |||
1737 | 26902 | vcaballero | // ICoordTrans ct = getCoordTrans();
|
1738 | 12466 | jaume | |
1739 | 26848 | vcaballero | // Se supone que la geometria ya esta
|
1740 | // repoyectada y no hay que hacer
|
||
1741 | 26416 | jmvivo | // ninguna transformacion
|
1742 | // if (ct!=null) {
|
||
1743 | //// geomBounds = ct.getInverted().convert(geomBounds);
|
||
1744 | // geomBounds = ct.convert(geomBounds);
|
||
1745 | // }
|
||
1746 | 12466 | jaume | |
1747 | double dist1Pixel = viewPort.getDist1pixel();
|
||
1748 | |||
1749 | onePoint = (geomBounds.getWidth() <= dist1Pixel |
||
1750 | && geomBounds.getHeight() <= dist1Pixel); |
||
1751 | |||
1752 | if (onePoint) {
|
||
1753 | // avoid out of range exceptions
|
||
1754 | FPoint2D p = new FPoint2D(geomBounds.getMinX(), geomBounds.getMinY());
|
||
1755 | p.transform(viewPort.getAffineTransform()); |
||
1756 | 14409 | vcaballero | p.transform(graphicsTransform); |
1757 | 12466 | jaume | xyCoords[0] = (int) p.getX(); |
1758 | xyCoords[1] = (int) p.getY(); |
||
1759 | |||
1760 | } |
||
1761 | |||
1762 | 14409 | vcaballero | } |
1763 | 12466 | jaume | return onePoint;
|
1764 | } |
||
1765 | 12349 | jaume | /*
|
1766 | * jaume. Stuff from ILabeled.
|
||
1767 | */
|
||
1768 | private boolean isLabeled; |
||
1769 | private ILabelingStrategy strategy;
|
||
1770 | 10679 | jaume | |
1771 | 12349 | jaume | public boolean isLabeled() { |
1772 | return isLabeled;
|
||
1773 | } |
||
1774 | 10679 | jaume | |
1775 | 12349 | jaume | public void setIsLabeled(boolean isLabeled) { |
1776 | this.isLabeled = isLabeled;
|
||
1777 | } |
||
1778 | 10679 | jaume | |
1779 | 12349 | jaume | public ILabelingStrategy getLabelingStrategy() {
|
1780 | return strategy;
|
||
1781 | } |
||
1782 | 10679 | jaume | |
1783 | 12349 | jaume | public void setLabelingStrategy(ILabelingStrategy strategy) { |
1784 | this.strategy = strategy;
|
||
1785 | 25729 | vcaballero | try {
|
1786 | strategy.setLayer(this);
|
||
1787 | } catch (ReadDriverException e) {
|
||
1788 | // TODO Auto-generated catch block
|
||
1789 | e.printStackTrace(); |
||
1790 | } |
||
1791 | 12349 | jaume | } |
1792 | 10679 | jaume | |
1793 | 12820 | jaume | public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort, |
1794 | 18621 | jdominguez | Cancellable cancel, double scale, double dpi) throws ReadDriverException { |
1795 | 14450 | vcaballero | if (strategy!=null && isWithinScale(scale)) { |
1796 | 18621 | jdominguez | strategy.draw(image, g, viewPort, cancel, dpi); |
1797 | 12349 | jaume | } |
1798 | } |
||
1799 | 24274 | vcaballero | public void printLabels(Graphics2D g, ViewPort viewPort, |
1800 | 24271 | vcaballero | Cancellable cancel, double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
1801 | if (strategy!=null) { |
||
1802 | strategy.print(g, viewPort, cancel, properties); |
||
1803 | } |
||
1804 | } |
||
1805 | 10679 | jaume | |
1806 | 13558 | evercher | |
1807 | //M?todos para el uso de HyperLinks en capas FLyerVect
|
||
1808 | |||
1809 | /**
|
||
1810 | * Return true, because a Vectorial Layer supports HyperLink
|
||
1811 | */
|
||
1812 | public boolean allowLinks() |
||
1813 | { |
||
1814 | return true; |
||
1815 | } |
||
1816 | |||
1817 | /**
|
||
1818 | * Returns an instance of AbstractLinkProperties that contains the information
|
||
1819 | * of the HyperLink
|
||
1820 | * @return Abstra
|
||
1821 | */
|
||
1822 | public AbstractLinkProperties getLinkProperties()
|
||
1823 | { |
||
1824 | return linkProperties;
|
||
1825 | } |
||
1826 | |||
1827 | /**
|
||
1828 | * Provides an array with URIs. Returns one URI by geometry that includes the point
|
||
1829 | * in its own geometry limits with a allowed tolerance.
|
||
1830 | * @param layer, the layer
|
||
1831 | * @param point, the point to check that is contained or not in the geometries in the layer
|
||
1832 | * @param tolerance, the tolerance allowed. Allowed margin of error to detect if the point
|
||
1833 | * is contained in some geometries of the layer
|
||
1834 | * @return
|
||
1835 | */
|
||
1836 | public URI[] getLink(Point2D point, double tolerance) |
||
1837 | { |
||
1838 | //return linkProperties.getLink(this)
|
||
1839 | return linkProperties.getLink(this,point,tolerance); |
||
1840 | } |
||
1841 | 24376 | vcaballero | // /**
|
1842 | // * @deprecated Don?t use Strategy, you should be use iterators.
|
||
1843 | // */
|
||
1844 | // public boolean isUseStrategy() {
|
||
1845 | // return useStrategy;
|
||
1846 | // }
|
||
1847 | // /**
|
||
1848 | // * @deprecated Don?t use Strategy, you should be use iterators.
|
||
1849 | // */
|
||
1850 | // public void setUseStrategy(boolean useStrategy) {
|
||
1851 | // this.useStrategy = useStrategy;
|
||
1852 | // }
|
||
1853 | //
|
||
1854 | // @Override
|
||
1855 | // public void load() throws LoadLayerException {
|
||
1856 | // super.load();
|
||
1857 | // useStrategy=forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD;
|
||
1858 | // }
|
||
1859 | 13558 | evercher | |
1860 | 24160 | jmvivo | public void selectionChanged(SelectionEvent e) { |
1861 | this.updateDrawVersion();
|
||
1862 | } |
||
1863 | |||
1864 | public void afterFieldEditEvent(AfterFieldEditEvent e) { |
||
1865 | 24405 | jmvivo | this.updateDrawVersion();
|
1866 | 24160 | jmvivo | } |
1867 | |||
1868 | public void afterRowEditEvent(IRow feat, AfterRowEditEvent e) { |
||
1869 | this.updateDrawVersion();
|
||
1870 | |||
1871 | } |
||
1872 | |||
1873 | public void beforeFieldEditEvent(BeforeFieldEditEvent e) { |
||
1874 | |||
1875 | } |
||
1876 | |||
1877 | public void beforeRowEditEvent(IRow feat, BeforeRowEditEvent e) { |
||
1878 | |||
1879 | } |
||
1880 | |||
1881 | public void processEvent(EditionEvent e) { |
||
1882 | if (e.getChangeType()== e.ROW_EDITION){
|
||
1883 | this.updateDrawVersion();
|
||
1884 | } |
||
1885 | |||
1886 | } |
||
1887 | 24271 | vcaballero | |
1888 | 25033 | jmvivo | public void legendCleared(LegendClearEvent event) { |
1889 | this.updateDrawVersion();
|
||
1890 | LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
||
1891 | legend, legend); |
||
1892 | this.callLegendChanged(e);
|
||
1893 | } |
||
1894 | |||
1895 | public boolean symbolChanged(SymbolLegendEvent e) { |
||
1896 | this.updateDrawVersion();
|
||
1897 | LegendChangedEvent event = LegendChangedEvent.createLegendChangedEvent( |
||
1898 | legend, legend); |
||
1899 | this.callLegendChanged(event);
|
||
1900 | return true; |
||
1901 | } |
||
1902 | 26342 | vcaballero | public String getTypeStringVectorLayer() throws ReadDriverException { |
1903 | String typeString=""; |
||
1904 | int typeShape=((FLyrVect)this).getShapeType(); |
||
1905 | if (FShape.MULTI==typeShape){
|
||
1906 | ReadableVectorial rv=((FLyrVect)this).getSource();
|
||
1907 | if (rv.getShapeCount()>0){ |
||
1908 | if ((rv.getShape(0).getGeometryType() & FShape.Z) == FShape.Z){ |
||
1909 | typeString="Geometries3D";
|
||
1910 | }else{
|
||
1911 | typeString="Geometries2D";
|
||
1912 | 26366 | vcaballero | } |
1913 | } |
||
1914 | 26342 | vcaballero | }else{
|
1915 | ReadableVectorial rv=((FLyrVect)this).getSource();
|
||
1916 | if (rv.getShapeCount()>0){ |
||
1917 | int type=rv.getShape(0).getGeometryType(); |
||
1918 | if (FShape.POINT == type){
|
||
1919 | typeString="Point2D";
|
||
1920 | } else if (FShape.LINE == type){ |
||
1921 | typeString="Line2D";
|
||
1922 | } else if (FShape.POLYGON == type){ |
||
1923 | typeString="Polygon2D";
|
||
1924 | } else if (FShape.MULTIPOINT == type){ |
||
1925 | typeString="MultiPint2D";
|
||
1926 | } else if ((FShape.POINT | FShape.Z) == type ){ |
||
1927 | typeString="Point3D";
|
||
1928 | } else if ((FShape.LINE | FShape.Z) == type ){ |
||
1929 | typeString="Line3D";
|
||
1930 | } else if ((FShape.POLYGON | FShape.Z) == type ){ |
||
1931 | typeString="Polygon3D";
|
||
1932 | } else if ((FShape.MULTIPOINT | FShape.Z) == type ){ |
||
1933 | typeString="MultiPoint3D";
|
||
1934 | } else if ((FShape.POINT | FShape.M) == type ){ |
||
1935 | typeString="PointM";
|
||
1936 | } else if ((FShape.LINE | FShape.M) == type ){ |
||
1937 | typeString="LineM";
|
||
1938 | } else if ((FShape.POLYGON | FShape.M) == type ){ |
||
1939 | typeString="PolygonM";
|
||
1940 | } else if ((FShape.MULTIPOINT | FShape.M) == type ){ |
||
1941 | typeString="MultiPointM";
|
||
1942 | } else if ((FShape.MULTI | FShape.M) == type ){ |
||
1943 | typeString="M";
|
||
1944 | } |
||
1945 | } |
||
1946 | return typeString;
|
||
1947 | } |
||
1948 | return ""; |
||
1949 | } |
||
1950 | public int getTypeIntVectorLayer() throws ReadDriverException { |
||
1951 | int typeInt=0; |
||
1952 | int typeShape=((FLyrVect)this).getShapeType(); |
||
1953 | if (FShape.MULTI==typeShape){
|
||
1954 | ReadableVectorial rv=((FLyrVect)this).getSource();
|
||
1955 | if (rv.getShapeCount()>0){ |
||
1956 | if ((rv.getShape(0).getGeometryType() & FShape.Z) == FShape.Z){ |
||
1957 | typeInt=FShape.MULTI | FShape.Z; |
||
1958 | }else{
|
||
1959 | typeInt=FShape.MULTI; |
||
1960 | } |
||
1961 | } |
||
1962 | }else{
|
||
1963 | ReadableVectorial rv=((FLyrVect)this).getSource();
|
||
1964 | if (rv.getShapeCount()>0){ |
||
1965 | int type=rv.getShape(0).getGeometryType(); |
||
1966 | typeInt=type; |
||
1967 | } |
||
1968 | return typeInt;
|
||
1969 | } |
||
1970 | return typeInt;
|
||
1971 | } |
||
1972 | 13749 | jaume | } |