svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / ext3Dgui / src / com / iver / ai2 / gvsig3dgui / view / InsertPosition.java @ 15491
History | View | Annotate | Download (13.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. 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 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.ai2.gvsig3dgui.view; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.Insets; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
import java.util.Enumeration; |
48 |
|
49 |
import javax.swing.AbstractAction; |
50 |
import javax.swing.Action; |
51 |
import javax.swing.BorderFactory; |
52 |
import javax.swing.ButtonGroup; |
53 |
import javax.swing.JPanel; |
54 |
import javax.swing.JRadioButton; |
55 |
import javax.swing.JTextField; |
56 |
|
57 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
58 |
import org.gvsig.gui.beans.swing.JButton; |
59 |
|
60 |
import com.iver.ai2.gvsig3dgui.ProjectView3D; |
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
63 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
64 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
65 |
|
66 |
import es.upv.ai2.libjosg.Vec3; |
67 |
import es.upv.ai2.libjosg.planets.Planet.PlanetType; |
68 |
|
69 |
/**
|
70 |
* Dialogo donde se muestran las propiedades de una vista
|
71 |
*
|
72 |
* @author Fernando Gonz?lez Cort?s
|
73 |
*/
|
74 |
public class InsertPosition extends GridBagLayoutPanel implements |
75 |
SingletonWindow { |
76 |
|
77 |
private ProjectView3D view3D;
|
78 |
|
79 |
private JTextField txtName; |
80 |
|
81 |
private JPanel jPanelSelectProjection; |
82 |
|
83 |
private ButtonGroup radioButtonGroup; |
84 |
|
85 |
private int width = 375; |
86 |
|
87 |
private int height = 300; |
88 |
|
89 |
private GridBagLayoutPanel okCancelPanel;
|
90 |
|
91 |
private JButton okButton; |
92 |
|
93 |
private JButton cancelButton; |
94 |
|
95 |
private GridBagLayoutPanel sphericalPanel;
|
96 |
|
97 |
private GridBagLayoutPanel cartesianasPanel;
|
98 |
|
99 |
private GridBagLayoutPanel coordPanel;
|
100 |
|
101 |
private JTextField coordX; |
102 |
|
103 |
private JTextField coordY; |
104 |
|
105 |
private JTextField coordZ; |
106 |
|
107 |
private JTextField latG; |
108 |
|
109 |
private JTextField lonG; |
110 |
|
111 |
private JTextField altura; |
112 |
|
113 |
private JTextField latH; |
114 |
|
115 |
private JTextField lonH; |
116 |
|
117 |
private JTextField latM; |
118 |
|
119 |
private JTextField lonM; |
120 |
|
121 |
private GridBagLayoutPanel cartesianasLatitudPanel;
|
122 |
|
123 |
private GridBagLayoutPanel cartesianasLongitudPanel;
|
124 |
|
125 |
/**
|
126 |
* This is the default constructor
|
127 |
*
|
128 |
* @param f
|
129 |
* Frame padre del dialogo
|
130 |
* @param v
|
131 |
* Vista que se representa
|
132 |
*/
|
133 |
public InsertPosition(IProjectView v) {
|
134 |
view3D = (ProjectView3D) v; |
135 |
|
136 |
initialize(); |
137 |
} |
138 |
|
139 |
/**
|
140 |
* This method initializes this
|
141 |
*/
|
142 |
private void initialize() { |
143 |
// Inicialize component
|
144 |
setName("Insercion de punto 3D");
|
145 |
// Introducing the margin
|
146 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
147 |
// Dimension of the panel
|
148 |
// setSize(new Dimension(width, height));
|
149 |
this.setPreferredSize(new Dimension(width, height)); |
150 |
|
151 |
// ADDING COMPONENTS
|
152 |
|
153 |
// Name Component
|
154 |
this.addComponent("Nombre:", getTxtName(), new Insets(0, 10, 2, 10)); |
155 |
|
156 |
// Projection selector (Radio buton group)
|
157 |
// this.addComponent("Seleccione proyecci?n:",
|
158 |
// getJPanelSelectProjection(), new Insets(2, 10, 2, 10));
|
159 |
|
160 |
// this.addComponent(getSphericalPanel());
|
161 |
this.addComponent(getCoordPanel(), new Insets(2, 10, 2, 10)); |
162 |
|
163 |
// Accept buton
|
164 |
this.addComponent(getOkCancelPanel(), new Insets(2, 150, 2, 0)); |
165 |
|
166 |
// Inicialicing default values
|
167 |
coordX.setEnabled(true);
|
168 |
coordY.setEnabled(true);
|
169 |
coordZ.setEnabled(true);
|
170 |
|
171 |
latG.setText("0");
|
172 |
lonG.setText("0");
|
173 |
latH.setText("0");
|
174 |
lonH.setText("0");
|
175 |
latM.setText("0");
|
176 |
lonM.setText("0");
|
177 |
latG.setEnabled(true);
|
178 |
lonG.setEnabled(true);
|
179 |
latH.setEnabled(true);
|
180 |
lonH.setEnabled(true);
|
181 |
latM.setEnabled(true);
|
182 |
lonM.setEnabled(true);
|
183 |
altura.setText("0");
|
184 |
altura.setEnabled(true);
|
185 |
} |
186 |
|
187 |
private javax.swing.JTextField getTxtName() {
|
188 |
if (txtName == null) { |
189 |
txtName = new javax.swing.JTextField();
|
190 |
txtName.setPreferredSize(new java.awt.Dimension(150, 23)); |
191 |
} |
192 |
|
193 |
return txtName;
|
194 |
} |
195 |
|
196 |
private JPanel getJPanelSelectProjection() { |
197 |
if (jPanelSelectProjection == null) { |
198 |
// Create JPanel
|
199 |
jPanelSelectProjection = new GridBagLayoutPanel();
|
200 |
|
201 |
if (radioButtonGroup == null) { |
202 |
radioButtonGroup = getRadioButonGroup(); |
203 |
} |
204 |
for (Enumeration e = radioButtonGroup.getElements(); e |
205 |
.hasMoreElements();) { |
206 |
JRadioButton b = (JRadioButton) e.nextElement(); |
207 |
jPanelSelectProjection.add(b, null);
|
208 |
} |
209 |
|
210 |
} |
211 |
|
212 |
return jPanelSelectProjection;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Method to inicialize the radio button group
|
217 |
*
|
218 |
* @return the radio button group
|
219 |
*/
|
220 |
private ButtonGroup getRadioButonGroup() { |
221 |
if (radioButtonGroup == null) { |
222 |
|
223 |
// Create an action for each radio button
|
224 |
Action sphericalAction = new AbstractAction("spherical") { |
225 |
// This method is called whenever the radio button is pressed,
|
226 |
// even if it is already selected; this method is not called
|
227 |
// if the radio button was selected programmatically
|
228 |
public void actionPerformed(ActionEvent evt) { |
229 |
sphericalPanel.setEnabled(true);
|
230 |
cartesianasPanel.setEnabled(false);
|
231 |
coordX.setEnabled(true);
|
232 |
coordY.setEnabled(true);
|
233 |
coordZ.setEnabled(true);
|
234 |
latG.setEnabled(false);
|
235 |
lonG.setEnabled(false);
|
236 |
altura.setEnabled(false);
|
237 |
|
238 |
} |
239 |
}; |
240 |
Action flatAction = new AbstractAction("flat") { |
241 |
// See above
|
242 |
public void actionPerformed(ActionEvent evt) { |
243 |
sphericalPanel.setEnabled(false);
|
244 |
cartesianasPanel.setEnabled(true);
|
245 |
coordX.setEnabled(false);
|
246 |
coordY.setEnabled(false);
|
247 |
coordZ.setEnabled(false);
|
248 |
latG.setEnabled(true);
|
249 |
lonG.setEnabled(true);
|
250 |
altura.setEnabled(true);
|
251 |
} |
252 |
}; |
253 |
|
254 |
// Create the radio buttons using the actions
|
255 |
JRadioButton spherical = new JRadioButton(sphericalAction); |
256 |
JRadioButton flat = new JRadioButton(flatAction); |
257 |
|
258 |
// Inicialize the button properties
|
259 |
spherical.setName("spherical");
|
260 |
spherical.setLabel("Esferica");
|
261 |
flat.setName("flat");
|
262 |
flat.setLabel("Plana");
|
263 |
|
264 |
if (view3D.getPlanetType() == PlanetType.GEOCENTRIC)
|
265 |
spherical.setSelected(true);
|
266 |
else
|
267 |
flat.setSelected(true);
|
268 |
|
269 |
// Associate the two buttons with a button group
|
270 |
radioButtonGroup = new ButtonGroup(); |
271 |
radioButtonGroup.add(spherical); |
272 |
radioButtonGroup.add(flat); |
273 |
} |
274 |
|
275 |
return radioButtonGroup;
|
276 |
} |
277 |
|
278 |
private GridBagLayoutPanel getCoordPanel() {
|
279 |
if (coordPanel == null) { |
280 |
coordPanel = new GridBagLayoutPanel();
|
281 |
// coordPanel.addComponent(getSphericalPanel());
|
282 |
coordPanel.addComponent(getCartesianasPanel()); |
283 |
getSphericalPanel(); |
284 |
} |
285 |
|
286 |
return coordPanel;
|
287 |
} |
288 |
|
289 |
private GridBagLayoutPanel getSphericalPanel() {
|
290 |
if (sphericalPanel == null) { |
291 |
sphericalPanel = new GridBagLayoutPanel();
|
292 |
sphericalPanel.setSize(new java.awt.Dimension(200, 100)); |
293 |
sphericalPanel.setPreferredSize(new java.awt.Dimension(200, 100)); |
294 |
sphericalPanel.addComponent("X ", getCoordX());
|
295 |
sphericalPanel.addComponent("Y ", getCoordY());
|
296 |
sphericalPanel.addComponent("Z ", getCoordZ());
|
297 |
} |
298 |
|
299 |
return sphericalPanel;
|
300 |
} |
301 |
|
302 |
private javax.swing.JTextField getCoordX() {
|
303 |
if (coordX == null) { |
304 |
coordX = new javax.swing.JTextField();
|
305 |
coordX.setPreferredSize(new java.awt.Dimension(150, 23)); |
306 |
} |
307 |
|
308 |
return coordX;
|
309 |
} |
310 |
|
311 |
private javax.swing.JTextField getCoordY() {
|
312 |
if (coordY == null) { |
313 |
coordY = new javax.swing.JTextField();
|
314 |
coordY.setPreferredSize(new java.awt.Dimension(150, 23)); |
315 |
} |
316 |
|
317 |
return coordY;
|
318 |
} |
319 |
|
320 |
private javax.swing.JTextField getCoordZ() {
|
321 |
if (coordZ == null) { |
322 |
coordZ = new javax.swing.JTextField();
|
323 |
coordZ.setPreferredSize(new java.awt.Dimension(150, 23)); |
324 |
} |
325 |
|
326 |
return coordZ;
|
327 |
} |
328 |
|
329 |
private GridBagLayoutPanel getCartesianasPanel() {
|
330 |
if (cartesianasPanel == null) { |
331 |
cartesianasPanel = new GridBagLayoutPanel();
|
332 |
latG = new JTextField(); |
333 |
latG.setPreferredSize(new java.awt.Dimension(40, 23)); |
334 |
latG.setAlignmentX(GridBagLayoutPanel.LEFT_ALIGNMENT); |
335 |
latG.setMargin(new Insets(2, 5, 2, 5)); |
336 |
lonG = new JTextField(); |
337 |
lonG.setPreferredSize(new java.awt.Dimension(40, 23)); |
338 |
lonG.setAlignmentX(GridBagLayoutPanel.LEFT_ALIGNMENT); |
339 |
lonG.setMargin(new Insets(2, 5, 2, 5)); |
340 |
latH = new JTextField(); |
341 |
latH.setPreferredSize(new java.awt.Dimension(40, 23)); |
342 |
latH.setAlignmentX(GridBagLayoutPanel.LEFT_ALIGNMENT); |
343 |
lonH = new JTextField(); |
344 |
lonH.setPreferredSize(new java.awt.Dimension(40, 23)); |
345 |
lonH.setAlignmentX(GridBagLayoutPanel.LEFT_ALIGNMENT); |
346 |
latM = new JTextField(); |
347 |
latM.setPreferredSize(new java.awt.Dimension(40, 23)); |
348 |
latM.setAlignmentX(GridBagLayoutPanel.LEFT_ALIGNMENT); |
349 |
lonM = new JTextField(); |
350 |
lonM.setPreferredSize(new java.awt.Dimension(40, 23)); |
351 |
lonM.setAlignmentX(GridBagLayoutPanel.LEFT_ALIGNMENT); |
352 |
altura = new JTextField(); |
353 |
altura.setPreferredSize(new java.awt.Dimension(40, 23)); |
354 |
altura.setAlignmentX(GridBagLayoutPanel.LEFT_ALIGNMENT); |
355 |
cartesianasPanel.addComponent("Longitud",getCartesianasLongitudPanel());
|
356 |
cartesianasPanel.addComponent("Latitud ", getCartesianasLatitudPanel());
|
357 |
cartesianasPanel.addComponent("Altura ", getHeithg());
|
358 |
} |
359 |
|
360 |
return cartesianasPanel;
|
361 |
} |
362 |
|
363 |
private GridBagLayoutPanel getCartesianasLatitudPanel() {
|
364 |
if (cartesianasLatitudPanel == null) { |
365 |
cartesianasLatitudPanel = new GridBagLayoutPanel();
|
366 |
// latG = new JTextField();
|
367 |
// latG.setPreferredSize(new java.awt.Dimension(50, 23));
|
368 |
// lonG = new JTextField();
|
369 |
// lonG.setPreferredSize(new java.awt.Dimension(50, 23));
|
370 |
// latH = new JTextField();
|
371 |
// latH.setPreferredSize(new java.awt.Dimension(50, 23));
|
372 |
cartesianasLatitudPanel.addComponent(latG,latH,latM); |
373 |
} |
374 |
|
375 |
return cartesianasLatitudPanel;
|
376 |
} |
377 |
|
378 |
private GridBagLayoutPanel getCartesianasLongitudPanel() {
|
379 |
if (cartesianasLongitudPanel == null) { |
380 |
cartesianasLongitudPanel = new GridBagLayoutPanel();
|
381 |
// lonG = new JTextField();
|
382 |
// lonG.setPreferredSize(new java.awt.Dimension(50, 23));
|
383 |
// lonH = new JTextField();
|
384 |
// lonH.setPreferredSize(new java.awt.Dimension(50, 23));
|
385 |
// lonM = new JTextField();
|
386 |
// lonM.setPreferredSize(new java.awt.Dimension(50, 23));
|
387 |
cartesianasLongitudPanel.addComponent(lonG,lonH,lonM); |
388 |
} |
389 |
|
390 |
return cartesianasLongitudPanel;
|
391 |
} |
392 |
|
393 |
|
394 |
|
395 |
// private javax.swing.JTextField getLat() {
|
396 |
// if (latG == null) {
|
397 |
// latG = new javax.swing.JTextField();
|
398 |
// latG.setPreferredSize(new java.awt.Dimension(150, 23));
|
399 |
// }
|
400 |
//
|
401 |
// return latG;
|
402 |
// }
|
403 |
//
|
404 |
// private javax.swing.JTextField getLon() {
|
405 |
// if (lonG == null) {
|
406 |
// lonG = new javax.swing.JTextField();
|
407 |
// lonG.setPreferredSize(new java.awt.Dimension(150, 23));
|
408 |
// }
|
409 |
//
|
410 |
// return lonG;
|
411 |
// }
|
412 |
|
413 |
private javax.swing.JTextField getHeithg() {
|
414 |
if (altura == null) { |
415 |
altura = new javax.swing.JTextField();
|
416 |
altura.setPreferredSize(new java.awt.Dimension(150, 23)); |
417 |
} |
418 |
|
419 |
return altura;
|
420 |
} |
421 |
|
422 |
private GridBagLayoutPanel getOkCancelPanel() {
|
423 |
if (okCancelPanel == null) { |
424 |
ActionListener okAction, cancelAction;
|
425 |
okAction = new java.awt.event.ActionListener() {
|
426 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
427 |
//Pulsacion del boton de Aceptar
|
428 |
|
429 |
if (latG.isEnabled()){
|
430 |
double h = Double.valueOf(altura.getText()).doubleValue(); |
431 |
|
432 |
double lati = Double.valueOf(latG.getText()).doubleValue(); |
433 |
double longi = Double.valueOf(lonG.getText()).doubleValue(); |
434 |
lati = lati + (Double.valueOf(latG.getText()).doubleValue()/60); |
435 |
longi = longi + (Double.valueOf(lonG.getText()).doubleValue()/60); |
436 |
lati = lati + (Double.valueOf(latG.getText()).doubleValue()/3600); |
437 |
longi = longi + (Double.valueOf(lonG.getText()).doubleValue()/3600); |
438 |
|
439 |
// Vec3 posicion = new Vec3(h,lati,longi);
|
440 |
Vec3 posicion = new Vec3(lati,longi,h);
|
441 |
view3D.insertaText(txtName.getText(),posicion); |
442 |
|
443 |
} |
444 |
PluginServices.getMDIManager().closeWindow( |
445 |
InsertPosition.this); |
446 |
} |
447 |
}; |
448 |
cancelAction = new java.awt.event.ActionListener() {
|
449 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
450 |
PluginServices.getMDIManager().closeWindow( |
451 |
InsertPosition.this); |
452 |
} |
453 |
}; |
454 |
|
455 |
okCancelPanel = new GridBagLayoutPanel();
|
456 |
okCancelPanel.setAlignmentX(GridBagLayoutPanel.RIGHT_ALIGNMENT); |
457 |
okButton = new JButton(); |
458 |
okButton.setLabel("Aceptar");
|
459 |
okButton.addActionListener(okAction); |
460 |
cancelButton = new JButton(); |
461 |
cancelButton.setLabel("Cancelar");
|
462 |
cancelButton.addActionListener(cancelAction); |
463 |
|
464 |
okCancelPanel.addComponent(okButton, cancelButton); |
465 |
} |
466 |
return okCancelPanel;
|
467 |
} |
468 |
|
469 |
public Object getWindowModel() { |
470 |
// TODO Auto-generated method stub
|
471 |
return view3D;
|
472 |
} |
473 |
|
474 |
public WindowInfo getWindowInfo() {
|
475 |
WindowInfo m_viewinfo = new WindowInfo();
|
476 |
m_viewinfo.setTitle("Insercion_de_punto_3D");
|
477 |
m_viewinfo.setHeight(height); |
478 |
m_viewinfo.setWidth(width); |
479 |
return m_viewinfo;
|
480 |
} |
481 |
|
482 |
} |