Statistics
| Revision:

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

History | View | Annotate | Download (6.03 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
import org.geotools.resources.geometry.XRectangle2D;
68

    
69

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

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

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

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

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

    
119
                        FLabel theLabel = (FLabel) m_labels.get(numReg);
120
                        if ((theLabel == null) || (theLabel.getOrig() == null)) continue;
121
            
122
                        if (elExtent.contains(theLabel.getOrig())) // TODO: Aqui hay que ponerle al FLabel un getExtent()
123
                         {
124
                                theSymbol = getLegend().getDefaultSymbol();
125

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

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

    
141
        /* (non-Javadoc)
142
         * @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)
143
         */
144
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
145
                Cancellable cancel,double scale) throws DriverException {
146
                if (isVisible() && isWithinScale(scale)){        
147
                drawLabels(image, g, viewPort, cancel);
148
                }
149
        }
150

    
151
        /* (non-Javadoc)
152
         * @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)
153
         */
154
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
155
                throws DriverException {
156
                if (isVisible() && isWithinScale(scale)){        
157
                drawLabels(null, g, viewPort, cancel);
158
                }
159
        }
160

    
161
        /* (non-Javadoc)
162
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial#setLegend(com.iver.cit.gvsig.fmap.rendering.VectorialLegend)
163
         */
164
        public void setLegend(VectorialLegend r)
165
                throws DriverException, FieldNotFoundException {
166
                legend = r;
167
        }
168

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

    
176
        /* (non-Javadoc)
177
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
178
         */
179
        public void removeLegendListener(LegendListener listener) {
180
                // TODO Auto-generated method stub
181
        }
182

    
183
        /* (non-Javadoc)
184
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getLegend()
185
         */
186
        public Legend getLegend() {
187
                return legend;
188
        }
189

    
190
        /* (non-Javadoc)
191
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
192
         */
193
        public int getShapeType() throws DriverException {
194
                return FShape.TEXT;
195
        }
196

    
197
        /**
198
         * Devuelve un ArrayList con los textos de la capa.
199
         *
200
         * @return Texto de la capa.
201
         */
202
        public ArrayList getLabels() {
203
                return m_labels;
204
        }
205

    
206
        /**
207
         * Inserta los textos de la capa
208
         *
209
         * @param m_labels ArrayList con los textos de la capa.
210
         */
211
        public void setLabels(ArrayList m_labels) {
212
                this.m_labels = m_labels;
213
        }
214
}