Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / impl / Curve2D.java @ 27049

History | View | Annotate | Download (4.5 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 org.gvsig.fmap.geom.primitive.impl;
42

    
43
import java.awt.geom.Line2D;
44
import java.awt.geom.Point2D;
45

    
46
import org.cresques.cts.IProjection;
47
import org.gvsig.fmap.geom.GeometryLocator;
48
import org.gvsig.fmap.geom.primitive.Curve;
49
import org.gvsig.fmap.geom.primitive.FShape;
50
import org.gvsig.fmap.geom.primitive.GeneralPathX;
51
import org.gvsig.fmap.geom.primitive.Point;
52
import org.gvsig.fmap.geom.type.GeometryType;
53
import org.gvsig.fmap.geom.util.UtilFunctions;
54

    
55
/**
56
 * DOCUMENT ME!
57
 *
58
 * @author Fernando Gonz?lez Cort?s
59
 */
60
public class Curve2D extends DefaultCurve implements Curve {
61
        private static final long serialVersionUID = 8161943328767877860L;
62
        
63
        private static GeometryType geomType = GeometryLocator.getGeometryManager()
64
        .registerGeometryType(Curve2D.class, null, TYPES.CURVE, SUBTYPES.GEOM2D);
65

    
66
        /**
67
         * Constructor without arguments. It is necessary to create
68
         * geometries using the {@link GeometryType}{@link #create()}
69
         * method
70
         */
71
        public Curve2D() {
72
                super();                
73
        }
74
        
75
        public Curve2D(String id, IProjection projection, GeneralPathX gpx) {
76
                super(id, projection, gpx);
77
                gp=gpx;
78
        }
79

    
80
        public Curve2D(GeneralPathX gpx) {
81
                this(null, null, gpx);
82
                gp=gpx;
83
        }
84

    
85
        /*
86
         * (non-Javadoc)
87
         * @see org.gvsig.fmap.geom.Geometry#getShapeType()
88
         */
89
        public int getShapeType() {
90
                return FShape.LINE;
91
        }
92

    
93
        /*
94
         * (non-Javadoc)
95
         * @see org.gvsig.fmap.geom.primitive.FShape#cloneFShape()
96
         */
97
        public FShape cloneFShape() {
98
                return new Curve2D(id, projection, (GeneralPathX) gp.clone());
99
        }
100

    
101
        /*
102
         * (non-Javadoc)
103
         * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
104
         */
105
        public GeometryType getGeometryType() {
106
                return geomType;
107
        }
108

    
109
        /*
110
         * (non-Javadoc)
111
         * @see org.gvsig.fmap.geom.Geometry#getType()
112
         */
113
        public int getType() {
114
                return geomType.getType();
115
        }
116

    
117
        /*
118
         * (non-Javadoc)
119
         * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
120
         */
121
        public GeneralPathX getGeneralPath() {
122
                return gp;
123
        }
124

    
125
        /*
126
         * (non-Javadoc)
127
         * @see org.gvsig.fmap.geom.primitive.impl.DefaultCurve#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
128
         */
129
        public void setGeneralPath(GeneralPathX generalPathX) {
130
                gp = generalPathX;                
131
        }
132

    
133
        /* (non-Javadoc)
134
         * @see org.gvsig.fmap.geom.primitive.Curve#setCoordinateAt(int, int, double)
135
         */
136
        public void setCoordinateAt(int index, int dimension, double value) {
137
                throw new UnsupportedOperationException("Use setGeneralPathX");
138
        }
139

    
140
        /* (non-Javadoc)
141
         * @see org.gvsig.fmap.geom.primitive.Curve#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
142
         */
143
        public void setPoints(Point startPoint, Point endPoint) {
144
                Point2D _startPoint = new java.awt.geom.Point2D.Double(startPoint.getCoordinateAt(0), startPoint.getCoordinateAt(1));                
145
                Point2D _endPoint = new java.awt.geom.Point2D.Double(endPoint.getCoordinateAt(0), endPoint.getCoordinateAt(1));
146
                setPoints(_startPoint, _endPoint);
147
        }
148

    
149
        /* (non-Javadoc)
150
         * @see org.gvsig.fmap.geom.primitive.Curve#setPoints(java.awt.geom.Point2D, java.awt.geom.Point2D)
151
         */
152
        private void setPoints(Point2D startPoint, Point2D endPoint) {
153
                Line2D line = UtilFunctions.createLine(startPoint, endPoint);
154
                setGeneralPath(new GeneralPathX(line));
155
        }
156

    
157
        /* (non-Javadoc)
158
         * @see org.gvsig.fmap.geom.primitive.Curve#addPoint(org.gvsig.fmap.geom.primitive.Point)
159
         */
160
        public void addVertex(Point point) {
161
                gp.lineTo(point.getX(), point.getY());                
162
        }
163
}