Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FCircle2D.java @ 5880

History | View | Annotate | Download (6.41 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.geom.AffineTransform;
44
import java.awt.geom.Arc2D;
45
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47

    
48
import java.util.ArrayList;
49

    
50
import com.iver.cit.gvsig.fmap.edition.UtilFunctions;
51

    
52

    
53

    
54
/**
55
 * DOCUMENT ME!
56
 *
57
 * @author Vicente Caballero Navarro
58
 */
59
public class FCircle2D extends FPolyline2D {
60
        private Point2D center;
61
        private double radio;
62

    
63

    
64
        /**
65
         * DOCUMENT ME!
66
         *
67
         * @param gpx
68
         */
69
        public FCircle2D(GeneralPathX gpx,Point2D c,double r) {
70
                super(gpx);
71
                center=c;
72
                radio=r;
73
        }
74
        public Point2D getCenter(){
75
                return center;
76
        }
77
        public double getRadio(){
78
                return radio;
79
        }
80
        /* (non-Javadoc)
81
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
82
         */
83
        public FShape cloneFShape() {
84
                return new FCircle2D((GeneralPathX) gp.clone(),center,radio);
85
        }
86
        /**
87
         * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
88
         */
89
        public int getShapeType() {
90
                return FShape.CIRCLE;
91
        }
92
        /**
93
         * DOCUMENT ME!
94
         *
95
         * @param at DOCUMENT ME!
96
         */
97
        public void transform(AffineTransform at) {
98
                Point2D pdist=UtilFunctions.getPerpendicularPoint(new Point2D.Double(center.getX()+10,center.getY()),new Point2D.Double(center.getX()-10,center.getY()),center,radio);
99
                Point2D aux=new Point2D.Double();
100
                at.transform(center,aux);
101
                center=aux;
102
                Point2D aux3=new Point2D.Double();
103
                at.transform(pdist,aux3);
104
                radio=center.distance(aux3);
105
                gp.transform(at);
106
        }
107
        /**
108
         * DOCUMENT ME!
109
         *
110
         * @return DOCUMENT ME!
111
         */
112
        public Handler[] getStretchingHandlers() {
113
                ArrayList handlers = new ArrayList();
114
                Rectangle2D rect = this.getBounds2D();
115
                handlers.add(new CenterHandler(0, rect.getCenterX(), rect.getCenterY()));
116
                //handlers.add(new RadioHandler(1, rect.getX(), rect.getCenterY()));
117
                //handlers.add(new RadioHandler(2, rect.getMaxX(), rect.getCenterY()));
118
                //handlers.add(new RadioHandler(3, rect.getCenterX(), rect.getY()));
119
                //handlers.add(new RadioHandler(3, rect.getCenterX(), rect.getMaxY()));
120

    
121
                return (Handler[]) handlers.toArray(new Handler[0]);
122
        }
123
        public Handler[] getSelectHandlers() {
124
                ArrayList handlers = new ArrayList();
125
                handlers.add(new CenterSelHandler(0,center.getX(), center.getY()));
126
                handlers.add(new RadioSelHandler(1, center.getX()-radio, center.getY()));
127
                handlers.add(new RadioSelHandler(2, center.getX()+radio, center.getY()));
128
                handlers.add(new RadioSelHandler(3, center.getX(), center.getY()-radio));
129
                handlers.add(new RadioSelHandler(3, center.getX(), center.getY()+radio));
130

    
131
                return (Handler[]) handlers.toArray(new Handler[0]);
132
        }
133
        /**
134
         * DOCUMENT ME!
135
         *
136
         * @author Vicente Caballero Navarro
137
         */
138
        class CenterHandler extends AbstractHandler {
139
                /**
140
                 * Crea un nuevo PointHandler.
141
                 *
142
                 * @param i DOCUMENT ME!
143
                 * @param x DOCUMENT ME!
144
                 * @param y DOCUMENT ME!
145
                 */
146
                public CenterHandler(int i, double x, double y) {
147
                        point = new Point2D.Double(x, y);
148
                        index = i;
149
                }
150

    
151
                /**
152
                 * DOCUMENT ME!
153
                 *
154
                 * @param x DOCUMENT ME!
155
                 * @param y DOCUMENT ME!
156
                 *
157
                 * @return DOCUMENT ME!
158
                 */
159
                public void move(double x, double y) {
160
                        center=new Point2D.Double(center.getX()+x,center.getY()+y);
161
                        for (int i=0;i<gp.numCoords/2;i++){
162
                                gp.pointCoords[i*2]+=x;
163
                                gp.pointCoords[i*2+1]+=y;
164
                        }
165
                }
166

    
167
                /**
168
                 * @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
169
                 */
170
                public void set(double x, double y) {
171
                }
172

    
173
        }
174
        /**
175
         * DOCUMENT ME!
176
         *
177
         * @author Vicente Caballero Navarro
178
         */
179
        class CenterSelHandler extends AbstractHandler {
180
                /**
181
                 * Crea un nuevo PointHandler.
182
                 *
183
                 * @param i DOCUMENT ME!
184
                 * @param x DOCUMENT ME!
185
                 * @param y DOCUMENT ME!
186
                 */
187
                public CenterSelHandler(int i, double x, double y) {
188
                        point = new Point2D.Double(x, y);
189
                        index = i;
190
                }
191

    
192
                /**
193
                 * DOCUMENT ME!
194
                 *
195
                 * @param x DOCUMENT ME!
196
                 * @param y DOCUMENT ME!
197
                 *
198
                 * @return DOCUMENT ME!
199
                 */
200
                public void move(double x, double y) {
201
                        for (int i=0;i<gp.numCoords/2;i++){
202
                                gp.pointCoords[i*2]+=x;
203
                                gp.pointCoords[i*2+1]+=y;
204
                        }
205
                }
206

    
207
                /**
208
                 * @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
209
                 */
210
                public void set(double x, double y) {
211
                        center=new Point2D.Double(x,y);
212
                        Arc2D.Double arc = new Arc2D.Double(center.getX()-radio, center.getY() - radio,
213
                                        2 * radio, 2 * radio, 0, 360, Arc2D.OPEN);
214
                        gp=new GeneralPathX(arc);
215

    
216
                }
217
        }
218

    
219
        /**
220
         * DOCUMENT ME!
221
         *
222
         * @author Vicente Caballero Navarro
223
         */
224
        class RadioSelHandler extends AbstractHandler {
225

    
226
                /**
227
                 * Crea un nuevo PointHandler.
228
                 *
229
                 * @param i DOCUMENT ME!
230
                 * @param x DOCUMENT ME!
231
                 * @param y DOCUMENT ME!
232
                 */
233
                public RadioSelHandler(int i, double x, double y) {
234
                        point = new Point2D.Double(x, y);
235
                        index = i;
236
                }
237

    
238
                /**
239
                 * DOCUMENT ME!
240
                 *
241
                 * @param x DOCUMENT ME!
242
                 * @param y DOCUMENT ME!
243
                 *
244
                 * @return DOCUMENT ME!
245
                 */
246
                public void move(double x, double y) {
247

    
248
                }
249

    
250
                /**
251
                 * @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
252
                 */
253
                public void set(double x, double y) {
254
                        radio = center.distance(x,y);
255
                        Arc2D.Double arc = new Arc2D.Double(center.getX()-radio, center.getY() - radio,
256
                                        2 * radio, 2 * radio, 0, 360, Arc2D.OPEN);
257
                        gp=new GeneralPathX(arc);
258
                }
259
        }
260

    
261
        /* (non-Javadoc)
262
         * @see com.iver.cit.gvsig.fmap.core.FPolyline2D#intersects(java.awt.geom.Rectangle2D)
263
         */
264
        public boolean intersects(Rectangle2D r) {
265
                return gp.intersects(r);
266
        }
267

    
268
}