Revision 11743 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/layers/Annotation_Layer.java

View differences:

Annotation_Layer.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

  
1 43
package com.iver.cit.gvsig.fmap.layers;
2 44

  
3 45
import java.awt.Color;
......
26 68
import com.iver.cit.gvsig.fmap.DriverException;
27 69
import com.iver.cit.gvsig.fmap.ViewPort;
28 70
import com.iver.cit.gvsig.fmap.core.FPoint2D;
71
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
72
import com.iver.cit.gvsig.fmap.core.FShape;
29 73
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
30 74
import com.iver.cit.gvsig.fmap.core.IGeometry;
31 75
import com.iver.cit.gvsig.fmap.core.ISymbol;
32 76
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
33 77
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
78
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
79
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
34 80
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
35 81
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
36 82
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
......
49 95
import com.iver.utiles.XMLEntity;
50 96
import com.iver.utiles.swing.threads.Cancellable;
51 97

  
98

  
52 99
/**
53 100
 * Annotation's layer.
54
 * 
101
 *
55 102
 * @author Vicente Caballero Navarro
56 103
 */
57 104
public class Annotation_Layer extends FLyrVect {
58
	private Annotation_Mapping mapping = null;
105
    private Annotation_Mapping mapping = null;
59 106

  
60
	// private ArrayList m_labels;
107
    // private ArrayList m_labels;
108
    private int indexEditing = -1;
61 109

  
62
	private int indexEditing = -1;
110
    //private boolean inPixels = false;
111
    private Annotation_Legend aLegend;
112
    private Strategy strategy = null;
63 113

  
64
	private boolean inPixels = false;
114
    /**
115
     * Crea un nuevo FLyrAnnotation.
116
     */
117
    public Annotation_Layer() {
118
        super();
119
    }
65 120

  
66
	private Annotation_Legend aLegend;
121
    /**
122
     * DOCUMENT ME!
123
     *
124
     * @param mapping DOCUMENT ME!
125
     */
126
    public void setMapping(Annotation_Mapping mapping) {
127
        this.mapping = mapping;
128
        aLegend = new Annotation_Legend();
67 129

  
68
	private Strategy strategy = null;
130
        // try {
131
        setLegend();
69 132

  
70
	/**
71
	 * Crea un nuevo FLyrAnnotation.
72
	 */
73
	public Annotation_Layer() {
74
		super();
133
        // createLabels();
134
        // } catch (DriverException e) {
135
        // e.printStackTrace();
136
        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
137
        // PluginServices.getText(this,"Este fichero no es posible abirlo como
138
        // capa de anotaciones"));
139
        // }
140
    }
75 141

  
76
	}
142
    /**
143
     * DOCUMENT ME!
144
     *
145
     * @return DOCUMENT ME!
146
     */
147
    public Annotation_Mapping getAnnotatonMapping() {
148
        return mapping;
149
    }
77 150

  
78
	/**
79
	 * DOCUMENT ME!
80
	 * 
81
	 * @param mapping
82
	 *            DOCUMENT ME!
83
	 */
84
	public void setMapping(Annotation_Mapping mapping) {
85
		this.mapping = mapping;
86
		aLegend = new Annotation_Legend();
87
		// try {
88
		setLegend();
89
		// createLabels();
90
		// } catch (DriverException e) {
91
		// e.printStackTrace();
92
		// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
93
		// PluginServices.getText(this,"Este fichero no es posible abirlo como
94
		// capa de anotaciones"));
95
		// }
96
	}
151
    /**
152
     * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
153
     *      java.awt.Graphics2D, ISymbol)
154
     */
155
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
156
        Cancellable cancel, double scale) throws DriverException {
157
        if (isWithinScale(scale)) {
158
            // Las que solo tienen etiquetado sin pintar el shape,
159
            // no pasamos por ellas
160
            boolean bDrawShapes = true;
97 161

  
98
	/**
99
	 * DOCUMENT ME!
100
	 * 
101
	 * @return DOCUMENT ME!
102
	 */
103
	public Annotation_Mapping getAnnotatonMapping() {
104
		return mapping;
105
	}
162
            if (bDrawShapes) {
163
                if (strategy == null) {
164
                    strategy = new Annotation_Strategy(this);
165
                }
106 166

  
107
	/**
108
	 * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
109
	 *      java.awt.Graphics2D, ISymbol)
110
	 */
111
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
112
			Cancellable cancel, double scale) throws DriverException {
167
                try {
168
                    g.setColor(Color.black);
113 169

  
114
		if (isWithinScale(scale)) {
115
			// Las que solo tienen etiquetado sin pintar el shape,
116
			// no pasamos por ellas
117
			boolean bDrawShapes = true;
170
                    ReadableVectorial adapter = getSource();
171
                    adapter.start();
118 172

  
119
			if (bDrawShapes) {
120
				if (strategy == null) {
121
					strategy = new Annotation_Strategy(this);
122
				}
123
				try {
124
					g.setColor(Color.black);
125
					ReadableVectorial adapter = getSource();
126
					adapter.start();
173
                    strategy.draw(image, g, viewPort, cancel);
174
                    adapter.stop();
127 175

  
128
					strategy.draw(image, g, viewPort, cancel);
129
					adapter.stop();
130
					// if (getISpatialIndex()==null && !isEditing()) {
131
					// createSpatialIndex();
132
					// }
133
				} catch (DriverException e) {
134
					this.setVisible(false);
135
					this.setActive(false);
136
					throw e;
137
				} catch (DriverIOException e) {
138
					this.setVisible(false);
139
					this.setActive(false);
140
					throw new DriverException(e);
141
				}
142
			}
176
                    // if (getISpatialIndex()==null && !isEditing()) {
177
                    // createSpatialIndex();
178
                    // }
179
                } catch (DriverException e) {
180
                    this.setVisible(false);
181
                    this.setActive(false);
182
                    throw e;
183
                } catch (DriverIOException e) {
184
                    this.setVisible(false);
185
                    this.setActive(false);
186
                    throw new DriverException(e);
187
                }
188
            }
143 189

  
144
			if (getVirtualLayers() != null) {
145
				getVirtualLayers().draw(image, g, viewPort, cancel, scale);
146
			}
147
		}
148
	}
190
            if (getVirtualLayers() != null) {
191
                getVirtualLayers().draw(image, g, viewPort, cancel, scale);
192
            }
193
        }
194
    }
149 195

  
150
	/**
151
	 * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
152
	 */
153
	public Rectangle2D getFullExtent() throws DriverException {
154
		try {
155
			Rectangle2D rAux;
196
    /**
197
     * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
198
     */
199
    public Rectangle2D getFullExtent() throws DriverException {
200
        try {
201
            Rectangle2D rAux;
156 202

  
157
			// logger.debug("source.start()");
158
			getSource().start();
159
			rAux = getSource().getFullExtent();
203
            // logger.debug("source.start()");
204
            getSource().start();
205
            rAux = getSource().getFullExtent();
160 206

  
161
			// logger.debug("source.stop()");
162
			getSource().stop();
207
            // logger.debug("source.stop()");
208
            getSource().stop();
163 209

  
164
			// Si existe reproyecci?n, reproyectar el extent
165
			ICoordTrans ct = getCoordTrans();
210
            // Si existe reproyecci?n, reproyectar el extent
211
            ICoordTrans ct = getCoordTrans();
166 212

  
167
			if (ct != null) {
168
				Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
169
				Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
170
				pt1 = ct.convert(pt1, null);
171
				pt2 = ct.convert(pt2, null);
172
				rAux = new Rectangle2D.Double();
173
				rAux.setFrameFromDiagonal(pt1, pt2);
174
			}
213
            if (ct != null) {
214
                Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
215
                Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
216
                pt1 = ct.convert(pt1, null);
217
                pt2 = ct.convert(pt2, null);
218
                rAux = new Rectangle2D.Double();
219
                rAux.setFrameFromDiagonal(pt1, pt2);
220
            }
175 221

  
176
			return rAux;
177
		} catch (DriverIOException e) {
178
			throw new DriverException(e);
179
		}
180
	}
222
            return rAux;
223
        } catch (DriverIOException e) {
224
            throw new DriverException(e);
225
        }
226
    }
181 227

  
182
	/**
183
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
184
	 *      com.iver.cit.gvsig.fmap.ViewPort,
185
	 *      com.iver.utiles.swing.threads.Cancellable)
186
	 */
187
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
188
			double scale, PrintRequestAttributeSet properties)
189
			throws DriverException {
190
		if (isVisible() && isWithinScale(scale)) {
191
			Strategy strategy = StrategyManager.getStrategy(this);
192
			strategy.print(g, viewPort, cancel, properties);
193
		}
194
	}
228
    /**
229
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
230
     *      com.iver.cit.gvsig.fmap.ViewPort,
231
     *      com.iver.utiles.swing.threads.Cancellable)
232
     */
233
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
234
        double scale, PrintRequestAttributeSet properties)
235
        throws DriverException {
236
        if (isVisible() && isWithinScale(scale)) {
237
            Strategy strategy = StrategyManager.getStrategy(this);
238
            strategy.print(g, viewPort, cancel, properties);
239
        }
240
    }
195 241

  
196
	/*
197
	 * (non-Javadoc)
198
	 * 
199
	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
200
	 */
201
	public FBitSet queryByRect(Rectangle2D rect) throws DriverException {
202
		Strategy s = StrategyManager.getStrategy(this);
242
    /*
243
     * (non-Javadoc)
244
     *
245
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
246
     */
247
    public FBitSet queryByRect(Rectangle2D rect) throws DriverException {
248
        Strategy s = StrategyManager.getStrategy(this);
203 249

  
204
		return s.queryByRect(rect);
205
	}
250
        return s.queryByRect(rect);
251
    }
206 252

  
207
	/**
208
	 * DOCUMENT ME!
209
	 * 
210
	 * @param p
211
	 *            DOCUMENT ME!
212
	 * @param tolerance
213
	 *            DOCUMENT ME!
214
	 * 
215
	 * @return DOCUMENT ME!
216
	 * 
217
	 * @throws DriverException
218
	 *             DOCUMENT ME!
219
	 */
220
	public FBitSet queryByPoint(Point2D p, double tolerance)
221
			throws DriverException {
222
		Strategy s = StrategyManager.getStrategy(this);
253
    /**
254
     * DOCUMENT ME!
255
     *
256
     * @param p DOCUMENT ME!
257
     * @param tolerance DOCUMENT ME!
258
     *
259
     * @return DOCUMENT ME!
260
     *
261
     * @throws DriverException DOCUMENT ME!
262
     */
263
    public FBitSet queryByPoint(Point2D p, double tolerance)
264
        throws DriverException {
265
        Strategy s = StrategyManager.getStrategy(this);
223 266

  
224
		return s.queryByPoint(p, tolerance);
225
	}
267
        return s.queryByPoint(p, tolerance);
268
    }
226 269

  
227
	/**
228
	 * DOCUMENT ME!
229
	 * 
230
	 * @param g
231
	 *            DOCUMENT ME!
232
	 * @param relationship
233
	 *            DOCUMENT ME!
234
	 * 
235
	 * @return DOCUMENT ME!
236
	 * 
237
	 * @throws DriverException
238
	 *             DOCUMENT ME!
239
	 * @throws VisitException
240
	 *             DOCUMENT ME!
241
	 */
242
	public FBitSet queryByShape(IGeometry g, int relationship)
243
			throws DriverException, VisitException {
244
		Strategy s = StrategyManager.getStrategy(this);
270
    /**
271
     * DOCUMENT ME!
272
     *
273
     * @param g DOCUMENT ME!
274
     * @param relationship DOCUMENT ME!
275
     *
276
     * @return DOCUMENT ME!
277
     *
278
     * @throws DriverException DOCUMENT ME!
279
     * @throws VisitException DOCUMENT ME!
280
     */
281
    public FBitSet queryByShape(IGeometry g, int relationship)
282
        throws DriverException, VisitException {
283
        Strategy s = StrategyManager.getStrategy(this);
245 284

  
246
		return s.queryByShape(g, relationship);
247
	}
285
        return s.queryByShape(g, relationship);
286
    }
248 287

  
249
	/**
250
	 * DOCUMENT ME!
251
	 * 
252
	 * @return DOCUMENT ME!
253
	 * 
254
	 * @throws XMLException
255
	 * 
256
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
257
	 */
258
	public XMLEntity getXMLEntity() throws XMLException {
259
		XMLEntity xml = super.getXMLEntity();
260
		// xml.addChild(mapping.getXMLEntity());
261
		xml.putProperty("isInPixels", isInPixels());
288
    /**
289
     * DOCUMENT ME!
290
     *
291
     * @return DOCUMENT ME!
292
     *
293
     * @throws XMLException
294
     *
295
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
296
     */
297
    public XMLEntity getXMLEntity() throws XMLException {
298
        XMLEntity xml = super.getXMLEntity();
262 299

  
263
		return xml;
264
	}
300
        // xml.addChild(mapping.getXMLEntity());
301
        //		xml.putProperty("isInPixels", isInPixels());
302
        return xml;
303
    }
265 304

  
266
	/**
267
	 * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
268
	 */
269
	public void setXMLEntity(XMLEntity xml) throws XMLException {
270
		// Iterator
271
		// iter=xml.findChildren("className",Annotation_Mapping.class.getName());
272
		// if (iter.hasNext())
273
		// mapping = Annotation_Mapping.createFromXML((XMLEntity)iter.next());
274
		// else{
275
		// //Este else para versiones anteriores a la 1.0.2.(908)
276
		// if (xml.getChildrenCount()==3)
277
		// mapping = Annotation_Mapping.createFromXML(xml.getChild(2));
278
		// else
279
		// mapping = Annotation_Mapping.createFromXML(xml.getChild(3));
280
		// }
281
		IProjection proj = null;
282
		if (xml.contains("proj")) {
283
			proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
284
		} else {
285
			proj = this.getMapContext().getViewPort().getProjection();
286
		}
287
		if (xml.contains("file")) {
288
			Driver d;
289
			try {
290
				d = LayerFactory.getDM().getDriver(
291
						xml.getStringProperty("driverName"));
292
			} catch (DriverLoadException e1) {
293
				throw new XMLException(e1);
294
			}
295
			FLyrVect lv = (FLyrVect) LayerFactory.createLayer(xml.getName(),
296
					(VectorialFileDriver) d, new File(xml
297
							.getStringProperty("file")), proj);
298
			try {
299
				this.setSource(lv.getSource());
300
				this.setRecordset(lv.getRecordset());
301
				this.setProjection(lv.getProjection());
302
				this.setLegend((VectorialLegend) lv.getLegend());
303
				Annotation_Mapping.addAnnotationMapping(this);
304
			} catch (DriverException e) {
305
				// TODO Auto-generated catch block
306
				e.printStackTrace();
307
			} catch (FieldNotFoundException e) {
308
				// TODO Auto-generated catch block
309
				e.printStackTrace();
310
			} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
311
				// TODO Auto-generated catch block
312
				e.printStackTrace();
313
			}
314
		}
315
		setInPixels(xml.getBooleanProperty("isInPixels"));
305
    /**
306
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
307
     */
308
    public void setXMLEntity(XMLEntity xml) throws XMLException {
309
        // Iterator
310
        // iter=xml.findChildren("className",Annotation_Mapping.class.getName());
311
        // if (iter.hasNext())
312
        // mapping = Annotation_Mapping.createFromXML((XMLEntity)iter.next());
313
        // else{
314
        // //Este else para versiones anteriores a la 1.0.2.(908)
315
        // if (xml.getChildrenCount()==3)
316
        // mapping = Annotation_Mapping.createFromXML(xml.getChild(2));
317
        // else
318
        // mapping = Annotation_Mapping.createFromXML(xml.getChild(3));
319
        // }
320
        IProjection proj = null;
316 321

  
317
		// IProjection proj = null;
318
		//
319
		// if (xml.contains("proj")) {
320
		// proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
321
		// }
322
        if (xml.contains("proj")) {
323
            proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
324
        } else {
325
            proj = this.getMapContext().getViewPort().getProjection();
326
        }
322 327

  
323
		// VectorialAdapter adapter=null;
324
		// if (xml.contains("file")){
325
		// adapter = new VectorialFileAdapter(new File(xml
326
		// .getStringProperty("file")));
327
		// }else if (xml.contains("db")){
328
		// adapter = new VectorialDBAdapter();
329
		// }
330
		// Driver d;
331
		//
332
		// try {
333
		// d = LayerFactory.getDM().getDriver(
334
		// xml.getStringProperty("driverName"));
335
		// } catch (DriverLoadException e1) {
336
		// throw new XMLException(e1);
337
		// }
338
		//
339
		// adapter.setDriver((VectorialDriver) d);
340
		// // TODO Meter esto dentro de la comprobaci?n de si hay memoria
341
		// if (false) {
342
		// } else {
343
		// setSource(adapter);
344
		// setProjection(proj);
345
		// }
328
        if (xml.contains("file")) {
329
            Driver d;
346 330

  
347
		// Le asignamos tambi?n una legenda por defecto acorde con
348
		// el tipo de shape que tenga. Tampoco s? si es aqu? el
349
		// sitio adecuado, pero en fin....
350
		/*
351
		 * if (d instanceof WithDefaultLegend) { WithDefaultLegend aux =
352
		 * (WithDefaultLegend) d; adapter.start(); setLegend((VectorialLegend)
353
		 * aux.getDefaultLegend()); adapter.stop(); } else {
354
		 * setLegend(LegendFactory.createSingleSymbolLegend(getShapeType())); }
355
		 */
331
            try {
332
                d = LayerFactory.getDM().getDriver(xml.getStringProperty(
333
                            "driverName"));
334
            } catch (DriverLoadException e1) {
335
                throw new XMLException(e1);
336
            }
356 337

  
357
		super.setXMLEntity(xml);
358
		// try {
359
		// createLabels();
360
		// } catch (DriverException e) {
361
		// // TODO Auto-generated catch block
362
		// e.printStackTrace();
363
		// }
364
	}
338
            FLyrVect lv = (FLyrVect) LayerFactory.createLayer(xml.getName(),
339
                    (VectorialFileDriver) d,
340
                    new File(xml.getStringProperty("file")), proj);
365 341

  
366
	/**
367
	 * Esto tiene el fallo de que obligas a una etiqueta por entidad, para poder
368
	 * evitar esto, una posible soluci?n ser?a que un FLabel pudiera ser una
369
	 * colecci?n de FLabel (Patr?n Composite)
370
	 * 
371
	 * @param lyrVect
372
	 * @throws DriverException
373
	 */
374
	// private void createLabels() throws DriverException {
375
	// SelectableDataSource ds = getRecordset();
376
	// FSymbol symbol;
377
	// try {
378
	// ReadableVectorial adapter = getSource();
379
	// adapter.start();
380
	// if (isJoined()){
381
	// ds.start();
382
	// }
383
	// int sc;
384
	// // El mapping[0] es el text
385
	// int fieldId = mapping.getColumnText();
386
	// // El mapping[1] es el ?ngulo
387
	// int idFieldRotationText = mapping.getColumnRotate();
388
	// // El mapping[2] es el color
389
	// int idFieldColorText = mapping.getColumnColor();
390
	// // El mapping[3] es el alto
391
	// int idFieldHeightText = mapping.getColumnHeight();
392
	// // El mapping[4] es el tipo de fuente
393
	// int idFieldTypeFontText = mapping.getColumnTypeFont();
394
	// // El mapping[5] es el estilo de fuente
395
	// int idFieldStyleFontText = mapping.getColumnStyleFont();
396
	//
397
	// sc = (int) ds.getRowCount();
398
	// m_labels = new ArrayList(sc);
399
	// DriverAttributes attr = adapter.getDriverAttributes();
400
	// boolean bMustClone = false;
401
	// if (attr != null) {
402
	// if (attr.isLoadedInMemory()) {
403
	// bMustClone = attr.isLoadedInMemory();
404
	// }
405
	// }
406
	// ICoordTrans ct = getCoordTrans();
407
	// FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol();
408
	// for (int i = 0; i < sc; i++) {
409
	// IGeometry geom = adapter.getShape(i);
410
	//
411
	// if (geom == null) {
412
	// m_labels.add(null);
413
	// continue;
414
	// }
415
	// if (ct != null) {
416
	// if (bMustClone)
417
	// geom = geom.cloneGeometry();
418
	// geom.reProject(ct);
419
	// }
420
	//
421
	// // TODO: El m?todo contenedor (createLabelLayer) debe recoger
422
	// // los par?metros de posicionamiento y de allowDuplicates
423
	// // if (i >= 328)
424
	// // System.out.println("i= " + i + " " + val.toString());
425
	// //ArrayList values=new ArrayList(4);
426
	// // String t=new String();
427
	// Value val = ds.getFieldValue(i, fieldId);
428
	//
429
	// //Value total=ValueFactory.createValue((Value[])values.toArray(new
430
	// Value[0]));
431
	// Value total=getSymbolKey(i);//ValueFactory.createValue(t);
432
	// if ((val instanceof NullValue) || (val == null)) {
433
	// m_labels.add(null);
434
	// continue;
435
	// }
436
	// FLabel[] lbls = geom.createLabels(0, true);
437
	// for (int j = 0; j < lbls.length; j++) {
438
	// if (lbls[j] != null) {
439
	// lbls[j].setString(val.toString());
440
	// if (idFieldRotationText != -1) {
441
	// NumericValue rotation = (NumericValue) ds
442
	// .getFieldValue(i, idFieldRotationText);
443
	// lbls[j].setRotation(rotation.doubleValue());
444
	// } else {
445
	// lbls[j].setRotation(defaultSym.getRotation());
446
	// }
447
	//
448
	// float height;
449
	// if (idFieldHeightText != -1) {
450
	// NumericValue h = (NumericValue) ds
451
	// .getFieldValue(i, idFieldHeightText);
452
	// height=h.floatValue();
453
	// lbls[j].setHeight(height);
454
	// } else {
455
	// height=defaultSym.getFontSize();
456
	// lbls[j].setHeight(height);
457
	// }
458
	//
459
	//
460
	//
461
	// if (aLegend.getSymbolByValue(total)==null){
462
	// Color color;
463
	// if (idFieldColorText != -1) {
464
	// NumericValue c = (NumericValue) ds.getFieldValue(
465
	// i, idFieldColorText);
466
	// color=new Color(c.intValue());
467
	// } else {
468
	// color=defaultSym.getFontColor();
469
	// }
470
	// String typeFont;
471
	// if (idFieldTypeFontText != -1) {
472
	// StringValue tf = (StringValue) ds
473
	// .getFieldValue(i, idFieldTypeFontText);
474
	// typeFont=tf.getValue();
475
	// } else {
476
	// typeFont=defaultSym.getFont().getFontName();
477
	// }
478
	// int style;
479
	// if (idFieldStyleFontText != -1) {
480
	// NumericValue sf = (NumericValue) ds
481
	// .getFieldValue(i, idFieldStyleFontText);
482
	// style=sf.intValue();
483
	// } else {
484
	// style=defaultSym.getFont().getStyle();
485
	// }
486
	// symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
487
	// symbol.setFontSizeInPixels(isInPixels());
488
	// symbol.setFont(new Font(typeFont,style,(int)height));
489
	// symbol.setDescription(lbls[j].getString());
490
	// symbol.setFontColor(color);
491
	// aLegend.addSymbol(total,symbol);
492
	// }
493
	//
494
	// }
495
	// m_labels.add(lbls[j]);
496
	//
497
	// }
498
	// }
499
	//
500
	// if (this.isJoined()){
501
	// ds.stop();
502
	// }
503
	// adapter.stop();
504
	// } catch (DriverIOException e) {
505
	// e.printStackTrace();
506
	// throw new DriverException(e);
507
	// } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
508
	// e.printStackTrace();
509
	// throw new DriverException(e);
510
	// }
511
	//
512
	// }
513
	public Value getSymbolKey(int i)
514
			throws com.hardcode.gdbms.engine.data.driver.DriverException,
515
			DriverException {
516
		SelectableDataSource ds = getRecordset();
517
		String t = new String();
518
		Value val = ds.getFieldValue(i, mapping.getColumnText());
519
		t = val.toString();
520
		// values.add(val);
521
		if (mapping.getColumnColor() != -1) {
522
			Value valColor = ds.getFieldValue(i, mapping.getColumnColor());
523
			t = t.concat(valColor.toString());
524
			// values.add(valColor);
525
		}
526
		if (mapping.getColumnTypeFont() != -1) {
527
			Value valTypeFont = ds
528
					.getFieldValue(i, mapping.getColumnTypeFont());
529
			t = t.concat(valTypeFont.toString());
530
			// values.add(valTypeFont);
531
		}
342
            try {
343
                this.setSource(lv.getSource());
344
                this.setRecordset(lv.getRecordset());
345
                this.setProjection(lv.getProjection());
346
                this.setLegend((VectorialLegend) lv.getLegend());
347
                Annotation_Mapping.addAnnotationMapping(this);
348
            } catch (DriverException e) {
349
                // TODO Auto-generated catch block
350
                e.printStackTrace();
351
            } catch (FieldNotFoundException e) {
352
                // TODO Auto-generated catch block
353
                e.printStackTrace();
354
            } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
355
                // TODO Auto-generated catch block
356
                e.printStackTrace();
357
            }
358
        }
532 359

  
533
		if (mapping.getColumnStyleFont() != -1) {
534
			Value valStyleFont = ds.getFieldValue(i, mapping
535
					.getColumnStyleFont());
536
			t = t.concat(valStyleFont.toString());
537
			// values.add(valStyleFont);
538
		}
539
		// Value total=ValueFactory.createValue((Value[])values.toArray(new
540
		// Value[0]));
541
		Value total = ValueFactory.createValue(t);
542
		return total;
543
	}
360
        //		setInPixels(xml.getBooleanProperty("isInPixels"));
361
        // IProjection proj = null;
362
        //
363
        // if (xml.contains("proj")) {
364
        // proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
365
        // }
366
        // VectorialAdapter adapter=null;
367
        // if (xml.contains("file")){
368
        // adapter = new VectorialFileAdapter(new File(xml
369
        // .getStringProperty("file")));
370
        // }else if (xml.contains("db")){
371
        // adapter = new VectorialDBAdapter();
372
        // }
373
        // Driver d;
374
        //
375
        // try {
376
        // d = LayerFactory.getDM().getDriver(
377
        // xml.getStringProperty("driverName"));
378
        // } catch (DriverLoadException e1) {
379
        // throw new XMLException(e1);
380
        // }
381
        //
382
        // adapter.setDriver((VectorialDriver) d);
383
        // // TODO Meter esto dentro de la comprobaci?n de si hay memoria
384
        // if (false) {
385
        // } else {
386
        // setSource(adapter);
387
        // setProjection(proj);
388
        // }
389
        // Le asignamos tambi?n una legenda por defecto acorde con
390
        // el tipo de shape que tenga. Tampoco s? si es aqu? el
391
        // sitio adecuado, pero en fin....
392
        /*
393
         * if (d instanceof WithDefaultLegend) { WithDefaultLegend aux =
394
         * (WithDefaultLegend) d; adapter.start(); setLegend((VectorialLegend)
395
         * aux.getDefaultLegend()); adapter.stop(); } else {
396
         * setLegend(LegendFactory.createSingleSymbolLegend(getShapeType())); }
397
         */
398
        super.setXMLEntity(xml);
544 399

  
545
	// public FLabel getLabel(int numReg) {
546
	// if (m_labels == null || numReg == -1)
547
	// return null;
548
	// if (getSource() instanceof Annotation_EditableAdapter){
549
	// Annotation_EditableAdapter aea=((Annotation_EditableAdapter)getSource());
550
	// return aea.getLabel(numReg,false);
551
	// }
552
	// return (FLabel)m_labels.get(numReg);
553
	// }
554
	// private FLabel getLabelNew(int numReg) throws DriverException{
555
	// SelectableDataSource ds = getRecordset();
556
	// FSymbol symbol;
557
	// try {
558
	// ReadableVectorial adapter = getSource();
559
	// adapter.start();
560
	// if (isJoined()){
561
	// ds.start();
562
	// }
563
	// int sc;
564
	// // El mapping[0] es el text
565
	// int fieldId = mapping.getColumnText();
566
	// // El mapping[1] es el ?ngulo
567
	// int idFieldRotationText = mapping.getColumnRotate();
568
	// // El mapping[2] es el color
569
	// int idFieldColorText = mapping.getColumnColor();
570
	// // El mapping[3] es el alto
571
	// int idFieldHeightText = mapping.getColumnHeight();
572
	// // El mapping[4] es el tipo de fuente
573
	// int idFieldTypeFontText = mapping.getColumnTypeFont();
574
	// // El mapping[5] es el estilo de fuente
575
	// int idFieldStyleFontText = mapping.getColumnStyleFont();
576
	//
577
	// // sc = (int) ds.getRowCount();
578
	// // m_labels = new ArrayList(sc);
579
	// // DriverAttributes attr = adapter.getDriverAttributes();
580
	// boolean bMustClone = false;
581
	// // if (attr != null) {
582
	// // if (attr.isLoadedInMemory()) {
583
	// // bMustClone = attr.isLoadedInMemory();
584
	// // }
585
	// // }
586
	// ICoordTrans ct = getCoordTrans();
587
	// FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol();
588
	// // for (int i = 0; i < sc; i++) {
589
	// IGeometry geom = adapter.getShape(numReg);
590
	//
591
	// if (geom == null) {
592
	// // m_labels.add(null);
593
	// return null;
594
	// }
595
	// if (ct != null) {
596
	// if (bMustClone)
597
	// geom = geom.cloneGeometry();
598
	// geom.reProject(ct);
599
	// }
600
	//
601
	// // TODO: El m?todo contenedor (createLabelLayer) debe recoger
602
	// // los par?metros de posicionamiento y de allowDuplicates
603
	// // if (i >= 328)
604
	// // System.out.println("i= " + i + " " + val.toString());
605
	// //ArrayList values=new ArrayList(4);
606
	// String t=new String();
607
	// Value val = ds.getFieldValue(numReg, fieldId);
608
	// t=val.toString();
609
	// //values.add(val);
610
	// if (idFieldColorText!=-1){
611
	// Value valColor=ds.getFieldValue(numReg,idFieldColorText);
612
	// t=t.concat(valColor.toString());
613
	// //values.add(valColor);
614
	// }
615
	// if (idFieldTypeFontText!=-1){
616
	// Value valTypeFont=ds.getFieldValue(numReg,idFieldTypeFontText);
617
	// t=t.concat(valTypeFont.toString());
618
	// //values.add(valTypeFont);
619
	// }
620
	//
621
	// if (idFieldStyleFontText!=-1){
622
	// Value valStyleFont=ds.getFieldValue(numReg,idFieldStyleFontText);
623
	// t=t.concat(valStyleFont.toString());
624
	// //values.add(valStyleFont);
625
	// }
626
	// //Value total=ValueFactory.createValue((Value[])values.toArray(new
627
	// Value[0]));
628
	// Value total=ValueFactory.createValue(t);
629
	// if ((val instanceof NullValue) || (val == null)) {
630
	// return null;
631
	// }
632
	// FLabel[] lbls = geom.createLabels(0, true);
633
	// for (int j = 0; j < lbls.length; j++) {
634
	// if (lbls[j] != null) {
635
	// lbls[j].setString(val.toString());
636
	// if (idFieldRotationText != -1) {
637
	// NumericValue rotation = (NumericValue) ds
638
	// .getFieldValue(numReg, idFieldRotationText);
639
	// lbls[j].setRotation(rotation.doubleValue());
640
	// } else {
641
	// lbls[j].setRotation(defaultSym.getRotation());
642
	// }
643
	//
644
	// float height;
645
	// if (idFieldHeightText != -1) {
646
	// NumericValue h = (NumericValue) ds
647
	// .getFieldValue(numReg, idFieldHeightText);
648
	// height=h.floatValue();
649
	// lbls[j].setHeight(height);
650
	// } else {
651
	// height=defaultSym.getFontSize();
652
	// lbls[j].setHeight(height);
653
	// }
654
	//
655
	//
656
	//
657
	// if (aLegend.getSymbolByValue(total)==null){
658
	// Color color;
659
	// if (idFieldColorText != -1) {
660
	// NumericValue c = (NumericValue) ds.getFieldValue(
661
	// numReg, idFieldColorText);
662
	// color=new Color(c.intValue());
663
	// } else {
664
	// color=defaultSym.getFontColor();
665
	// }
666
	// String typeFont;
667
	// if (idFieldTypeFontText != -1) {
668
	// StringValue tf = (StringValue) ds
669
	// .getFieldValue(numReg, idFieldTypeFontText);
670
	// typeFont=tf.getValue();
671
	// } else {
672
	// typeFont=defaultSym.getFont().getFontName();
673
	// }
674
	// int style;
675
	// if (idFieldStyleFontText != -1) {
676
	// NumericValue sf = (NumericValue) ds
677
	// .getFieldValue(numReg, idFieldStyleFontText);
678
	// style=sf.intValue();
679
	// } else {
680
	// style=defaultSym.getFont().getStyle();
681
	// }
682
	// symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
683
	// symbol.setFontSizeInPixels(isInPixels());
684
	// symbol.setFont(new Font(typeFont,style,(int)height));
685
	// symbol.setDescription(lbls[j].getString());
686
	// symbol.setFontColor(color);
687
	// aLegend.addSymbol(total,symbol);
688
	// }
689
	//
690
	// }
691
	// return lbls[j];
692
	//
693
	// }
694
	// // }
695
	//
696
	// if (this.isJoined()){
697
	// ds.stop();
698
	// }
699
	// adapter.stop();
700
	// } catch (DriverIOException e) {
701
	// e.printStackTrace();
702
	// throw new DriverException(e);
703
	// } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
704
	// e.printStackTrace();
705
	// throw new DriverException(e);
706
	// }
707
	// return null;
708
	// }
709
	/*
710
	 * (non-Javadoc)
711
	 * 
712
	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
713
	 */
714
	public void createSpatialIndex() {
715
		// FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
716
		// QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
717
		// para que acepten recorrer sin geometria, solo con rectangulos.
400
        // try {
401
        // createLabels();
402
        // } catch (DriverException e) {
403
        // // TODO Auto-generated catch block
404
        // e.printStackTrace();
405
        // }
406
    }
718 407

  
719
		// AZABALA: Como no tengo claro de donde se crean las capas de textos
720
		// el ?ndice espacial creado seguir? siendo el Quadtree en memoria
721
		// de JTS (QuadtreeJts es un adapter a nuestra api de indices)
722
		spatialIndex = new QuadtreeJts();
723
		ReadableVectorial va = getSource();
724
		ICoordTrans ct = getCoordTrans();
725
		BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
726
		try {
727
			va.start();
728
			for (int i = 0; i < va.getShapeCount(); i++) {
729
				Rectangle2D r = null;
730
				IGeometry geom = va.getShape(i);
731
				// FSymbol symbol=(FSymbol)aLegend.getSymbol(i);
732
				// IGeometry geom=aLegend.getTextWrappingGeometry(symbol,i);
733
				// FLabel label=getLabel(i);
734
				if (geom != null) {
735
					r = geom.getBounds2D();
736
				} else {
737
					r = shapeBounds.getShapeBounds(i);
738
				}
739
				// TODO: MIRAR COMO SE TRAGAR?A ESTO LO DE LAS REPROYECCIONES
740
				if (ct != null) {
741
					r = ct.convert(r);
742
				}
743
				if (r != null) {
744
					// Coordinate c1 = new Coordinate(r.getMinX(), r.getMinY());
745
					// Coordinate c2 = new Coordinate(r.getMaxX(), r.getMaxY());
746
					// Envelope env = new Envelope(c1, c2);
747
					// spatialIndex.insert(env, new Integer(i));
748
					spatialIndex.insert(r, i);
749
				}
750
			} // for
751
			va.stop();
752
		} catch (DriverIOException e) {
753
			e.printStackTrace();
754
		} catch (IOException e) {
755
			e.printStackTrace();
756
		}
757
	}
408
    /**
409
     * Esto tiene el fallo de que obligas a una etiqueta por entidad, para
410
     * poder evitar esto, una posible soluci?n ser?a que un FLabel pudiera ser
411
     * una colecci?n de FLabel (Patr?n Composite)
412
     *
413
     * @param i
414
     *
415
     * @return DOCUMENT ME!
416
     *
417
     * @throws com.hardcode.gdbms.engine.data.driver.DriverException DOCUMENT
418
     *  ME!
419
     * @throws DriverException
420
     */
758 421

  
759
	public void setSelectedEditing() throws DriverException {
760
		FBitSet bitSet = getRecordset().getSelection();
761
		if (bitSet.cardinality() == 0)
762
			return;
763
		indexEditing = bitSet.nextSetBit(0);
764
	}
422
    // private void createLabels() throws DriverException {
423
    // SelectableDataSource ds = getRecordset();
424
    // FSymbol symbol;
425
    // try {
426
    // ReadableVectorial adapter = getSource();
427
    // adapter.start();
428
    // if (isJoined()){
429
    // ds.start();
430
    // }
431
    // int sc;
432
    // // El mapping[0] es el text
433
    // int fieldId = mapping.getColumnText();
434
    // // El mapping[1] es el ?ngulo
435
    // int idFieldRotationText = mapping.getColumnRotate();
436
    // // El mapping[2] es el color
437
    // int idFieldColorText = mapping.getColumnColor();
438
    // // El mapping[3] es el alto
439
    // int idFieldHeightText = mapping.getColumnHeight();
440
    // // El mapping[4] es el tipo de fuente
441
    // int idFieldTypeFontText = mapping.getColumnTypeFont();
442
    // // El mapping[5] es el estilo de fuente
443
    // int idFieldStyleFontText = mapping.getColumnStyleFont();
444
    //
445
    // sc = (int) ds.getRowCount();
446
    // m_labels = new ArrayList(sc);
447
    // DriverAttributes attr = adapter.getDriverAttributes();
448
    // boolean bMustClone = false;
449
    // if (attr != null) {
450
    // if (attr.isLoadedInMemory()) {
451
    // bMustClone = attr.isLoadedInMemory();
452
    // }
453
    // }
454
    // ICoordTrans ct = getCoordTrans();
455
    // FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol();
456
    // for (int i = 0; i < sc; i++) {
457
    // IGeometry geom = adapter.getShape(i);
458
    //
459
    // if (geom == null) {
460
    // m_labels.add(null);
461
    // continue;
462
    // }
463
    // if (ct != null) {
464
    // if (bMustClone)
465
    // geom = geom.cloneGeometry();
466
    // geom.reProject(ct);
467
    // }
468
    //
469
    // // TODO: El m?todo contenedor (createLabelLayer) debe recoger
470
    // // los par?metros de posicionamiento y de allowDuplicates
471
    // // if (i >= 328)
472
    // // System.out.println("i= " + i + " " + val.toString());
473
    // //ArrayList values=new ArrayList(4);
474
    // // String t=new String();
475
    // Value val = ds.getFieldValue(i, fieldId);
476
    //
477
    // //Value total=ValueFactory.createValue((Value[])values.toArray(new
478
    // Value[0]));
479
    // Value total=getSymbolKey(i);//ValueFactory.createValue(t);
480
    // if ((val instanceof NullValue) || (val == null)) {
481
    // m_labels.add(null);
482
    // continue;
483
    // }
484
    // FLabel[] lbls = geom.createLabels(0, true);
485
    // for (int j = 0; j < lbls.length; j++) {
486
    // if (lbls[j] != null) {
487
    // lbls[j].setString(val.toString());
488
    // if (idFieldRotationText != -1) {
489
    // NumericValue rotation = (NumericValue) ds
490
    // .getFieldValue(i, idFieldRotationText);
491
    // lbls[j].setRotation(rotation.doubleValue());
492
    // } else {
493
    // lbls[j].setRotation(defaultSym.getRotation());
494
    // }
495
    //
496
    // float height;
497
    // if (idFieldHeightText != -1) {
498
    // NumericValue h = (NumericValue) ds
499
    // .getFieldValue(i, idFieldHeightText);
500
    // height=h.floatValue();
501
    // lbls[j].setHeight(height);
502
    // } else {
503
    // height=defaultSym.getFontSize();
504
    // lbls[j].setHeight(height);
505
    // }
506
    //
507
    //
508
    //
509
    // if (aLegend.getSymbolByValue(total)==null){
510
    // Color color;
511
    // if (idFieldColorText != -1) {
512
    // NumericValue c = (NumericValue) ds.getFieldValue(
513
    // i, idFieldColorText);
514
    // color=new Color(c.intValue());
515
    // } else {
516
    // color=defaultSym.getFontColor();
517
    // }
518
    // String typeFont;
519
    // if (idFieldTypeFontText != -1) {
520
    // StringValue tf = (StringValue) ds
521
    // .getFieldValue(i, idFieldTypeFontText);
522
    // typeFont=tf.getValue();
523
    // } else {
524
    // typeFont=defaultSym.getFont().getFontName();
525
    // }
526
    // int style;
527
    // if (idFieldStyleFontText != -1) {
528
    // NumericValue sf = (NumericValue) ds
529
    // .getFieldValue(i, idFieldStyleFontText);
530
    // style=sf.intValue();
531
    // } else {
532
    // style=defaultSym.getFont().getStyle();
533
    // }
534
    // symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
535
    // symbol.setFontSizeInPixels(isInPixels());
536
    // symbol.setFont(new Font(typeFont,style,(int)height));
537
    // symbol.setDescription(lbls[j].getString());
538
    // symbol.setFontColor(color);
539
    // aLegend.addSymbol(total,symbol);
540
    // }
541
    //
542
    // }
543
    // m_labels.add(lbls[j]);
544
    //
545
    // }
546
    // }
547
    //
548
    // if (this.isJoined()){
549
    // ds.stop();
550
    // }
551
    // adapter.stop();
552
    // } catch (DriverIOException e) {
553
    // e.printStackTrace();
554
    // throw new DriverException(e);
555
    // } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
556
    // e.printStackTrace();
557
    // throw new DriverException(e);
558
    // }
559
    //
560
    // }
561
    public Value getSymbolKey(int i)
562
        throws com.hardcode.gdbms.engine.data.driver.DriverException,
563
            DriverException {
564
        SelectableDataSource ds = getRecordset();
565
        String t = new String();
566
        Value val = ds.getFieldValue(i, mapping.getColumnText());
567
        t = val.toString();
765 568

  
766
	public void setInPixels(boolean b) {
767
		inPixels = b;
768
		if (aLegend != null)
769
			aLegend.setInPixels(b);
770
	}
569
        // values.add(val);
570
        if (mapping.getColumnColor() != -1) {
571
            Value valColor = ds.getFieldValue(i, mapping.getColumnColor());
572
            t = t.concat(valColor.toString());
771 573

  
772
	public boolean isInPixels() {
773
		return inPixels;
774
	}
574
            // values.add(valColor);
575
        }
775 576

  
776
	public void setInEdition(int i) {
777
		indexEditing = i;
577
        if (mapping.getColumnTypeFont() != -1) {
578
            Value valTypeFont = ds.getFieldValue(i, mapping.getColumnTypeFont());
579
            t = t.concat(valTypeFont.toString());
778 580

  
779
	}
581
            // values.add(valTypeFont);
582
        }
780 583

  
781
	public int getInEdition() {
782
		return indexEditing;
783
	}
584
        if (mapping.getColumnStyleFont() != -1) {
585
            Value valStyleFont = ds.getFieldValue(i,
586
                    mapping.getColumnStyleFont());
587
            t = t.concat(valStyleFont.toString());
784 588

  
785
	// public ArrayList getLabels() {
786
	// return m_labels;
787
	// }
589
            // values.add(valStyleFont);
590
        }
788 591

  
789
	public void setLegend() {
790
		try {
791
			getSource().getRecordset().start();
792
			aLegend.setFieldName(getSource().getRecordset().getFieldName(
793
					mapping.getColumnText()));
794
			// aLegend.setDefaultSymbol(new
795
			// FSymbol(FConstant.SYMBOL_TYPE_TEXT));
796
			setLegend(aLegend);
797
			getSource().getRecordset().stop();
798
		} catch (FieldNotFoundException e) {
799
			e.printStackTrace();
800
		} catch (DriverException e) {
801
			e.printStackTrace();
802
		} catch (DriverLoadException e) {
803
			e.printStackTrace();
804
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
805
			e.printStackTrace();
806
		}
592
        // Value total=ValueFactory.createValue((Value[])values.toArray(new
593
        // Value[0]));
594
        Value total = ValueFactory.createValue(t);
807 595

  
808
	}
596
        return total;
597
    }
809 598

  
810
	public Strategy getStrategy() {
811
		return strategy;
812
	}
599
    // public FLabel getLabel(int numReg) {
600
    // if (m_labels == null || numReg == -1)
601
    // return null;
602
    // if (getSource() instanceof Annotation_EditableAdapter){
603
    // Annotation_EditableAdapter aea=((Annotation_EditableAdapter)getSource());
604
    // return aea.getLabel(numReg,false);
605
    // }
606
    // return (FLabel)m_labels.get(numReg);
607
    // }
608
    // private FLabel getLabelNew(int numReg) throws DriverException{
609
    // SelectableDataSource ds = getRecordset();
610
    // FSymbol symbol;
611
    // try {
612
    // ReadableVectorial adapter = getSource();
613
    // adapter.start();
614
    // if (isJoined()){
615
    // ds.start();
616
    // }
617
    // int sc;
618
    // // El mapping[0] es el text
619
    // int fieldId = mapping.getColumnText();
620
    // // El mapping[1] es el ?ngulo
621
    // int idFieldRotationText = mapping.getColumnRotate();
622
    // // El mapping[2] es el color
623
    // int idFieldColorText = mapping.getColumnColor();
624
    // // El mapping[3] es el alto
625
    // int idFieldHeightText = mapping.getColumnHeight();
626
    // // El mapping[4] es el tipo de fuente
627
    // int idFieldTypeFontText = mapping.getColumnTypeFont();
628
    // // El mapping[5] es el estilo de fuente
629
    // int idFieldStyleFontText = mapping.getColumnStyleFont();
630
    //
631
    // // sc = (int) ds.getRowCount();
632
    // // m_labels = new ArrayList(sc);
633
    // // DriverAttributes attr = adapter.getDriverAttributes();
634
    // boolean bMustClone = false;
635
    // // if (attr != null) {
636
    // // if (attr.isLoadedInMemory()) {
637
    // // bMustClone = attr.isLoadedInMemory();
638
    // // }
639
    // // }
640
    // ICoordTrans ct = getCoordTrans();
641
    // FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol();
642
    // // for (int i = 0; i < sc; i++) {
643
    // IGeometry geom = adapter.getShape(numReg);
644
    //
645
    // if (geom == null) {
646
    // // m_labels.add(null);
647
    // return null;
648
    // }
649
    // if (ct != null) {
650
    // if (bMustClone)
651
    // geom = geom.cloneGeometry();
652
    // geom.reProject(ct);
653
    // }
654
    //
655
    // // TODO: El m?todo contenedor (createLabelLayer) debe recoger
656
    // // los par?metros de posicionamiento y de allowDuplicates
657
    // // if (i >= 328)
658
    // // System.out.println("i= " + i + " " + val.toString());
659
    // //ArrayList values=new ArrayList(4);
660
    // String t=new String();
661
    // Value val = ds.getFieldValue(numReg, fieldId);
662
    // t=val.toString();
663
    // //values.add(val);
664
    // if (idFieldColorText!=-1){
665
    // Value valColor=ds.getFieldValue(numReg,idFieldColorText);
666
    // t=t.concat(valColor.toString());
667
    // //values.add(valColor);
668
    // }
669
    // if (idFieldTypeFontText!=-1){
670
    // Value valTypeFont=ds.getFieldValue(numReg,idFieldTypeFontText);
671
    // t=t.concat(valTypeFont.toString());
672
    // //values.add(valTypeFont);
673
    // }
674
    //
675
    // if (idFieldStyleFontText!=-1){
676
    // Value valStyleFont=ds.getFieldValue(numReg,idFieldStyleFontText);
677
    // t=t.concat(valStyleFont.toString());
678
    // //values.add(valStyleFont);
679
    // }
680
    // //Value total=ValueFactory.createValue((Value[])values.toArray(new
681
    // Value[0]));
682
    // Value total=ValueFactory.createValue(t);
683
    // if ((val instanceof NullValue) || (val == null)) {
684
    // return null;
685
    // }
686
    // FLabel[] lbls = geom.createLabels(0, true);
687
    // for (int j = 0; j < lbls.length; j++) {
688
    // if (lbls[j] != null) {
689
    // lbls[j].setString(val.toString());
690
    // if (idFieldRotationText != -1) {
691
    // NumericValue rotation = (NumericValue) ds
692
    // .getFieldValue(numReg, idFieldRotationText);
693
    // lbls[j].setRotation(rotation.doubleValue());
694
    // } else {
695
    // lbls[j].setRotation(defaultSym.getRotation());
696
    // }
697
    //
698
    // float height;
699
    // if (idFieldHeightText != -1) {
700
    // NumericValue h = (NumericValue) ds
701
    // .getFieldValue(numReg, idFieldHeightText);
702
    // height=h.floatValue();
703
    // lbls[j].setHeight(height);
704
    // } else {
705
    // height=defaultSym.getFontSize();
706
    // lbls[j].setHeight(height);
707
    // }
708
    //
709
    //
710
    //
711
    // if (aLegend.getSymbolByValue(total)==null){
712
    // Color color;
713
    // if (idFieldColorText != -1) {
714
    // NumericValue c = (NumericValue) ds.getFieldValue(
715
    // numReg, idFieldColorText);
716
    // color=new Color(c.intValue());
717
    // } else {
718
    // color=defaultSym.getFontColor();
719
    // }
720
    // String typeFont;
721
    // if (idFieldTypeFontText != -1) {
722
    // StringValue tf = (StringValue) ds
723
    // .getFieldValue(numReg, idFieldTypeFontText);
724
    // typeFont=tf.getValue();
725
    // } else {
726
    // typeFont=defaultSym.getFont().getFontName();
727
    // }
728
    // int style;
729
    // if (idFieldStyleFontText != -1) {
730
    // NumericValue sf = (NumericValue) ds
731
    // .getFieldValue(numReg, idFieldStyleFontText);
732
    // style=sf.intValue();
733
    // } else {
734
    // style=defaultSym.getFont().getStyle();
735
    // }
736
    // symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
737
    // symbol.setFontSizeInPixels(isInPixels());
738
    // symbol.setFont(new Font(typeFont,style,(int)height));
739
    // symbol.setDescription(lbls[j].getString());
740
    // symbol.setFontColor(color);
741
    // aLegend.addSymbol(total,symbol);
742
    // }
743
    //
744
    // }
745
    // return lbls[j];
746
    //
747
    // }
748
    // // }
749
    //
750
    // if (this.isJoined()){
751
    // ds.stop();
752
    // }
753
    // adapter.stop();
754
    // } catch (DriverIOException e) {
755
    // e.printStackTrace();
756
    // throw new DriverException(e);
757
    // } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
758
    // e.printStackTrace();
759
    // throw new DriverException(e);
760
    // }
761
    // return null;
762
    // }
813 763

  
814
	public void setEditing(boolean b) throws EditionException {
815
		super.setEditing(b);
816
		try {
817
			if (b) {
818
				Annotation_EditableAdapter aea = new Annotation_EditableAdapter(
819
						this);
820
				aea
821
						.setOriginalVectorialAdapter(((VectorialEditableAdapter) super
822
								.getSource()).getOriginalAdapter());
823
				((VectorialEditableAdapter) super.getSource())
824
						.cancelEdition(EditionEvent.GRAPHIC);
825
				aea.start();
826
				// CHEMA
827
				aea.startEdition(EditionEvent.GRAPHIC);
828
				setSource(aea);
829
				getRecordset().setSelectionSupport(
830
						aea.getOriginalAdapter().getRecordset()
831
								.getSelectionSupport());
832
			} else {
833
				// createLabels();
834
			}
835
		} catch (DriverIOException e) {
836
			throw new EditionException();
837
		} catch (DriverLoadException e) {
838
			throw new EditionException();
839
		} catch (DriverException e) {
840
			throw new EditionException();
841
		} catch (IOException e) {
842
			throw new EditionException();
843
		}
844
		deleteSpatialIndex();
764
    /*
765
     * (non-Javadoc)
766
     *
767
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
768
     */
769
    public void createSpatialIndex() {
770
        // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
771
        // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
772
        // para que acepten recorrer sin geometria, solo con rectangulos.
773
        // AZABALA: Como no tengo claro de donde se crean las capas de textos
774
        // el ?ndice espacial creado seguir? siendo el Quadtree en memoria
775
        // de JTS (QuadtreeJts es un adapter a nuestra api de indices)
776
        spatialIndex = new QuadtreeJts();
845 777

  
846
	}
778
        ReadableVectorial va = getSource();
779
        ICoordTrans ct = getCoordTrans();
780
        BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
847 781

  
848
	public static FLayer createLayerFromVect(FLyrVect layer)
849
			throws DriverException, FieldNotFoundException {
850
		Annotation_Layer la = new Annotation_Layer();
851
		la.setSource(layer.getSource());
852
		la.setRecordset(layer.getRecordset());
853
		la.setProjection(layer.getProjection());
854
		la.setLegend((VectorialLegend) layer.getLegend());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff