Class StaticTextDataTransformer
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.components.tags.StaticTextDataTransformer
-
- All Implemented Interfaces:
Transformer
public class StaticTextDataTransformer extends Object implements Transformer
A special implementation of the
Transformer
interface for converting data toStaticTextData
objects.This transformer class is useful if
StaticTextTag
is used to produce labels in forms which should display some data. The data is to be provided as part of the form's model. If only textual data is involved, it is pretty inconvenient to expose properties of typeStaticTextData
in the model bean. Rather, this class can be assigned asTransformer
to the static text fields. It createsStaticTextData
objects and populates them from the object passed to thetransform(Object, TransformerContext)
method. The following objects can be handled:- Objects implementing the
CharSequence
interface become the text of theStaticTextData
object. - Objects of type
TextIconAlignment
are passed to thealignment
property. - If the object passed to
transform()
is already of typeStaticTextData
, it is returned without changes. - Other objects are interpreted as icons and stored in the
icon
property.
An instance defines properties for all elements of a
StaticTextData
object. If set, the corresponding values are written in the newly created objects. For instance, if theicon
property is set and aCharSequence
object is passed totransform()
, the resulting object will have this icon and the text of theCharSequence
. These properties can be overridden by properties in theTransformerContext
. Here the following properties are supported:Property Description Default text The text to be written into the StaticTextData
object.undefined icon The icon to be written into the StaticTextData
object.undefined alignment The alignment for the StaticTextData
object.undefined - Version:
- $Id: StaticTextDataTransformer.java 208 2012-02-11 20:57:33Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description StaticTextDataTransformer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
convertProperty(Object o, StaticTextDataImpl data, TransformerContext ctx)
Performs the transformation if the object to be converted must be set as a property of aStaticTextData
object.TextIconAlignment
getAlignment()
Returns the defaultTextIconAlignment
.Object
getIcon()
Returns the default icon for the newly createdStaticTextData
objects.String
getText()
Returns the default text for the newly createdStaticTextData
objects.protected void
populate(StaticTextDataImpl data, TransformerContext ctx)
Fills the specified data object with default values.void
setAlignment(TextIconAlignment alignment)
Sets the defaultTextIconAlignment
.void
setIcon(Object icon)
Sets the default icon for the newly createdStaticTextData
objects.void
setText(String text)
Sets the default text for the newly createdStaticTextData
objects.Object
transform(Object o, TransformerContext ctx)
The main method of theTransformer
interface.
-
-
-
Method Detail
-
getText
public String getText()
Returns the default text for the newly createdStaticTextData
objects.- Returns:
- the default text
-
setText
public void setText(String text)
Sets the default text for the newly createdStaticTextData
objects.- Parameters:
text
- the default text
-
getIcon
public Object getIcon()
Returns the default icon for the newly createdStaticTextData
objects.- Returns:
- the default icon
-
setIcon
public void setIcon(Object icon)
Sets the default icon for the newly createdStaticTextData
objects.- Parameters:
icon
- the default icon
-
getAlignment
public TextIconAlignment getAlignment()
Returns the defaultTextIconAlignment
.- Returns:
- the default alignment
-
setAlignment
public void setAlignment(TextIconAlignment alignment)
Sets the defaultTextIconAlignment
.- Parameters:
alignment
- the default alignment
-
transform
public Object transform(Object o, TransformerContext ctx) throws Exception
The main method of theTransformer
interface. This method takes the object to be transformed and returns an appropriate converted representation of it. The also passed inTransformerContext
object can be used to access system information that may be needed for generating the transformed representation, e.g. the actualLocale
. Performs the transformation as described in the class comment.- Specified by:
transform
in interfaceTransformer
- Parameters:
o
- the object to be transformedctx
- theTransformerContext
object- Returns:
- the transformed instance
- Throws:
Exception
- Transformers can throw arbitrary exceptions if the conversion is not possible
-
populate
protected void populate(StaticTextDataImpl data, TransformerContext ctx)
Fills the specified data object with default values. This method is called bytransform()
to write default values into the result object. It evaluates the properties in the context and the member fields of this instance.- Parameters:
data
- the data object to be filledctx
- theTransformerContext
-
convertProperty
protected void convertProperty(Object o, StaticTextDataImpl data, TransformerContext ctx) throws Exception
Performs the transformation if the object to be converted must be set as a property of aStaticTextData
object. This method is called bytransform()
if the passed in object is not null and not aStaticTextData
object. The base implementation sets the corresponding property in the passed in data object based on the class of the object to be converted.- Parameters:
o
- the object to be converteddata
- the data object to be filledctx
- theTransformerContext
- Throws:
Exception
- if an error occurs
-
-