root / import / ext3D / trunk / ext3D / src / com / iver / ai2 / gvsig3d / gui / Hud.java @ 15090
History | View | Annotate | Download (4.61 KB)
1 |
package com.iver.ai2.gvsig3d.gui; |
---|---|
2 |
|
3 |
import java.awt.event.MouseEvent; |
4 |
import java.awt.event.MouseMotionListener; |
5 |
|
6 |
import es.upv.ai2.libjosg.Group; |
7 |
import es.upv.ai2.libjosg.Vec4; |
8 |
import es.upv.ai2.libjosg.features.Text; |
9 |
import es.upv.ai2.libjosg.planets.Planet; |
10 |
import es.upv.ai2.libjosg.viewer.Viewer; |
11 |
|
12 |
/**
|
13 |
* Use this class for draw items in HUD
|
14 |
*
|
15 |
* @author julio
|
16 |
*
|
17 |
*/
|
18 |
public class Hud extends Group implements MouseMotionListener { |
19 |
|
20 |
private Viewer m_canvas3d = null; |
21 |
|
22 |
private Planet m_planet = null; |
23 |
|
24 |
private String lonText; |
25 |
|
26 |
private String latText; |
27 |
|
28 |
private String lon; |
29 |
|
30 |
private String lat; |
31 |
|
32 |
private Text textoHud = new Text(); |
33 |
|
34 |
/**
|
35 |
* Constructor
|
36 |
*
|
37 |
* @param m_canvas3d
|
38 |
* Viewer instance
|
39 |
* @param m_planet
|
40 |
* Planet instance
|
41 |
*/
|
42 |
public Hud(Viewer m_canvas3d, Planet m_planet) {
|
43 |
super();
|
44 |
this.m_canvas3d = m_canvas3d;
|
45 |
this.m_planet = m_planet;
|
46 |
// Inicialize object
|
47 |
init(); |
48 |
} |
49 |
|
50 |
/**
|
51 |
* Inicilize the object params
|
52 |
*/
|
53 |
private void init() { |
54 |
|
55 |
// Setting up longitud and latitud string
|
56 |
lonText = "LONG";
|
57 |
latText = "LAT";
|
58 |
|
59 |
// Adding text to group
|
60 |
this.addChild(textoHud);
|
61 |
|
62 |
// Seting up text
|
63 |
textoHud.setCharacterSize(14);
|
64 |
textoHud.setColor(new Vec4(1.0f, 1.0f, 1.0f, 1.0f)); |
65 |
textoHud.setBackdropColor(0.0f, 0.0f, 1.0f, 1.0f); |
66 |
String textPath = System.getProperty("user.dir") |
67 |
+ "/gvSIG/extensiones/com.iver.ai2.gvsig3d/resources/" + "arial.ttf"; |
68 |
textoHud.setFont(textPath); |
69 |
textoHud.setPosition(10, 10, 0); |
70 |
textoHud.setBackdropType(Text.BackdropType.OUTLINE); |
71 |
textoHud.setAlignment(Text.AlignmentType.LEFT_CENTER); |
72 |
|
73 |
// Add mouse listener to viewer
|
74 |
m_canvas3d.addMouseMotionListener(this);
|
75 |
|
76 |
// Update Hud
|
77 |
updateHud(); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* This method updates information of the HUD
|
82 |
*/
|
83 |
public void updateHud() { |
84 |
|
85 |
if (m_planet.getType() == Planet.PlanetType.SPHERICAL_MODE) {
|
86 |
// Getting longitud and latitud informacion from planet
|
87 |
lon = Hud.getSexagesinal(m_planet.getLongitude(), true);
|
88 |
lat = Hud.getSexagesinal(m_planet.getLatitude(), false);
|
89 |
|
90 |
// Updating text information
|
91 |
textoHud.setText(lonText + " " + lon + " " + latText + " " + lat); |
92 |
} else {
|
93 |
// Getting longitud and latitud informacion from planet
|
94 |
lon = Double.toString(m_planet.getLongitude());
|
95 |
lat = Double.toString(m_planet.getLatitude());
|
96 |
|
97 |
// Updating text information
|
98 |
textoHud.setText(lonText + " " + lon + " " + latText + " " + lat); |
99 |
} |
100 |
} |
101 |
|
102 |
public String getLat() { |
103 |
return lat;
|
104 |
} |
105 |
|
106 |
public void setLat(String lat) { |
107 |
this.lat = lat;
|
108 |
} |
109 |
|
110 |
public String getLatText() { |
111 |
return latText;
|
112 |
} |
113 |
|
114 |
public void setLatText(String latText) { |
115 |
this.latText = latText;
|
116 |
} |
117 |
|
118 |
public String getLon() { |
119 |
return lon;
|
120 |
} |
121 |
|
122 |
public void setLon(String lon) { |
123 |
this.lon = lon;
|
124 |
} |
125 |
|
126 |
public String getLonText() { |
127 |
return lonText;
|
128 |
} |
129 |
|
130 |
public void setLonText(String lonText) { |
131 |
this.lonText = lonText;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* To transform longitud and latitud to sexagesinal format degress minuts
|
136 |
* seconds
|
137 |
*
|
138 |
* @param num
|
139 |
* number to transform
|
140 |
* @param lat
|
141 |
* is tatitud or not
|
142 |
* @return sexagesinal format
|
143 |
*/
|
144 |
public static String getSexagesinal(double num, boolean lat) { |
145 |
|
146 |
String result = ""; |
147 |
String ori = ""; |
148 |
// Setting up North or South and East or West
|
149 |
if (num < 0) { |
150 |
num = num * (-1);
|
151 |
if (lat) {
|
152 |
ori = "S";
|
153 |
} else {
|
154 |
ori = "O";
|
155 |
} |
156 |
} else {
|
157 |
if (lat) {
|
158 |
ori = "N";
|
159 |
} else {
|
160 |
ori = "E";
|
161 |
} |
162 |
} |
163 |
|
164 |
// transform degrees in sexagesinal format
|
165 |
int grados = (int) num; |
166 |
double resG = num - grados;
|
167 |
int minutos = (int) (resG * 60); |
168 |
double minutosD = (resG * 60); |
169 |
double resM = minutosD - minutos;
|
170 |
int segundos = (int) (resM * 60); |
171 |
String cadG = ""; |
172 |
if (grados < 10) |
173 |
cadG = cadG + "0";
|
174 |
cadG = cadG + grados; |
175 |
|
176 |
String cadM = ""; |
177 |
if (minutos < 10) |
178 |
cadM = cadM + "0";
|
179 |
cadM = cadM + minutos; |
180 |
|
181 |
String cadS = ""; |
182 |
if (segundos < 10) |
183 |
cadS = cadS + "0";
|
184 |
cadS = cadS + segundos; |
185 |
|
186 |
// Building result string
|
187 |
result = cadG + " " + cadM + " " + cadS + " " + ori; |
188 |
|
189 |
return result;
|
190 |
} |
191 |
|
192 |
// MOUSE MOTION EVENTS
|
193 |
|
194 |
public void mouseDragged(MouseEvent e) { |
195 |
// Updating Hud information
|
196 |
updateHud(); |
197 |
|
198 |
// System.out.println("***************************************");
|
199 |
// System.out.println("Longitud : " + m_planet.getLongitude());
|
200 |
// System.out.println("Latitud : " + m_planet.getLatitude());
|
201 |
// System.out.println("***************************************");
|
202 |
|
203 |
} |
204 |
|
205 |
public void mouseMoved(MouseEvent e) { |
206 |
// TODO Auto-generated method stub
|
207 |
|
208 |
} |
209 |
|
210 |
} |