gvsig-3d / 1.10 / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / import3D / ControlImport3D.java @ 70
History | View | Annotate | Download (21.1 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
|
20 |
package org.gvsig.gvsig3dgui.import3D; |
21 |
|
22 |
import java.awt.BorderLayout; |
23 |
import java.awt.Component; |
24 |
import java.awt.GridLayout; |
25 |
import java.awt.Point; |
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.awt.event.KeyEvent; |
29 |
import java.awt.event.MouseEvent; |
30 |
import java.awt.event.MouseListener; |
31 |
import java.awt.geom.Point2D; |
32 |
import java.io.File; |
33 |
import java.io.FileInputStream; |
34 |
import java.io.FileNotFoundException; |
35 |
import java.util.Hashtable; |
36 |
import java.util.Iterator; |
37 |
|
38 |
import javax.swing.JButton; |
39 |
import javax.swing.JFileChooser; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JOptionPane; |
42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JTextField; |
44 |
import javax.swing.SpringLayout; |
45 |
import javax.swing.border.TitledBorder; |
46 |
import javax.swing.filechooser.FileFilter; |
47 |
|
48 |
import org.gvsig.driver.OSGDriver; |
49 |
import org.gvsig.geometries3D.MultiGeometry; |
50 |
import org.gvsig.gpe.osg.OSGParser; |
51 |
import org.gvsig.gui.beans.datainput.DataInputField; |
52 |
import org.gvsig.gvsig3d.cacheservices.OSGCacheService; |
53 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
54 |
import org.gvsig.gvsig3dgui.view.View3D; |
55 |
import org.gvsig.osgvp.core.osg.Node; |
56 |
import org.gvsig.osgvp.core.osg.Vec3; |
57 |
import org.gvsig.osgvp.viewer.Intersections; |
58 |
import org.gvsig.osgvp.core.osgdb.osgDB; |
59 |
import org.gvsig.osgvp.core.osgutil.Optimizer; |
60 |
import org.gvsig.osgvp.exceptions.node.LoadNodeException; |
61 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
62 |
|
63 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.andami.ui.mdiManager.IWindow; |
66 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
67 |
import com.iver.cit.gvsig.fmap.MapContext; |
68 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
70 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
71 |
|
72 |
/**
|
73 |
* @author �ngel Fraile Gri��n e-mail: angel.fraile@iver.es
|
74 |
* @since 1.1
|
75 |
*
|
76 |
*/
|
77 |
public class ControlImport3D extends JPanel implements IWindow, ActionListener, |
78 |
MouseListener {
|
79 |
|
80 |
private static final long serialVersionUID = 8557746972654979029L; |
81 |
|
82 |
private int tipoObjectImport; |
83 |
private View3D _view3D;
|
84 |
private File _fileOSG = null; |
85 |
private FileInputStream _fileInput = null; |
86 |
private Vec3 _position = new Vec3(0, 0, 0); |
87 |
private Hashtable iveExtensionsSupported = null; |
88 |
private Hashtable osgExtensionsSupported = null; |
89 |
private String lastPath = null; |
90 |
private JPanel panelPosition; |
91 |
private JPanel panelAux; |
92 |
private JPanel panelPath; |
93 |
private JPanel panelButtons; |
94 |
private JPanel panelObjectPosition; |
95 |
private TitledBorder borderPanelPosition; |
96 |
private TitledBorder borderPanelPath; |
97 |
private JLabel labelInfo; |
98 |
private JLabel labelLatitud; |
99 |
private JLabel labelLongitud; |
100 |
private JLabel labelAltura; |
101 |
private JLabel labelX; |
102 |
private JLabel labelY; |
103 |
private JLabel labelEscaladoX; |
104 |
private JLabel labelEscaladoY; |
105 |
private JLabel labelEscaladoZ; |
106 |
private JLabel labelRotacionX; |
107 |
private JLabel labelRotacionY; |
108 |
private JLabel labelRotacionZ; |
109 |
private JTextField textFile; |
110 |
private DataInputField textLatitud;
|
111 |
private DataInputField textLongitud;
|
112 |
private DataInputField textAltura;
|
113 |
private DataInputField textX;
|
114 |
private DataInputField textY;
|
115 |
private DataInputField textEscaladoX;
|
116 |
private DataInputField textEscaladoY;
|
117 |
private DataInputField textEscaladoZ;
|
118 |
private DataInputField textRotacionX;
|
119 |
private DataInputField textRotacionY;
|
120 |
private DataInputField textRotacionZ;
|
121 |
private JButton buttonImport; |
122 |
private JButton buttonAccept; |
123 |
private JButton buttonCancel; |
124 |
|
125 |
/**
|
126 |
* Building the panel options
|
127 |
*
|
128 |
* @param tipoObjeto
|
129 |
* @param vista3D
|
130 |
* : actual 3D view selected
|
131 |
*/
|
132 |
public ControlImport3D(int tipoObjeto, View3D view3D) { |
133 |
|
134 |
tipoObjectImport = tipoObjeto; |
135 |
_view3D = view3D; |
136 |
|
137 |
initialize(); |
138 |
|
139 |
_view3D.getCanvas3d().addMouseListener(this);
|
140 |
|
141 |
} |
142 |
|
143 |
public void initialize() { |
144 |
this.setLayout(new BorderLayout(5, 5)); |
145 |
this.add(getPanelAux(), BorderLayout.NORTH); |
146 |
// fake panel to grow up with the windows
|
147 |
// beacause the window is always resizable with docking skin
|
148 |
this.add(new JPanel(), BorderLayout.CENTER); |
149 |
} |
150 |
|
151 |
public JPanel getPanelAux() { |
152 |
if(panelAux == null) { |
153 |
panelAux = new JPanel(new BorderLayout()); |
154 |
panelAux.add(getPanelPosition(), BorderLayout.NORTH);
|
155 |
panelAux.add(getPanelFile(), BorderLayout.CENTER);
|
156 |
panelAux.add(getPanelButtons(), BorderLayout.SOUTH);
|
157 |
} |
158 |
|
159 |
return panelAux;
|
160 |
} |
161 |
|
162 |
public JPanel getPanelPosition() { |
163 |
if(panelPosition == null) { |
164 |
|
165 |
panelPosition = new JPanel(); |
166 |
panelPosition.setLayout(new BorderLayout(5, 5)); |
167 |
|
168 |
borderPanelPosition = new TitledBorder(PluginServices.getText( |
169 |
this, "Opciones de objeto")); |
170 |
panelPosition.setBorder(this.borderPanelPosition);
|
171 |
|
172 |
labelInfo = new JLabel(PluginServices.getText(this, "input_object_info"), JLabel.LEFT); |
173 |
|
174 |
panelObjectPosition = new JPanel(); |
175 |
panelObjectPosition.setLayout(new GridLayout(5, 6, 5, 5)); |
176 |
|
177 |
textLatitud = new DataInputField();
|
178 |
labelLatitud = new JLabel( |
179 |
PluginServices.getText(this, "Latitude"), JLabel.RIGHT); |
180 |
|
181 |
textLongitud = new DataInputField();
|
182 |
labelLongitud = new JLabel(PluginServices.getText(this, |
183 |
"Longitude"), JLabel.RIGHT); |
184 |
|
185 |
textAltura = new DataInputField();
|
186 |
labelAltura = new JLabel(PluginServices.getText(this, "Hight"), |
187 |
JLabel.RIGHT);
|
188 |
|
189 |
textX = new DataInputField();
|
190 |
labelX = new JLabel(PluginServices.getText(this, "Coordenada X:"), |
191 |
JLabel.RIGHT);
|
192 |
|
193 |
textY = new DataInputField();
|
194 |
labelY = new JLabel(PluginServices.getText(this, "Coordenada Y:"), |
195 |
JLabel.RIGHT);
|
196 |
|
197 |
textEscaladoX = new DataInputField();
|
198 |
textEscaladoX.setValue("1");
|
199 |
labelEscaladoX = new JLabel(PluginServices.getText(this, |
200 |
"EscaladoX"), JLabel.RIGHT); |
201 |
|
202 |
textEscaladoY = new DataInputField();
|
203 |
textEscaladoY.setValue("1");
|
204 |
labelEscaladoY = new JLabel(PluginServices.getText(this, |
205 |
"EscaladoY"), JLabel.RIGHT); |
206 |
|
207 |
textEscaladoZ = new DataInputField();
|
208 |
textEscaladoZ.setValue("1");
|
209 |
labelEscaladoZ = new JLabel(PluginServices.getText(this, |
210 |
"EscaladoZ"), JLabel.RIGHT); |
211 |
|
212 |
textRotacionX = new DataInputField();
|
213 |
labelRotacionX = new JLabel(PluginServices.getText(this, |
214 |
"Rotation_degreesX"), JLabel.RIGHT); |
215 |
|
216 |
textRotacionY = new DataInputField();
|
217 |
labelRotacionY = new JLabel(PluginServices.getText(this, |
218 |
"Rotation_degreesY"), JLabel.RIGHT); |
219 |
|
220 |
textRotacionZ = new DataInputField();
|
221 |
labelRotacionZ = new JLabel(PluginServices.getText(this, |
222 |
"Rotation_degreesZ"), JLabel.RIGHT); |
223 |
|
224 |
panelObjectPosition.add(this.labelLatitud);
|
225 |
panelObjectPosition.add(this.textLatitud);
|
226 |
panelObjectPosition.add(this.labelX);
|
227 |
panelObjectPosition.add(this.textX);
|
228 |
panelObjectPosition.add(new JPanel()); |
229 |
panelObjectPosition.add(new JPanel()); |
230 |
|
231 |
panelObjectPosition.add(this.labelLongitud);
|
232 |
panelObjectPosition.add(this.textLongitud);
|
233 |
panelObjectPosition.add(this.labelY);
|
234 |
panelObjectPosition.add(this.textY);
|
235 |
panelObjectPosition.add(new JPanel()); |
236 |
panelObjectPosition.add(new JPanel()); |
237 |
|
238 |
panelObjectPosition.add(this.labelAltura);
|
239 |
panelObjectPosition.add(this.textAltura);
|
240 |
panelObjectPosition.add(new JPanel()); |
241 |
panelObjectPosition.add(new JPanel()); |
242 |
panelObjectPosition.add(new JPanel()); |
243 |
panelObjectPosition.add(new JPanel()); |
244 |
|
245 |
panelObjectPosition.add(this.labelEscaladoX);
|
246 |
panelObjectPosition.add(this.textEscaladoX);
|
247 |
panelObjectPosition.add(this.labelEscaladoY);
|
248 |
panelObjectPosition.add(this.textEscaladoY);
|
249 |
panelObjectPosition.add(this.labelEscaladoZ);
|
250 |
panelObjectPosition.add(this.textEscaladoZ);
|
251 |
|
252 |
panelObjectPosition.add(this.labelRotacionX);
|
253 |
panelObjectPosition.add(this.textRotacionX);
|
254 |
panelObjectPosition.add(this.labelRotacionY);
|
255 |
panelObjectPosition.add(this.textRotacionY);
|
256 |
panelObjectPosition.add(this.labelRotacionZ);
|
257 |
panelObjectPosition.add(this.textRotacionZ);
|
258 |
|
259 |
panelPosition.add(labelInfo, BorderLayout.NORTH);
|
260 |
panelPosition.add(panelObjectPosition, BorderLayout.SOUTH);
|
261 |
} |
262 |
return panelPosition;
|
263 |
} |
264 |
|
265 |
public JPanel getPanelFile() { |
266 |
if(panelPath == null) { |
267 |
panelPath = new JPanel(); |
268 |
panelPath.setLayout(new BorderLayout(5,5)); |
269 |
|
270 |
borderPanelPath = new TitledBorder(PluginServices.getText(this, |
271 |
"File"));
|
272 |
panelPath.setBorder(borderPanelPath); |
273 |
|
274 |
textFile = new JTextField(); |
275 |
textFile.setBounds(new java.awt.Rectangle(5,10,350,23)); |
276 |
textFile.addKeyListener(new java.awt.event.KeyAdapter() {
|
277 |
public void keyReleased(KeyEvent arg0) { |
278 |
if (!textFile.getText().equals("")) |
279 |
buttonAccept.setEnabled(true);
|
280 |
else
|
281 |
buttonAccept.setEnabled(false);
|
282 |
} |
283 |
|
284 |
}); |
285 |
|
286 |
buttonImport = new JButton(); |
287 |
buttonImport.setText("...");
|
288 |
buttonImport.setBounds(new java.awt.Rectangle(355,10,32,22)); |
289 |
buttonImport.addActionListener(this);
|
290 |
|
291 |
panelPath.add(textFile, BorderLayout.CENTER);
|
292 |
panelPath.add(buttonImport, BorderLayout.EAST);
|
293 |
|
294 |
} |
295 |
|
296 |
return panelPath;
|
297 |
} |
298 |
|
299 |
public JPanel getPanelButtons() { |
300 |
if(panelButtons == null) { |
301 |
JPanel panelButtonsAux = new JPanel(); |
302 |
panelButtonsAux.setLayout(new GridLayout(1, 2, 5, 5)); |
303 |
|
304 |
panelButtons = new JPanel(); |
305 |
panelButtons.setLayout(new BorderLayout()); |
306 |
|
307 |
buttonAccept = new JButton(PluginServices.getText(this, "Accept")); |
308 |
buttonAccept.addActionListener(this);
|
309 |
buttonAccept.setEnabled(false);
|
310 |
|
311 |
buttonCancel = new JButton(PluginServices.getText(this, "Cancel")); |
312 |
buttonCancel.addActionListener(this);
|
313 |
|
314 |
panelButtonsAux.add(buttonAccept); |
315 |
panelButtonsAux.add(buttonCancel); |
316 |
panelButtons.add(panelButtonsAux, BorderLayout.EAST);
|
317 |
} |
318 |
|
319 |
return panelButtons;
|
320 |
} |
321 |
|
322 |
/**
|
323 |
* Window properties
|
324 |
*
|
325 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
326 |
*/
|
327 |
|
328 |
public WindowInfo getWindowInfo() {
|
329 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.TOOL_PROFILE);
|
330 |
String cad = null; |
331 |
|
332 |
if (tipoObjectImport == 0) |
333 |
cad = "Importar_Objeto_3D";
|
334 |
else if (tipoObjectImport == 1) |
335 |
cad = "Importar_Objeto_3D_Vectorial";
|
336 |
|
337 |
m_viewinfo.setTitle(PluginServices.getText(this, cad));
|
338 |
m_viewinfo.setHeight(280);
|
339 |
m_viewinfo.setWidth(500);
|
340 |
return m_viewinfo;
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* Buttons events listener
|
345 |
*/
|
346 |
public void actionPerformed(ActionEvent event) { |
347 |
if (event.getSource() == this.buttonImport) { |
348 |
actionPerformedImport(); |
349 |
|
350 |
} |
351 |
if (event.getSource() == this.buttonAccept) { |
352 |
actionPerformedAccept(); |
353 |
|
354 |
} |
355 |
if (event.getSource() == this.buttonCancel) { |
356 |
PluginServices.getMDIManager().closeWindow(this);
|
357 |
} |
358 |
} |
359 |
|
360 |
/**
|
361 |
* Accept button listener
|
362 |
*/
|
363 |
private void actionPerformedAccept() { |
364 |
|
365 |
if (_fileOSG == null) {// of the user write the file |
366 |
if (getJTextFieldFichero().equals("")) { |
367 |
JOptionPane.showMessageDialog(null, PluginServices.getText( |
368 |
this, "root_in"), PluginServices.getText(this, |
369 |
"no_file"), JOptionPane.WARNING_MESSAGE); |
370 |
return;
|
371 |
} else {
|
372 |
_fileOSG = new File(getJTextFieldFichero()); |
373 |
if (!_fileOSG.exists()) {
|
374 |
JOptionPane.showMessageDialog(null, PluginServices.getText( |
375 |
this, "no_root"), PluginServices.getText(this, |
376 |
"no_file2"), JOptionPane.WARNING_MESSAGE); |
377 |
_fileOSG = null;
|
378 |
this.setTextFieldFichero();
|
379 |
return;
|
380 |
} |
381 |
} |
382 |
|
383 |
} else {
|
384 |
try {
|
385 |
if (!_fileOSG.exists()) {
|
386 |
JOptionPane.showMessageDialog(null, PluginServices.getText( |
387 |
this, "root_in"), PluginServices.getText(this, |
388 |
"no_file"), JOptionPane.WARNING_MESSAGE); |
389 |
return;
|
390 |
} |
391 |
_fileInput = new FileInputStream(_fileOSG); |
392 |
|
393 |
} catch (FileNotFoundException e) { |
394 |
e.printStackTrace(); |
395 |
} |
396 |
} |
397 |
|
398 |
// OSGDriver _osgDriver = new OSGDriver();
|
399 |
// OSGParser parser = new OSGParser("OSG", "OSG File Formats Parser");
|
400 |
// parser.parse(_osgDriver, null, _fileOSG.toURI());
|
401 |
// MultiGeometry root = _osgDriver.getRootFeature();
|
402 |
|
403 |
IProjectView model = _view3D.getModel(); |
404 |
MapContext mapContext = model.getMapContext(); |
405 |
FLayers layers = mapContext.getLayers(); |
406 |
FLayer[] actives = layers.getActives();
|
407 |
if (actives.length == 1 |
408 |
&& Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
|
409 |
OSGCacheService osgCache = (OSGCacheService) Layer3DProps |
410 |
.getLayer3DProps(actives[0]).getCacheService();
|
411 |
Vec3 scale = new Vec3(Double.parseDouble(textEscaladoX.getValue()), |
412 |
Double.parseDouble(textEscaladoY.getValue()), Double |
413 |
.parseDouble(textEscaladoZ.getValue())); |
414 |
Vec3 rotation = new Vec3(Double.parseDouble(textRotacionX |
415 |
.getValue()), Double.parseDouble(textRotacionY.getValue()),
|
416 |
Double.parseDouble(textRotacionZ.getValue()));
|
417 |
// osgCache.AddGeometryToLayer(root,_position,rotation,scale);
|
418 |
|
419 |
try {
|
420 |
//If you want to use Optimizer take care because texure could disappear.
|
421 |
//Optimizer opt = new Optimizer();
|
422 |
Node n = osgDB.readNodeFile(_fileOSG.toString()); |
423 |
//opt.optimize(n);
|
424 |
osgCache.AddNodeToLayer(n, _position, rotation, scale); |
425 |
} catch (LoadNodeException e) {
|
426 |
// TODO Auto-generated catch block
|
427 |
e.printStackTrace(); |
428 |
} catch (FileNotFoundException e) { |
429 |
// TODO Auto-generated catch block
|
430 |
e.printStackTrace(); |
431 |
} catch (NodeException e) {
|
432 |
// TODO Auto-generated catch block
|
433 |
e.printStackTrace(); |
434 |
} |
435 |
|
436 |
} else {
|
437 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, |
438 |
"editable_layer_select_info"), PluginServices.getText(this, |
439 |
"editable_layer_select"), JOptionPane.WARNING_MESSAGE); |
440 |
return;
|
441 |
} |
442 |
|
443 |
_view3D.getCanvas3d().removeMouseListener(this);
|
444 |
PluginServices.getMDIManager().closeWindow(this);
|
445 |
} |
446 |
|
447 |
/**
|
448 |
* Import file button listener
|
449 |
*/
|
450 |
private void actionPerformedImport() { |
451 |
JFileChooser jfc = new JFileChooser(lastPath); |
452 |
jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter()); |
453 |
iveExtensionsSupported = new Hashtable(); |
454 |
osgExtensionsSupported = new Hashtable(); |
455 |
osgExtensionsSupported.put("osg", new MyFileFilter("osg", |
456 |
PluginServices.getText(this, "Ficheros *.osg"), "osg")); |
457 |
iveExtensionsSupported.put("ive", new MyFileFilter("ive", |
458 |
PluginServices.getText(this, "Ficheros *.ive"), "ive")); |
459 |
iveExtensionsSupported.put("obj", new MyFileFilter("obj", |
460 |
PluginServices.getText(this, "Ficheros *.obj"), "obj")); |
461 |
iveExtensionsSupported.put("dae", new MyFileFilter("dae", |
462 |
PluginServices.getText(this, "Ficheros *.dae"), "dae")); |
463 |
iveExtensionsSupported.put("3ds", new MyFileFilter("3ds", |
464 |
PluginServices.getText(this, "Ficheros *.3ds"), "3ds")); |
465 |
iveExtensionsSupported.put("3dc", new MyFileFilter("3dc", |
466 |
PluginServices.getText(this, "Ficheros *.3dc"), "3dc")); |
467 |
iveExtensionsSupported.put("*", new MyFileFilter("*", PluginServices |
468 |
.getText(this, "Ficheros *.*"), "*.*")); |
469 |
|
470 |
Iterator iter = osgExtensionsSupported.values().iterator();
|
471 |
|
472 |
while (iter.hasNext()) {
|
473 |
jfc.addChoosableFileFilter((FileFilter) iter.next());
|
474 |
} |
475 |
|
476 |
iter = iveExtensionsSupported.values().iterator(); |
477 |
while (iter.hasNext()) {
|
478 |
jfc.addChoosableFileFilter((FileFilter) iter.next());
|
479 |
} |
480 |
|
481 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
482 |
|
483 |
_fileOSG = jfc.getSelectedFile(); |
484 |
if (_fileOSG.exists()) {// file don't exists in the directory. |
485 |
|
486 |
MyFileFilter filter = (MyFileFilter) jfc.getFileFilter(); |
487 |
_fileOSG = filter.normalizeExtension(_fileOSG); |
488 |
textFile.setText(_fileOSG.getAbsolutePath()); |
489 |
} else {
|
490 |
JOptionPane.showMessageDialog(null, PluginServices.getText( |
491 |
this, "no_root"), PluginServices.getText(this, |
492 |
"no_file2"), JOptionPane.WARNING_MESSAGE); |
493 |
return;
|
494 |
} |
495 |
buttonAccept.setEnabled(true);
|
496 |
}// If aprove option.
|
497 |
else {
|
498 |
buttonAccept.setEnabled(false);
|
499 |
} |
500 |
} |
501 |
|
502 |
/**
|
503 |
* Getters and Setters of all TextFields values
|
504 |
*/
|
505 |
public String getJTextFieldFichero() { |
506 |
//return textFile.getText();
|
507 |
return null; |
508 |
} |
509 |
|
510 |
public void setTextFieldFichero() { |
511 |
//textFile.setText(null);
|
512 |
} |
513 |
|
514 |
/*
|
515 |
* All MouseListener methods
|
516 |
*/
|
517 |
public void mouseClicked(MouseEvent e) { |
518 |
// TODO Auto-generated method stub
|
519 |
} |
520 |
|
521 |
public void mouseEntered(MouseEvent e) { |
522 |
// TODO Auto-generated method stub
|
523 |
|
524 |
} |
525 |
|
526 |
public void mouseExited(MouseEvent e) { |
527 |
// TODO Auto-generated method stub
|
528 |
|
529 |
} |
530 |
|
531 |
public void mousePressed(MouseEvent e) { |
532 |
// TODO Auto-generated method stub
|
533 |
} |
534 |
|
535 |
public void mouseReleased(MouseEvent e) { |
536 |
|
537 |
Point pScreen = e.getPoint();
|
538 |
|
539 |
if (e.getButton() == MouseEvent.BUTTON1) { |
540 |
Vec3 intersection = null;
|
541 |
|
542 |
textX.setValue(Double.toString(pScreen.getX()));
|
543 |
textY.setValue(Double.toString(pScreen.getY()));
|
544 |
|
545 |
IProjectView model = _view3D.getModel(); |
546 |
|
547 |
MapContext3D mcontext = (MapContext3D) model.getMapContext(); |
548 |
mcontext.getCanvas3d(); |
549 |
|
550 |
Intersections hits = mcontext.getCanvas3d().getOSGViewer().rayPick( |
551 |
(int) pScreen.getX(), (int) pScreen.getY()); |
552 |
Point2D pWorld = new Point2D.Double(); |
553 |
if (hits.containsIntersections()) {
|
554 |
Vec3 hit = hits.getFirstIntersection().getIntersectionPoint(); |
555 |
// convert to geo coordinates
|
556 |
_position = hit; |
557 |
if (mcontext.getProjection().getAbrev().compareToIgnoreCase(
|
558 |
"EPSG:4326") == 0) { |
559 |
Vec3 geoPt = mcontext.getTerrain() |
560 |
.convertXYZToLatLongHeight(hit); |
561 |
// Swap the coordinates X and Y, because they are invert.
|
562 |
intersection = new Vec3(geoPt.y(), geoPt.x(), geoPt.z());
|
563 |
} else {
|
564 |
intersection = hit; |
565 |
} |
566 |
} else {
|
567 |
if (mcontext.getProjection().getAbrev().compareToIgnoreCase(
|
568 |
"EPSG:4326") == 0) { |
569 |
pWorld.setLocation(360, 120); |
570 |
intersection = new Vec3(360, 120, 0); |
571 |
} else {
|
572 |
intersection = new Vec3(1e100, 1e100, 0); |
573 |
// pWorld.setLocation(1e100, 1e100);
|
574 |
} |
575 |
} |
576 |
|
577 |
textLatitud.setValue(Double.toString(intersection.x()));
|
578 |
textLongitud.setValue(Double.toString(intersection.y()));
|
579 |
|
580 |
textAltura.setValue(Double.toString(intersection.z()));
|
581 |
|
582 |
}// if e.getButton()
|
583 |
}// if hits
|
584 |
|
585 |
public Object getWindowProfile() { |
586 |
return WindowInfo.PROPERTIES_PROFILE;
|
587 |
} |
588 |
|
589 |
} |
590 |
|
591 |
/**
|
592 |
*
|
593 |
* @version 14/08/2007
|
594 |
* @author Borja S�nchez Zamorano (borja.sanchez@iver.es)
|
595 |
*
|
596 |
*/
|
597 |
class MyFileFilter extends FileFilter { |
598 |
|
599 |
private String[] extensiones = new String[1]; |
600 |
private String description; |
601 |
private boolean dirs = true; |
602 |
private String info = null; |
603 |
|
604 |
public MyFileFilter(String[] ext, String desc) { |
605 |
extensiones = ext; |
606 |
description = desc; |
607 |
} |
608 |
|
609 |
public MyFileFilter(String[] ext, String desc, String info) { |
610 |
extensiones = ext; |
611 |
description = desc; |
612 |
this.info = info;
|
613 |
} |
614 |
|
615 |
public MyFileFilter(String ext, String desc) { |
616 |
extensiones[0] = ext;
|
617 |
description = desc; |
618 |
} |
619 |
|
620 |
public MyFileFilter(String ext, String desc, String info) { |
621 |
extensiones[0] = ext;
|
622 |
description = desc; |
623 |
this.info = info;
|
624 |
} |
625 |
|
626 |
public MyFileFilter(String ext, String desc, boolean dirs) { |
627 |
extensiones[0] = ext;
|
628 |
description = desc; |
629 |
this.dirs = dirs;
|
630 |
} |
631 |
|
632 |
public MyFileFilter(String ext, String desc, boolean dirs, String info) { |
633 |
extensiones[0] = ext;
|
634 |
description = desc; |
635 |
this.dirs = dirs;
|
636 |
this.info = info;
|
637 |
} |
638 |
|
639 |
public boolean accept(File f) { |
640 |
if (f.isDirectory()) {
|
641 |
if (dirs) {
|
642 |
return true; |
643 |
} else {
|
644 |
return false; |
645 |
} |
646 |
} |
647 |
for (int i = 0; i < extensiones.length; i++) { |
648 |
if (extensiones[i].equals("")) { |
649 |
continue;
|
650 |
} |
651 |
if (getExtensionOfAFile(f).equalsIgnoreCase(extensiones[i])) {
|
652 |
return true; |
653 |
} |
654 |
} |
655 |
|
656 |
return false; |
657 |
} |
658 |
|
659 |
/**
|
660 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
661 |
*/
|
662 |
public String getDescription() { |
663 |
return description;
|
664 |
} |
665 |
|
666 |
public String[] getExtensions() { |
667 |
return extensiones;
|
668 |
} |
669 |
|
670 |
public boolean isDirectory() { |
671 |
return dirs;
|
672 |
} |
673 |
|
674 |
private String getExtensionOfAFile(File file) { |
675 |
String name;
|
676 |
int dotPos;
|
677 |
name = file.getName(); |
678 |
dotPos = name.lastIndexOf(".");
|
679 |
if (dotPos < 1) { |
680 |
return ""; |
681 |
} |
682 |
return name.substring(dotPos + 1); |
683 |
} |
684 |
|
685 |
public File normalizeExtension(File file) { |
686 |
String ext = getExtensionOfAFile(file);
|
687 |
if (ext.equals("") || !(this.accept(file))) { |
688 |
return new File(file.getAbsolutePath() + "." + extensiones[0]); |
689 |
} |
690 |
return file;
|
691 |
} |
692 |
|
693 |
public String getInfo() { |
694 |
return this.info; |
695 |
} |
696 |
|
697 |
public void setInfo(String info) { |
698 |
this.info = info;
|
699 |
} |
700 |
|
701 |
} |