svn-gvsig-desktop / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / view / View3D.java @ 24767
History | View | Annotate | Download (14.3 KB)
1 |
/* Generated by Together */
|
---|---|
2 |
|
3 |
package org.gvsig.gvsig3dgui.view; |
4 |
|
5 |
import java.awt.BorderLayout; |
6 |
import java.awt.Color; |
7 |
import java.awt.Component; |
8 |
import java.awt.Cursor; |
9 |
import java.awt.Dimension; |
10 |
import java.awt.Image; |
11 |
import java.awt.Point; |
12 |
import java.awt.Toolkit; |
13 |
import java.awt.geom.Rectangle2D; |
14 |
import java.beans.PropertyChangeEvent; |
15 |
import java.beans.PropertyChangeListener; |
16 |
import java.net.URL; |
17 |
|
18 |
import javax.swing.ImageIcon; |
19 |
import javax.swing.JPanel; |
20 |
import javax.swing.JSplitPane; |
21 |
|
22 |
import org.cresques.cts.IProjection; |
23 |
import org.gvsig.gvsig3d.listener.canvasListener; |
24 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
25 |
import org.gvsig.gvsig3d.map3d.MapControl3D; |
26 |
import org.gvsig.gvsig3d.map3d.ViewPort3D; |
27 |
import org.gvsig.gvsig3d.navigation.NavigationMode; |
28 |
import org.gvsig.gvsig3dgui.ProjectView3D; |
29 |
import org.gvsig.gvsig3dgui.behavior.RectangleBehavior3D; |
30 |
import org.gvsig.gvsig3dgui.listener.PointSelectListerner3D; |
31 |
import org.gvsig.gvsig3dgui.listener.RectangleSelectListener3D; |
32 |
import org.gvsig.osgvp.planets.Planet; |
33 |
import org.gvsig.osgvp.planets.RequestLayerListener; |
34 |
import org.gvsig.osgvp.viewer.Camera; |
35 |
import org.gvsig.osgvp.viewer.DisplaySettings; |
36 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
37 |
import org.gvsig.osgvp.viewer.OSGViewer; |
38 |
|
39 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
40 |
import com.iver.andami.PluginServices; |
41 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
42 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
43 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
44 |
import com.iver.cit.gvsig.fmap.ProjectionEvent; |
45 |
import com.iver.cit.gvsig.fmap.ViewPort; |
46 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
47 |
import com.iver.cit.gvsig.fmap.MapControl.MapToolListener; |
48 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
49 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
50 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
51 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
52 |
import com.iver.cit.gvsig.project.documents.view.MapOverview; |
53 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
54 |
import com.iver.cit.gvsig.project.documents.view.toc.gui.TOC; |
55 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.InfoListener; |
56 |
|
57 |
public class View3D extends BaseView { |
58 |
|
59 |
private static final long serialVersionUID = 1L; |
60 |
|
61 |
private IViewerContainer m_canvas3d;
|
62 |
|
63 |
private Planet m_planet;
|
64 |
|
65 |
private FLayers m_layers;
|
66 |
|
67 |
private UpdateView3D updateViewThread;
|
68 |
|
69 |
private NavigationMode navMode = null; |
70 |
|
71 |
private String buttonPath; |
72 |
|
73 |
public View3D() {
|
74 |
this.setName("View3D"); |
75 |
|
76 |
} |
77 |
|
78 |
public DisplaySettings getDisplaySettings() {
|
79 |
|
80 |
return ((OSGViewer) getCanvas3d().getOSGViewer()).getDisplaySettings();
|
81 |
|
82 |
} |
83 |
|
84 |
public void setModel(ProjectView3D model) { |
85 |
this.modelo = model;
|
86 |
|
87 |
initComponents(); |
88 |
|
89 |
// Se registra como listener de cambios en FMap
|
90 |
MapContext3D fmap = (MapContext3D) modelo.getMapContext(); |
91 |
|
92 |
m_layers = fmap.getLayers(); |
93 |
/*
|
94 |
* for (int i=0;i<layers.getLayersCount();i++){ if
|
95 |
* (layers.getLayer(i).isEditing() && layers.getLayer(i) instanceof
|
96 |
* FLyrVect){ this.showConsole(); } }
|
97 |
*/
|
98 |
|
99 |
// Make layers listen to tile requests
|
100 |
m_planet.setRequestLayerListener((RequestLayerListener) fmap); |
101 |
// .getTileListener();
|
102 |
// tileManager.setTileCreatedListener((TileCreatedListener) fmap);
|
103 |
// tileManager.setRequestLayerListener((RequestLayerListener) fmap);
|
104 |
|
105 |
// set projection for 3D view
|
106 |
IProjection projection = null;
|
107 |
ViewPort vp = null;
|
108 |
Rectangle2D extend;
|
109 |
if (m_planet.getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) {
|
110 |
projection = CRSFactory.getCRS("EPSG:4326");
|
111 |
extend = new Rectangle2D.Double(-180.0, 90.0, 180.0, -90.0); |
112 |
} else {
|
113 |
if ((fmap != null) && (fmap.getProjection() != null)) |
114 |
projection = fmap.getProjection(); |
115 |
else
|
116 |
projection = CRSFactory.getCRS("EPSG:23030"); // test |
117 |
// projection = CRSFactory.getCRS("EPSG:4326"); // test
|
118 |
// extend = new Rectangle2D.Double(-20000000.0, 10000000.0,
|
119 |
// 40000000.0, 20000000.0);
|
120 |
extend = new Rectangle2D.Double(20000000.0, 10000000.0, |
121 |
-20000000.0, -10000000.0); |
122 |
} |
123 |
vp = new ViewPort3D(projection);
|
124 |
vp.setExtent(extend); |
125 |
fmap.setViewPort(vp); |
126 |
((ViewPort3D) vp).setPlanet(this.m_planet);
|
127 |
|
128 |
// Add ViewPort3D listener to canvas3D. to refresh locator.
|
129 |
m_canvas3d.addMouseListener((ViewPort3D) vp); |
130 |
|
131 |
// Pass JOSG objects to MapContext3D
|
132 |
fmap.setViewer(m_canvas3d); |
133 |
fmap.setViewProjection(projection); |
134 |
fmap.setPlanet(m_planet); |
135 |
|
136 |
// Se configura el mapControl
|
137 |
|
138 |
canvasListener lis = new canvasListener();
|
139 |
lis.setPlanet(m_planet); |
140 |
lis.setCanvas(m_canvas3d); |
141 |
m_canvas3d.addKeyListener(lis); |
142 |
m_canvas3d.addMouseListener(lis); |
143 |
|
144 |
MapToolListener mapToolListener = m_MapControl.getMapToolListener(); |
145 |
m_canvas3d.addMouseListener(mapToolListener); |
146 |
m_canvas3d.addMouseMotionListener(mapToolListener); |
147 |
m_canvas3d.addMouseWheelListener(mapToolListener); |
148 |
|
149 |
m_MapControl.setMapContext(fmap); |
150 |
m_TOC.setMapContext(fmap); |
151 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
152 |
if (modelo.getMapOverViewContext() != null) { |
153 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
154 |
} |
155 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
156 |
public void propertyChange(PropertyChangeEvent evt) { |
157 |
if (evt.getPropertyName().equals("name")) { |
158 |
PluginServices.getMDIManager().getWindowInfo(View3D.this) |
159 |
.setTitle( |
160 |
PluginServices.getText(this, "Vista3D") |
161 |
+ " : "
|
162 |
+ (String) evt.getNewValue());
|
163 |
} |
164 |
} |
165 |
}); |
166 |
if (m_MapControl.getViewPort() != null) { |
167 |
m_MapControl.getViewPort().addViewPortListener( |
168 |
new ViewPortListener() {
|
169 |
public void extentChanged(ExtentEvent e) { |
170 |
/*
|
171 |
* if (PluginServices.getMainFrame() != null){
|
172 |
* PluginServices.getMainFrame().getStatusBar().setControlValue("scale",String.valueOf(m_MapControl.getMapContext().getScaleView()));
|
173 |
* PluginServices.getMainFrame().getStatusBar().setMessage("projection",
|
174 |
* getMapControl().getViewPort().getProjection().getAbrev()); }
|
175 |
*/
|
176 |
} |
177 |
|
178 |
public void backColorChanged(ColorEvent e) { |
179 |
} |
180 |
|
181 |
public void projectionChanged(ProjectionEvent e) { |
182 |
m_MapLoc.setProjection(e.getNewProjection()); |
183 |
} |
184 |
}); |
185 |
} |
186 |
} |
187 |
|
188 |
/**
|
189 |
* DOCUMENT ME!
|
190 |
*/
|
191 |
// FALTA CONVERTIR QUE CANVAS3D HAGA EL PAPEL DE m_MapControl
|
192 |
protected void initComponents() { // GEN-BEGIN:initComponents |
193 |
m_MapControl = new MapControl3D(this); // Default is paintEnabled = |
194 |
// false.
|
195 |
// Remember to activate it
|
196 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
197 |
// modelo.setMapContext(m_MapControl.getMapContext());
|
198 |
|
199 |
// m_MapControl.setAcceptEvents(true); Lo comento porque ya se hace en
|
200 |
// el setModel
|
201 |
m_TOC = new TOC();
|
202 |
|
203 |
// Ponemos el localizador
|
204 |
m_MapLoc = new MapOverview(m_MapControl);
|
205 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
206 |
removeAll(); |
207 |
tempMainSplit = new ViewSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
208 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
209 |
if (!isPalette()) {
|
210 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
211 |
tempSplitToc.setTopComponent(m_TOC); |
212 |
tempSplitToc.setBottomComponent(m_MapLoc); |
213 |
tempSplitToc.setResizeWeight(0.7);
|
214 |
tempMainSplit.setLeftComponent(tempSplitToc); |
215 |
} else {
|
216 |
tempMainSplit.setLeftComponent(m_TOC); |
217 |
} |
218 |
m_TOC.setVisible(true);
|
219 |
JPanel panel = new JPanel(); |
220 |
panel.setLayout(new BorderLayout()); |
221 |
panel.add((Component) m_canvas3d /* m_MapControl */); |
222 |
tempMainSplit.setRightComponent(panel); |
223 |
panel.setMinimumSize(new Dimension(100, 100)); |
224 |
// split.setBottomComponent(getConsolePanel());
|
225 |
// split.setTopComponent(tempMainSplit);
|
226 |
// split.setResizeWeight(0.9);
|
227 |
this.setLayout(new BorderLayout()); |
228 |
this.add(tempMainSplit, BorderLayout.CENTER); |
229 |
|
230 |
// default cursor
|
231 |
|
232 |
String oldPath = ResourcesFactory.getExtPath();// Save the path. |
233 |
ResourcesFactory |
234 |
.setExtPath("/gvSIG/extensiones/com.iver.ai2.gvsig3dgui/images/");// my |
235 |
// new
|
236 |
// path
|
237 |
buttonPath = ResourcesFactory.getResourcesPath(); |
238 |
ResourcesFactory.setExtPath(oldPath);// Restore the old path.
|
239 |
System.out.println(oldPath);
|
240 |
System.out.println(buttonPath);
|
241 |
|
242 |
URL path;
|
243 |
path = this.getClass().getClassLoader().getResource("images/"); |
244 |
buttonPath = path.getPath(); |
245 |
|
246 |
Image navCursorImage = new ImageIcon(buttonPath |
247 |
+ "/NavigationCursor.gif").getImage();
|
248 |
|
249 |
// Image navCursorImage = new ImageIcon(this.getClass().getResource(
|
250 |
// "images/NavigationCursor.gif")).getImage();
|
251 |
Cursor navCursor = Toolkit.getDefaultToolkit().createCustomCursor( |
252 |
navCursorImage, new Point(16, 16), ""); |
253 |
((Component) m_canvas3d).setCursor(navCursor);
|
254 |
|
255 |
// hideConsole();
|
256 |
|
257 |
// //Listener de eventos de movimiento que pone las coordenadas del
|
258 |
// rat�n en la barra de estado
|
259 |
// StatusBarListener sbl = new StatusBarListener(m_MapControl);
|
260 |
//
|
261 |
// // Zoom out (pinchas y el mapa se centra y te muestra m�s).
|
262 |
// // No es dibujando un rect�ngulo, es solo pinchando.
|
263 |
//
|
264 |
// ZoomOutListener zol = new ZoomOutListener(m_MapControl);
|
265 |
// m_MapControl.addMapTool("zoomOut", new Behavior[]{new
|
266 |
// PointBehavior(zol), new MouseMovementBehavior(sbl)});
|
267 |
//
|
268 |
// // pan
|
269 |
//
|
270 |
// PanListener pl = new PanListener(m_MapControl);
|
271 |
// m_MapControl.addMapTool("pan", new Behavior[]{new MoveBehavior(pl),
|
272 |
// new MouseMovementBehavior(sbl)});
|
273 |
//
|
274 |
// // Medir
|
275 |
//
|
276 |
// MeasureListener mli = new MeasureListener(m_MapControl);
|
277 |
// m_MapControl.addMapTool("medicion", new Behavior[]{new
|
278 |
// PolylineBehavior(mli), new MouseMovementBehavior(sbl)});
|
279 |
//
|
280 |
// // Area
|
281 |
//
|
282 |
// AreaListener ali = new AreaListener(m_MapControl);
|
283 |
// m_MapControl.addMapTool("area", new Behavior[]{new
|
284 |
// PolygonBehavior(ali), new MouseMovementBehavior(sbl)});
|
285 |
//
|
286 |
// Seleccion por punto
|
287 |
|
288 |
PointSelectListerner3D psl = new PointSelectListerner3D(m_MapControl);
|
289 |
m_MapControl.addMapTool("pointSelection",
|
290 |
new Behavior[] { new PointBehavior(psl) }); |
291 |
//
|
292 |
// Info por punto
|
293 |
InfoListener il = new InfoListener(m_MapControl);
|
294 |
m_MapControl.addMapTool("info",
|
295 |
new Behavior[] { new PointBehavior(il) }); |
296 |
// new MouseMovementBehavior(sbl)});
|
297 |
//
|
298 |
// // Link por punto
|
299 |
// LinkListener ll = new LinkListener(m_MapControl);
|
300 |
// m_MapControl.addMapTool("link", new Behavior[]{new PointBehavior(ll),
|
301 |
// new MouseMovementBehavior(sbl)});
|
302 |
//
|
303 |
// Selecci�n por rect�ngulo
|
304 |
RectangleSelectListener3D rsl = new RectangleSelectListener3D(
|
305 |
m_MapControl); |
306 |
m_MapControl.addMapTool("rectSelection",
|
307 |
new Behavior[] { new RectangleBehavior3D(rsl) }); |
308 |
//
|
309 |
// //Selecci�n por pol�gono
|
310 |
// PolygonSelectListener poligSel = new
|
311 |
// PolygonSelectListener(m_MapControl);
|
312 |
// m_MapControl.addMapTool("polSelection", new Behavior[]{new
|
313 |
// PolygonBehavior(poligSel), new MouseMovementBehavior(sbl)});
|
314 |
//
|
315 |
// // Zoom por rect�ngulo
|
316 |
// ZoomOutRightButtonListener zoil = new
|
317 |
// ZoomOutRightButtonListener(m_MapControl);
|
318 |
// ZoomInListener zil = new ZoomInListener(m_MapControl);
|
319 |
// m_MapControl.addMapTool("zoomIn", new Behavior[]{new
|
320 |
// RectangleBehavior(zil),
|
321 |
// new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
|
322 |
//
|
323 |
// SelectImageListener sil = new SelectImageListener(m_MapControl);
|
324 |
// m_MapControl.addMapTool("selectImage", new Behavior[]{
|
325 |
// new PointBehavior(sil), new MouseMovementBehavior(sbl)});
|
326 |
//
|
327 |
// ZoomPixelCursorListener zp = new
|
328 |
// ZoomPixelCursorListener(m_MapControl);
|
329 |
// m_MapControl.addMapTool("zoom_pixel_cursor", new Behavior[]{new
|
330 |
// PointBehavior(zp), new MouseMovementBehavior(sbl)});
|
331 |
//
|
332 |
// m_MapControl.setTool("zoomIn"); // Por defecto
|
333 |
// m_MapControl.setPaintEnabled(true);
|
334 |
} |
335 |
|
336 |
public WindowInfo getWindowInfo() {
|
337 |
if (m_viewInfo == null) { |
338 |
m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE
|
339 |
| WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE); |
340 |
|
341 |
m_viewInfo.setWidth(500);
|
342 |
m_viewInfo.setHeight(300);
|
343 |
m_viewInfo.setTitle(PluginServices.getText(this, "Vista3D") + " : " |
344 |
+ modelo.getName()); |
345 |
} |
346 |
return m_viewInfo;
|
347 |
} |
348 |
|
349 |
public IViewerContainer getCanvas3d() {
|
350 |
return m_canvas3d;
|
351 |
} |
352 |
|
353 |
public void setCanvas3d(IViewerContainer canvas3d) { |
354 |
m_canvas3d = canvas3d; |
355 |
|
356 |
// Launching slider update
|
357 |
// Create the object with the run() method
|
358 |
updateViewThread = new UpdateView3D(30000); |
359 |
|
360 |
// Create the thread supplying it with the runnable object
|
361 |
Thread thread = new Thread(updateViewThread); |
362 |
|
363 |
// Start the thread
|
364 |
thread.start(); |
365 |
} |
366 |
|
367 |
public Planet getPlanet() {
|
368 |
return m_planet;
|
369 |
} |
370 |
|
371 |
public void setPlanet(Planet planet) { |
372 |
if (m_canvas3d == null) |
373 |
return;
|
374 |
m_planet = planet; |
375 |
|
376 |
// Preguntar a rafa si cuando se hace un setSceneData se cuelga un nodo
|
377 |
// nuevo o se destruye el grafo entero y se crea de nuevo
|
378 |
// m_canvas3d.setSceneData(m_planet);
|
379 |
} |
380 |
|
381 |
public void windowActivated() { |
382 |
m_canvas3d.repaint(); |
383 |
|
384 |
} |
385 |
|
386 |
public void windowClosed() { |
387 |
super.windowClosed();
|
388 |
} |
389 |
|
390 |
public void repaint() { |
391 |
if (m_canvas3d != null) |
392 |
m_canvas3d.repaint(); |
393 |
super.repaint();
|
394 |
} |
395 |
|
396 |
public Camera getCamera() {
|
397 |
return getCanvas3d().getOSGViewer().getCamera();
|
398 |
} |
399 |
|
400 |
public void setCamera(Camera camera) { |
401 |
getCanvas3d().getOSGViewer().setCamera(camera); |
402 |
} |
403 |
|
404 |
/**
|
405 |
* Class to repaint canvas 3D. This class implements runnable and contructor
|
406 |
* with time parameter.
|
407 |
*
|
408 |
* @author julio
|
409 |
*
|
410 |
*/
|
411 |
public class UpdateView3D implements Runnable { |
412 |
|
413 |
private boolean finish = false; |
414 |
|
415 |
private long time; |
416 |
|
417 |
public UpdateView3D(long time) { |
418 |
this.time = time;
|
419 |
} |
420 |
|
421 |
// This method is called when the thread runs
|
422 |
public void run() { |
423 |
while (true) { |
424 |
try {
|
425 |
Thread.sleep(time);
|
426 |
synchronized (this) { |
427 |
if (finish) {
|
428 |
break;
|
429 |
} |
430 |
} |
431 |
} catch (InterruptedException e) { |
432 |
|
433 |
e.printStackTrace(); |
434 |
} |
435 |
// Repainting canvas
|
436 |
m_canvas3d.repaint(); |
437 |
} |
438 |
} |
439 |
|
440 |
public synchronized void end() { |
441 |
finish = true;
|
442 |
} |
443 |
|
444 |
public long getTime() { |
445 |
return time;
|
446 |
} |
447 |
|
448 |
public void setTime(long time) { |
449 |
this.time = time;
|
450 |
} |
451 |
|
452 |
} |
453 |
|
454 |
public NavigationMode getNavMode() {
|
455 |
return navMode;
|
456 |
} |
457 |
|
458 |
public void setNavMode(NavigationMode navMode) { |
459 |
this.navMode = navMode;
|
460 |
} |
461 |
|
462 |
public Object getWindowProfile() { |
463 |
return null; |
464 |
} |
465 |
} |