public class Resources

  1. Object
  2. Resources

Known subtypesMutableResource

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.

Methods

public static boolean isFailOnMissingTruetype()
public static void setFailOnMissingTruetype(boolean aFailOnMissingTruetype)
public static boolean isEnableMediaQueries()
public static void setEnableMediaQueries(boolean enable)
public static void setRuntimeMultiImageEnabled(boolean b)Deprecated 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!
public static void setPassword(String password)Sets the password to use for password protected resource files
public static Resources openLayered(String resource) throws IOExceptionOpens a multi-layer resource file that supports overriding features on a specific platform.
public static Resources open(String resource) throws IOExceptionCreates a resource object from the local JAR resource identifier
public static Resources open(InputStream resource) throws IOExceptionCreates a resource object from the given input stream
public static Resources openLayered(String resource, int dpi) throws IOExceptionOpens a multi-layer resource file that supports overriding features on a specific platform.
public static Resources open(String resource, int dpi) throws IOExceptionCreates a resource object from the local JAR resource identifier
public static Resources open(InputStream resource, int dpi) throws IOExceptionCreates a resource object from the given input stream
public static Resources getSystemResource()Gets the system resource which can be located /CN1Images.res.
public static Resources getGlobalResources()Global resources are used by new GUI builder apps to keep track of the applications resources
public static void setGlobalResources(Resources res)Global resources are used by new GUI builder apps to keep track of the applications resources
public void override(InputStream input) throws IOExceptionThis method allows overriding the data of a resource file with another resource file thus replacing or enhancing existing content with platform specific content.
public int getMajorVersion()Returns the version number for this resource file.
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.
public String[] getMetaData()Returns optional meta-data associated with the resource file
public String[] getResourceNames()Returns the names of the resources within this bundle
public String[] getDataResourceNames()Returns the names of the data resources within this bundle
public String[] getUIResourceNames()Returns the names of the ui resources within this bundle
public String[] getL10NResourceNames()Returns the names of the localization bundles within this bundle
public String[] getFontResourceNames()Returns the names of the fonts within this bundle
public String[] getThemeResourceNames()Returns the names of the images within this bundle
public String[] getImageResourceNames()Returns the names of the images within this bundle
public boolean isL10N(String name)Returns true if this is a generic data resource
public boolean isTheme(String name)Returns true if this is a theme resource
public boolean isFont(String name)Returns true if this is a font resource
public boolean isAnimation(String name)Deprecated Returns true if this is an animation resource
public boolean isData(String name)Returns true if this is a data resource
public boolean isUI(String name)Returns true if this is a UI resource
public boolean isImage(String name)Returns true if this is an image resource
public Image getImage(String id)Returns the image resource from the file
public void setImage(String id, Image image)Install an Image into this resources bundle under the given name so a subsequent getImage(String) returns it.
public static void registerGeneratedImage(String id, Image image)Add an Image to the global registry consulted by every getImage(String) call as a fallback.
public InputStream getData(String id)Returns the data resource from the file
public Hashtable<String, String> getL10N(String id, String locale)Returns a hashmap containing localized String key/value pairs for the given locale name
public Enumeration listL10NLocales(String id)Returns an enumration of the locales supported by this resource id
public Collection<String> l10NLocaleSet(String id)Returns a collection of the l10 locale names
public Font getFont(String id)Returns the font resource from the file
public Hashtable getTheme(String id)Returns the theme resource from the file

Inherited methods

Method details

isFailOnMissingTruetype

public static boolean isFailOnMissingTruetype()

Returns

the failOnMissingTruetype

setFailOnMissingTruetype

public static void setFailOnMissingTruetype(boolean aFailOnMissingTruetype)

Parameters

aFailOnMissingTruetype boolean
the failOnMissingTruetype to set

isEnableMediaQueries

public static boolean isEnableMediaQueries()

setEnableMediaQueries

public static void setEnableMediaQueries(boolean enable)

setRuntimeMultiImageEnabled

public static void setRuntimeMultiImageEnabled(boolean b)
Deprecated. do not use this method!
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!

setPassword

public static void setPassword(String password)
Sets the password to use for password protected resource files

Parameters

password String
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 String
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

open

public static Resources open(String resource) throws IOException
Creates a resource object from the local JAR resource identifier

Parameters

resource String
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

open

public static Resources open(InputStream resource) throws IOException
Creates a resource object from the given input stream

Parameters

resource InputStream
stream from which to read the resource

Returns

a resource object

Throws

java.io.IOException
if opening/reading the resource fails

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 String
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 int
the dpi used for the loaded images

Returns

a resource object

Throws

java.io.IOException
if opening/reading the resource fails

open

public static Resources open(String resource, int dpi) throws IOException
Creates a resource object from the local JAR resource identifier

Parameters

resource String
a local reference to a resource using the syntax of Class.getResourceAsStream(String)
dpi int
the dpi used for the loaded images

Returns

a resource object

Throws

java.io.IOException
if opening/reading the resource fails

open

public static Resources open(InputStream resource, int dpi) throws IOException
Creates a resource object from the given input stream

Parameters

resource InputStream
stream from which to read the resource
dpi int
the dpi used for the loaded images

Returns

a resource object

Throws

java.io.IOException
if opening/reading the resource fails

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 Resources
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 InputStream
a new resource file

Throws

IOException
exception thrown from the stream

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 String
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 String
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 String
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)
Deprecated. animations are no longer distinguished from images in the resource file, use Image.isAnimation instead
Returns true if this is an animation resource

Parameters

name String
the name of the resource

Returns

true if the resource is an animation

Throws

NullPointerException
if the resource doesn’t exist

isData

public boolean isData(String name)
Returns true if this is a data resource

Parameters

name String
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 String
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 String
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 String
name of the image resource

Returns

cached image instance

setImage

public void setImage(String id, Image image)
Install an Image into this resources bundle under the given name so a subsequent getImage(String) returns it. Used by the build-time SVG transcoder registry to inject generated images alongside the resources loaded from the .res file.

registerGeneratedImage

public static void registerGeneratedImage(String id, Image image)

Add an Image to the global registry consulted by every getImage(String) call as a fallback. Intended for the auto-generated com.codename1.generated.svg.SVGRegistry produced by the SVG transcoder mojo – application code should not normally call this directly.

Registers the image both under the supplied id and (if id ends with .svg) under the bare filename stem so a CSS reference like url(home.svg) and a code reference like getImage("home") both resolve to the same instance.

getData

public InputStream getData(String id)
Returns the data resource from the file

Parameters

id String
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 String
the name of the locale resource
locale String
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 String
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 String
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 String
name of the font resource

Returns

cached font instance

getTheme

public Hashtable getTheme(String id)
Returns the theme resource from the file

Parameters

id String
name of the theme resource

Returns

cached theme instance