Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 1132

History | View | Annotate | Download (5.38 KB)

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

    
49
import com.iver.cit.gvsig.fmap.ViewPort;
50
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
51
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
52
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
53
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
54
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
55

    
56
import com.vividsolutions.jts.geom.Geometry;
57

    
58
import org.cresques.cts.ICoordTrans;
59

    
60
import java.awt.Graphics2D;
61
import java.awt.geom.AffineTransform;
62
import java.awt.geom.Rectangle2D;
63

    
64

    
65
/**
66
 * Geometr?a.
67
 *
68
 * @author FJP
69
 */
70
public class FGeometry implements IGeometry {
71
        private FShape shp;
72

    
73
        /**
74
         * Crea un nuevo FGeometry.
75
         *
76
         * @param shp DOCUMENT ME!
77
         */
78
        FGeometry(FShape shp) {
79
                this.shp = shp;
80
        }
81

    
82
        /* (non-Javadoc)
83
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, org.geotools.renderer.style.Style2D)
84
         */
85
        public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) {
86
                // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
87
                // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL 
88
                // SHAPE
89
                // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
90
                transform(vp.getAffineTransform());
91

    
92
                switch (shp.getShapeType()) {
93
                        case FShape.POINT:
94
                                shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
95

    
96
                                break;
97

    
98
                        case FShape.LINE:
99
                                shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
100

    
101
                                break;
102

    
103
                        case FShape.POLYGON:
104
                                shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
105

    
106
                                break;
107

    
108
                        case FShape.TEXT:
109
                                shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
110
                }
111
        }
112

    
113
        /**
114
         * Dibuja la geometria actual en el graphics que se le pasa como par?metro,
115
         * aplicandole las caracter?sticas del s?mbolo.
116
         *
117
         * @param g Graphics2D.
118
         * @param vp ViewPort.
119
         * @param symbol S?mbolo.
120
         */
121
        public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) {
122
                // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
123
                // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL 
124
                // SHAPE
125
                // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
126
                transform(vp.getAffineTransform());
127
                FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol);
128
        }
129

    
130
        /**
131
         * Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
132
         * que se pasa como par?metro.
133
         *
134
         * @param at Matriz de transformaci?n.
135
         */
136
        private void transform(AffineTransform at) {
137
                if (shp instanceof FPolyline2D) {
138
                        ((FPolyline2D) shp).transform(at);
139
                }
140

    
141
                if (shp instanceof FPoint2D) {
142
                        ((FPoint2D) shp).transform(at);
143
                }
144
        }
145

    
146
        /* (non-Javadoc)
147
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
148
         */
149
        public boolean intersects(Rectangle2D r) {
150
                return shp.intersects(r);
151
        }
152

    
153
        /* (non-Javadoc)
154
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
155
         */
156
        public Rectangle2D getBounds2D() {
157
                return shp.getBounds2D();
158
        }
159

    
160
        /* (non-Javadoc)
161
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
162
         */
163
        public Geometry toJTSGeometry() {
164
                return FConverter.java2d_to_jts(shp);
165
        }
166

    
167
        /* (non-Javadoc)
168
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
169
         */
170
        public FLabel[] createLabels(int position, boolean duplicates) {
171
                FLabel[] aux = new FLabel[1];
172
                aux[0] = FLabel.createFLabel(shp);
173

    
174
                return aux;
175
        }
176

    
177
        /**
178
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
179
         */
180
        public int getGeometryType() {
181
                return shp.getShapeType();
182
        }
183

    
184
        /* (non-Javadoc)
185
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
186
         */
187
        public IGeometry cloneGeometry() {
188
                return new FGeometry(shp.cloneFShape());
189
        }
190

    
191
        /* (non-Javadoc)
192
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
193
         */
194
        public void reProject(ICoordTrans ct) {
195
                shp.reProject(ct);
196
        }
197

    
198
        /**
199
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
200
         */
201
        public GeneralPathXIterator getGeneralPathXIterator() {
202
                return (GeneralPathXIterator)shp.getPathIterator(null);
203
        }
204
}