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