# Class Resources

java.lang.Object
com.codename1.ui.util.Resources

Direct Known Subclasses:
  `MutableResource`

public class Resources extends Object
Loads resources from the binary resource file generated by the Codename One Designer. A resource is loaded entirely into memory since random file access is not supported in all platforms. Any other approach would be inefficient. This means that memory must be made available to accommodate the resource file.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `InputStream`
  `getData(String id)`
  Returns the data resource from the file
  `String[]`
  `getDataResourceNames()`
  Returns the names of the data resources within this bundle
  `Font`
  `getFont(String id)`
  Returns the font resource from the file
  `String[]`
  `getFontResourceNames()`
  Returns the names of the fonts within this bundle
  `static Resources`
  `getGlobalResources()`
  Global resources are used by new GUI builder apps to keep track of the applications resources
  `Image`
  `getImage(String id)`
  Returns the image resource from the file
  `String[]`
  `getImageResourceNames()`
  Returns the names of the images within this bundle
  `Hashtable<String,String>`
  `getL10N(String id, String locale)`
  Returns a hashmap containing localized String key/value pairs for the given locale name
  `String[]`
  `getL10NResourceNames()`
  Returns the names of the localization bundles within this bundle
  `int`
  `getMajorVersion()`
  Returns the version number for this resource file.
  `String[]`
  `getMetaData()`
  Returns optional meta-data associated with the resource file
  `int`
  `getMinorVersion()`
  Returns the minor version number for this resource file This value relates to the value from the header defined by the resource file specification.
  `String[]`
  `getResourceNames()`
  Returns the names of the resources within this bundle
  `static Resources`
  `getSystemResource()`
  Gets the system resource which can be located /CN1Images.res.
  `Hashtable`
  `getTheme(String id)`
  Returns the theme resource from the file
  `String[]`
  `getThemeResourceNames()`
  Returns the names of the images within this bundle
  `String[]`
  `getUIResourceNames()`
  Returns the names of the ui resources within this bundle
  `boolean`
  `isAnimation(String name)`
  Returns true if this is an animation resource
  `boolean`
  `isData(String name)`
  Returns true if this is a data resource
  `static boolean`
  `isEnableMediaQueries()`
  `static boolean`
  `isFailOnMissingTruetype()`

  ###### Returns

  `boolean`
  `isFont(String name)`
  Returns true if this is a font resource
  `boolean`
  `isImage(String name)`
  Returns true if this is an image resource
  `boolean`
  `isL10N(String name)`
  Returns true if this is a generic data resource
  `boolean`
  `isTheme(String name)`
  Returns true if this is a theme resource
  `boolean`
  `isUI(String name)`
  Returns true if this is a UI resource
  `Collection<String>`
  `l10NLocaleSet(String id)`
  Returns a collection of the l10 locale names
  `Enumeration`
  `listL10NLocales(String id)`
  Returns an enumration of the locales supported by this resource id
  `static Resources`
  `open(InputStream resource)`
  Creates a resource object from the given input stream
  `static Resources`
  `open(InputStream resource, int dpi)`
  Creates a resource object from the given input stream
  `static Resources`
  `open(String resource)`
  Creates a resource object from the local JAR resource identifier
  `static Resources`
  `open(String resource, int dpi)`
  Creates a resource object from the local JAR resource identifier
  `static Resources`
  `openLayered(String resource)`
  Opens a multi-layer resource file that supports overriding features on a specific platform.
  `static Resources`
  `openLayered(String resource, int dpi)`
  Opens a multi-layer resource file that supports overriding features on a specific platform.
  `void`
  `override(InputStream input)`
  This method allows overriding the data of a resource file with another resource file thus replacing or enhancing existing content with platform specific content.
  `static void`
  `setEnableMediaQueries(boolean enable)`
  `static void`
  `setFailOnMissingTruetype(boolean aFailOnMissingTruetype)`

  ###### Parameters

  `static void`
  `setGlobalResources(Resources res)`
  Global resources are used by new GUI builder apps to keep track of the applications resources
  `static void`
  `setPassword(String password)`
  Sets the password to use for password protected resource files
  `static void`
  `setRuntimeMultiImageEnabled(boolean b)`
  This flag should be off and it is off by default, some special case implementations for development e.g.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `final Class`
  `getClass()`
  Returns the runtime class of an object.
  `int`
  `hashCode()`
  Returns a hash code value for the object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes current thread to wait until another thread invokes the method or the method for this object.
  `final void`
  `wait(long timeout)`
  Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
  `final void`
  `wait(long timeout, int nanos)`
  Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

- ## Method Details

  - ### isFailOnMissingTruetype

    public static boolean isFailOnMissingTruetype()

    ###### Returns

    the failOnMissingTruetype

  - ### setFailOnMissingTruetype

    public static void setFailOnMissingTruetype(boolean aFailOnMissingTruetype)

    ###### Parameters

    - `aFailOnMissingTruetype`: the failOnMissingTruetype to set

  - ### isEnableMediaQueries

    public static boolean isEnableMediaQueries()

  - ### setEnableMediaQueries

    public static void setEnableMediaQueries(boolean enable)

  - ### setRuntimeMultiImageEnabled

    public static void setRuntimeMultiImageEnabled(boolean b)

    This flag should be off and it is off by default, some special case implementations for development e.g. the AWT implementation activate this flag in order to use the EncodedImage multi-image support which is entirely for development only!

    ###### Deprecated

    do not use this method!

  - ### setPassword

    public static void setPassword(String password)

    Sets the password to use for password protected resource files

    ###### Parameters

    - `password`: the password or null to clear the password

  - ### openLayered

    public static Resources openLayered(String resource) throws IOException

    Opens a multi-layer resource file that supports overriding features on a specific platform. Notice that the ".res" extension MUST not be given to this method!

    ###### Parameters

    - `resource`: @param resource a local reference to a resource using the syntax of Class.getResourceAsStream(String) however the extension MUST not be included in the name! E.g. to reference /x.res use /x

    ###### Returns

    a resource object

    ###### Throws

    - `java.io.IOException`: if opening/reading the resource fails
    Throws:
      `IOException`

  - ### open

    public static Resources open(String resource) throws IOException

    Creates a resource object from the local JAR resource identifier

    ###### Parameters

    - `resource`: a local reference to a resource using the syntax of Class.getResourceAsStream(String)

    ###### Returns

    a resource object

    ###### Throws

    - `java.io.IOException`: if opening/reading the resource fails
    Throws:
      `IOException`

  - ### open

    public static Resources open(InputStream resource) throws IOException

    Creates a resource object from the given input stream

    ###### Parameters

    - `resource`: stream from which to read the resource

    ###### Returns

    a resource object

    ###### Throws

    - `java.io.IOException`: if opening/reading the resource fails
    Throws:
      `IOException`

  - ### openLayered

    public static Resources openLayered(String resource, int dpi) throws IOException

    Opens a multi-layer resource file that supports overriding features on a specific platform. Notice that the ".res" extension MUST not be given to this method!

    ###### Parameters

    - `resource`: @param resource a local reference to a resource using the syntax of Class.getResourceAsStream(String) however the extension MUST not be included in the name! E.g. to reference /x.res use /x

    - `dpi`: the dpi used for the loaded images

    ###### Returns

    a resource object

    ###### Throws

    - `java.io.IOException`: if opening/reading the resource fails
    Throws:
      `IOException`

  - ### open

    public static Resources open(String resource, int dpi) throws IOException

    Creates a resource object from the local JAR resource identifier

    ###### Parameters

    - `resource`: a local reference to a resource using the syntax of Class.getResourceAsStream(String)

    - `dpi`: the dpi used for the loaded images

    ###### Returns

    a resource object

    ###### Throws

    - `java.io.IOException`: if opening/reading the resource fails
    Throws:
      `IOException`

  - ### open

    public static Resources open(InputStream resource, int dpi) throws IOException

    Creates a resource object from the given input stream

    ###### Parameters

    - `resource`: stream from which to read the resource

    - `dpi`: the dpi used for the loaded images

    ###### Returns

    a resource object

    ###### Throws

    - `java.io.IOException`: if opening/reading the resource fails
    Throws:
      `IOException`

  - ### getSystemResource

    public static Resources getSystemResource()

    Gets the system resource which can be located /CN1Images.res.

    ###### Returns

    a Resources object which contains the system resources

  - ### getGlobalResources

    public static Resources getGlobalResources()

    Global resources are used by new GUI builder apps to keep track of the applications resources

    ###### Returns

    the resource object used by default in the GUI builder forms

  - ### setGlobalResources

    public static void setGlobalResources(Resources res)

    Global resources are used by new GUI builder apps to keep track of the applications resources

    ###### Parameters

    - `res`: the resource object used by default in the GUI builder forms

  - ### override

    public void override(InputStream input) throws IOException

    This method allows overriding the data of a resource file with another resource file thus replacing or enhancing existing content with platform specific content. E.g. default icons for the application can be overriden on a specific platform

    ###### Parameters

    - `input`: a new resource file

    ###### Throws

    - `IOException`: exception thrown from the stream
    Throws:
      `IOException`

  - ### getMajorVersion

    public int getMajorVersion()

    Returns the version number for this resource file. This value relates to the value from the header defined by the resource file specification. 0 is returned for legacy versions of the resource file format.

    ###### Returns

    major version number for the resource file

  - ### getMinorVersion

    public int getMinorVersion()

    Returns the minor version number for this resource file This value relates to the value from the header defined by the resource file specification.

    ###### Returns

    minor version number for the resource file

  - ### getMetaData

    public String[] getMetaData()

    Returns optional meta-data associated with the resource file

    ###### Returns

    optional meta-data associated with the file

  - ### getResourceNames

    public String[] getResourceNames()

    Returns the names of the resources within this bundle

    ###### Returns

    array of names of all the resources in this bundle

  - ### getDataResourceNames

    public String[] getDataResourceNames()

    Returns the names of the data resources within this bundle

    ###### Returns

    array of names of the data resources in this bundle

  - ### getUIResourceNames

    public String[] getUIResourceNames()

    Returns the names of the ui resources within this bundle

    ###### Returns

    array of names of the ui resources in this bundle

  - ### getL10NResourceNames

    public String[] getL10NResourceNames()

    Returns the names of the localization bundles within this bundle

    ###### Returns

    array of names of the localization resources in this bundle

  - ### getFontResourceNames

    public String[] getFontResourceNames()

    Returns the names of the fonts within this bundle

    ###### Returns

    array of names of the font resources in this bundle

  - ### getThemeResourceNames

    public String[] getThemeResourceNames()

    Returns the names of the images within this bundle

    ###### Returns

    array of names of the image resources in this bundle

  - ### getImageResourceNames

    public String[] getImageResourceNames()

    Returns the names of the images within this bundle

    ###### Returns

    array of names of the image resources in this bundle

  - ### isL10N

    public boolean isL10N(String name)

    Returns true if this is a generic data resource

    ###### Parameters

    - `name`: the name of the resource

    ###### Returns

    true if the resource is a data resource

    ###### Throws

    - `NullPointerException`: if the resource doesn't exist

  - ### isTheme

    public boolean isTheme(String name)

    Returns true if this is a theme resource

    ###### Parameters

    - `name`: the name of the resource

    ###### Returns

    true if the resource is a theme

    ###### Throws

    - `NullPointerException`: if the resource doesn't exist

  - ### isFont

    public boolean isFont(String name)

    Returns true if this is a font resource

    ###### Parameters

    - `name`: the name of the resource

    ###### Returns

    true if the resource is a font

    ###### Throws

    - `NullPointerException`: if the resource doesn't exist

  - ### isAnimation

    public boolean isAnimation(String name)

    Returns true if this is an animation resource

    ###### Parameters

    - `name`: the name of the resource

    ###### Returns

    true if the resource is an animation

    ###### Throws

    - `NullPointerException`: if the resource doesn't exist

    ###### Deprecated

    animations are no longer distinguished from images in the resource file, use Image.isAnimation instead

  - ### isData

    public boolean isData(String name)

    Returns true if this is a data resource

    ###### Parameters

    - `name`: the name of the resource

    ###### Returns

    true if the resource is a data resource

    ###### Throws

    - `NullPointerException`: if the resource doesn't exist

  - ### isUI

    public boolean isUI(String name)

    Returns true if this is a UI resource

    ###### Parameters

    - `name`: the name of the resource

    ###### Returns

    true if the resource is a UI resource

    ###### Throws

    - `NullPointerException`: if the resource doesn't exist

  - ### isImage

    public boolean isImage(String name)

    Returns true if this is an image resource

    ###### Parameters

    - `name`: the name of the resource

    ###### Returns

    true if the resource is an image

    ###### Throws

    - `NullPointerException`: if the resource doesn't exist

  - ### getImage

    public Image getImage(String id)

    Returns the image resource from the file

    ###### Parameters

    - `id`: name of the image resource

    ###### Returns

    cached image instance

  - ### getData

    public InputStream getData(String id)

    Returns the data resource from the file

    ###### Parameters

    - `id`: name of the data resource

    ###### Returns

    newly created input stream that allows reading the data of the resource

  - ### getL10N

    public Hashtable<String,String> getL10N(String id, String locale)

    Returns a hashmap containing localized String key/value pairs for the given locale name

    ###### Parameters

    - `id`: the name of the locale resource

    - `locale`: name of the locale resource

    ###### Returns

    Hashtable containing key value pairs for localized data

  - ### listL10NLocales

    public Enumeration listL10NLocales(String id)

    Returns an enumration of the locales supported by this resource id

    ###### Parameters

    - `id`: the name of the locale resource

    ###### Returns

    enumeration of strings containing bundle names

  - ### l10NLocaleSet

    public Collection<String> l10NLocaleSet(String id)

    Returns a collection of the l10 locale names

    ###### Parameters

    - `id`: the name of the locale resource

    ###### Returns

    collection of strings containing bundle names

  - ### getFont

    public Font getFont(String id)

    Returns the font resource from the file

    ###### Parameters

    - `id`: name of the font resource

    ###### Returns

    cached font instance

  - ### getTheme

    public Hashtable getTheme(String id)

    Returns the theme resource from the file

    ###### Parameters

    - `id`: name of the theme resource

    ###### Returns

    cached theme instance