Kanzi  3.9.6
Java API
ResourceDictionary Class Reference

A resource dictionary is a container that maps resource IDs to resources. More...

Inheritance diagram for ResourceDictionary:
[legend]

Classes

class  UrlMapPair
 Represents a record in resource ID to URL map as a key-URL pair. More...
 

Public Member Functions

ObjectRef< Resourceacquire (ResourceID key)
 Gets from the resource dictionary the resource with the resource ID that you pass to the function. More...
 
ResourceManager.AcquireTask acquireAsync (ResourceID key, ResourceManager.AcquireTask.Callback callback)
 Asynchronously acquires a resource. More...
 
void add (ResourceID key, String url)
 Adds a resource ID to a resource URL mapping to a resource dictionary. More...
 
void add (ResourceID key, Resource resource)
 Adds a resource ID to a resource mapping to a resource dictionary. More...
 
void add (ResourceDictionary resourceDictionary)
 Adds a nested resource dictionary to a resource dictionary. More...
 
void addAnonymousResource (Resource resource)
 Adds an anonymous resource to a resource dictionary. More...
 
ObjectRef< ResourceDictionaryclone ()
 Duplicates a resource dictionary. More...
 
boolean contains (ResourceID key)
 Returns whether a resource dictionary contains a mapping for the resource ID that you pass to the function. More...
 
String find (ResourceID key)
 Resolves the mapping from the resource ID that you pass to the function to the URL of the resource. More...
 
ResourceDictionary findDictionary (String name)
 Searches for a nested dictionary with the specified name and returns a pointer to it. More...
 
Resource findStoredResource (ResourceID key)
 Finds an explicitly stored resource pointer from a dictionary. More...
 
int getDictionaryCount ()
 Gets the number of nested resource dictionaries in a resource dictionary. More...
 
Iterable< ResourceiterateAnonymousResources ()
 Returns an Iterable object that you can use to iterate the anonymous resources stored by this resource dictionary object. More...
 
Iterable< UrlMapPairiterateUrls ()
 Returns an Iterable object that you can use to iterate elements of the URL mappings container. More...
 
void merge (ResourceDictionary preferredDictionary)
 Copies into this resource dictionary the contents of the resource dictionary that you pass to the function. More...
 
void remove (ResourceID key)
 Removes a resource ID mapping from a resource dictionary. More...
 
void removeAnonymousResource (Resource resource)
 Removes an anonymous resource from the resource dictionary. More...
 
void removeDictionary (int index)
 Removes a nested resource dictionary from a resource dictionary. More...
 
Iterable< ResourceDictionaryreverseIterateNestedResourceDictionaries ()
 Returns an Iterable object that you can use to iterate nested resource dictionary container in reversed order. More...
 
- Public Member Functions inherited from Resource
String getName ()
 Gets the resource name. More...
 
String getUrl ()
 Gets the resource URL. More...
 
void setKeepAlive (boolean keepAlive)
 Sets the keep alive flag. More...
 
- Public Member Functions inherited from KanziObject
boolean equals (Object object)
 
Domain getDomain ()
 Returns the domain the object belongs to. More...
 
Metaclass getDynamicMetaclass ()
 Returns the metaclass of the dynamic type of the object. More...
 
long getNative ()
 Gets a pointer to the backing C++ instance. More...
 
TDataType getOptionalProperty (PropertyType< TDataType > propertyType)
 Returns the current value of a property type, but does not use the default value if there are no inputs to the property value. More...
 
TDataType getProperty (PropertyType< TDataType > propertyType)
 Returns the current value of a property type. More...
 
EnumType getProperty (PropertyType< Integer > propertyType, Class< EnumType > enumClass)
 Returns the current value of an integer property type converted to a matching constant from specified enumeration. More...
 
int hashCode ()
 
boolean hasValue (PropertyType< TDataType > propertyType)
 Evaluates whether there are any inputs into the property value. More...
 
boolean isStale ()
 Test if the object is stale i.e. More...
 
void removeLocalValue (PropertyType< TDataType > propertyType)
 Removes the local value associated with the property. More...
 
void setProperty (PropertyType< TDataType > propertyType, TDataType value)
 Sets the local value of a property type. More...
 
void setProperty (PropertyType< Integer > propertyType, EnumType value)
 Sets the local value of an integer property type using a constant from an enumeration. More...
 
ObjectRef< TType > tryCreateObjectRef (Class< TType > clazz)
 Tries to create an owning ObjectRef instance to this KanziObject. More...
 

Static Public Member Functions

static ObjectRef< T > create (Domain domain, String name)
 Constructs a new ResourceDictionary. More...
 

Static Public Attributes

static final Metaclass metaclass
 The Metaclass for the class. More...
 
- Static Public Attributes inherited from Resource
static final Metaclass metaclass
 The Metaclass for the class. More...
 
- Static Public Attributes inherited from KanziObject
static final Metaclass metaclass = new AbstractMetaclass("Kanzi.Object")
 The Metaclass for the class.
 

Additional Inherited Members

- Public Attributes inherited from ResourceMetadata
AbstractMetaclass metaclass = new AbstractMetaclass("Kanzi.Resource")
 Metaclass for Resource.
 
- Public Attributes inherited from ResourceDictionaryMetadata
AbstractMetaclass metaclass = new AbstractMetaclass("Kanzi.ResourceDictionary")
 Metaclass for ResourceDictionary.
 

Detailed Description

A resource dictionary is a container that maps resource IDs to resources.

A node can refer to resources by setting resource IDs to resource ID properties. You can set a resource dictionary to the node, or to any of its parent nodes, to define which resources the node uses. You can use a resource dictionary to group similar resources to logical entity, such as themes or locales, and change a resource dictionary of a node to change multiple resources at the same time.

Use Node::acquireResource to get the resource from a resource dictionary of a node or from the resource dictionaries of its parent nodes.

A resource dictionary can map resource IDs to resources in these ways:

  • Directly to a resource
  • Indirectly to a resource with a resource URL

Use acquire(ResourceID) and functions to get a mapped resource regardless of the way a resource ID is mapped to a resource.

You can store nested resource dictionaries in a resource dictionary. When you are getting a resource from a resource dictionary and the resource dictionary cannot find the resource ID that you specify, the resource dictionary looks for the resource ID recursively in the nested resource dictionaries.

In a resource dictionary you can store resources without mapping a resource ID to them. In Kanzi such resources are called anonymous resources. You can get anonymous resources with iterateAnonymousResources().

Member Function Documentation

◆ acquire()

ObjectRef<Resource> acquire ( ResourceID  key)

Gets from the resource dictionary the resource with the resource ID that you pass to the function.

The function forwards the resource URL mappings to ResourceManager::acquireResource. Classes that derive from ResourceDictionary can override the behavior of acquire by implementing acquireOverride.

Parameters
keyThe resource ID of the resource that you want to get.
Returns
The resource to which the resource ID is mapped.
  • If the resource ID is mapped to a resource pointer, the function returns the resource pointer.
  • If the resource ID is mapped to a resource URL, the function uses the URL to query the resource from ResourceManager#acquireResource(String).
  • If the resource dictionary has nested resource dictionaries, the function forwards the query to the nested dictionaries. It first searches the last nested resource dictionary and it searches last the first nested resource dictionary.
  • If the resource ID is not mapped to anything in this resource dictionary or any of the nested dictionaries, the function returns nullptr.

◆ acquireAsync()

ResourceManager.AcquireTask acquireAsync ( ResourceID  key,
ResourceManager.AcquireTask.Callback  callback 
)

Asynchronously acquires a resource.

If the function cannot find a resource URL mapping, it does not launch an asynchronous task. Kanzi executes the callback only the next time when it executes callbacks, if there are no asynchronous task to launch.

Parameters
keyThe resource ID of the resource that you want to get.
callbackThe callback to execute when loading is complete.
Returns
The launched asynchronous task.

◆ add() [1/3]

void add ( ResourceID  key,
String  url 
)

Adds a resource ID to a resource URL mapping to a resource dictionary.

Parameters
keyThe resource ID to add.
urlThe URL that points to the resource to map to the resource ID.

◆ add() [2/3]

void add ( ResourceID  key,
Resource  resource 
)

Adds a resource ID to a resource mapping to a resource dictionary.

Parameters
keyThe resource ID to add.
resourceThe resource to map to the resource ID.

◆ add() [3/3]

void add ( ResourceDictionary  resourceDictionary)

Adds a nested resource dictionary to a resource dictionary.

You can add to multiple resource dictionaries the same resource dictionary as a nested resource dictionary. Do not form cycles with the nested resource dictionaries.

Parameters
resourceDictionaryThe nested resource dictionary that you want to add to the resource dictionary.

◆ addAnonymousResource()

void addAnonymousResource ( Resource  resource)

Adds an anonymous resource to a resource dictionary.

Parameters
resourceThe anonymous resource that you want to add to the resource dictionary.

◆ clone()

Duplicates a resource dictionary.

When you duplicate a resource dictionary that contains nested resource dictionaries, the function creates a shallow copy: it copies the pointers to the nested resource dictionaries, not the contents of the nested resource dictionaries.

Returns
The duplicated resource dictionary.

◆ contains()

boolean contains ( ResourceID  key)

Returns whether a resource dictionary contains a mapping for the resource ID that you pass to the function.

Parameters
keyThe resource ID for which you want to check whether there is a mapping in the resource dictionary.
Returns
If the resource dictionary or a nested resource dictionary contains a mapping for the resource ID that you passed to the function, true, otherwise false.

◆ create()

static ObjectRef<T> create ( Domain  domain,
String  name 
)
static

Constructs a new ResourceDictionary.

Parameters
domainUI Domain where this object belongs.
nameName of the object.

◆ find()

String find ( ResourceID  key)

Resolves the mapping from the resource ID that you pass to the function to the URL of the resource.

This function ignores the direct resource ID to resource mappings.

Parameters
keyThe resource ID of the resource for which you want to get the URL.
Returns
If the resource dictionary or a nested resource dictionary contains a resource URL, a resource ID that you passed, otherwise null.

◆ findDictionary()

ResourceDictionary findDictionary ( String  name)

Searches for a nested dictionary with the specified name and returns a pointer to it.

Parameters
nameThe name of the dictionary to find.
Returns
A child dictionary with the specified name. If a dictionary with the specified name does not exist, returns null.

◆ findStoredResource()

Resource findStoredResource ( ResourceID  key)

Finds an explicitly stored resource pointer from a dictionary.

Does not try to acquire a resource from the resource manager. To acquire a resource, use acquire(ResourceID).

Parameters
keyThe resource ID of the resource that you want to get.
Returns
The resource to which the resource ID is mapped.

◆ getDictionaryCount()

int getDictionaryCount ( )

Gets the number of nested resource dictionaries in a resource dictionary.

Returns
The number of nested resource dictionaries in the resource dictionary.

◆ iterateAnonymousResources()

Iterable<Resource> iterateAnonymousResources ( )

Returns an Iterable object that you can use to iterate the anonymous resources stored by this resource dictionary object.

Returns
An Iterable object of the anonymous resources stored by this resource dictionary object.

◆ iterateUrls()

Iterable<UrlMapPair> iterateUrls ( )

Returns an Iterable object that you can use to iterate elements of the URL mappings container.

The elements in the container are represented with the com.rightware.kanzi.ResourceDictionary.UrlMapPair class.

Returns
An Iterable object of the elements of the URL mappings container of this resource dictionary object.

◆ merge()

void merge ( ResourceDictionary  preferredDictionary)

Copies into this resource dictionary the contents of the resource dictionary that you pass to the function.

The function adds to this resource dictionary:

  • Resource ID mappings
  • References to the nested resource directories
  • Anonymous resources from the given resource directory

If there are duplicate values for the resource ID mappings, prefers the values from the resource directory that you pass to the function.

Parameters
preferredDictionaryThe resource dictionary that you want to merge to this resource dictionary.

◆ remove()

void remove ( ResourceID  key)

Removes a resource ID mapping from a resource dictionary.

Parameters
keyThe resource ID that you want to remove.

◆ removeAnonymousResource()

void removeAnonymousResource ( Resource  resource)

Removes an anonymous resource from the resource dictionary.

If the resource does not exist in a resource dictionary, the function does not do anything.

Parameters
resourceThe anonymous resource that you want to remove from the resource dictionary.

◆ removeDictionary()

void removeDictionary ( int  index)

Removes a nested resource dictionary from a resource dictionary.

Parameters
indexThe index of the nested resource dictionary that you want to remove.

◆ reverseIterateNestedResourceDictionaries()

Iterable<ResourceDictionary> reverseIterateNestedResourceDictionaries ( )

Returns an Iterable object that you can use to iterate nested resource dictionary container in reversed order.

Returns
An Iterable object of nested resource dictionary container in reversed order.

Member Data Documentation

◆ metaclass

final Metaclass metaclass
static