public class Resources
- Object
- 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
Inherited methods
Method details
isFailOnMissingTruetype
public static boolean isFailOnMissingTruetype()Returns
the failOnMissingTruetype
setFailOnMissingTruetype
public static void setFailOnMissingTruetype(boolean aFailOnMissingTruetype)Parameters
aFailOnMissingTruetypeboolean- 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
passwordString- the password or null to clear the password
openLayered
public static Resources openLayered(String resource)
throws IOExceptionOpens 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
resourceString- 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 IOExceptionCreates a resource object from the local JAR resource identifier
Parameters
resourceString- 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 IOExceptionCreates a resource object from the given input stream
Parameters
resourceInputStream- 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 IOExceptionOpens 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
resourceString- 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
dpiint- 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 IOExceptionCreates a resource object from the local JAR resource identifier
Parameters
resourceString- a local reference to a resource using the syntax of Class.getResourceAsStream(String)
dpiint- 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 IOExceptionCreates a resource object from the given input stream
Parameters
resourceInputStream- stream from which to read the resource
dpiint- 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
resResources- the resource object used by default in the GUI builder forms
override
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. E.g. default icons for the application
can be overriden on a specific platform
Parameters
inputInputStream- 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
nameString- 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
nameString- 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
nameString- 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
nameString- 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
nameString- 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
nameString- 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
nameString- 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
idString- 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
idString- 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
idString- the name of the locale resource
localeString- 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
idString- 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
idString- 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
idString- name of the font resource
Returns
cached font instance
getTheme
public Hashtable getTheme(String id)Returns the theme resource from the file
Parameters
idString- name of the theme resource
Returns
cached theme instance