Statistics
| Revision:

svn-gvsig-desktop / branches / Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 1848

History | View | Annotate | Download (5.66 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
import java.io.Serializable;
64

    
65

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

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

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

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

    
97
                                break;
98

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

    
102
                                break;
103

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

    
107
                                break;
108

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

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

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

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

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

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

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

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

    
175
                return aux;
176
        }
177

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

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

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

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

    
206
    /* (non-Javadoc)
207
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
208
     */
209
    public boolean fastIntersects(double x, double y, double w, double h) {
210
        return shp.intersects(x,y,w,h);
211
    }
212
}