svn-gvsig-desktop / trunk / libraries / lib3DMap / src / org / gvsig / gvsig3d / gui / Hud.java @ 26259
History | View | Annotate | Download (7.49 KB)
1 |
package org.gvsig.gvsig3d.gui; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.event.MouseEvent; |
5 |
import java.awt.event.MouseMotionListener; |
6 |
|
7 |
import org.apache.log4j.Logger; |
8 |
import org.gvsig.gui.beans.Messages; |
9 |
import org.gvsig.osgvp.Group; |
10 |
import org.gvsig.osgvp.Node; |
11 |
import org.gvsig.osgvp.UpdateNodeListener; |
12 |
import org.gvsig.osgvp.Vec3; |
13 |
import org.gvsig.osgvp.Vec4; |
14 |
import org.gvsig.osgvp.exceptions.InvalidValueException; |
15 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
16 |
import org.gvsig.osgvp.features.Text; |
17 |
import org.gvsig.osgvp.planets.Planet; |
18 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
19 |
|
20 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
21 |
import com.iver.andami.PluginServices; |
22 |
|
23 |
/**
|
24 |
* Use this class for draw items in HUD
|
25 |
*
|
26 |
* @author julio
|
27 |
*
|
28 |
*/
|
29 |
public class Hud extends Group implements MouseMotionListener { |
30 |
|
31 |
private IViewerContainer m_canvas3d = null; |
32 |
|
33 |
private Planet m_planet = null; |
34 |
|
35 |
private String lonText; |
36 |
|
37 |
private String latText; |
38 |
|
39 |
private String lon; |
40 |
|
41 |
private String lat; |
42 |
|
43 |
private Text textoHud;
|
44 |
|
45 |
private static String north; |
46 |
|
47 |
private static String south; |
48 |
|
49 |
private static String east; |
50 |
|
51 |
private static String west; |
52 |
|
53 |
private static Compass compass; |
54 |
|
55 |
private static Logger logger = Logger.getLogger(Hud.class.getName()); |
56 |
|
57 |
static {
|
58 |
north = Messages.getText("North");
|
59 |
south = Messages.getText("South");
|
60 |
east = Messages.getText("East");
|
61 |
west = Messages.getText("West");
|
62 |
|
63 |
} |
64 |
|
65 |
private int projectionType; |
66 |
|
67 |
/**
|
68 |
* Constructor
|
69 |
*
|
70 |
* @param m_canvas3d
|
71 |
* Viewer instance
|
72 |
* @param m_planet
|
73 |
* Planet instance
|
74 |
*/
|
75 |
public Hud(IViewerContainer m_canvas3d, Planet m_planet) {
|
76 |
super();
|
77 |
this.m_canvas3d = m_canvas3d;
|
78 |
this.m_planet = m_planet;
|
79 |
this.projectionType = m_planet.getCoordinateSystemType();
|
80 |
// Inicialize object
|
81 |
init(); |
82 |
} |
83 |
|
84 |
/**
|
85 |
* Inicilize the object params
|
86 |
*/
|
87 |
private void init() { |
88 |
|
89 |
try {
|
90 |
textoHud = new Text();
|
91 |
compass = new Compass(m_planet);
|
92 |
if(projectionType == Planet.CoordinateSystemType.GEOCENTRIC){
|
93 |
compass.setPanetType(Compass.Mode.SPHERIC); |
94 |
} |
95 |
else compass.setPanetType(Compass.Mode.FLAT);
|
96 |
} catch (NodeException e1) {
|
97 |
// TODO Auto-generated catch block
|
98 |
e1.printStackTrace(); |
99 |
} |
100 |
if (getProjectionType() == Planet.CoordinateSystemType.GEOCENTRIC) {
|
101 |
// Setting up longitud and latitud string
|
102 |
lonText = PluginServices.getText(this, "Ext3D.longitude"); |
103 |
latText = PluginServices.getText(this, "Ext3D.latitude"); |
104 |
} else {
|
105 |
lonText = PluginServices.getText(this, "X") + " "; |
106 |
; |
107 |
latText = PluginServices.getText(this, "Y") + " "; |
108 |
; |
109 |
} |
110 |
|
111 |
// Adding text to group
|
112 |
try {
|
113 |
this.addChild(textoHud);
|
114 |
this.addChild(compass);
|
115 |
} catch (NodeException e) {
|
116 |
logger.error("Comand:" + "Error al a�adir nodo al hud.",e); |
117 |
} |
118 |
|
119 |
//Setting up the lighting mode to disable (rgaitan)
|
120 |
try {
|
121 |
getOrCreateStateSet().setLightingMode(Node.Mode.OFF | Node.Mode.PROTECTED); |
122 |
} catch (InvalidValueException e) {
|
123 |
logger.error("Comand:" + "Error al inicializar las luces.",e); |
124 |
}; |
125 |
|
126 |
// Seting up text
|
127 |
textoHud.setCharacterSize(14);
|
128 |
textoHud.setColor(new Vec4(1.0f, 1.0f, 1.0f, 1.0f)); |
129 |
textoHud.setBackdropColor(0.0f, 0.0f, 1.0f, 1.0f); |
130 |
|
131 |
if (ResourcesFactory.exitsResouce("arial.ttf")) |
132 |
textoHud.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
|
133 |
else {
|
134 |
// TODO: This freeze the execution.. disable when working.
|
135 |
textoHud.setFont("arial.ttf");
|
136 |
} |
137 |
|
138 |
textoHud.setPosition(10, 10, 0); |
139 |
textoHud.setBackdropType(Text.BackdropType.OUTLINE); |
140 |
textoHud.setAlignment(Text.AlignmentType.LEFT_CENTER); |
141 |
|
142 |
compass.setUpdateListener(new UpdateNodeListener(){
|
143 |
|
144 |
public void update(Node arg0) { |
145 |
compass.update(m_canvas3d.getOSGViewer().getCamera()); |
146 |
|
147 |
}}); |
148 |
|
149 |
//disabling compass.
|
150 |
compass.setEnabledNode(false);
|
151 |
|
152 |
// Add mouse listener to viewer
|
153 |
((Component) m_canvas3d).addMouseMotionListener(this); |
154 |
|
155 |
// Update Hud
|
156 |
updateHud(); |
157 |
} |
158 |
|
159 |
/**
|
160 |
* This method updates information of the HUD
|
161 |
*/
|
162 |
public void updateHud() { |
163 |
|
164 |
if (m_planet.getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) {
|
165 |
// Getting longitud and latitud informacion from planet
|
166 |
lon = Hud.getSexagesinal(m_planet.getLongitude(), true);
|
167 |
lat = Hud.getSexagesinal(m_planet.getLatitude(), false);
|
168 |
|
169 |
|
170 |
// Updating text information
|
171 |
textoHud.setText(lonText + " " + lon + " " + latText + " " + lat); |
172 |
} else {
|
173 |
// Getting longitud and latitud informacion from planet
|
174 |
lon = Double.toString(m_planet.getLongitude());
|
175 |
lat = Double.toString(m_planet.getLatitude());
|
176 |
|
177 |
// Updating text information
|
178 |
textoHud.setText(lonText + " " + lon + " " + latText + " " + lat); |
179 |
} |
180 |
|
181 |
compass.setScale(new Vec3(75,75,75)); |
182 |
compass.setPosition(new Vec3(m_canvas3d.getWidth()-70,m_canvas3d.getHeight()-70,0)); |
183 |
// Repainting view
|
184 |
if (m_canvas3d != null) |
185 |
m_canvas3d.repaint(); |
186 |
} |
187 |
|
188 |
public String getLat() { |
189 |
return lat;
|
190 |
} |
191 |
|
192 |
public void setLat(String lat) { |
193 |
this.lat = lat;
|
194 |
} |
195 |
|
196 |
public String getLatText() { |
197 |
return latText;
|
198 |
} |
199 |
|
200 |
public void setLatText(String latText) { |
201 |
this.latText = latText;
|
202 |
} |
203 |
|
204 |
public String getLon() { |
205 |
return lon;
|
206 |
} |
207 |
|
208 |
public void setLon(String lon) { |
209 |
this.lon = lon;
|
210 |
} |
211 |
|
212 |
public String getLonText() { |
213 |
return lonText;
|
214 |
} |
215 |
|
216 |
public void setLonText(String lonText) { |
217 |
this.lonText = lonText;
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* To transform longitud and latitud to sexagesinal format degress minuts
|
222 |
* seconds
|
223 |
*
|
224 |
* @param num
|
225 |
* number to transform
|
226 |
* @param lat
|
227 |
* is tatitud or not
|
228 |
* @return sexagesinal format
|
229 |
*/
|
230 |
public static String getSexagesinal(double num, boolean lat) { |
231 |
|
232 |
String result = ""; |
233 |
String ori = ""; |
234 |
|
235 |
// Setting up North or South and East or West
|
236 |
if (num < 0) { |
237 |
num = num * (-1);
|
238 |
if (lat) {
|
239 |
ori = east;//south;// Messages.getText("South");
|
240 |
} else {
|
241 |
ori = north;//north;// Messages.getText("North");
|
242 |
} |
243 |
} else {
|
244 |
if (lat) {
|
245 |
ori = west;//west;// Messages.getText("West");
|
246 |
} else {
|
247 |
ori = south;//east;// Messages.getText("East");
|
248 |
} |
249 |
} |
250 |
|
251 |
// transform degrees in sexagesinal format
|
252 |
int grados = (int) num; |
253 |
double resG = num - grados;
|
254 |
int minutos = (int) (resG * 60); |
255 |
double minutosD = (resG * 60); |
256 |
double resM = minutosD - minutos;
|
257 |
int segundos = (int) (resM * 60); |
258 |
String cadG = ""; |
259 |
if (grados < 10) |
260 |
cadG = cadG + "0";
|
261 |
cadG = cadG + grados; |
262 |
|
263 |
String cadM = ""; |
264 |
if (minutos < 10) |
265 |
cadM = cadM + "0";
|
266 |
cadM = cadM + minutos; |
267 |
|
268 |
String cadS = ""; |
269 |
if (segundos < 10) |
270 |
cadS = cadS + "0";
|
271 |
cadS = cadS + segundos; |
272 |
|
273 |
// Building result string
|
274 |
result = cadG + " " + cadM + " " + cadS + " " + ori; |
275 |
|
276 |
return result;
|
277 |
} |
278 |
|
279 |
// MOUSE MOTION EVENTS
|
280 |
|
281 |
public void mouseDragged(MouseEvent e) { |
282 |
// Updating Hud information+
|
283 |
// If not update the hud information when mouses dragged the hud don�t change
|
284 |
updateHud(); |
285 |
|
286 |
// System.out.println("***************************************");
|
287 |
// System.out.println("Longitud : " + m_planet.getLongitude());
|
288 |
// System.out.println("Latitud : " + m_planet.getLatitude());
|
289 |
// System.out.println("***************************************");
|
290 |
|
291 |
} |
292 |
|
293 |
public void mouseMoved(MouseEvent e) { |
294 |
// TODO Auto-generated method stub
|
295 |
updateHud(); |
296 |
} |
297 |
|
298 |
public int getProjectionType() { |
299 |
return projectionType;
|
300 |
} |
301 |
|
302 |
public void setProjectionType(int projectionType) { |
303 |
this.projectionType = projectionType;
|
304 |
} |
305 |
|
306 |
} |