Package net.sf.jguiraffe.gui.app
Class TextResource
- java.lang.Object
-
- net.sf.jguiraffe.gui.app.TextResource
-
public abstract class TextResource extends Object
A class representing a textual resource.
This class can be used in scenarios where either a plain text or a text from the application's resources can be provided. Different factory methods for these use cases are provided. Instances can be queried for the data they contain. They also have a
resolve()
method which - given anApplicationContext
reference - returns the textual value of this resource.- Since:
- 1.4
-
-
Field Summary
Fields Modifier and Type Field Description static TextResource
UNDEFINED
Constant for an undefined text resource.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
static TextResource
fromResourceID(Object resID)
Creates a new instance ofTextResource
that represents an application resource with the given ID.static TextResource
fromText(String text)
Creates a new instance ofTextResource
that represents the given plain text.String
getPlainText()
Returns the plain text for this resource.Object
getResourceID()
Returns the resource ID for this object.int
hashCode()
String
resolveText(ApplicationContext applicationContext)
Resolves this resource and returns its text value.String
toString()
Returns a string representation of this object.
-
-
-
Field Detail
-
UNDEFINED
public static final TextResource UNDEFINED
Constant for an undefined text resource. This instance returns null for all access methods.
-
-
Method Detail
-
getPlainText
public String getPlainText()
Returns the plain text for this resource. This method is defined if a plain text is available (i.e. the text does not have to be fetched from application resources). Otherwise, it returns null.- Returns:
- the plain text for this resource or null
-
getResourceID
public Object getResourceID()
Returns the resource ID for this object. This method is defined if this resource represents an entry from the application's resources. Otherwise, result is null- Returns:
- the resource ID or null
-
resolveText
public String resolveText(ApplicationContext applicationContext)
Resolves this resource and returns its text value. If necessary, does a resource lookup using the given application context. The final text represented by this object is returned. For an undefined resource result is null.- Parameters:
applicationContext
- the application context- Returns:
- the text represented by this resource
-
toString
public String toString()
Returns a string representation of this object. The string contains the data that is defined: the plain text or the resource ID. (For the undefined resource, neither is available.)
-
fromText
public static TextResource fromText(String text)
Creates a new instance ofTextResource
that represents the given plain text. No resource lookup is necessary; the text is directly provided. If the text is null, however, an undefined resource is returned.- Parameters:
text
- the plain text- Returns:
- a
TextResource
representing this plain text
-
fromResourceID
public static TextResource fromResourceID(Object resID)
Creates a new instance ofTextResource
that represents an application resource with the given ID. The actual text is obtained via a resource lookup in theresolve()
method. If the resource ID is null, however, an undefined resource is returned.- Parameters:
resID
- the resource ID- Returns:
- a
TextResource
representing this resource ID
-
-