root / branches / Mobile_Compatible_Hito_1 / libFMap / src / es / prodevelop / gvsig / mobile / fmap / core / acetate / MapCursor.java @ 21606
History | View | Annotate | Download (3.36 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* http://www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*
|
43 |
* or
|
44 |
*
|
45 |
* Instituto de Rob?tica
|
46 |
* Apartado de correos 2085
|
47 |
* 46071 Valencia
|
48 |
* (Spain)
|
49 |
*
|
50 |
* +34 963 543 577
|
51 |
* jjordan@robotica.uv.es
|
52 |
* http://robotica.uv.es
|
53 |
*
|
54 |
*/
|
55 |
|
56 |
package es.prodevelop.gvsig.mobile.fmap.core.acetate; |
57 |
|
58 |
import java.awt.Component; |
59 |
import java.awt.Graphics; |
60 |
import java.awt.Graphics2D; |
61 |
import java.awt.Image; |
62 |
import java.awt.geom.AffineTransform; |
63 |
import java.awt.geom.Point2D; |
64 |
|
65 |
import org.apache.log4j.Logger; |
66 |
|
67 |
/**
|
68 |
*
|
69 |
* This class contains the GPS cursor used to indicate the position delivered by the
|
70 |
* GPS device.
|
71 |
*
|
72 |
*
|
73 |
* @author jcarras
|
74 |
*
|
75 |
*/
|
76 |
public class MapCursor extends Component implements IAcetateElement { |
77 |
|
78 |
private static Logger logger = Logger.getLogger(MapCursor.class); |
79 |
|
80 |
private boolean visible = false; |
81 |
private Image icon; |
82 |
private double rotationDegrees = 0; |
83 |
|
84 |
private Point2D geoPoint = new Point2D.Double(); |
85 |
private int radius_x = 0; |
86 |
private int radius_y = 0; |
87 |
|
88 |
/**
|
89 |
* Constructor
|
90 |
* @param i the icon image to be used. Preferable, a square image
|
91 |
* with odd size: w = h = 2n + 1 (n is a natural number).
|
92 |
*
|
93 |
*/
|
94 |
public MapCursor(Image i){ |
95 |
icon=i; |
96 |
|
97 |
radius_x = icon.getWidth(null) / 2; |
98 |
radius_y = icon.getHeight(null) / 2;; |
99 |
} |
100 |
|
101 |
public void paint(Graphics g) { |
102 |
if (icon != null && visible) { |
103 |
g.drawImage(icon, 0, 0, null); |
104 |
logger.debug("MapCursor Icon painted");
|
105 |
} |
106 |
} |
107 |
|
108 |
public void setXY(double x, double y) { |
109 |
geoPoint.setLocation(x, y); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* @return the icon image
|
114 |
*/
|
115 |
public Image getIcon() { |
116 |
return icon;
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* Sets the icon image.
|
121 |
*/
|
122 |
public void setIcon(Image i) { |
123 |
icon = i; |
124 |
radius_x = icon.getWidth(null) / 2; |
125 |
radius_y = icon.getHeight(null) / 2; |
126 |
} |
127 |
|
128 |
public double getRotation() { |
129 |
return rotationDegrees;
|
130 |
} |
131 |
|
132 |
public void setRotation(double r) { |
133 |
rotationDegrees = r; |
134 |
} |
135 |
|
136 |
public void draw(Graphics2D g, AffineTransform at) { |
137 |
|
138 |
Point2D aux = new Point2D.Double(0, 0); |
139 |
at.transform(geoPoint, aux); |
140 |
int screenx = (int) Math.round(aux.getX()) - radius_x; |
141 |
int screeny = (int) Math.round(aux.getY()) - radius_y; |
142 |
g.drawImage(icon, screenx, screeny, null);
|
143 |
} |
144 |
|
145 |
} |