net.rim.device.api.util
Class StringProvider

java.lang.Object
  extended by net.rim.device.api.util.StringProvider

public final class StringProvider
extends Object

Provides a String that can be changed. The most common use case would be for locale changes. The StringProvider is immutable to external changes - i.e. there are no public mutator methods. For applications needing mutator methods, use StringProviderMutator. Use:

 protected void layout(int width, int height) {
     _cachedValue = _myLabel.toString();
     Font font = getFont();
     width = font.getAdvance(_cachedValue);
     setExtent(width, font.getHeight());
 }
 protected void paint(Graphics graphics) {
     if( ! _myLabel.toString().equals( _cachedValue ) ) {
         updateLayout();
     }
     graphics.drawText(_myLabel.getString(), 0, 0);
 }
 

See Also:
StringProviderMutator
Since:
BlackBerry API 6.0.0

Constructor Summary
StringProvider(String string)
          Constructs a new StringProvider instance with initial text from a specified string.
StringProvider(String family, int id)
          Constructs a new StringProvider instance with initial text from a resource bundle.
StringProvider(StringProvider provider)
          Constructs a new StringProvider instance with initial text from an existing StringProvider.
 
Method Summary
 boolean equals(Object o)
          Checks to see if another object is equal to this StringProvider.
 int getResourceBundleId()
          Retrieves the resource bundle ID set in this provider.
 String getResourceBundleName()
          Retrieves the resource bundle name set in this provider.
 String toString()
          Returns the string of this provider.
 StringProvider toStringProviderWithoutHotkey()
          Creates a new StringProvider where the StringProvider.toString() method will return strings without the hot keys.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 



Constructor Detail

StringProvider

public StringProvider(String family,
                      int id)
Constructs a new StringProvider instance with initial text from a resource bundle.

Parameters:
family - Name of resource bundle containing inital text.
id - ID in resource bundle containing initial text.
Since:
BlackBerry API 6.0.0

StringProvider

public StringProvider(String string)
Constructs a new StringProvider instance with initial text from a specified string.

Parameters:
string - String containing inital text.
Since:
BlackBerry API 6.0.0

StringProvider

public StringProvider(StringProvider provider)
Constructs a new StringProvider instance with initial text from an existing StringProvider.

Parameters:
provider - StringProvider to copy.
Since:
BlackBerry API 6.0.0


Method Detail

equals

public boolean equals(Object o)
Checks to see if another object is equal to this StringProvider.

This provider is equal to another StringProvider if the result of their getResourceBundleID and getResourceBundleName are equivalent. If the bundle ID or name are null, checks to see if the result of toString is equivalent.

Two StringProviders which have identical resource information but different strings due to absence or presence of hotkeys are considered unequal.

Overrides:
equals in class Object
Parameters:
o - Object to compare to
Returns:
True if object is the same as this, false otherwise.
See Also:
Boolean.hashCode(), Hashtable
Since:
BlackBerry API 6.0.0

getResourceBundleId

public int getResourceBundleId()
Retrieves the resource bundle ID set in this provider.

Returns:
Resource bundle ID of text or -1 if not set.
Since:
BlackBerry API 6.0.0

getResourceBundleName

public String getResourceBundleName()
Retrieves the resource bundle name set in this provider.

Returns:
Resource bundle name containing text or null if not set.
Since:
BlackBerry API 6.0.0

toString

public String toString()
Returns the string of this provider. If the locale has changed, this will return the updated string from the resource bundle.

Overrides:
toString in class Object
Returns:
String representation of the text in this provider. Is null if text not set or if resource bundle does not exist.
Since:
BlackBerry API 6.0.0

toStringProviderWithoutHotkey

public StringProvider toStringProviderWithoutHotkey()
Creates a new StringProvider where the StringProvider.toString() method will return strings without the hot keys.

Returns:
A copy of this StringProvider with the hotkeys removed.
Since:
BlackBerry API 6.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal