Package net.sf.freecol.common.resources
Class ResourceManager
- java.lang.Object
-
- net.sf.freecol.common.resources.ResourceManager
-
public class ResourceManager extends java.lang.Object
Class for getting resources (images, audio etc).
-
-
Field Summary
Fields Modifier and Type Field Description private static FreeColDataFile
baseDataFile
private static ResourceMapping
baseResourceMapping
private static java.util.logging.Logger
logger
private static ResourceMapping
mergedContainer
All the mappings are merged in order into this single ResourceMapping.private static java.util.List<ResourceMapping>
modResourceMappings
private static java.util.List<? extends FreeColDataFile>
mods
private static boolean
preloadDone
Flag to inform the preload thead that all mappings are queued.private static java.lang.Thread
preloadThread
The thread that handles preloading of resources.private static FreeColSavegameFile
savegameFile
private static ResourceMapping
savegameResourceMapping
private static FreeColDataFile
tcDataFile
private static ResourceMapping
tcResourceMapping
-
Constructor Summary
Constructors Constructor Description ResourceManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
finishPreloading()
Signal to the preload thread that no further mappings need to be loaded.static java.io.File
getAudio(java.lang.String key)
Gets an audio resource with the given name.static AudioResource
getAudioResource(java.lang.String key, boolean warn)
Get an audio resource.static java.awt.Color
getColor(java.lang.String key, java.awt.Color replacement)
Gets a color resource with the given name.static ColorResource
getColorResource(java.lang.String key, boolean warn)
Get a color resource.static FAFile
getFAFile(java.lang.String key)
Gets a FAFile resource with the given name.static FAFileResource
getFAFileResource(java.lang.String key, boolean warn)
Get a FAFile resource.static java.awt.Font
getFont(java.lang.String key)
Gets the font with the given name.static FontResource
getFontResource(java.lang.String key, boolean warn)
Get a font resource.static java.awt.image.BufferedImage
getImage(java.lang.String key)
Get the image specified by the given key.static java.awt.image.BufferedImage
getImage(java.lang.String key, java.awt.Dimension size, boolean grayscale)
Get the image specified by the given name, size and grayscale.static java.util.List<java.lang.String>
getImageKeys(java.lang.String prefix)
Get a list of all image keys starting with the given prefix.static ImageResource
getImageResource(java.lang.String key, boolean warn)
Get an image resource.static java.lang.String
getString(java.lang.String key)
Gets a string resource with the given name.static StringResource
getStringResource(java.lang.String key, boolean warn)
Get a string resource.static SimpleZippedAnimation
getSZA(java.lang.String key)
Returns the animation specified by the given name.static SimpleZippedAnimation
getSZA(java.lang.String key, float scale)
Returns the animation specified by the given name.static SZAResource
getSZAResource(java.lang.String key, boolean warn)
Get a SZA resource.static Video
getVideo(java.lang.String key)
Gets theVideo
represented by the given resource.static VideoResource
getVideoResource(java.lang.String key, boolean warn)
Get a video resource.static void
prepare()
static void
reload()
Clear all caches andstatic void
setBaseData(FreeColDataFile baseDataFile)
static <T extends FreeColDataFile>
voidsetMods(java.util.List<T> mods)
static void
setSavegameFile(FreeColSavegameFile savegameFile)
static void
setTcData(FreeColDataFile tcDataFile)
static void
startPreloading(java.lang.Runnable afterPreloadHasCompleted)
Create and start a new background preload thread.static void
summarizeImageResources(java.lang.StringBuilder sb)
Summarize the image resources.private static void
waitForPreloadingToStop()
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
preloadThread
private static java.lang.Thread preloadThread
The thread that handles preloading of resources.
-
preloadDone
private static volatile boolean preloadDone
Flag to inform the preload thead that all mappings are queued.
-
mergedContainer
private static ResourceMapping mergedContainer
All the mappings are merged in order into this single ResourceMapping.
-
baseDataFile
private static FreeColDataFile baseDataFile
-
baseResourceMapping
private static ResourceMapping baseResourceMapping
-
tcDataFile
private static FreeColDataFile tcDataFile
-
tcResourceMapping
private static ResourceMapping tcResourceMapping
-
mods
private static java.util.List<? extends FreeColDataFile> mods
-
modResourceMappings
private static java.util.List<ResourceMapping> modResourceMappings
-
savegameFile
private static FreeColSavegameFile savegameFile
-
savegameResourceMapping
private static ResourceMapping savegameResourceMapping
-
-
Method Detail
-
setBaseData
public static void setBaseData(FreeColDataFile baseDataFile)
-
setTcData
public static void setTcData(FreeColDataFile tcDataFile)
-
setMods
public static <T extends FreeColDataFile> void setMods(java.util.List<T> mods)
-
setSavegameFile
public static void setSavegameFile(FreeColSavegameFile savegameFile)
-
prepare
public static void prepare()
-
reload
public static void reload()
Clear all caches and
-
waitForPreloadingToStop
private static void waitForPreloadingToStop()
-
startPreloading
public static void startPreloading(java.lang.Runnable afterPreloadHasCompleted)
Create and start a new background preload thread. Synchronization protects preloadThread. The thread is the only place mergedContainer is written.- Parameters:
afterPreloadHasCompleted
- ARunnable
to run when it says.
-
finishPreloading
public static void finishPreloading()
Signal to the preload thread that no further mappings need to be loaded.
-
getAudioResource
public static AudioResource getAudioResource(java.lang.String key, boolean warn)
Get an audio resource.- Parameters:
key
- The resource to get.warn
- Log a warning if the resource is not found.- Returns:
- The resource if there is one with the given
resource key and type, or else
null
.
-
getColorResource
public static ColorResource getColorResource(java.lang.String key, boolean warn)
Get a color resource.- Parameters:
key
- The resource to get.warn
- Log a warning if the resource is not found.- Returns:
- The resource if there is one with the given
resource key and type, or else
null
.
-
getFAFileResource
public static FAFileResource getFAFileResource(java.lang.String key, boolean warn)
Get a FAFile resource.- Parameters:
key
- The resource to get.warn
- Log a warning if the resource is not found.- Returns:
- The resource if there is one with the given
resource key and type, or else
null
.
-
getFontResource
public static FontResource getFontResource(java.lang.String key, boolean warn)
Get a font resource.- Parameters:
key
- The resource to get.warn
- Log a warning if the resource is not found.- Returns:
- The resource if there is one with the given
resource key and type, or else
null
.
-
getImageResource
public static ImageResource getImageResource(java.lang.String key, boolean warn)
Get an image resource.- Parameters:
key
- The resource to get.warn
- Log a warning if the resource is not found.- Returns:
- The resource if there is one with the given
resource key and type, or else
null
.
-
getStringResource
public static StringResource getStringResource(java.lang.String key, boolean warn)
Get a string resource.- Parameters:
key
- The resource to get.warn
- Log a warning if the resource is not found.- Returns:
- The resource if there is one with the given
resource key and type, or else
null
.
-
getSZAResource
public static SZAResource getSZAResource(java.lang.String key, boolean warn)
Get a SZA resource.- Parameters:
key
- The resource to get.warn
- Log a warning if the resource is not found.- Returns:
- The resource if there is one with the given
resource key and type, or else
null
.
-
getVideoResource
public static VideoResource getVideoResource(java.lang.String key, boolean warn)
Get a video resource.- Parameters:
key
- The resource to get.warn
- Log a warning if the resource is not found.- Returns:
- The resource if there is one with the given
resource key and type, or else
null
.
-
getAudio
public static java.io.File getAudio(java.lang.String key)
Gets an audio resource with the given name. This can return null as there as not all necessary sounds have been added to the game. FIXME: Change calling code to check using hasResource, then replace null return with calling FreeColClient.fatal on error.- Parameters:
key
- The name of the resource to query.- Returns:
- A
File
containing the audio data.
-
getColor
public static java.awt.Color getColor(java.lang.String key, java.awt.Color replacement)
Gets a color resource with the given name.- Parameters:
key
- The name of the resource to query.replacement
- A fallback color.- Returns:
- The
Color
found, or if not found, the replacement color, or finally the generic replacement color.
-
getFAFile
public static FAFile getFAFile(java.lang.String key)
Gets a FAFile resource with the given name. This can return null as there is only one FAFile in FreeCol. FIXME: Consider calling FreeColClient.fatal on error.- Parameters:
key
- The name of the resource to query.- Returns:
- The
FAFile
found in a FAFileResource.
-
getFont
public static java.awt.Font getFont(java.lang.String key)
Gets the font with the given name.- Parameters:
key
- The name of the resource to query.- Returns:
- The
Font
found in a FontResource, or the default Java font if not found.
-
getImage
public static java.awt.image.BufferedImage getImage(java.lang.String key)
Get the image specified by the given key.- Parameters:
key
- The name of the resource to return.- Returns:
- The image identified by
resource
.
-
getImage
public static java.awt.image.BufferedImage getImage(java.lang.String key, java.awt.Dimension size, boolean grayscale)
Get the image specified by the given name, size and grayscale.- Parameters:
key
- The name of the resource to return.size
- The size of the requested image. Rescaling will be performed if necessary.grayscale
- If true return a grayscale image.- Returns:
- The image identified by
resource
.
-
getImageKeys
public static java.util.List<java.lang.String> getImageKeys(java.lang.String prefix)
Get a list of all image keys starting with the given prefix.- Parameters:
prefix
- The prefix.- Returns:
- A list of all image resource keys starting with the prefix.
-
getString
public static java.lang.String getString(java.lang.String key)
Gets a string resource with the given name. Trying to get a nonexisting string is an error, but returns a replacement string to prevent crashes.- Parameters:
key
- The name of the resource to query.- Returns:
- The string value.
-
getSZA
public static SimpleZippedAnimation getSZA(java.lang.String key)
Returns the animation specified by the given name. As the artwork is still incomplete and animations exist only for some military units, null can still be returned in many cases. FIXME: Check using hasResource before calling this, then replace null return with calling FreeColClient.fatal on error.- Parameters:
key
- The name of the resource to return.- Returns:
- The animation identified by
resource
ornull
if there is no animation identified by that name.
-
getSZA
public static SimpleZippedAnimation getSZA(java.lang.String key, float scale)
Returns the animation specified by the given name.- Parameters:
key
- 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
ornull
if there is no animation identified by that name.
-
getVideo
public static Video getVideo(java.lang.String key)
Gets theVideo
represented by the given resource. This can return null as there is only one video in FreeCol. FIXME: Consider calling FreeColClient.fatal on error.- Parameters:
key
- The name of the resource to return.- Returns:
- The
Video
in it's original size.
-
summarizeImageResources
public static void summarizeImageResources(java.lang.StringBuilder sb)
Summarize the image resources.- Parameters:
sb
- AStringBuilder
to summarize to.
-
-