Statistics
| Revision:

svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / lib3DMap / src / com / iver / ai2 / gvsig3d / gui / Hud.java @ 15490

History | View | Annotate | Download (6.12 KB)

1
package com.iver.ai2.gvsig3d.gui;
2

    
3
import java.awt.Component;
4
import java.awt.event.MouseEvent;
5
import java.awt.event.MouseMotionListener;
6

    
7
import org.gvsig.gui.beans.Messages;
8

    
9
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
10
import com.iver.andami.PluginServices;
11

    
12
import es.upv.ai2.libjosg.Group;
13
import es.upv.ai2.libjosg.Vec4;
14
import es.upv.ai2.libjosg.features.Text;
15
import es.upv.ai2.libjosg.planets.Planet;
16
import es.upv.ai2.libjosg.planets.PlanetViewer;
17
import es.upv.ai2.libjosg.planets.Planet.PlanetType;
18
import es.upv.ai2.libjosg.viewer.IViewerContainer;
19

    
20
/**
21
 * Use this class for draw items in HUD
22
 * 
23
 * @author julio
24
 * 
25
 */
26
public class Hud extends Group implements MouseMotionListener {
27

    
28
        private IViewerContainer m_canvas3d = null;
29
        
30
        private Planet m_planet = null;
31

    
32
        private String lonText;
33

    
34
        private String latText;
35

    
36
        private String lon;
37

    
38
        private String lat;
39

    
40
        private Text textoHud = new Text();
41

    
42
        private static String north;
43

    
44
        private static String south;
45

    
46
        private static String east;
47

    
48
        private static String west;
49

    
50
        static {
51
                north = Messages.getText("North");
52
                south = Messages.getText("South");
53
                east = Messages.getText("East");
54
                west = Messages.getText("West");
55

    
56
        }
57

    
58
        private int projectionType;
59

    
60
        /**
61
         * Constructor
62
         * 
63
         * @param m_canvas3d
64
         *            Viewer instance
65
         * @param m_planet
66
         *            Planet instance
67
         */
68
        public Hud(IViewerContainer m_canvas3d, Planet m_planet) {
69
                super();
70
                this.m_canvas3d = m_canvas3d;
71
                this.m_planet = m_planet;
72
                this.projectionType = m_planet.getType();
73
                // Inicialize object
74
                init();
75
        }
76

    
77
        /**
78
         * Inicilize the object params
79
         */
80
        private void init() {
81

    
82
                if (getProjectionType() == PlanetType.GEOCENTRIC) {
83
                        // Setting up longitud and latitud string
84
                        lonText = PluginServices.getText(this, "Ext3D.longitude");
85
                        latText = PluginServices.getText(this, "Ext3D.latitude");
86
                } else {
87
                        lonText = PluginServices.getText(this, "X") + " ";
88
                        ;
89
                        latText = PluginServices.getText(this, "Y") + " ";
90
                        ;
91
                }
92

    
93
                // Adding text to group
94
                this.addChild(textoHud);
95

    
96
                // Seting up text
97
                textoHud.setCharacterSize(14);
98
                textoHud.setColor(new Vec4(1.0f, 1.0f, 1.0f, 1.0f));
99
                textoHud.setBackdropColor(0.0f, 0.0f, 1.0f, 1.0f);
100

    
101
                if (ResourcesFactory.exitsResouce("arial.ttf"))
102
                        textoHud.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
103
                else {
104
                        // TODO: This freeze the execution.. disable when working. 
105
                        //textoHud.setFont("arial.ttf");
106
                }
107

    
108
                textoHud.setPosition(10, 10, 0);
109
                textoHud.setBackdropType(Text.BackdropType.OUTLINE);
110
                textoHud.setAlignment(Text.AlignmentType.LEFT_CENTER);
111

    
112
                // Add mouse listener to viewer
113
                ((Component) m_canvas3d).addMouseMotionListener(this);
114

    
115
                // Update Hud
116
                updateHud();
117
        }
118

    
119
        /**
120
         * This method updates information of the HUD
121
         */
122
        public void updateHud() {
123

    
124
                if (m_planet.getType() == Planet.PlanetType.GEOCENTRIC) {
125
                        // Getting longitud and latitud informacion from planet
126
                        lon = Hud.getSexagesinal(m_planet.getLongitude(), true);
127
                        lat = Hud.getSexagesinal(m_planet.getLatitude(), false);
128

    
129
                        // Updating text information
130
                        textoHud.setText(lonText + " " + lon + " " + latText + " " + lat);
131
                } else {
132
                        // Getting longitud and latitud informacion from planet
133
                        lon = Double.toString(m_planet.getLongitude());
134
                        lat = Double.toString(m_planet.getLatitude());
135

    
136
                        // Updating text information
137
                        textoHud.setText(lonText + " " + lon + " " + latText + " " + lat);
138
                }
139
                // Repainting view
140
                if (m_canvas3d != null)
141
                        m_canvas3d.repaint();
142
        }
143

    
144
        public String getLat() {
145
                return lat;
146
        }
147

    
148
        public void setLat(String lat) {
149
                this.lat = lat;
150
        }
151

    
152
        public String getLatText() {
153
                return latText;
154
        }
155

    
156
        public void setLatText(String latText) {
157
                this.latText = latText;
158
        }
159

    
160
        public String getLon() {
161
                return lon;
162
        }
163

    
164
        public void setLon(String lon) {
165
                this.lon = lon;
166
        }
167

    
168
        public String getLonText() {
169
                return lonText;
170
        }
171

    
172
        public void setLonText(String lonText) {
173
                this.lonText = lonText;
174
        }
175

    
176
        /**
177
         * To transform longitud and latitud to sexagesinal format degress minuts
178
         * seconds
179
         * 
180
         * @param num
181
         *            number to transform
182
         * @param lat
183
         *            is tatitud or not
184
         * @return sexagesinal format
185
         */
186
        public static String getSexagesinal(double num, boolean lat) {
187

    
188
                String result = "";
189
                String ori = "";
190
                // Setting up North or South and East or West
191
                if (num < 0) {
192
                        num = num * (-1);
193
                        if (lat) {
194
                                ori = east;//south;// Messages.getText("South");
195
                        } else {
196
                                ori = north;//north;// Messages.getText("North");
197
                        }
198
                } else {
199
                        if (lat) {
200
                                ori = west;//west;// Messages.getText("West");
201
                        } else {
202
                                ori = south;//east;// Messages.getText("East");
203
                        }
204
                }
205

    
206
                // transform degrees in sexagesinal format
207
                int grados = (int) num;
208
                double resG = num - grados;
209
                int minutos = (int) (resG * 60);
210
                double minutosD = (resG * 60);
211
                double resM = minutosD - minutos;
212
                int segundos = (int) (resM * 60);
213
                String cadG = "";
214
                if (grados < 10)
215
                        cadG = cadG + "0";
216
                cadG = cadG + grados;
217

    
218
                String cadM = "";
219
                if (minutos < 10)
220
                        cadM = cadM + "0";
221
                cadM = cadM + minutos;
222

    
223
                String cadS = "";
224
                if (segundos < 10)
225
                        cadS = cadS + "0";
226
                cadS = cadS + segundos;
227

    
228
                // Building result string
229
                result = cadG + " " + cadM + " " + cadS + " " + ori;
230

    
231
                return result;
232
        }
233

    
234
        // MOUSE MOTION EVENTS
235

    
236
        public void mouseDragged(MouseEvent e) {
237
                // Updating Hud information+
238
                // If not update the hud information when mouses dragged the hud don�t change
239
                updateHud();
240

    
241
                // System.out.println("***************************************");
242
                // System.out.println("Longitud : " + m_planet.getLongitude());
243
                // System.out.println("Latitud : " + m_planet.getLatitude());
244
                // System.out.println("***************************************");
245

    
246
        }
247

    
248
        public void mouseMoved(MouseEvent e) {
249
                // TODO Auto-generated method stub
250
                updateHud();
251
        }
252

    
253
        public int getProjectionType() {
254
                return projectionType;
255
        }
256

    
257
        public void setProjectionType(int projectionType) {
258
                this.projectionType = projectionType;
259
        }
260

    
261
}