svn-gvsig-desktop / tags / Root_CqCMSGisPlanet / libraries / libCq CMS for java.old / src / org / cresques / geo / Graticule.java @ 1933
History | View | Annotate | Download (2.06 KB)
1 |
/*
|
---|---|
2 |
* Created on 26-abr-2004
|
3 |
*/
|
4 |
package org.cresques.geo; |
5 |
|
6 |
import java.awt.Color; |
7 |
import java.awt.Graphics2D; |
8 |
import java.awt.geom.GeneralPath; |
9 |
import java.awt.geom.Point2D; |
10 |
import java.util.Iterator; |
11 |
import java.util.Vector; |
12 |
|
13 |
class Text2D extends Point2D { |
14 |
private double x,y; |
15 |
private String txt; |
16 |
|
17 |
public Text2D(String txt, Point2D pt) { |
18 |
this.txt = txt;
|
19 |
setLocation(pt.getX(),pt.getY()); |
20 |
} |
21 |
|
22 |
public double getX() { return x; } |
23 |
public double getY() { return y; } |
24 |
public void setLocation(double x, double y) { |
25 |
this.x = x;
|
26 |
this.y = y;
|
27 |
} |
28 |
public void draw(Graphics2D g, ViewPortData vp) { |
29 |
g.drawString(txt, (int) x, (int) y) ; |
30 |
} |
31 |
} |
32 |
/**
|
33 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
34 |
*
|
35 |
* TODO A?adir soporte para hasta 3 niveles de grid (3 colores y 3 GeneralPath
|
36 |
*/
|
37 |
|
38 |
public class Graticule { |
39 |
static final Color color = new Color(128,128,128,192); |
40 |
Color pc = null; |
41 |
Color tColor = null; |
42 |
GeneralPath gp = null, gp1 = null; |
43 |
Vector vText = null; |
44 |
Projection proj; |
45 |
|
46 |
public Graticule(Projection proj) {
|
47 |
this.proj = proj;
|
48 |
gp = new GeneralPath(); |
49 |
gp1 = new GeneralPath(); |
50 |
vText = new Vector(); |
51 |
setColor(color); |
52 |
} |
53 |
|
54 |
public Color getColor() {return pc;} |
55 |
public void setColor(Color color) { |
56 |
pc = color; |
57 |
tColor = new Color(pc.getRed(), pc.getGreen(), pc.getBlue(), 255); |
58 |
} |
59 |
|
60 |
public void addLine(Point2D pt1, Point2D pt2) { |
61 |
gp.moveTo((float) pt1.getX(), (float) pt1.getY()); |
62 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
63 |
} |
64 |
public void addLine(Point2D pt1, Point2D pt2, int num) { |
65 |
if (num == 0) { |
66 |
gp.moveTo((float) pt1.getX(), (float) pt1.getY()); |
67 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
68 |
} else if (num == 1) { |
69 |
gp1.moveTo((float) pt1.getX(), (float) pt1.getY()); |
70 |
gp1.lineTo((float) pt2.getX(), (float) pt2.getY()); |
71 |
} |
72 |
} |
73 |
|
74 |
public void addText(String txt, Point2D pt) { |
75 |
vText.add(new Text2D(txt, pt));
|
76 |
} |
77 |
|
78 |
public void draw(Graphics2D g, ViewPortData vp) { |
79 |
g.setColor(pc); |
80 |
g.draw(gp); |
81 |
|
82 |
g.setColor(tColor); |
83 |
g.draw(gp1); |
84 |
Iterator iter = vText.iterator();
|
85 |
while (iter.hasNext())
|
86 |
((Text2D) iter.next()).draw(g, vp); |
87 |
} |
88 |
} |