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
Transformerinterface for converting data toStaticTextDataobjects.This transformer class is useful if
StaticTextTagis 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 typeStaticTextDatain the model bean. Rather, this class can be assigned asTransformerto the static text fields. It createsStaticTextDataobjects and populates them from the object passed to thetransform(Object, TransformerContext)method. The following objects can be handled:- Objects implementing the
CharSequenceinterface become the text of theStaticTextDataobject. - Objects of type
TextIconAlignmentare passed to thealignmentproperty. - 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
iconproperty.
An instance defines properties for all elements of a
StaticTextDataobject. If set, the corresponding values are written in the newly created objects. For instance, if theiconproperty is set and aCharSequenceobject 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 StaticTextDataobject.undefined icon The icon to be written into the StaticTextDataobject.undefined alignment The alignment for the StaticTextDataobject.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 voidconvertProperty(Object o, StaticTextDataImpl data, TransformerContext ctx)Performs the transformation if the object to be converted must be set as a property of aStaticTextDataobject.TextIconAlignmentgetAlignment()Returns the defaultTextIconAlignment.ObjectgetIcon()Returns the default icon for the newly createdStaticTextDataobjects.StringgetText()Returns the default text for the newly createdStaticTextDataobjects.protected voidpopulate(StaticTextDataImpl data, TransformerContext ctx)Fills the specified data object with default values.voidsetAlignment(TextIconAlignment alignment)Sets the defaultTextIconAlignment.voidsetIcon(Object icon)Sets the default icon for the newly createdStaticTextDataobjects.voidsetText(String text)Sets the default text for the newly createdStaticTextDataobjects.Objecttransform(Object o, TransformerContext ctx)The main method of theTransformerinterface.
-
-
-
Method Detail
-
getText
public String getText()
Returns the default text for the newly createdStaticTextDataobjects.- Returns:
- the default text
-
setText
public void setText(String text)
Sets the default text for the newly createdStaticTextDataobjects.- Parameters:
text- the default text
-
getIcon
public Object getIcon()
Returns the default icon for the newly createdStaticTextDataobjects.- Returns:
- the default icon
-
setIcon
public void setIcon(Object icon)
Sets the default icon for the newly createdStaticTextDataobjects.- 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 theTransformerinterface. This method takes the object to be transformed and returns an appropriate converted representation of it. The also passed inTransformerContextobject 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:
transformin interfaceTransformer- Parameters:
o- the object to be transformedctx- theTransformerContextobject- 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 aStaticTextDataobject. This method is called bytransform()if the passed in object is not null and not aStaticTextDataobject. 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
-
-