Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FMultiPoint2D.java @ 4711

History | View | Annotate | Download (7.87 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.Point2D;
47
import java.awt.geom.Rectangle2D;
48
import java.io.IOException;
49
import java.util.ArrayList;
50

    
51
import org.cresques.cts.ICoordTrans;
52

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

    
60

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

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

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

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

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

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

    
120
                return aux;
121
        }
122

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

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

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

    
154
        /* (non-Javadoc)
155
         * @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)
156
         */
157
        public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) {
158
                //int size = 2;
159
                //int hw = 4;
160

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

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

    
178
        /* (non-Javadoc)
179
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
180
         */
181
        public IGeometry cloneGeometry() {
182
                FPoint2D[] aux = new FPoint2D[getNumPoints()];
183
                for (int i=0; i < getNumPoints(); i++)
184
                {
185
                        aux[i] = (FPoint2D) points[i].cloneFShape();
186
                }
187
                return new FMultiPoint2D(aux);
188
        }
189

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

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

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

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

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

    
290
        }
291
        public byte[] toWKB() throws IOException {
292
                // TODO Auto-generated method stub
293
                return null;
294
        }
295
        public boolean contains(IGeometry g) {
296
                return false;
297
        }
298
        public boolean intersects(IGeometry geom) {
299
                return false;
300
        }
301
}