Statistics
| Revision:

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

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

    
50
import org.cresques.cts.ICoordTrans;
51

    
52
import com.iver.cit.gvsig.fmap.ViewPort;
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.rendering.styling.FStyle2D;
57
import com.vividsolutions.jts.geom.Geometry;
58

    
59

    
60
/**
61
 * Multipunto 2D.
62
 *
63
 * @author Vicente Caballero Navarro
64
 */
65
public class FMultiPoint2D implements IGeometry {
66
        double[] x = null;
67
        double[] y = 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
                this.x = x;
77
                this.y = y;
78
        }
79
        public FMultiPoint2D(FPoint2D[] points) {
80
                double[] auxX=new double[points.length];
81
                double[] auxY=new double[points.length];
82
                for (int i=0;i<points.length;i++){
83
                        auxX[i]=points[i].getX();
84
                        auxY[i]=points[i].getY();
85
                }
86
        // Aportado por Fernando desde su auto-destierro
87
        this.x = auxX;
88
        this.y = auxY;
89
        }
90
        /**
91
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D,
92
         *                 ViewPort, FStyle2D)
93
         */
94
        public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) {
95
                int size = 2;
96
                int hw = 4;
97

    
98
                for (int i = 0; i < x.length; i++) {
99
                        java.awt.geom.Point2D.Double p = new java.awt.geom.Point2D.Double(x[i],
100
                                        y[i]);
101
                        vp.getAffineTransform().transform(p, p);
102
                        g.setColor(Color.red);
103
                        g.fillOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
104
                        g.setColor(Color.black);
105
                        g.drawOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
106
                }
107
        }
108

    
109
        /**
110
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
111
         */
112
        public Geometry toJTSGeometry() {
113
        // TODO.
114
                return null;
115
        }
116

    
117
        /**
118
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
119
         */
120
        public FLabel[] createLabels(int position, boolean duplicates) {
121
        FLabel[] aux = new FLabel[getNumPoints()];
122
        for (int i=0; i < getNumPoints(); i++)
123
        {
124
            aux[i] = FLabel.createFLabel(new FPoint2D(x[i],y[i]));
125
        }
126

    
127
                return aux;
128
        }
129

    
130
        /* (non-Javadoc)
131
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
132
         */
133
        public boolean intersects(Rectangle2D r) {
134
                for (int i=0;i<getNumPoints();i++){
135
                        if (r.contains(x[i],y[i]))return true;
136
                }
137
                return false;
138
        }
139

    
140
        /* (non-Javadoc)
141
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
142
         */
143
        public Rectangle2D getBounds2D() {
144
                Rectangle2D r=null;
145
                if (getNumPoints()>0){
146
                        r=new Rectangle2D.Double(x[0],y[0],0.001,0.001);
147
                }
148
                for (int i=1;i<getNumPoints();i++){
149
                        r.add(x[i],y[i]);
150
                }
151
                return r;
152
        }
153

    
154
        /**
155
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
156
         */
157
        public int getGeometryType() {
158
                return FShape.MULTIPOINT;
159
        }
160

    
161
        /* (non-Javadoc)
162
         * @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)
163
         */
164
        public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) {
165
                //int size = 2;
166
                //int hw = 4;
167

    
168
                for (int i = 0; i < x.length; i++) {
169
                        java.awt.geom.Point2D.Double p = new java.awt.geom.Point2D.Double(x[i],
170
                                        y[i]);
171
                        vp.getAffineTransform().transform(p, p);
172
                        FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), new FPoint2D(p.getX(),p.getY()), symbol);
173

    
174
                /*        java.awt.geom.Point2D.Double p = new java.awt.geom.Point2D.Double(x[i],
175
                                        y[i]);
176
                        vp.getAffineTransform().transform(p, p);
177
                        g.setColor(Color.red);
178
                        g.fillOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
179
                        g.setColor(Color.black);
180
                        g.drawOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
181
                */
182
                }
183
        }
184

    
185
        /* (non-Javadoc)
186
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
187
         */
188
        public IGeometry cloneGeometry() {
189
                return new FMultiPoint2D((double[])x.clone(),(double[])y.clone());
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
                // TODO Auto-generated method stub
197
        }
198
        public int getNumPoints(){
199
                return x.length;
200
        }
201
        public FPoint2D getPoint(int i){
202
                return new FPoint2D(x[i],y[i]);
203
        }
204
        /**
205
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
206
         */
207
        public GeneralPathXIterator getGeneralPathXIterator() {
208
                GeneralPathX gpx=new GeneralPathX();
209
                if (getNumPoints()>0){
210
                        gpx.moveTo(x[0],y[0]);
211
                }
212
                for (int i=1;i<getNumPoints();i++){
213
                        gpx.lineTo(x[i],y[i]);
214
                }
215
                return (GeneralPathXIterator)gpx.getPathIterator(null);
216
        }
217
    /* (non-Javadoc)
218
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
219
     */
220
    public boolean fastIntersects(double x, double y, double w, double h) {
221
        // TODO Auto-generated method stub
222
        return false;
223
    }
224
    /**
225
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#toWKB()
226
     */
227
    public byte[] toWKB() throws IOException {
228
        // TODO Auto-generated method stub
229
        return null;
230
    }
231
    /* (non-Javadoc)
232
     * @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)
233
     */
234
    public void drawInts(Graphics2D g, ViewPort vp, FSymbol symbol) {
235
        draw(g,vp, symbol);
236

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

    
267
                /**
268
                 * DOCUMENT ME!
269
                 *
270
                 * @param x DOCUMENT ME!
271
                 * @param y DOCUMENT ME!
272
                 *
273
                 * @return DOCUMENT ME!
274
                 */
275
                public void move(double x, double y) {
276
                        p.setLocation(p.getX()+x,p.getY()+y);
277
                }
278

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

    
286
        }
287
        public void move(double x, double y) {
288
                // TODO Auto-generated method stub
289

    
290
        }
291
        /**
292
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#rotate(double, double, double)
293
         */
294
        public void rotate(double r, double x, double y) {
295
        }
296
        /**
297
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#scale(java.awt.geom.Point2D, double, double)
298
         */
299
        public void scale(Point2D point, double x, double y) {
300
        }
301
}