Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libDXF / src / org / cresques / geo / Graticule.java @ 21930

History | View | Annotate | Download (3.42 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.geo;
25

    
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.geom.GeneralPath;
29
import java.awt.geom.Point2D;
30
import java.util.Iterator;
31
import java.util.Vector;
32

    
33
import org.gvsig.projection.geo.ViewPortData;
34

    
35

    
36
class Text2D extends Point2D {
37
    private double x;
38
    private double y;
39
    private String txt;
40

    
41
    public Text2D(String txt, Point2D pt) {
42
        this.txt = txt;
43
        setLocation(pt.getX(), pt.getY());
44
    }
45

    
46
    public double getX() {
47
        return x;
48
    }
49

    
50
    public double getY() {
51
        return y;
52
    }
53

    
54
    public void setLocation(double x, double y) {
55
        this.x = x;
56
        this.y = y;
57
    }
58

    
59
    public void draw(Graphics2D g, ViewPortData vp) {
60
        g.drawString(txt, (int) x, (int) y);
61
    }
62
}
63

    
64

    
65
/**
66
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
67
 *
68
 * TODO A?adir soporte para hasta 3 niveles de grid (3 colores y 3 GeneralPath
69
 */
70
public class Graticule {
71
    static final Color color = new Color(128, 128, 128, 192);
72
    Color pc = null;
73
    Color tColor = null;
74
    GeneralPath gp = null;
75
    GeneralPath gp1 = null;
76
    Vector vText = null;
77
    Projection proj;
78

    
79
    public Graticule(Projection proj) {
80
        this.proj = proj;
81
        gp = new GeneralPath();
82
        gp1 = new GeneralPath();
83
        vText = new Vector();
84
        setColor(color);
85
    }
86

    
87
    public Color getColor() {
88
        return pc;
89
    }
90

    
91
    public void setColor(Color color) {
92
        pc = color;
93
        tColor = new Color(pc.getRed(), pc.getGreen(), pc.getBlue(), 255);
94
    }
95

    
96
    public void addLine(Point2D pt1, Point2D pt2) {
97
        gp.moveTo((float) pt1.getX(), (float) pt1.getY());
98
        gp.lineTo((float) pt2.getX(), (float) pt2.getY());
99
    }
100

    
101
    public void addLine(Point2D pt1, Point2D pt2, int num) {
102
        if (num == 0) {
103
            gp.moveTo((float) pt1.getX(), (float) pt1.getY());
104
            gp.lineTo((float) pt2.getX(), (float) pt2.getY());
105
        } else if (num == 1) {
106
            gp1.moveTo((float) pt1.getX(), (float) pt1.getY());
107
            gp1.lineTo((float) pt2.getX(), (float) pt2.getY());
108
        }
109
    }
110

    
111
    public void addText(String txt, Point2D pt) {
112
        vText.add(new Text2D(txt, pt));
113
    }
114

    
115
    public void draw(Graphics2D g, ViewPortData vp) {
116
        g.setColor(pc);
117
        g.draw(gp);
118

    
119
        g.setColor(tColor);
120
        g.draw(gp1);
121

    
122
        Iterator iter = vText.iterator();
123

    
124
        while (iter.hasNext())
125
            ((Text2D) iter.next()).draw(g, vp);
126
    }
127
}