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