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