Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / FLyrText.java @ 24494

History | View | Annotate | Download (15.6 KB)

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

    
47
import java.awt.Graphics2D;
48
import java.awt.image.BufferedImage;
49
import java.util.ArrayList;
50

    
51
import javax.print.attribute.PrintRequestAttributeSet;
52

    
53
import org.gvsig.fmap.dal.exceptions.ReadException;
54
import org.gvsig.fmap.geom.Geometry;
55
import org.gvsig.fmap.geom.primitive.Envelope;
56
import org.gvsig.fmap.mapcontext.ViewPort;
57
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
58
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
59
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
60
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
61
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener;
62

    
63
import com.iver.utiles.swing.threads.Cancellable;
64

    
65
/**
66
 * Capa de texto.
67
 *
68
 * @author FJP
69
 * @deprecated
70
 */
71
public class FLyrText extends FLyrDefault implements ClassifiableVectorial {
72
    /**
73
     * <code>m_labels</code> es una arrayList de FLabel (string + punto de
74
     * inserci?n + rotaci?n + altura de texto
75
     */
76
    private ArrayList m_labels = new ArrayList();
77

    
78
    private IVectorLegend legend;
79

    
80
    // private Rectangle2D fullExtent;
81
    private FLyrVect assocLyrVect = null;
82

    
83
    /**
84
     * Crea un nuevo FLyrText.
85
     *
86
     * @param arrayLabels
87
     *            DOCUMENT ME!
88
     * @throws DriverException
89
     * @throws com.hardcode.gdbms.engine.data.driver.DriverException
90
     */
91
    public FLyrText() {
92
    }
93

    
94
//    /**
95
//     * Esto tiene el fallo de que obligas a una etiqueta por
96
//     * entidad, para poder evitar esto, una posible soluci?n
97
//     * ser?a que un FLabel pudiera ser una colecci?n de FLabel
98
//     * (Patr?n Composite)
99
//     * @param lyrVect
100
//     * @throws DriverException
101
//     */
102
//    public void createLabels(FLyrVect lyrVect) throws ReadDriverException {
103
//
104
//        assocLyrVect = lyrVect;
105
//        SelectableDataSource ds=null;
106
//                        ds = lyrVect.getRecordset();
107
//
108
//        try {
109
//                   ReadableVectorial adapter = lyrVect.getSource();
110
//            adapter.start();
111
//            ds.start();
112
//            int sc;
113
//            int fieldId = ds.getFieldIndexByName(legend.getLabelField());
114
//            IVectorialLegend l = (IVectorialLegend) getLegend();
115
//            int idFieldHeightText = -1;
116
//            int idFieldRotationText = -1;
117
//
118
////            FSymbol defaultSym = (FSymbol) l.getDefaultSymbol();
119
////
120
////            if (l.getLabelHeightField() != null) {
121
////                idFieldHeightText = ds.getFieldIndexByName(l
122
////                        .getLabelHeightField());
123
////                defaultSym.setFontSizeInPixels(false);
124
////            }
125
////
126
////            if (l.getLabelRotationField() != null) {
127
////                idFieldRotationText = ds.getFieldIndexByName(l
128
////                        .getLabelRotationField());
129
////            }
130
//
131
//            sc = (int) ds.getRowCount();
132
//            m_labels = new ArrayList(sc);
133
//
134
//
135
//            DriverAttributes attr = adapter.getDriverAttributes();
136
//            boolean bMustClone = false;
137
//            if (attr != null) {
138
//                if (attr.isLoadedInMemory()) {
139
//                    bMustClone = attr.isLoadedInMemory();
140
//                }
141
//            }
142
//            ICoordTrans ct = getCoordTrans();
143
//
144
//
145
//            for (int i = 0; i < sc; i++) {
146
//                IGeometry geom = adapter.getShape(i);
147
//
148
//                if (geom == null) {
149
//                    m_labels.add(null);
150
//                    continue;
151
//                }
152
//                if (ct != null) {
153
//                    if (bMustClone)
154
//                        geom = geom.cloneGeometry();
155
//                    geom.reProject(ct);
156
//                }
157
//
158
//                // TODO: El m?todo contenedor (createLabelLayer) debe recoger
159
//                // los par?metros de posicionamiento y de allowDuplicates
160
//                // if (i >= 328)
161
//                // System.out.println("i= " + i + " " + val.toString());
162
//                Value val = ds.getFieldValue(i, fieldId);
163
//
164
//                if ((val instanceof NullValue) || (val == null)) {
165
//                    continue;
166
//                }
167
//
168
//                FLabel[] lbls = geom.createLabels(0, true);
169
//                                for (int j = 0; j < lbls.length; j++) {
170
//                                        if (lbls[j] != null) {
171
//                                                lbls[j].setString(val.toString());
172
//
173
//                                                if (idFieldHeightText != -1) {
174
//                                                        NumericValue height = (NumericValue) ds.getFieldValue(i,
175
//                                                                        idFieldHeightText);
176
//                                                        lbls[j].setHeight(height.floatValue());
177
//                                                } else {
178
//                            // El tama?o del texto va siempre en el simbolo por defecto
179
//                            // cuando no hay un campo de altura de texto
180
//                            // TODO: Todo esto cambiar? con el nuevo sistema de leyendas...
181
//// jaume                                                        if (l.getDefaultSymbol()!=null)
182
//// jaume                                        lbls[j].setHeight(defaultSym.getFontSize());
183
//                                                }
184
//
185
//                                                if (idFieldRotationText != -1) {
186
//                                                        DoubleValue rotation = (DoubleValue) ds.getFieldValue(i,
187
//                                                                        idFieldRotationText);
188
//                                                        lbls[j].setRotation(rotation.getValue());
189
//                                                }
190
//                                                m_labels.add(lbls[j]);
191
//                                        }
192
//
193
//
194
//                                }
195
//
196
//                /* if (lbls[0] == null)
197
//                    m_labels.add(null);
198
//                else
199
//                    m_labels.add(lbls[0].getOrig()); */
200
//            }
201
//
202
//            ds.stop();
203
//            adapter.stop();
204
//        } catch (ExpansionFileReadException e) {
205
//                 throw new ReadDriverException(getName(),e);
206
//                } catch (InitializeDriverException e) {
207
//                         throw new ReadDriverException(getName(),e);
208
//                }
209
//
210
//    }
211

    
212
    /**
213
     * Dibuja sobre el graphics los textos.
214
     *
215
     * @param image
216
     * @param g
217
     *            Graphics.
218
     * @param viewPort
219
     *            ViewPort.
220
     * @param cancel
221
     */
222
//    private void drawLabels(BufferedImage image, Graphics2D g,
223
//            ViewPort viewPort, Cancellable cancel) {
224
//        int numReg;
225
//        /*
226
//         * refactored... labels will be managed by the LabelingStrategy
227
//        Rectangle2D elExtent = viewPort.getAdjustedExtent();
228
//
229
//        // int anchoMapa;
230
//        // int altoMapa;
231
//        // double anchoReal;
232
//        // double altoReal;
233
//        // double escala;
234
//        ISymbol theSymbol = null;
235
//        System.out.println("Dibujando etiquetas...");
236
//
237
//        for (numReg = 0; numReg < m_labels.size(); numReg++) {
238
//            if (cancel.isCanceled()) {
239
//                break;
240
//            }
241
//
242
//            FLabel theLabel = (FLabel) m_labels.get(numReg);
243
//            if ((theLabel == null) || (theLabel.getOrig() == null))
244
//                continue;
245
//
246
//            if (elExtent.contains(theLabel.getOrig())) // TODO: Aqui hay que
247
//            // ponerle al FLabel un
248
//            // getExtent()
249
//            {
250
//                theSymbol = getLegend().getDefaultSymbol();
251
//
252
//                FShape shp = new FPoint2D(theLabel.getOrig().getX(), theLabel
253
//                        .getOrig().getY());
254
//
255
//                theLabel.draw(g, viewPort.getAffineTransform(), shp, theSymbol);
256
//                // FGraphicUtilities.DrawLabel(g, viewPort.getAffineTransform(),
257
//                //         shp, theSymbol, theLabel);
258
//            }
259
//        }
260
//        */
261
//    }
262

    
263
//    /**
264
//     * @deprecated use drawlabels (compatibility with postgis)
265
//     * @param image
266
//     * @param g
267
//     * @param viewPort
268
//     * @param cancel
269
//     * @throws DriverException
270
//     */
271
//    private void drawLabels2(BufferedImage image, Graphics2D g,
272
//            ViewPort viewPort, Cancellable cancel) throws ReadDriverException {
273
//        int numReg;
274
//        Rectangle2D elExtent = viewPort.getAdjustedExtent();
275
//
276
//        // int anchoMapa;
277
//        // int altoMapa;
278
//        // double anchoReal;
279
//        // double altoReal;
280
//        // double escala;
281
//        FSymbol theSymbol = null;
282
//        System.out.println("Dibujando etiquetas...");
283
//        FLabel theLabel = new FLabel();
284
//
285
//        SelectableDataSource ds=null;
286
//                        ds = assocLyrVect.getRecordset();
287
//                int fieldId = ds.getFieldIndexByName(legend.getLabelField());
288
//            IVectorialLegend l = (IVectorialLegend) getLegend();
289
//            int idFieldHeightText = -1;
290
//            int idFieldRotationText = -1;
291
//            FSymbol defaultSym = (FSymbol) l.getDefaultSymbol();
292
//
293
//            if (l.getLabelHeightField() != null) {
294
//                // l.setBWithHeightText(true);
295
//                idFieldHeightText = ds.getFieldIndexByName(l
296
//                        .getLabelHeightField());
297
//                defaultSym.setFontSizeInPixels(false);
298
//            }
299
//            /*
300
//             * }else{ l.setBWithHeightText(false); }
301
//             */
302
//
303
//            // boolean bWithRotationText = false;
304
//            if (l.getLabelRotationField() != null) {
305
//                // bWithRotationText = true;
306
//                idFieldRotationText = ds.getFieldIndexByName(l
307
//                        .getLabelRotationField());
308
//            }
309
//
310
//            for (numReg = 0; numReg < m_labels.size(); numReg++) {
311
//                if (cancel.isCanceled()) {
312
//                    break;
313
//                }
314
//
315
//                Point2D thePoint = (Point2D) m_labels.get(numReg);
316
//
317
//
318
//
319
//                if (thePoint == null)
320
//                    continue;
321
//                FPoint2D theShape = new FPoint2D(thePoint);
322
//                if (getCoordTrans() != null)
323
//                    theShape.reProject(this.getCoordTrans());
324
//
325
//                if (elExtent.contains(theShape.getX(), theShape.getY())) // TODO: Aqui hay que
326
//                // ponerle al FLabel un
327
//                // getExtent()
328
//                {
329
//                    Value val = ds.getFieldValue(numReg, fieldId);
330
//
331
//                    if ((val instanceof NullValue) || (val == null)) {
332
//                        continue;
333
//                    }
334
//
335
//                    theSymbol = defaultSym;
336
//                    theLabel.setString(val.toString());
337
//                    theLabel.setOrig(thePoint);
338
//
339
//                    if (idFieldHeightText != -1) {
340
//                        NumericValue height = (NumericValue) ds
341
//                                .getFieldValue(numReg, idFieldHeightText);
342
//                        theLabel.setHeight(height.floatValue());
343
//                    } else {
344
//                        // El tama?o del texto va siempre en el simbolo por
345
//                        // defecto
346
//                        // cuando no hay un campo de altura de texto
347
//                        // TODO: Todo esto cambiar? con el nuevo sistema de
348
//                        // leyendas...
349
//                        if (defaultSym != null)
350
//                            theLabel.setHeight(defaultSym.getFontSize());
351
//                    }
352
//
353
//                    if (idFieldRotationText != -1) {
354
//                        DoubleValue rotation = (DoubleValue) ds
355
//                                .getFieldValue(numReg, idFieldRotationText);
356
//                        theLabel.setRotation(rotation.getValue());
357
//                    }
358
//                    theLabel.draw(g, viewPort.getAffineTransform(), theShape, theSymbol);
359
//                }
360
//            }
361
//
362
//
363
//    }
364

    
365
    /*
366
     * (non-Javadoc)
367
     *
368
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
369
     */
370
    public Envelope getFullEnvelope() throws ReadException {
371
        return assocLyrVect.getFullEnvelope();
372
    }
373

    
374
    /*
375
     * (non-Javadoc)
376
     *
377
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
378
     *      java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
379
     *      com.iver.cit.gvsig.fmap.operations.Cancellable)
380
     */
381
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
382
            Cancellable cancel, double scale) throws ReadException {
383
//        if (isVisible() && isWithinScale(scale)) {
384
//            drawLabels(image, g, viewPort, cancel);
385
//        }
386
    }
387

    
388
    /*
389
     * (non-Javadoc)
390
     *
391
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
392
     *      com.iver.cit.gvsig.fmap.ViewPort,
393
     *      com.iver.cit.gvsig.fmap.operations.Cancellable)
394
     */
395
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
396
            double scale, PrintRequestAttributeSet properties) throws ReadException {
397
//        if (isVisible() && isWithinScale(scale)) {
398
//            drawLabels(null, g, viewPort, cancel);
399
//        }
400
    }
401

    
402
    /*
403
     * (non-Javadoc)
404
     *
405
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial#setLegend(com.iver.cit.gvsig.fmap.rendering.VectorialLegend)
406
     */
407
    public void setLegend(IVectorLegend r) {
408
        legend = r;
409
    }
410

    
411
    /*
412
     * (non-Javadoc)
413
     *
414
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#addLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
415
     */
416
    public void addLegendListener(LegendListener listener) {
417
        // TODO Auto-generated method stub
418
    }
419

    
420
    /*
421
     * (non-Javadoc)
422
     *
423
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
424
     */
425
    public void removeLegendListener(LegendListener listener) {
426
        // TODO Auto-generated method stub
427
    }
428

    
429
    /*
430
     * (non-Javadoc)
431
     *
432
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getLegend()
433
     */
434
    public ILegend getLegend() {
435
        return legend;
436
    }
437

    
438
    /*
439
     * (non-Javadoc)
440
     *
441
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
442
     */
443
    public int getShapeType() {
444
        return Geometry.TYPES.TEXT;
445
    }
446

    
447
    /**
448
     * Devuelve un ArrayList con los textos de la capa.
449
     *
450
     * @return Texto de la capa.
451
     */
452
    /* public ArrayList getLabels() {
453
        return m_labels;
454
    } */
455

    
456
    /**
457
     * Inserta los textos de la capa
458
     *
459
     * @param m_labels
460
     *            ArrayList con los textos de la capa.
461
     */
462
    /* public void setLabels(ArrayList m_labels) {
463
        this.m_labels = m_labels;
464
    } */
465
}