svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / geo / Graticule.java @ 2312
History | View | Annotate | Download (2.91 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 |
class Text2D extends Point2D { |
34 |
private double x,y; |
35 |
private String txt; |
36 |
|
37 |
public Text2D(String txt, Point2D pt) { |
38 |
this.txt = txt;
|
39 |
setLocation(pt.getX(),pt.getY()); |
40 |
} |
41 |
|
42 |
public double getX() { return x; } |
43 |
public double getY() { return y; } |
44 |
public void setLocation(double x, double y) { |
45 |
this.x = x;
|
46 |
this.y = y;
|
47 |
} |
48 |
public void draw(Graphics2D g, ViewPortData vp) { |
49 |
g.drawString(txt, (int) x, (int) y) ; |
50 |
} |
51 |
} |
52 |
/**
|
53 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
54 |
*
|
55 |
* TODO A?adir soporte para hasta 3 niveles de grid (3 colores y 3 GeneralPath
|
56 |
*/
|
57 |
|
58 |
public class Graticule { |
59 |
static final Color color = new Color(128,128,128,192); |
60 |
Color pc = null; |
61 |
Color tColor = null; |
62 |
GeneralPath gp = null, gp1 = null; |
63 |
Vector vText = null; |
64 |
Projection proj; |
65 |
|
66 |
public Graticule(Projection proj) {
|
67 |
this.proj = proj;
|
68 |
gp = new GeneralPath(); |
69 |
gp1 = new GeneralPath(); |
70 |
vText = new Vector(); |
71 |
setColor(color); |
72 |
} |
73 |
|
74 |
public Color getColor() {return pc;} |
75 |
public void setColor(Color color) { |
76 |
pc = color; |
77 |
tColor = new Color(pc.getRed(), pc.getGreen(), pc.getBlue(), 255); |
78 |
} |
79 |
|
80 |
public void addLine(Point2D pt1, Point2D pt2) { |
81 |
gp.moveTo((float) pt1.getX(), (float) pt1.getY()); |
82 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
83 |
} |
84 |
public void addLine(Point2D pt1, Point2D pt2, int num) { |
85 |
if (num == 0) { |
86 |
gp.moveTo((float) pt1.getX(), (float) pt1.getY()); |
87 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
88 |
} else if (num == 1) { |
89 |
gp1.moveTo((float) pt1.getX(), (float) pt1.getY()); |
90 |
gp1.lineTo((float) pt2.getX(), (float) pt2.getY()); |
91 |
} |
92 |
} |
93 |
|
94 |
public void addText(String txt, Point2D pt) { |
95 |
vText.add(new Text2D(txt, pt));
|
96 |
} |
97 |
|
98 |
public void draw(Graphics2D g, ViewPortData vp) { |
99 |
g.setColor(pc); |
100 |
g.draw(gp); |
101 |
|
102 |
g.setColor(tColor); |
103 |
g.draw(gp1); |
104 |
Iterator iter = vText.iterator();
|
105 |
while (iter.hasNext())
|
106 |
((Text2D) iter.next()).draw(g, vp); |
107 |
} |
108 |
} |