org.gjt.universe
Class UniverseData

java.lang.Object
  |
  +--org.gjt.universe.UniverseData

public class UniverseData
extends java.lang.Object

Encapsulates searching for resources (e.g. images, sounds, custom data files) used by the game into a single facade, so that callers need not know how or where these data are stored.

Currently all resources are kept in a single jar file, UniverseData.jar, which should be in the same directory as the game's jar. However, in the future a more complex scheme may be employed (e.g. to support custom variations of the game, localization, etc.).

Note that the game is unable to run without UniverseData.jar and if it is not detected or is believed to be damaged, an fatal error explaining this will be reported ot the user and the application will exit.

Note: if additional resource files are desired (in addition to UniverseData.jar, they can be automatically used just by adding the file name to the urlsToLoadFrom variable.

Some changes were made: file-handling methods will throw a FileNotFoundException instead of null, to make error handling easier (no need to test for null case).

Author:
Sean Starkey, Zach DelProposto, Allan Noordvyk

Field Summary
private static java.lang.String CHECK_FILE
           
private static java.net.URLClassLoader classLoader
           
private static UniverseData singleton
           
 
Constructor Summary
private UniverseData()
           
 
Method Summary
static void checkDataPresent()
          Checks the presence of the UniverseData.jar file, and, if not present, informs the user and exits.
static java.awt.Image getImage(java.lang.String name)
          Gets an Image to the named resource.
static javax.swing.ImageIcon getImageIcon(java.lang.String name)
          Get an ImageIcon.
static java.io.InputStream getInputStream(java.lang.String name)
          Gets an InputStream to the named resource; throws an exception if the resource could not be found.
static java.io.InputStreamReader getInputStreamReader(java.lang.String name)
          Gets an InputStreamReader to the named resource.
static java.lang.String getText(java.lang.String name)
          Returns a resource as a String.
static java.net.URL getURL(java.lang.String name)
          Given a resource name, extract a URL for the given resource.
static boolean isDataPresent()
          Check if the UniverseData.jar (or whatever it is named) is available (on the classpath).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

private static UniverseData singleton

classLoader

private static java.net.URLClassLoader classLoader

CHECK_FILE

private static final java.lang.String CHECK_FILE
See Also:
Constant Field Values
Constructor Detail

UniverseData

private UniverseData()
Method Detail

isDataPresent

public static boolean isDataPresent()
Check if the UniverseData.jar (or whatever it is named) is available (on the classpath).


checkDataPresent

public static void checkDataPresent()
Checks the presence of the UniverseData.jar file, and, if not present, informs the user and exits.


getURL

public static java.net.URL getURL(java.lang.String name)
Given a resource name, extract a URL for the given resource.


getImageIcon

public static javax.swing.ImageIcon getImageIcon(java.lang.String name)
Get an ImageIcon. Return null if an ImageIcon could not be found.


getInputStream

public static java.io.InputStream getInputStream(java.lang.String name)
                                          throws java.io.IOException
Gets an InputStream to the named resource; throws an exception if the resource could not be found.

java.io.IOException

getInputStreamReader

public static java.io.InputStreamReader getInputStreamReader(java.lang.String name)
                                                      throws java.io.IOException
Gets an InputStreamReader to the named resource.

java.io.IOException

getImage

public static java.awt.Image getImage(java.lang.String name)
Gets an Image to the named resource. Returns null if an error occurs.

We take the easy way out here....


getText

public static java.lang.String getText(java.lang.String name)
Returns a resource as a String. Note that this may not be the best choice for large resources or where additional parsing is required. If an IOException occurs, this method will return null.



Copyright © 2001 Universe Dev Team All Rights Reserved.