Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / lib3DMap / src / com / iver / ai2 / gvsig3d / gui / Hud.java @ 18219

History | View | Annotate | Download (6.22 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.osgvp.Group;
13
import es.upv.ai2.osgvp.Node;
14
import es.upv.ai2.osgvp.Vec4;
15
import es.upv.ai2.osgvp.features.Text;
16
import es.upv.ai2.osgvp.planets.Planet;
17
import es.upv.ai2.osgvp.viewer.IViewerContainer;
18

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

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

    
31
        private String lonText;
32

    
33
        private String latText;
34

    
35
        private String lon;
36

    
37
        private String lat;
38

    
39
        private Text textoHud = new Text();
40

    
41
        private static String north;
42

    
43
        private static String south;
44

    
45
        private static String east;
46

    
47
        private static String west;
48

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

    
55
        }
56

    
57
        private int projectionType;
58

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

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

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

    
92
                // Adding text to group
93
                this.addChild(textoHud);
94
                
95
                //Setting up the lighting mode to disable (rgaitan)
96
                this.setLightingMode(Node.Mode.OFF | Node.Mode.PROTECTED);        
97

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

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

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

    
114
                // Add mouse listener to viewer
115
                ((Component) m_canvas3d).addMouseMotionListener(this);
116

    
117
                // Update Hud
118
                updateHud();
119
        }
120

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

    
126
                if (m_planet.getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) {
127
                        // Getting longitud and latitud informacion from planet
128
                        lon = Hud.getSexagesinal(m_planet.getLongitude(), true);
129
                        lat = Hud.getSexagesinal(m_planet.getLatitude(), false);
130
                        
131

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

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

    
147
        public String getLat() {
148
                return lat;
149
        }
150

    
151
        public void setLat(String lat) {
152
                this.lat = lat;
153
        }
154

    
155
        public String getLatText() {
156
                return latText;
157
        }
158

    
159
        public void setLatText(String latText) {
160
                this.latText = latText;
161
        }
162

    
163
        public String getLon() {
164
                return lon;
165
        }
166

    
167
        public void setLon(String lon) {
168
                this.lon = lon;
169
        }
170

    
171
        public String getLonText() {
172
                return lonText;
173
        }
174

    
175
        public void setLonText(String lonText) {
176
                this.lonText = lonText;
177
        }
178

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

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

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

    
222
                String cadM = "";
223
                if (minutos < 10)
224
                        cadM = cadM + "0";
225
                cadM = cadM + minutos;
226

    
227
                String cadS = "";
228
                if (segundos < 10)
229
                        cadS = cadS + "0";
230
                cadS = cadS + segundos;
231

    
232
                // Building result string
233
                result = cadG + " " + cadM + " " + cadS + " " + ori;
234

    
235
                return result;
236
        }
237

    
238
        // MOUSE MOTION EVENTS
239

    
240
        public void mouseDragged(MouseEvent e) {
241
                // Updating Hud information+
242
                // If not update the hud information when mouses dragged the hud don�t change
243
                updateHud();
244

    
245
                // System.out.println("***************************************");
246
                // System.out.println("Longitud : " + m_planet.getLongitude());
247
                // System.out.println("Latitud : " + m_planet.getLatitude());
248
                // System.out.println("***************************************");
249

    
250
        }
251

    
252
        public void mouseMoved(MouseEvent e) {
253
                // TODO Auto-generated method stub
254
                updateHud();
255
        }
256

    
257
        public int getProjectionType() {
258
                return projectionType;
259
        }
260

    
261
        public void setProjectionType(int projectionType) {
262
                this.projectionType = projectionType;
263
        }
264

    
265
}