Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / gml / LineString.java @ 2312

History | View | Annotate | Download (2.94 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 * 
22
 * cresques@gmail.com
23
 */
24
package org.cresques.px.gml;
25

    
26
import java.awt.Color;
27
import java.awt.geom.Point2D;
28

    
29
import java.awt.Graphics2D;
30
import java.awt.geom.AffineTransform;
31

    
32
import java.util.Iterator;
33
import java.util.Vector;
34

    
35
import java.awt.geom.Line2D;
36

    
37
import org.cresques.cts.ICoordTrans;
38
import org.cresques.cts.IProjection;
39
import org.cresques.geo.ViewPortData;
40
import org.cresques.px.Extent;
41

    
42
/**
43
 * Geometria de tipo Polygon
44
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
45
 */
46

    
47
public class LineString extends Geometry {
48
        public static int pointNr = 0;
49

    
50
        public LineString() {
51
                super();
52
        }
53
        
54
        public void add(Point2D pt) {
55
                pointNr++;
56
                super.add(pt);
57
        }
58
        public void remove(int i) {
59
                getData().remove(i);
60
        }
61
        
62
        private Color fColor = null; //new Color(255,222,165,64);
63
        private Color color = new Color(255,0,0); //Color(255,214,132,255);
64
        
65
        public Color c() {return color;}
66
        public Color c(Color color) {this.color = color; return color;}
67

    
68
        public Color fillColor() {return fColor;}
69
        public Color fillColor(Color c) {fColor = c; return fColor;}
70

    
71
        public IProjection getProjection() { return proj; }
72
        public void setProjection(IProjection p) { proj = p; }
73
        public void reProject(ICoordTrans rp) {
74
                Vector saveLine = data;
75

    
76
                data = new Vector();
77
                extent = new Extent();
78
                Point2D ptDest = null;
79
                for (int i=0; i<saveLine.size(); i++) {
80
                        ptDest = rp.getPDest().createPoint(0.0,0.0);
81
                        ptDest = rp.convert((Point2D) saveLine.get(i), ptDest);
82
                        data.add(ptDest);
83
                        extent.add(ptDest);
84
                }
85
                setProjection(rp.getPDest());
86
        }
87
        
88
        public void draw(Graphics2D g, ViewPortData vp) {
89
                AffineTransform msave=g.getTransform();
90
                g.setTransform(vp.mat);
91
                // relleno el marco si es preciso
92
                if (fillColor() != null) {
93
                        g.setColor(fillColor());
94
//                        outPol.fill(g);
95
                }
96
                // pinto el marco si es preciso
97
                g.setColor(c());
98
                drawLine2D(g, data);
99
                g.setTransform(msave);
100
        }
101
        
102
        void drawLine2D(Graphics2D g, Vector v) {
103
                Point2D pt=null, pt1=null;
104
                Iterator iter = v.iterator();
105
                while (iter.hasNext()) {
106
                        pt1 = (Point2D) iter.next();
107
                        if (pt != null)
108
                                g.draw(new Line2D.Double(pt,pt1));
109
                        pt = pt1;
110
                }
111
        }
112
}
113

    
114