Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrText.java @ 1100

History | View | Annotate | Download (5.76 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 com.iver.cit.gvsig.fmap.layers;
46

    
47
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
48

    
49
import com.iver.cit.gvsig.fmap.DriverException;
50
import com.iver.cit.gvsig.fmap.ViewPort;
51
import com.iver.cit.gvsig.fmap.core.FPoint2D;
52
import com.iver.cit.gvsig.fmap.core.FShape;
53
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
54
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
55
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
56
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
57
import com.iver.cit.gvsig.fmap.operations.Cancellable;
58
import com.iver.cit.gvsig.fmap.rendering.Legend;
59
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
60

    
61
import java.awt.Graphics2D;
62
import java.awt.geom.Rectangle2D;
63
import java.awt.image.BufferedImage;
64

    
65
import java.util.ArrayList;
66

    
67

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

    
82
        /**
83
         * Crea un nuevo FLyrText.
84
         *
85
         * @param arrayLabels DOCUMENT ME!
86
         */
87
        public FLyrText(ArrayList arrayLabels) {
88
                m_labels = arrayLabels;
89
        }
90

    
91
        /**
92
         * Dibuja sobre el graphics los textos.
93
         *
94
         * @param image
95
         * @param g Graphics.
96
         * @param viewPort ViewPort.
97
         * @param cancel
98
         */
99
        private void drawLabels(BufferedImage image, Graphics2D g,
100
                ViewPort viewPort, Cancellable cancel) {
101
                int numReg;
102
                Rectangle2D elExtent = viewPort.getExtent();
103

    
104
                int anchoMapa;
105
                int altoMapa;
106
                double anchoReal;
107
                double altoReal;
108
                double escala;
109
                FSymbol theSymbol = null;
110
                System.out.println("Dibujando etiquetas...");
111

    
112
                for (numReg = 0; numReg < m_labels.size(); numReg++) {
113
                        if (cancel.isCanceled()) {
114
                                break;
115
                        }
116

    
117
                        FLabel theLabel = (FLabel) m_labels.get(numReg);
118

    
119
                        if (elExtent.contains(theLabel.getOrig())) // TODO: Aqui hay que ponerle al FLabel un getExtent()
120
                         {
121
                                theSymbol = getLegend().getDefaultSymbol();
122

    
123
                                FShape shp = new FPoint2D(theLabel.getOrig().getX(),
124
                                                theLabel.getOrig().getY());
125
                                FGraphicUtilities.DrawLabel(g, viewPort.getAffineTransform(),
126
                                        shp, theSymbol, theLabel);
127
                        }
128
                }
129
        }
130

    
131
        /* (non-Javadoc)
132
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
133
         */
134
        public Rectangle2D getFullExtent() throws DriverException {
135
                return fullExtent;
136
        }
137

    
138
        /* (non-Javadoc)
139
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
140
         */
141
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
142
                Cancellable cancel) throws DriverException {
143
                drawLabels(image, g, viewPort, cancel);
144
        }
145

    
146
        /* (non-Javadoc)
147
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
148
         */
149
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel)
150
                throws DriverException {
151
                drawLabels(null, g, viewPort, cancel);
152
        }
153

    
154
        /* (non-Javadoc)
155
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial#setLegend(com.iver.cit.gvsig.fmap.rendering.VectorialLegend)
156
         */
157
        public void setLegend(VectorialLegend r)
158
                throws DriverException, FieldNotFoundException {
159
                legend = r;
160
        }
161

    
162
        /* (non-Javadoc)
163
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#addLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
164
         */
165
        public void addLegendListener(LegendListener listener) {
166
                // TODO Auto-generated method stub
167
        }
168

    
169
        /* (non-Javadoc)
170
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
171
         */
172
        public void removeLegendListener(LegendListener listener) {
173
                // TODO Auto-generated method stub
174
        }
175

    
176
        /* (non-Javadoc)
177
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getLegend()
178
         */
179
        public Legend getLegend() {
180
                return legend;
181
        }
182

    
183
        /* (non-Javadoc)
184
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
185
         */
186
        public int getShapeType() throws DriverException {
187
                return FShape.TEXT;
188
        }
189

    
190
        /**
191
         * Devuelve un ArrayList con los textos de la capa.
192
         *
193
         * @return Texto de la capa.
194
         */
195
        public ArrayList getLabels() {
196
                return m_labels;
197
        }
198

    
199
        /**
200
         * Inserta los textos de la capa
201
         *
202
         * @param m_labels ArrayList con los textos de la capa.
203
         */
204
        public void setLabels(ArrayList m_labels) {
205
                this.m_labels = m_labels;
206
        }
207
}