2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
;
9 import gov
.nasa
.worldwind
.avlist
.*;
10 import gov
.nasa
.worldwind
.cache
.*;
11 import gov
.nasa
.worldwind
.exception
.WWRuntimeException
;
12 import gov
.nasa
.worldwind
.retrieve
.RetrievalService
;
13 import gov
.nasa
.worldwind
.util
.*;
15 import java
.util
.logging
.Level
;
16 import java
.beans
.PropertyChangeListener
;
20 * @version $Id: WorldWind.java 3735 2007-12-06 02:20:43Z tgaskins $
22 public final class WorldWind
24 public static final String SHUTDOWN_EVENT
= "gov.nasa.worldwind.ShutDown";
26 private static WorldWind instance
= new WorldWind();
28 private WWObjectImpl wwo
;
29 private MemoryCacheSet memoryCacheSet
;
30 private FileCache dataFileCache
;
31 private RetrievalService retrievalService
;
32 private TaskService taskService
;
33 private NetworkStatus networkStatus
;
35 private WorldWind() // Singleton, prevent public instantiation.
40 private void initialize()
42 this.wwo
= new WWObjectImpl();
43 this.retrievalService
= (RetrievalService
) createConfigurationComponent(AVKey
.RETRIEVAL_SERVICE_CLASS_NAME
);
44 this.taskService
= (TaskService
) createConfigurationComponent(AVKey
.TASK_SERVICE_CLASS_NAME
);
45 this.dataFileCache
= (FileCache
) createConfigurationComponent(AVKey
.DATA_FILE_CACHE_CLASS_NAME
);
46 this.memoryCacheSet
= (MemoryCacheSet
) createConfigurationComponent(AVKey
.MEMORY_CACHE_SET_CLASS_NAME
);
47 this.networkStatus
= (NetworkStatus
) createConfigurationComponent(AVKey
.NETWORK_STATUS_CLASS_NAME
);
50 private void dispose()
52 if (this.taskService
!= null)
53 this.taskService
.shutdown(true);
54 if (this.retrievalService
!= null)
55 this.retrievalService
.shutdown(true);
56 if (this.memoryCacheSet
!= null)
57 this.memoryCacheSet
.clear();
61 * Reinitialize World Wind to its initial ready state. Shut down and restart all World Wind services and clear all
62 * World Wind memory caches. Cache memory will be released at the next JVM garbage collection.
64 * Call this method to reduce World Wind's current resource usage to its initial, empty state. This is typically
65 * required by applets when the user leaves the applet page.
67 * World Wind can continue to be used after calling this method. The state of any existing World Wind drawables is
68 * subsequently indeterminate and they should be disposed.
70 public static synchronized void shutDown()
72 instance
.wwo
.firePropertyChange("gov.nasa.worldwind.ShutDown", null, -1);
74 instance
= new WorldWind();
75 instance
.initialize();
78 public static MemoryCacheSet
getMemoryCacheSet()
80 return instance
.memoryCacheSet
;
83 public static synchronized MemoryCache
getMemoryCache(String key
)
85 return instance
.memoryCacheSet
.getCache(key
);
88 public static FileCache
getDataFileCache()
90 return instance
.dataFileCache
;
93 public static RetrievalService
getRetrievalService()
95 return instance
.retrievalService
;
98 public static TaskService
getTaskService()
100 return instance
.taskService
;
103 public static NetworkStatus
getNetworkStatus()
105 return instance
.networkStatus
;
109 * Indicates whether World Wind will attempt to connect to the network to retrieve data or for other reasons.
111 * @return <code>true</code> if World Wind is in off-line mode, <code>false</code> if not.
114 public boolean isOfflineMode()
116 return getNetworkStatus().isOfflineMode();
120 * Indicate whether World Wind should attempt to connect to the network to retrieve data or for other reasons. The
121 * default value for this attribute is <code>false</code>, indicating that the network should be used.
123 * @param offlineMode <code>true</code> if World Wind should use the network, <code>false</code> otherwise
126 public void setOfflineMode(boolean offlineMode
)
128 getNetworkStatus().setOfflineMode(offlineMode
);
132 * @param className the full name, including package names, of the component to create
133 * @return the new component
134 * @throws WWRuntimeException if the <code>Object</code> could not be created
135 * @throws IllegalArgumentException if <code>className</code> is null or zero length
137 public static Object
createComponent(String className
) throws WWRuntimeException
139 if (className
== null || className
.length() == 0)
141 Logging
.logger().severe("WorldWind.ClassNameKeyNulZero");
142 throw new IllegalArgumentException(Logging
.getMessage("WorldWind.ClassNameKeyNulZero"));
147 Class c
= Class
.forName(className
);
148 return c
.newInstance();
152 Logging
.logger().log(Level
.SEVERE
, "WorldWind.ExceptionCreatingComponent", className
);
153 throw new WWRuntimeException(Logging
.getMessage("WorldWind.ExceptionCreatingComponent", className
), e
);
157 Logging
.logger().log(Level
.SEVERE
, "WorldWind.ErrorCreatingComponent", className
);
158 throw new WWRuntimeException(Logging
.getMessage("WorldWind.ErrorCreatingComponent", className
), t
);
163 * @param classNameKey the key identifying the component
164 * @return the new component
165 * @throws IllegalStateException if no name could be found which corresponds to <code>classNameKey</code>
166 * @throws IllegalArgumentException if <code>classNameKey<code> is null
167 * @throws WWRuntimeException if the component could not be created
169 public static Object
createConfigurationComponent(String classNameKey
)
170 throws IllegalStateException
, IllegalArgumentException
172 if (classNameKey
== null)
174 Logging
.logger().severe("WorldWind.ClassNameKeyNulZero");
175 throw new IllegalArgumentException(Logging
.getMessage("WorldWind.ClassNameKeyNulZero"));
178 String name
= Configuration
.getStringValue(classNameKey
);
181 Logging
.logger().log(Level
.SEVERE
, "WorldWind.NoClassNameInConfigurationForKey", classNameKey
);
182 throw new WWRuntimeException(
183 Logging
.getMessage("WorldWind.NoClassNameInConfigurationForKey", classNameKey
));
188 return WorldWind
.createComponent(name
);
192 Logging
.logger().log(Level
.SEVERE
, "WorldWind.UnableToCreateClassForConfigurationKey", name
);
193 throw new IllegalStateException(
194 Logging
.getMessage("WorldWind.UnableToCreateClassForConfigurationKey", name
), e
);
198 public static void setValue(String key
, String value
)
200 instance
.wwo
.setValue(key
, value
);
203 public static Object
getValue(String key
)
205 return instance
.wwo
.getValue(key
);
208 public static String
getStringValue(String key
)
210 return instance
.wwo
.getStringValue(key
);
213 public static boolean hasKey(String key
)
215 return instance
.wwo
.hasKey(key
);
218 public static void removeKey(String key
)
220 instance
.wwo
.removeKey(key
);
223 public static void addPropertyChangeListener(String propertyName
, PropertyChangeListener listener
)
225 instance
.wwo
.addPropertyChangeListener(propertyName
, listener
);
228 public static void removePropertyChangeListener(String propertyName
, PropertyChangeListener listener
)
230 instance
.wwo
.removePropertyChangeListener(propertyName
, listener
);
233 public static void addPropertyChangeListener(PropertyChangeListener listener
)
235 instance
.wwo
.addPropertyChangeListener(listener
);
238 public static void removePropertyChangeListener(PropertyChangeListener listener
)
240 instance
.wwo
.removePropertyChangeListener(listener
);