svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.projection / org.gvsig.projection.cresques / org.gvsig.projection.cresques.impl / src / main / java / org / cresques / impl / geo / Graticule.java @ 40559
History | View | Annotate | Download (3.35 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.cresques.impl.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 |
import org.cresques.geo.ViewPortData; |
35 |
|
36 |
|
37 |
class Text2D extends Point2D { |
38 |
private double x; |
39 |
private double y; |
40 |
private String txt; |
41 |
|
42 |
public Text2D(String txt, Point2D pt) { |
43 |
this.txt = txt;
|
44 |
setLocation(pt.getX(), pt.getY()); |
45 |
} |
46 |
|
47 |
public double getX() { |
48 |
return x;
|
49 |
} |
50 |
|
51 |
public double getY() { |
52 |
return y;
|
53 |
} |
54 |
|
55 |
public void setLocation(double x, double y) { |
56 |
this.x = x;
|
57 |
this.y = y;
|
58 |
} |
59 |
|
60 |
public void draw(Graphics2D g, ViewPortData vp) { |
61 |
g.drawString(txt, (int) x, (int) y); |
62 |
} |
63 |
} |
64 |
|
65 |
|
66 |
/**
|
67 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
68 |
*
|
69 |
* TODO A?adir soporte para hasta 3 niveles de grid (3 colores y 3 GeneralPath
|
70 |
*/
|
71 |
public class Graticule { |
72 |
static final Color color = new Color(128, 128, 128, 192); |
73 |
Color pc = null; |
74 |
Color tColor = null; |
75 |
GeneralPath gp = null; |
76 |
GeneralPath gp1 = null; |
77 |
Vector vText = null; |
78 |
Projection proj; |
79 |
|
80 |
public Graticule(Projection proj) {
|
81 |
this.proj = proj;
|
82 |
gp = new GeneralPath(); |
83 |
gp1 = new GeneralPath(); |
84 |
vText = new Vector(); |
85 |
setColor(color); |
86 |
} |
87 |
|
88 |
public Color getColor() { |
89 |
return pc;
|
90 |
} |
91 |
|
92 |
public void setColor(Color color) { |
93 |
pc = color; |
94 |
tColor = new Color(pc.getRed(), pc.getGreen(), pc.getBlue(), 255); |
95 |
} |
96 |
|
97 |
public void addLine(Point2D pt1, Point2D pt2) { |
98 |
gp.moveTo((float) pt1.getX(), (float) pt1.getY()); |
99 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
100 |
} |
101 |
|
102 |
public void addLine(Point2D pt1, Point2D pt2, int num) { |
103 |
if (num == 0) { |
104 |
gp.moveTo((float) pt1.getX(), (float) pt1.getY()); |
105 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
106 |
} else if (num == 1) { |
107 |
gp1.moveTo((float) pt1.getX(), (float) pt1.getY()); |
108 |
gp1.lineTo((float) pt2.getX(), (float) pt2.getY()); |
109 |
} |
110 |
} |
111 |
|
112 |
public void addText(String txt, Point2D pt) { |
113 |
vText.add(new Text2D(txt, pt));
|
114 |
} |
115 |
|
116 |
public void draw(Graphics2D g, ViewPortData vp) { |
117 |
g.setColor(pc); |
118 |
g.draw(gp); |
119 |
|
120 |
g.setColor(tColor); |
121 |
g.draw(gp1); |
122 |
|
123 |
Iterator iter = vText.iterator();
|
124 |
|
125 |
while (iter.hasNext())
|
126 |
((Text2D) iter.next()).draw(g, vp); |
127 |
} |
128 |
} |