forked from NASAWorldWind/WorldWindJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldWindowImpl.java
More file actions
321 lines (268 loc) · 9.22 KB
/
Copy pathWorldWindowImpl.java
File metadata and controls
321 lines (268 loc) · 9.22 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
/*
* 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;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.cache.*;
import gov.nasa.worldwind.event.*;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.Layer;
import gov.nasa.worldwind.pick.*;
import gov.nasa.worldwind.util.*;
import javax.swing.event.*;
import java.awt.*;
import java.util.*;
/**
* An implementation class for the {@link WorldWindow} interface. Classes implementing <code>WorldWindow</code> can
* subclass or aggregate this object to provide default <code>WorldWindow</code> functionality.
*
* @author Tom Gaskins
* @version $Id: WorldWindowImpl.java 1855 2014-02-28 23:01:02Z tgaskins $
*/
public abstract class WorldWindowImpl extends WWObjectImpl implements WorldWindow
{
private SceneController sceneController;
private final EventListenerList eventListeners = new EventListenerList();
private InputHandler inputHandler;
protected GpuResourceCache gpuResourceCache;
public WorldWindowImpl()
{
this.sceneController = (SceneController) WorldWind.createConfigurationComponent(
AVKey.SCENE_CONTROLLER_CLASS_NAME);
// Set up to initiate a repaint whenever a file is retrieved and added to the local file store.
WorldWind.getDataFileStore().addPropertyChangeListener(this);
}
/**
* Causes resources used by the WorldWindow to be freed. The WorldWindow cannot be used once this method is
* called. An OpenGL context for the window must be current.
*/
public void shutdown()
{
WorldWind.getDataFileStore().removePropertyChangeListener(this);
if (this.inputHandler != null)
{
this.inputHandler.dispose();
this.inputHandler = new NoOpInputHandler();
}
// Clear the texture cache
if (this.getGpuResourceCache() != null)
this.getGpuResourceCache().clear();
// Dispose all the layers // TODO: Need per-window dispose for layers
if (this.getModel() != null && this.getModel().getLayers() != null)
{
for (Layer layer : this.getModel().getLayers())
{
try
{
layer.dispose();
}
catch (Exception e)
{
Logging.logger().log(java.util.logging.Level.SEVERE, Logging.getMessage(
"WorldWindowGLCanvas.ExceptionWhileShuttingDownWorldWindow"), e);
}
}
}
SceneController sc = this.getSceneController();
if (sc != null)
sc.dispose();
}
public GpuResourceCache getGpuResourceCache()
{
return this.gpuResourceCache;
}
public void setGpuResourceCache(GpuResourceCache gpuResourceCache)
{
this.gpuResourceCache = gpuResourceCache;
this.sceneController.setGpuResourceCache(this.gpuResourceCache);
}
public void setModel(Model model)
{
// model can be null, that's ok - it indicates no model.
if (this.sceneController != null)
this.sceneController.setModel(model);
}
public Model getModel()
{
return this.sceneController != null ? this.sceneController.getModel() : null;
}
public void setView(View view)
{
// view can be null, that's ok - it indicates no view.
if (this.sceneController != null)
this.sceneController.setView(view);
}
public View getView()
{
return this.sceneController != null ? this.sceneController.getView() : null;
}
public void setModelAndView(Model model, View view)
{
this.setModel(model);
this.setView(view);
}
public SceneController getSceneController()
{
return this.sceneController;
}
public void setSceneController(SceneController sc)
{
if (sc != null && this.getSceneController() != null)
{
sc.setGpuResourceCache(this.sceneController.getGpuResourceCache());
}
this.sceneController = sc;
}
public InputHandler getInputHandler()
{
return this.inputHandler;
}
public void setInputHandler(InputHandler inputHandler)
{
this.inputHandler = inputHandler;
}
public void redraw()
{
}
public void redrawNow()
{
}
public void setPerFrameStatisticsKeys(Set<String> keys)
{
if (this.sceneController != null)
this.sceneController.setPerFrameStatisticsKeys(keys);
}
public Collection<PerformanceStatistic> getPerFrameStatistics()
{
if (this.sceneController == null || this.sceneController.getPerFrameStatistics() == null)
return new ArrayList<PerformanceStatistic>(0);
return this.sceneController.getPerFrameStatistics();
}
public PickedObjectList getObjectsAtCurrentPosition()
{
return null;
}
public PickedObjectList getObjectsInSelectionBox()
{
return null;
}
public Position getCurrentPosition()
{
if (this.sceneController == null)
return null;
PickedObjectList pol = this.getSceneController().getPickedObjectList();
if (pol == null || pol.size() < 1)
return null;
Position p = null;
PickedObject top = pol.getTopPickedObject();
if (top != null && top.hasPosition())
p = top.getPosition();
else if (pol.getTerrainObject() != null)
p = pol.getTerrainObject().getPosition();
return p;
}
protected PickedObject getCurrentSelection()
{
if (this.sceneController == null)
return null;
PickedObjectList pol = this.getSceneController().getPickedObjectList();
if (pol == null || pol.size() < 1)
return null;
PickedObject top = pol.getTopPickedObject();
return top.isTerrain() ? null : top;
}
protected PickedObjectList getCurrentBoxSelection()
{
if (this.sceneController == null)
return null;
PickedObjectList pol = this.sceneController.getObjectsInPickRectangle();
return pol != null && pol.size() > 0 ? pol : null;
}
public void addRenderingListener(RenderingListener listener)
{
this.eventListeners.add(RenderingListener.class, listener);
}
public void removeRenderingListener(RenderingListener listener)
{
this.eventListeners.remove(RenderingListener.class, listener);
}
protected void callRenderingListeners(RenderingEvent event)
{
for (RenderingListener listener : this.eventListeners.getListeners(RenderingListener.class))
{
listener.stageChanged(event);
}
}
public void addPositionListener(PositionListener listener)
{
this.eventListeners.add(PositionListener.class, listener);
}
public void removePositionListener(PositionListener listener)
{
this.eventListeners.remove(PositionListener.class, listener);
}
protected void callPositionListeners(final PositionEvent event)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
for (PositionListener listener : eventListeners.getListeners(PositionListener.class))
{
listener.moved(event);
}
}
});
}
public void addSelectListener(SelectListener listener)
{
this.eventListeners.add(SelectListener.class, listener);
}
public void removeSelectListener(SelectListener listener)
{
this.eventListeners.remove(SelectListener.class, listener);
}
protected void callSelectListeners(final SelectEvent event)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
for (SelectListener listener : eventListeners.getListeners(SelectListener.class))
{
listener.selected(event);
}
}
});
}
public void addRenderingExceptionListener(RenderingExceptionListener listener)
{
this.eventListeners.add(RenderingExceptionListener.class, listener);
}
public void removeRenderingExceptionListener(RenderingExceptionListener listener)
{
this.eventListeners.remove(RenderingExceptionListener.class, listener);
}
protected void callRenderingExceptionListeners(final Throwable exception)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
for (RenderingExceptionListener listener : eventListeners.getListeners(
RenderingExceptionListener.class))
{
listener.exceptionThrown(exception);
}
}
});
}
private static final long FALLBACK_TEXTURE_CACHE_SIZE = 60000000;
public static GpuResourceCache createGpuResourceCache()
{
long cacheSize = Configuration.getLongValue(AVKey.TEXTURE_CACHE_SIZE, FALLBACK_TEXTURE_CACHE_SIZE);
return new BasicGpuResourceCache((long) (0.8 * cacheSize), cacheSize);
}
}