Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FMultiPoint2D.java @ 4835

History | View | Annotate | Download (8.14 KB)

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

    
43
import java.awt.Color;
44
import java.awt.Graphics2D;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.PathIterator;
47
import java.awt.geom.Point2D;
48
import java.awt.geom.Rectangle2D;
49
import java.io.IOException;
50
import java.util.ArrayList;
51

    
52
import org.cresques.cts.ICoordTrans;
53

    
54
import com.iver.cit.gvsig.fmap.ViewPort;
55
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
56
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
57
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
58
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
59
import com.vividsolutions.jts.geom.Geometry;
60

    
61

    
62
/**
63
 * Multipunto 2D.
64
 *
65
 * @author Vicente Caballero Navarro
66
 */
67
public class FMultiPoint2D implements IGeometry {
68
        FPoint2D[] points = null;
69

    
70
        /**
71
         * Crea un nuevo MultiPoint2D.
72
         *
73
         * @param x DOCUMENT ME!
74
         * @param y DOCUMENT ME!
75
         */
76
        public FMultiPoint2D(double[] x, double[] y) {
77
                for (int i=0;i<x.length;i++){
78
                        points[i] = new FPoint2D(x[i], y[i]);
79
                }
80

    
81
        }
82
        public FMultiPoint2D(FPoint2D[] points) {
83
        this.points = points;
84
        }
85
        /**
86
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D,
87
         *                 ViewPort, FStyle2D)
88
         */
89
        public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) {
90
                int size = 2;
91
                int hw = 4;
92

    
93
                for (int i = 0; i < points.length; i++) {
94
                        Point2D.Double p = new Point2D.Double(points[i].getX(), points[i].getY());
95
                        vp.getAffineTransform().transform(p, p);
96
                        g.setColor(Color.red);
97
                        g.fillOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
98
                        g.setColor(Color.black);
99
                        g.drawOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
100
                }
101
        }
102

    
103
        /**
104
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
105
         */
106
        public Geometry toJTSGeometry() {
107
        // TODO.
108
                return null;
109
        }
110

    
111
        /**
112
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
113
         */
114
        public FLabel[] createLabels(int position, boolean duplicates) {
115
        FLabel[] aux = new FLabel[getNumPoints()];
116
        for (int i=0; i < getNumPoints(); i++)
117
        {
118
            aux[i] = FLabel.createFLabel(points[i]);
119
        }
120

    
121
                return aux;
122
        }
123

    
124
        /* (non-Javadoc)
125
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
126
         */
127
        public boolean intersects(Rectangle2D r) {
128
                for (int i=0;i<getNumPoints();i++){
129
                        if (r.contains(points[i].getX(),points[i].getY()))return true;
130
                }
131
                return false;
132
        }
133

    
134
        /* (non-Javadoc)
135
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
136
         */
137
        public Rectangle2D getBounds2D() {
138
                Rectangle2D r=null;
139
                if (getNumPoints()>0){
140
                        r=new Rectangle2D.Double(points[0].getX(),points[0].getY(),0.001,0.001);
141
                }
142
                for (int i=1;i<getNumPoints();i++){
143
                        r.add(points[i].getX(),points[i].getY());
144
                }
145
                return r;
146
        }
147

    
148
        /**
149
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
150
         */
151
        public int getGeometryType() {
152
                return FShape.MULTIPOINT;
153
        }
154

    
155
        /* (non-Javadoc)
156
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
157
         */
158
        public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) {
159
                //int size = 2;
160
                //int hw = 4;
161

    
162
                for (int i = 0; i < getNumPoints(); i++) {
163
                        Point2D.Double p = new Point2D.Double(points[i].getX(),
164
                                        points[i].getY());
165
                        vp.getAffineTransform().transform(p, p);
166
                        FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), new FPoint2D(p.getX(),p.getY()), symbol);
167

    
168
                /*        java.awt.geom.Point2D.Double p = new java.awt.geom.Point2D.Double(x[i],
169
                                        y[i]);
170
                        vp.getAffineTransform().transform(p, p);
171
                        g.setColor(Color.red);
172
                        g.fillOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
173
                        g.setColor(Color.black);
174
                        g.drawOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
175
                */
176
                }
177
        }
178

    
179
        /* (non-Javadoc)
180
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
181
         */
182
        public IGeometry cloneGeometry() {
183
                FPoint2D[] aux = new FPoint2D[getNumPoints()];
184
                for (int i=0; i < getNumPoints(); i++)
185
                {
186
                        aux[i] = (FPoint2D) points[i].cloneFShape();
187
                }
188
                return new FMultiPoint2D(aux);
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
                for (int i=0; i < getNumPoints(); i++)
196
                {
197
                        points[i].reProject(ct);
198
                }
199
        }
200
        public int getNumPoints(){
201
                return points.length;
202
        }
203
        public FPoint2D getPoint(int i){
204
                return points[i];
205
        }
206
        /**
207
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
208
         */
209
        public GeneralPathXIterator getGeneralPathXIterator() {
210
                GeneralPathX gpx=new GeneralPathX();
211
                if (getNumPoints()>0){
212
                        gpx.moveTo(points[0].getX(), points[0].getY());
213
                }
214
                for (int i=1;i<getNumPoints();i++){
215
                        gpx.lineTo(points[i].getX(), points[i].getY());
216
                }
217
                return (GeneralPathXIterator)gpx.getPathIterator(null);
218
        }
219
    /* (non-Javadoc)
220
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
221
     */
222
    public boolean fastIntersects(double x, double y, double w, double h) {
223
                for (int i=0; i < getNumPoints(); i++)
224
                {
225
                        if (points[i].intersects(x,y,w,h))
226
                                return true;
227
                }
228
        return false;
229
    }
230
    /* (non-Javadoc)
231
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#drawInts(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
232
     */
233
    public void drawInts(Graphics2D g, ViewPort vp, FSymbol symbol) {
234
        draw(g,vp, symbol);
235

    
236
    }
237
        /* (non-Javadoc)
238
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers(int)
239
         */
240
        public Handler[] getHandlers(int type) {
241
                ArrayList handlers=new ArrayList();
242
                for (int i = 0; i < getNumPoints(); i++){
243
                        handlers.add(new PointHandler(i,points[i]));
244
                }
245
                return (Handler[])handlers.toArray(new Handler[0]);
246
        }
247
        /**
248
         * DOCUMENT ME!
249
         *
250
         * @author Vicente Caballero Navarro
251
         */
252
        class PointHandler extends AbstractHandler {
253
                /**
254
                 * Crea un nuevo PointHandler.
255
                 *
256
                 * @param x DOCUMENT ME!
257
                 * @param y DOCUMENT ME!
258
                 */
259
                public PointHandler(int i,FPoint2D p) {
260
                        point = new Point2D.Double(p.getX(), p.getY());
261
                        index=i;
262
                }
263

    
264
                /**
265
                 * DOCUMENT ME!
266
                 *
267
                 * @param x DOCUMENT ME!
268
                 * @param y DOCUMENT ME!
269
                 *
270
                 * @return DOCUMENT ME!
271
                 */
272
                public void move(double x, double y) {
273
                        point.setLocation(points[index].getX()+x,
274
                                        points[index].getY()+y);
275
                }
276

    
277
                /**
278
                 * @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
279
                 */
280
                public void set(double x, double y) {
281
                        point.setLocation(x, y);
282
                }
283

    
284
        }
285
        public void transform(AffineTransform at) {
286
                for (int i=0; i < getNumPoints(); i++)
287
                {
288
                        points[i].transform(at);
289
                }
290

    
291
        }
292
        public byte[] toWKB() throws IOException {
293
                // TODO Auto-generated method stub
294
                return null;
295
        }
296
        public PathIterator getGeneralPathIterator(AffineTransform at, double flatness) {
297
                GeneralPathX gpx=new GeneralPathX();
298
                if (getNumPoints()>0){
299
                        gpx.moveTo(points[0].getX(), points[0].getY());
300
                }
301
                for (int i=1;i<getNumPoints();i++){
302
                        gpx.lineTo(points[i].getX(), points[i].getY());
303
                }
304
                return (GeneralPathXIterator)gpx.getPathIterator(at, flatness);
305

    
306
        }
307
}