Package net.sf.freecol.common.resources
Class ResourceManager
- java.lang.Object
-
- net.sf.freecol.common.resources.ResourceManager
-
public class ResourceManager extends java.lang.ObjectClass for getting resources (images, audio etc).
-
-
Field Summary
Fields Modifier and Type Field Description private static FreeColDataFilebaseDataFileprivate static ResourceMappingbaseResourceMappingprivate static java.util.logging.Loggerloggerprivate static ResourceMappingmergedContainerAll the mappings are merged in order into this single ResourceMapping.private static java.util.List<ResourceMapping>modResourceMappingsprivate static java.util.List<? extends FreeColDataFile>modsprivate static booleanpreloadDoneFlag to inform the preload thead that all mappings are queued.private static java.lang.ThreadpreloadThreadThe thread that handles preloading of resources.private static FreeColSavegameFilesavegameFileprivate static ResourceMappingsavegameResourceMappingprivate static FreeColDataFiletcDataFileprivate static ResourceMappingtcResourceMapping
-
Constructor Summary
Constructors Constructor Description ResourceManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidfinishPreloading()Signal to the preload thread that no further mappings need to be loaded.static java.io.FilegetAudio(java.lang.String key)Gets an audio resource with the given name.static AudioResourcegetAudioResource(java.lang.String key, boolean warn)Get an audio resource.static java.awt.ColorgetColor(java.lang.String key, java.awt.Color replacement)Gets a color resource with the given name.static ColorResourcegetColorResource(java.lang.String key, boolean warn)Get a color resource.static FAFilegetFAFile(java.lang.String key)Gets a FAFile resource with the given name.static FAFileResourcegetFAFileResource(java.lang.String key, boolean warn)Get a FAFile resource.static java.awt.FontgetFont(java.lang.String key)Gets the font with the given name.static FontResourcegetFontResource(java.lang.String key, boolean warn)Get a font resource.static java.awt.image.BufferedImagegetImage(java.lang.String key)Get the image specified by the given key.static java.awt.image.BufferedImagegetImage(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 ImageResourcegetImageResource(java.lang.String key, boolean warn)Get an image resource.static java.lang.StringgetString(java.lang.String key)Gets a string resource with the given name.static StringResourcegetStringResource(java.lang.String key, boolean warn)Get a string resource.static SimpleZippedAnimationgetSZA(java.lang.String key)Returns the animation specified by the given name.static SimpleZippedAnimationgetSZA(java.lang.String key, float scale)Returns the animation specified by the given name.static SZAResourcegetSZAResource(java.lang.String key, boolean warn)Get a SZA resource.static VideogetVideo(java.lang.String key)Gets theVideorepresented by the given resource.static VideoResourcegetVideoResource(java.lang.String key, boolean warn)Get a video resource.static voidprepare()static voidreload()Clear all caches andstatic voidsetBaseData(FreeColDataFile baseDataFile)static <T extends FreeColDataFile>
voidsetMods(java.util.List<T> mods)static voidsetSavegameFile(FreeColSavegameFile savegameFile)static voidsetTcData(FreeColDataFile tcDataFile)static voidstartPreloading(java.lang.Runnable afterPreloadHasCompleted)Create and start a new background preload thread.static voidsummarizeImageResources(java.lang.StringBuilder sb)Summarize the image resources.private static voidwaitForPreloadingToStop()
-
-
-
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- ARunnableto 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
Filecontaining 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
Colorfound, 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
FAFilefound 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
Fontfound 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
resourceornullif 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
resourceornullif there is no animation identified by that name.
-
getVideo
public static Video getVideo(java.lang.String key)
Gets theVideorepresented 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
Videoin it's original size.
-
summarizeImageResources
public static void summarizeImageResources(java.lang.StringBuilder sb)
Summarize the image resources.- Parameters:
sb- AStringBuilderto summarize to.
-
-