Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / geo / Graticule.java @ 8026

History | View | Annotate | Download (3.25 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

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

    
34

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

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

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

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

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

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

    
63

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

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

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

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

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

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

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

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

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

    
121
        Iterator iter = vText.iterator();
122

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