forked from NASAWorldWind/WorldWindJava
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorldWindowGLCanvas.java
More file actions
465 lines (403 loc) · 17.1 KB
/
WorldWindowGLCanvas.java
File metadata and controls
465 lines (403 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwind.awt;
import gov.nasa.worldwind.*;
import gov.nasa.worldwind.avlist.*;
import gov.nasa.worldwind.cache.GpuResourceCache;
import gov.nasa.worldwind.event.*;
import gov.nasa.worldwind.exception.WWRuntimeException;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.pick.PickedObjectList;
import gov.nasa.worldwind.util.*;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import java.awt.*;
import java.beans.*;
import java.util.*;
/**
* <code>WorldWindowGLCanvas</code> is a heavyweight AWT component for displaying World Wind {@link Model}s (globe and
* layers). It's a self-contained component intended to serve as an application's <code>WorldWindow</code>. Construction
* options exist to specify a specific graphics device and to share graphics resources with another graphics device.
* <p/>
* Heavyweight AWT components such as instances of this class can be used in conjunction with lightweight Swing
* components. A discussion of doing so is in the <em>Heavyweight and Lightweight Issues</em> section of the <a
* href="http://download.java.net/media/jogl/doc/userguide/">"JOGL User's Guide"</a>. All that's typically necessary is
* to invoke the following methods of the indicated Swing classes: {@link javax.swing.ToolTipManager#setLightWeightPopupEnabled(boolean)},
* {@link javax.swing.JPopupMenu#setLightWeightPopupEnabled(boolean)} and {@link javax.swing.JPopupMenu#setLightWeightPopupEnabled(boolean)}.
* These methods should be invoked within a <code>static</code> block within an application's main class.
* <p/>
* This class is capable of supporting stereo devices. To cause a stereo device to be selected and used, specify the
* Java VM property "gov.nasa.worldwind.stereo.mode=device" prior to creating an instance of this class. A stereo
* capable {@link SceneController} such as {@link gov.nasa.worldwind.StereoSceneController} must also be specified in
* the World Wind {@link Configuration}. The default configuration specifies a stereo-capable controller. To prevent
* stereo from being used by subsequently opened {@code WorldWindowGLCanvas}es, set the property to a an empty string,
* "". If a stereo device cannot be selected and used, this falls back to a non-stereo device that supports World Wind's
* minimum requirements.
* <p/>
* Under certain conditions, JOGL replaces the <code>GLContext</code> associated with instances of this class. This then
* necessitates that all resources such as textures that have been stored on the graphic devices must be regenerated for
* the new context. World Wind does this automatically by clearing the associated {@link GpuResourceCache}. Objects
* subsequently rendered automatically re-create those resources. If an application creates its own graphics resources,
* including textures, vertex buffer objects and display lists, it must store them in the <code>GpuResourceCache</code>
* associated with the current {@link gov.nasa.worldwind.render.DrawContext} so that they are automatically cleared, and
* be prepared to re-create them if they do not exist in the <code>DrawContext</code>'s current
* <code>GpuResourceCache</code> when needed. Examples of doing this can be found by searching for usages of the method
* {@link GpuResourceCache#get(Object)} and {@link GpuResourceCache#getTexture(Object)}.
*
* @author Tom Gaskins
* @version $Id: WorldWindowGLCanvas.java 2924 2015-03-26 01:32:02Z tgaskins $
*/
public class WorldWindowGLCanvas extends GLCanvas implements WorldWindow, PropertyChangeListener
{
/** The drawable to which {@link WorldWindow} methods are delegated. */
protected final WorldWindowGLDrawable wwd; // WorldWindow interface delegates to wwd
/** Constructs a new <code>WorldWindowGLCanvas</code> on the default graphics device. */
public WorldWindowGLCanvas()
{
super(Configuration.getRequiredGLCapabilities(), new BasicGLCapabilitiesChooser(), null);
try
{
this.wwd = ((WorldWindowGLDrawable) WorldWind.createConfigurationComponent(AVKey.WORLD_WINDOW_CLASS_NAME));
this.wwd.initDrawable(this);
this.wwd.initGpuResourceCache(WorldWindowImpl.createGpuResourceCache());
this.createView();
this.createDefaultInputHandler();
WorldWind.addPropertyChangeListener(WorldWind.SHUTDOWN_EVENT, this);
this.wwd.endInitialization();
}
catch (Exception e)
{
String message = Logging.getMessage("Awt.WorldWindowGLSurface.UnabletoCreateWindow");
Logging.logger().severe(message);
throw new WWRuntimeException(message, e);
}
}
/**
* Constructs a new <code>WorldWindowGLCanvas</code> on the default graphics device and shares graphics resources
* with another <code>WorldWindow</code>.
*
* @param shareWith a <code>WorldWindow</code> with which to share graphics resources.
*
* @see GLCanvas#GLCanvas(com.jogamp.opengl.GLCapabilitiesImmutable, com.jogamp.opengl.GLCapabilitiesChooser,
* com.jogamp.opengl.GLContext, java.awt.GraphicsDevice)
*/
public WorldWindowGLCanvas(WorldWindow shareWith)
{
super(Configuration.getRequiredGLCapabilities(), new BasicGLCapabilitiesChooser(), null);
if (shareWith != null)
this.setSharedContext(shareWith.getContext());
try
{
this.wwd = ((WorldWindowGLDrawable) WorldWind.createConfigurationComponent(AVKey.WORLD_WINDOW_CLASS_NAME));
this.wwd.initDrawable(this);
if (shareWith != null)
this.wwd.initGpuResourceCache(shareWith.getGpuResourceCache());
else
this.wwd.initGpuResourceCache(WorldWindowImpl.createGpuResourceCache());
this.createView();
this.createDefaultInputHandler();
WorldWind.addPropertyChangeListener(WorldWind.SHUTDOWN_EVENT, this);
this.wwd.endInitialization();
}
catch (Exception e)
{
String message = Logging.getMessage("Awt.WorldWindowGLSurface.UnabletoCreateWindow");
Logging.logger().severe(message);
throw new WWRuntimeException(message, e);
}
}
/**
* Constructs a new <code>WorldWindowGLCanvas</code> on a specified graphics device and shares graphics resources
* with another <code>WorldWindow</code>.
*
* @param shareWith a <code>WorldWindow</code> with which to share graphics resources.
* @param device the <code>GraphicsDevice</code> on which to create the window. May be null, in which case the
* default screen device of the local {@link GraphicsEnvironment} is used.
*
* @see GLCanvas#GLCanvas(com.jogamp.opengl.GLCapabilitiesImmutable, com.jogamp.opengl.GLCapabilitiesChooser,
* com.jogamp.opengl.GLContext, java.awt.GraphicsDevice)
*/
public WorldWindowGLCanvas(WorldWindow shareWith, java.awt.GraphicsDevice device)
{
super(Configuration.getRequiredGLCapabilities(), new BasicGLCapabilitiesChooser(), device);
if (shareWith != null)
this.setSharedContext(shareWith.getContext());
try
{
this.wwd = ((WorldWindowGLDrawable) WorldWind.createConfigurationComponent(AVKey.WORLD_WINDOW_CLASS_NAME));
this.wwd.initDrawable(this);
if (shareWith != null)
this.wwd.initGpuResourceCache(shareWith.getGpuResourceCache());
else
this.wwd.initGpuResourceCache(WorldWindowImpl.createGpuResourceCache());
this.createView();
this.createDefaultInputHandler();
WorldWind.addPropertyChangeListener(WorldWind.SHUTDOWN_EVENT, this);
this.wwd.endInitialization();
}
catch (Exception e)
{
String message = Logging.getMessage("Awt.WorldWindowGLSurface.UnabletoCreateWindow");
Logging.logger().severe(message);
throw new WWRuntimeException(message, e);
}
}
/**
* Constructs a new <code>WorldWindowGLCanvas</code> on a specified device with the specified capabilities and
* shares graphics resources with another <code>WorldWindow</code>.
*
* @param shareWith a <code>WorldWindow</code> with which to share graphics resources.
* @param device the <code>GraphicsDevice</code> on which to create the window. May be null, in which case the
* default screen device of the local {@link GraphicsEnvironment} is used.
* @param capabilities a capabilities object indicating the OpenGL rendering context's capabilities. May be null, in
* which case a default set of capabilities is used.
* @param chooser a chooser object that customizes the specified capabilities. May be null, in which case a
* default chooser is used.
*
* @see GLCanvas#GLCanvas(com.jogamp.opengl.GLCapabilitiesImmutable, com.jogamp.opengl.GLCapabilitiesChooser,
* com.jogamp.opengl.GLContext, java.awt.GraphicsDevice)
*/
public WorldWindowGLCanvas(WorldWindow shareWith, java.awt.GraphicsDevice device,
GLCapabilities capabilities, GLCapabilitiesChooser chooser)
{
super(capabilities, chooser, device);
if (shareWith != null)
this.setSharedContext(shareWith.getContext());
try
{
this.wwd = ((WorldWindowGLDrawable) WorldWind.createConfigurationComponent(AVKey.WORLD_WINDOW_CLASS_NAME));
this.wwd.initDrawable(this);
if (shareWith != null)
this.wwd.initGpuResourceCache(shareWith.getGpuResourceCache());
else
this.wwd.initGpuResourceCache(WorldWindowImpl.createGpuResourceCache());
this.createView();
this.createDefaultInputHandler();
WorldWind.addPropertyChangeListener(WorldWind.SHUTDOWN_EVENT, this);
this.wwd.endInitialization();
}
catch (Exception e)
{
String message = Logging.getMessage("Awt.WorldWindowGLSurface.UnabletoCreateWindow");
Logging.logger().severe(message);
throw new WWRuntimeException(message, e);
}
}
public void propertyChange(PropertyChangeEvent evt)
{
//noinspection StringEquality
if (evt.getPropertyName() == WorldWind.SHUTDOWN_EVENT)
this.shutdown();
}
public void shutdown()
{
WorldWind.removePropertyChangeListener(WorldWind.SHUTDOWN_EVENT, this);
this.wwd.shutdown();
}
@Override
public boolean isEnableGpuCacheReinitialization()
{
return this.wwd.isEnableGpuCacheReinitialization();
}
@Override
public void setEnableGpuCacheReinitialization(boolean enableGpuCacheReinitialization)
{
this.wwd.setEnableGpuCacheReinitialization(enableGpuCacheReinitialization);
}
/** Constructs and attaches the {@link View} for this <code>WorldWindow</code>. */
protected void createView()
{
this.setView((View) WorldWind.createConfigurationComponent(AVKey.VIEW_CLASS_NAME));
}
/** Constructs and attaches the {@link InputHandler} for this <code>WorldWindow</code>. */
protected void createDefaultInputHandler()
{
this.setInputHandler((InputHandler) WorldWind.createConfigurationComponent(AVKey.INPUT_HANDLER_CLASS_NAME));
}
public InputHandler getInputHandler()
{
return this.wwd.getInputHandler();
}
public void setInputHandler(InputHandler inputHandler)
{
if (this.wwd.getInputHandler() != null)
this.wwd.getInputHandler().setEventSource(null); // remove this window as a source of events
this.wwd.setInputHandler(inputHandler != null ? inputHandler : new NoOpInputHandler());
if (inputHandler != null)
inputHandler.setEventSource(this);
}
public SceneController getSceneController()
{
return this.wwd.getSceneController();
}
public void setSceneController(SceneController sceneController)
{
this.wwd.setSceneController(sceneController);
}
public GpuResourceCache getGpuResourceCache()
{
return this.wwd.getGpuResourceCache();
}
public void redraw()
{
this.repaint();
}
public void redrawNow()
{
this.wwd.redrawNow();
}
public void setModel(Model model)
{
// null models are permissible
this.wwd.setModel(model);
}
public Model getModel()
{
return this.wwd.getModel();
}
public void setView(View view)
{
// null views are permissible
if (view != null)
this.wwd.setView(view);
}
public View getView()
{
return this.wwd.getView();
}
public void setModelAndView(Model model, View view)
{ // null models/views are permissible
this.setModel(model);
this.setView(view);
}
public void addRenderingListener(RenderingListener listener)
{
this.wwd.addRenderingListener(listener);
}
public void removeRenderingListener(RenderingListener listener)
{
this.wwd.removeRenderingListener(listener);
}
public void addSelectListener(SelectListener listener)
{
this.wwd.getInputHandler().addSelectListener(listener);
this.wwd.addSelectListener(listener);
}
public void removeSelectListener(SelectListener listener)
{
this.wwd.getInputHandler().removeSelectListener(listener);
this.wwd.removeSelectListener(listener);
}
public void addPositionListener(PositionListener listener)
{
this.wwd.addPositionListener(listener);
}
public void removePositionListener(PositionListener listener)
{
this.wwd.removePositionListener(listener);
}
public void addRenderingExceptionListener(RenderingExceptionListener listener)
{
this.wwd.addRenderingExceptionListener(listener);
}
public void removeRenderingExceptionListener(RenderingExceptionListener listener)
{
this.wwd.removeRenderingExceptionListener(listener);
}
public Position getCurrentPosition()
{
return this.wwd.getCurrentPosition();
}
public PickedObjectList getObjectsAtCurrentPosition()
{
return this.wwd.getSceneController() != null ? this.wwd.getSceneController().getPickedObjectList() : null;
}
public PickedObjectList getObjectsInSelectionBox()
{
return this.wwd.getSceneController() != null ? this.wwd.getSceneController().getObjectsInPickRectangle() : null;
}
public Object setValue(String key, Object value)
{
return this.wwd.setValue(key, value);
}
public AVList setValues(AVList avList)
{
return this.wwd.setValues(avList);
}
public Object getValue(String key)
{
return this.wwd.getValue(key);
}
public Collection<Object> getValues()
{
return this.wwd.getValues();
}
public Set<Map.Entry<String, Object>> getEntries()
{
return this.wwd.getEntries();
}
public String getStringValue(String key)
{
return this.wwd.getStringValue(key);
}
public boolean hasKey(String key)
{
return this.wwd.hasKey(key);
}
public Object removeKey(String key)
{
return this.wwd.removeKey(key);
}
@Override
public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
{
super.addPropertyChangeListener(listener);
this.wwd.addPropertyChangeListener(listener);
}
@Override
public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
{
super.addPropertyChangeListener(propertyName, listener);
this.wwd.addPropertyChangeListener(propertyName, listener);
}
@Override
public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
{
super.removePropertyChangeListener(listener);
this.wwd.removePropertyChangeListener(listener);
}
@Override
public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
{
super.removePropertyChangeListener(propertyName, listener);
this.wwd.removePropertyChangeListener(propertyName, listener);
}
@Override
public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
{
super.firePropertyChange(propertyName, oldValue, newValue);
}
public void firePropertyChange(PropertyChangeEvent propertyChangeEvent)
{
this.wwd.firePropertyChange(propertyChangeEvent);
}
public AVList copy()
{
return this.wwd.copy();
}
public AVList clearList()
{
return this.wwd.clearList();
}
public void setPerFrameStatisticsKeys(Set<String> keys)
{
this.wwd.setPerFrameStatisticsKeys(keys);
}
public Collection<PerformanceStatistic> getPerFrameStatistics()
{
return this.wwd.getPerFrameStatistics();
}
}