net.sf.freecol.common.resources
Class ResourceManager

java.lang.Object
  extended by net.sf.freecol.common.resources.ResourceManager

public class ResourceManager
extends java.lang.Object

Class for getting resources (images, audio etc).


Field Summary
private static ResourceMapping baseMapping
           
private static ResourceMapping campaignMapping
           
private static boolean dirty
           
private static java.awt.Dimension lastWindowSize
           
private static ResourceMapping mergedContainer
           
private static java.util.List<ResourceMapping> modMappings
           
private static java.lang.Thread preloadThread
           
private static ResourceMapping scenarioMapping
           
private static ResourceMapping tcMapping
           
 
Constructor Summary
ResourceManager()
           
 
Method Summary
private static void createMergedContainer()
          Creates a merged container for easy access to resources.
static java.awt.Color getColor(java.lang.String resource)
          Returns the Color with the given name.
static java.awt.Image getGrayscaleImage(java.lang.String resource, java.awt.Dimension size)
          Returns the a grayscale version of the image specified by the given name.
static java.awt.Image getGrayscaleImage(java.lang.String resource, double scale)
          Returns the grayscale version of the image specified by the given name.
static java.awt.Image getImage(java.lang.String resource)
          Returns the image specified by the given name.
static java.awt.Image getImage(java.lang.String resource, java.awt.Dimension size)
          Returns the image specified by the given name.
static java.awt.Image getImage(java.lang.String resource, double scale)
          Returns the image specified by the given name.
static javax.swing.ImageIcon getImageIcon(java.lang.String resource)
          Creates an ImageIcon for the image of the given name.
private static
<T> T
getResource(java.lang.String resourceId, java.lang.Class<T> type)
          Returns the resource of the given type.
static SimpleZippedAnimation getSimpleZippedAnimation(java.lang.String resource)
          Returns the animation specified by the given name.
static SimpleZippedAnimation getSimpleZippedAnimation(java.lang.String resource, double scale)
          Returns the animation specified by the given name.
static Video getVideo(java.lang.String resource)
          Gets the Video represented by the given resource.
static void preload(java.awt.Dimension windowSize)
          Preload resources.
static void setBaseMapping(ResourceMapping _baseMapping)
          Sets the mappings specified in the date/base-directory
static void setCampaignMapping(ResourceMapping _campaignMapping)
          Sets the mappings specified in a campaign.
static void setModMappings(java.util.List<ResourceMapping> _modMappings)
          Sets the mappings specified by mods.
static void setScenarioMapping(ResourceMapping _scenarioMapping)
          Sets the mappings specified in a scenario.
static void setTcMapping(ResourceMapping _tcMapping)
          Sets the mappings specified for a Total Conversion (TC).
static void startBackgroundPreloading(java.awt.Dimension windowSize)
          Starts background preloading of resources.
private static void updateIfDirty()
          Updates the resource mappings after making changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseMapping

private static ResourceMapping baseMapping

tcMapping

private static ResourceMapping tcMapping

campaignMapping

private static ResourceMapping campaignMapping

scenarioMapping

private static ResourceMapping scenarioMapping

modMappings

private static java.util.List<ResourceMapping> modMappings

mergedContainer

private static ResourceMapping mergedContainer

preloadThread

private static volatile java.lang.Thread preloadThread

dirty

private static volatile boolean dirty

lastWindowSize

private static java.awt.Dimension lastWindowSize
Constructor Detail

ResourceManager

public ResourceManager()
Method Detail

setBaseMapping

public static void setBaseMapping(ResourceMapping _baseMapping)
Sets the mappings specified in the date/base-directory

Parameters:
_baseMapping - The mapping between IDs and files.

setTcMapping

public static void setTcMapping(ResourceMapping _tcMapping)
Sets the mappings specified for a Total Conversion (TC).

Parameters:
_tcMapping - The mapping between IDs and files.

setModMappings

public static void setModMappings(java.util.List<ResourceMapping> _modMappings)
Sets the mappings specified by mods.

Parameters:
_modMappings - A list of the mapping between IDs and files.

setCampaignMapping

public static void setCampaignMapping(ResourceMapping _campaignMapping)
Sets the mappings specified in a campaign.

Parameters:
_campaignMapping - The mapping between IDs and files.

setScenarioMapping

public static void setScenarioMapping(ResourceMapping _scenarioMapping)
Sets the mappings specified in a scenario.

Parameters:
_scenarioMapping - The mapping between IDs and files.

preload

public static void preload(java.awt.Dimension windowSize)
Preload resources. This method is intended to be called when starting the application, as it blocks until resources needed for the first panels have been loaded. It also ensures that the background preloading thread is started.

Parameters:
windowSize -

startBackgroundPreloading

public static void startBackgroundPreloading(java.awt.Dimension windowSize)
Starts background preloading of resources.

Parameters:
windowSize - The window size to use when scaling full screen size images.

updateIfDirty

private static void updateIfDirty()
Updates the resource mappings after making changes.


createMergedContainer

private static void createMergedContainer()
Creates a merged container for easy access to resources.


getResource

private static <T> T getResource(java.lang.String resourceId,
                                 java.lang.Class<T> type)
Returns the resource of the given type.

Type Parameters:
T - The type of the resource to get.
Parameters:
resourceId - The resource to get.
type - The type of the resource to get.
Returns:
The resource if there is one with the given resourceId and type, or else null.

getSimpleZippedAnimation

public static SimpleZippedAnimation getSimpleZippedAnimation(java.lang.String resource)
Returns the animation specified by the given name.

Parameters:
resource - The name of the resource to return.
Returns:
The animation identified by resource or null if there is no animation identified by that name.

getVideo

public static Video getVideo(java.lang.String resource)
Gets the Video represented by the given resource.

Returns:
The Video in it's original size.

getSimpleZippedAnimation

public static SimpleZippedAnimation getSimpleZippedAnimation(java.lang.String resource,
                                                             double scale)
Returns the animation specified by the given name.

Parameters:
resource - The name of the resource to return.
scale - The size of the requested animation (with 1 being normal size, 2 twice the size, 0.5 half the size etc). Rescaling will be performed unless using 1.
Returns:
The animation identified by resource or null if there is no animation identified by that name.

getImage

public static java.awt.Image getImage(java.lang.String resource)
Returns the image specified by the given name.

Parameters:
resource - The name of the resource to return.
Returns:
The image identified by resource or null if there is no image identified by that name.

getImage

public static java.awt.Image getImage(java.lang.String resource,
                                      double scale)
Returns the image specified by the given name.

Parameters:
resource - The name of the resource to return.
scale - The size of the requested image (with 1 being normal size, 2 twice the size, 0.5 half the size etc). Rescaling will be performed unless using 1.
Returns:
The image identified by resource or null if there is no image identified by that name.

getImage

public static java.awt.Image getImage(java.lang.String resource,
                                      java.awt.Dimension size)
Returns the image specified by the given name.

Parameters:
resource - The name of the resource to return.
size - The size of the requested image. Rescaling will be performed if necessary.
Returns:
The image identified by resource or null if there is no image identified by that name.

getGrayscaleImage

public static java.awt.Image getGrayscaleImage(java.lang.String resource,
                                               java.awt.Dimension size)
Returns the a grayscale version of the image specified by the given name.

Parameters:
resource - The name of the resource to return.
size - The size of the requested image. Rescaling will be performed if necessary.
Returns:
The image identified by resource or null if there is no image identified by that name.

getGrayscaleImage

public static java.awt.Image getGrayscaleImage(java.lang.String resource,
                                               double scale)
Returns the grayscale version of the image specified by the given name.

Parameters:
resource - The name of the resource to return.
scale - The size of the requested image (with 1 being normal size, 2 twice the size, 0.5 half the size etc). Rescaling will be performed unless using 1.
Returns:
The image identified by resource or null if there is no image identified by that name.

getImageIcon

public static javax.swing.ImageIcon getImageIcon(java.lang.String resource)
Creates an ImageIcon for the image of the given name.

Parameters:
resource - The name of the resource to return.
Returns:
An ImageIcon created with the image identified by resource or null if there is no image identified by that name.
See Also:
getImage(String)

getColor

public static java.awt.Color getColor(java.lang.String resource)
Returns the Color with the given name.

Parameters:
resource - The name of the resource to return.
Returns:
An Color created with the image identified by resource or null if there is no color identified by that name.
See Also:
getImage(String)