Statistics
| Revision:

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

History | View | Annotate | Download (5.95 KB)

1 745 fjp
/*
2
 * Created on 28-dic-2004
3
 *
4
 */
5 1100 fjp
/* 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 745 fjp
package com.iver.cit.gvsig.fmap.layers;
46
47 1034 vcaballero
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
48 745 fjp
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 1034 vcaballero
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 745 fjp
/**
69 1034 vcaballero
 * Capa de texto.
70
 *
71 745 fjp
 * @author FJP
72
 */
73
public class FLyrText extends FLyrDefault implements ClassifiableVectorial {
74 1034 vcaballero
        /**
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 745 fjp
82 1034 vcaballero
        /**
83
         * Crea un nuevo FLyrText.
84
         *
85
         * @param arrayLabels DOCUMENT ME!
86
         */
87
        public FLyrText(ArrayList arrayLabels) {
88
                m_labels = arrayLabels;
89
        }
90 745 fjp
91 1034 vcaballero
        /**
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 745 fjp
104 2531 caballero
                //int anchoMapa;
105
                //int altoMapa;
106
                //double anchoReal;
107
                //double altoReal;
108
                //double escala;
109 1034 vcaballero
                FSymbol theSymbol = null;
110
                System.out.println("Dibujando etiquetas...");
111 745 fjp
112 1034 vcaballero
                for (numReg = 0; numReg < m_labels.size(); numReg++) {
113
                        if (cancel.isCanceled()) {
114
                                break;
115
                        }
116 745 fjp
117 1034 vcaballero
                        FLabel theLabel = (FLabel) m_labels.get(numReg);
118 1126 fjp
                        if ((theLabel == null) || (theLabel.getOrig() == null)) continue;
119 1034 vcaballero
                        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 745 fjp
        /* (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 2531 caballero
                Cancellable cancel,double scale) throws DriverException {
143
                if (isVisible() && isWithinScale(scale)){
144 745 fjp
                drawLabels(image, g, viewPort, cancel);
145 2531 caballero
                }
146 745 fjp
        }
147
148
        /* (non-Javadoc)
149
         * @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)
150
         */
151 2531 caballero
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
152 1034 vcaballero
                throws DriverException {
153 2531 caballero
                if (isVisible() && isWithinScale(scale)){
154 745 fjp
                drawLabels(null, g, viewPort, cancel);
155 2531 caballero
                }
156 745 fjp
        }
157
158
        /* (non-Javadoc)
159
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial#setLegend(com.iver.cit.gvsig.fmap.rendering.VectorialLegend)
160
         */
161 1034 vcaballero
        public void setLegend(VectorialLegend r)
162
                throws DriverException, FieldNotFoundException {
163
                legend = r;
164 745 fjp
        }
165
166
        /* (non-Javadoc)
167
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#addLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
168
         */
169
        public void addLegendListener(LegendListener listener) {
170
                // TODO Auto-generated method stub
171
        }
172
173
        /* (non-Javadoc)
174
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
175
         */
176
        public void removeLegendListener(LegendListener listener) {
177
                // TODO Auto-generated method stub
178
        }
179
180
        /* (non-Javadoc)
181
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getLegend()
182
         */
183
        public Legend getLegend() {
184
                return legend;
185
        }
186
187
        /* (non-Javadoc)
188
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
189
         */
190
        public int getShapeType() throws DriverException {
191
                return FShape.TEXT;
192
        }
193
194 1034 vcaballero
        /**
195
         * Devuelve un ArrayList con los textos de la capa.
196
         *
197
         * @return Texto de la capa.
198
         */
199 745 fjp
        public ArrayList getLabels() {
200
                return m_labels;
201
        }
202 1034 vcaballero
203
        /**
204
         * Inserta los textos de la capa
205
         *
206
         * @param m_labels ArrayList con los textos de la capa.
207
         */
208 745 fjp
        public void setLabels(ArrayList m_labels) {
209
                this.m_labels = m_labels;
210
        }
211
}