-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathWorldWind.java
More file actions
316 lines (275 loc) · 10.8 KB
/
WorldWind.java
File metadata and controls
316 lines (275 loc) · 10.8 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
/*
* 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.exception.WWRuntimeException;
import gov.nasa.worldwind.formats.tiff.GeotiffImageReaderSpi;
import gov.nasa.worldwind.retrieve.RetrievalService;
import gov.nasa.worldwind.util.*;
import javax.imageio.spi.IIORegistry;
import com.jogamp.opengl.GL;
import java.beans.PropertyChangeListener;
import java.util.logging.Level;
/**
* @author Tom Gaskins
* @version $Id: WorldWind.java 1171 2013-02-11 21:45:02Z dcollins $
*/
public final class WorldWind
{
public static final String SHUTDOWN_EVENT = "gov.nasa.worldwind.ShutDown";
// Altitude modes
public static final int ABSOLUTE = 0;
public static final int CLAMP_TO_GROUND = 1;
public static final int RELATIVE_TO_GROUND = 2;
public static final int CONSTANT = 3;
// Path types (Don't use these. Use the AVKey versions instead. Only Polyline still uses these.)
public final static int GREAT_CIRCLE = 0;
public final static int LINEAR = 1;
public final static int RHUMB_LINE = 2;
// Anti-alias hints
public final static int ANTIALIAS_DONT_CARE = GL.GL_DONT_CARE;
public final static int ANTIALIAS_FASTEST = GL.GL_FASTEST;
public final static int ANTIALIAS_NICEST = GL.GL_NICEST;
private static WorldWind instance = new WorldWind();
private WWObjectImpl wwo;
private MemoryCacheSet memoryCacheSet;
private FileStore dataFileStore;
private RetrievalService remoteRetrievalService;
private RetrievalService localRetrievalService;
private TaskService taskService;
private ScheduledTaskService scheduledTaskService;
private NetworkStatus networkStatus;
private SessionCache sessionCache;
private WorldWind() // Singleton, prevent public instantiation.
{
this.initialize();
}
private void initialize()
{
this.wwo = new WWObjectImpl();
this.remoteRetrievalService = (RetrievalService) createConfigurationComponent(
AVKey.RETRIEVAL_SERVICE_CLASS_NAME);
this.localRetrievalService = (RetrievalService) createConfigurationComponent(
AVKey.RETRIEVAL_SERVICE_CLASS_NAME);
this.taskService = (TaskService) createConfigurationComponent(AVKey.TASK_SERVICE_CLASS_NAME);
this.dataFileStore = (FileStore) createConfigurationComponent(AVKey.DATA_FILE_STORE_CLASS_NAME);
this.memoryCacheSet = (MemoryCacheSet) createConfigurationComponent(AVKey.MEMORY_CACHE_SET_CLASS_NAME);
this.networkStatus = (NetworkStatus) createConfigurationComponent(AVKey.NETWORK_STATUS_CLASS_NAME);
this.sessionCache = (SessionCache) createConfigurationComponent(AVKey.SESSION_CACHE_CLASS_NAME);
this.scheduledTaskService = new BasicScheduledTaskService();
// Seems like an unlikely place to load the tiff reader, but do it here nonetheless.
IIORegistry.getDefaultInstance().registerServiceProvider(GeotiffImageReaderSpi.inst());
}
private void dispose()
{
if (this.taskService != null)
this.taskService.shutdown(true);
if (this.remoteRetrievalService != null)
this.remoteRetrievalService.shutdown(true);
if (this.localRetrievalService != null)
this.localRetrievalService.shutdown(true);
if (this.memoryCacheSet != null)
this.memoryCacheSet.clear();
if (this.sessionCache != null)
this.sessionCache.clear();
if (this.scheduledTaskService != null)
this.scheduledTaskService.shutdown(true);
}
/**
* Reinitialize WorldWind to its initial ready state. Shut down and restart all WorldWind services and clear all
* WorldWind memory caches. Cache memory will be released at the next JVM garbage collection.
* <p/>
* Call this method to reduce WorldWind's current resource usage to its initial, empty state.
* <p/>
* The state of any open {@link WorldWindow} objects is indeterminate subsequent to invocation of this method. The
* core WorldWindow objects attempt to shut themselves down cleanly during the call, but their resulting window
* state is undefined.
* <p/>
* WorldWind can continue to be used after calling this method.
*/
public static synchronized void shutDown()
{
instance.wwo.firePropertyChange(SHUTDOWN_EVENT, null, -1);
instance.dispose();
instance = new WorldWind();
}
public static MemoryCacheSet getMemoryCacheSet()
{
return instance.memoryCacheSet;
}
public static synchronized MemoryCache getMemoryCache(String key)
{
return instance.memoryCacheSet.getCache(key);
}
public static FileStore getDataFileStore()
{
return instance.dataFileStore;
}
public static RetrievalService getRetrievalService()
{
return instance.remoteRetrievalService;
}
public static RetrievalService getRemoteRetrievalService()
{
return instance.remoteRetrievalService;
}
public static RetrievalService getLocalRetrievalService()
{
return instance.localRetrievalService;
}
public static TaskService getTaskService()
{
return instance.taskService;
}
/**
* Get the scheduled task service. This service can be used to scheduled tasks that execute after a delay, or
* execute repeatedly.
*
* @return the scheduled task service.
*/
public static ScheduledTaskService getScheduledTaskService()
{
return instance.scheduledTaskService;
}
public static NetworkStatus getNetworkStatus()
{
return instance.networkStatus;
}
public static SessionCache getSessionCache()
{
return instance.sessionCache;
}
/**
* Indicates whether WorldWind will attempt to connect to the network to retrieve data or for other reasons.
*
* @return <code>true</code> if WorldWind is in off-line mode, <code>false</code> if not.
*
* @see NetworkStatus
*/
public static boolean isOfflineMode()
{
return getNetworkStatus().isOfflineMode();
}
/**
* Indicate whether WorldWind should attempt to connect to the network to retrieve data or for other reasons. The
* default value for this attribute is <code>false</code>, indicating that the network should be used.
*
* @param offlineMode <code>true</code> if WorldWind should use the network, <code>false</code> otherwise
*
* @see NetworkStatus
*/
public static void setOfflineMode(boolean offlineMode)
{
getNetworkStatus().setOfflineMode(offlineMode);
}
/**
* @param className the full name, including package names, of the component to create
*
* @return the new component
*
* @throws WWRuntimeException if the <code>Object</code> could not be created
* @throws IllegalArgumentException if <code>className</code> is null or zero length
*/
public static Object createComponent(String className) throws WWRuntimeException
{
if (className == null || className.length() == 0)
{
Logging.logger().severe("nullValue.ClassNameIsNull");
throw new IllegalArgumentException(Logging.getMessage("nullValue.ClassNameIsNull"));
}
try
{
Class c = Class.forName(className.trim());
return c.newInstance();
}
catch (Exception e)
{
Logging.logger().log(Level.SEVERE, "WorldWind.ExceptionCreatingComponent", className);
throw new WWRuntimeException(Logging.getMessage("WorldWind.ExceptionCreatingComponent", className), e);
}
catch (Throwable t)
{
Logging.logger().log(Level.SEVERE, "WorldWind.ErrorCreatingComponent", className);
throw new WWRuntimeException(Logging.getMessage("WorldWind.ErrorCreatingComponent", className), t);
}
}
/**
* @param classNameKey the key identifying the component
*
* @return the new component
*
* @throws IllegalStateException if no name could be found which corresponds to <code>classNameKey</code>
* @throws IllegalArgumentException if <code>classNameKey<code> is null
* @throws WWRuntimeException if the component could not be created
*/
public static Object createConfigurationComponent(String classNameKey)
throws IllegalStateException, IllegalArgumentException
{
if (classNameKey == null || classNameKey.length() == 0)
{
Logging.logger().severe("nullValue.ClassNameKeyNullZero");
throw new IllegalArgumentException(Logging.getMessage("nullValue.ClassNameKeyNullZero"));
}
String name = Configuration.getStringValue(classNameKey);
if (name == null)
{
Logging.logger().log(Level.SEVERE, "WorldWind.NoClassNameInConfigurationForKey", classNameKey);
throw new WWRuntimeException(
Logging.getMessage("WorldWind.NoClassNameInConfigurationForKey", classNameKey));
}
try
{
return WorldWind.createComponent(name.trim());
}
catch (Throwable e)
{
Logging.logger().log(Level.SEVERE, "WorldWind.UnableToCreateClassForConfigurationKey", name);
throw new IllegalStateException(
Logging.getMessage("WorldWind.UnableToCreateClassForConfigurationKey", name), e);
}
}
public static void setValue(String key, Object value)
{
instance.wwo.setValue(key, value);
}
public static void setValue(String key, String value)
{
instance.wwo.setValue(key, value);
}
public static Object getValue(String key)
{
return instance.wwo.getValue(key);
}
public static String getStringValue(String key)
{
return instance.wwo.getStringValue(key);
}
public static boolean hasKey(String key)
{
return instance.wwo.hasKey(key);
}
public static void removeKey(String key)
{
instance.wwo.removeKey(key);
}
public static void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
{
instance.wwo.addPropertyChangeListener(propertyName, listener);
}
public static void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
{
instance.wwo.removePropertyChangeListener(propertyName, listener);
}
public static void addPropertyChangeListener(PropertyChangeListener listener)
{
instance.wwo.addPropertyChangeListener(listener);
}
public static void removePropertyChangeListener(PropertyChangeListener listener)
{
instance.wwo.removePropertyChangeListener(listener);
}
}