Class FontTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
-
- net.sf.jguiraffe.gui.builder.components.tags.FontTag
-
- All Implemented Interfaces:
ConditionalTag
,org.apache.commons.jelly.Tag
public class FontTag extends FormBaseTag
A specialized tag handler class for creating fonts.
With this tag handler class it is possible to create new font objects and store them in the current context or assign them to graphical components. Fonts are platform-specific and hence are created by the
ComponentManager
. This tag supports a limited set of standard attributes describing the font which should be supported by most platform. In addition, a reference to a map with platform-specific attributes can be provided. These attributes are taken into account by theComponentManager
. That way core attributes of fonts can be defined in a portable way while specific attributes an also be set.The following table lists the attributes supported by this tag:
Attribute Description Optional name The name of the font. This can be one of the reserved font names supported by every JVM or the name of any font available on the system. Yes size The size of the font in point. Yes bold A boolean flag indicating whether the font should have the style Bold. Yes italic A boolean flag indicating whether the font should have the style Italic. Yes var Here the name of a variable can be specified. If this attribute is set, the newly created font is stored in the Jelly context under this name. It can then be referenced from other tags defining graphical components. Yes attributes Using this attribute a map can be referenced which defines additional properties of the font to be created. A bean with this name is looked up in the current bean context. It must be a Map<?, ?>
. The properties defined by this map are evaluated by theComponentManager
.Yes Tags of this type can be placed in the body of a tag derived from
ComponentBaseTag
. In this case, the font is passed to the enclosing tag. Otherwise, thevar
attribute must be specified. If a tag is neither nested in aComponentBaseTag
tag nor has thevar
attribute set, an exception is thrown.The following example shows how this tag can be used to set the font of a label component:
<!-- A map with additional properties --> <di:map name="fontProperties"> ... </di:map> <!-- A label with a special font --> <f:label text="Text in a special font"> <f:font name="Serif" bold="true" italic="true" size=18" attributes="fontProperties"/> </f:label>
- Version:
- $Id: FontTag.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description FontTag()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
createFont(ComponentManager manager)
Calls theComponentManager
to create the font represented by this tag.protected Map<?,?>
fetchAttributesMap()
Obtains the map with the font's attributes.String
getAttributes()
Returns the name of a bean with additional attributes for the font to be created.Map<?,?>
getAttributesMap()
Returns a (unmodifiable) map with additional attributes of the font to be created.String
getName()
Returns the name of the font.int
getSize()
Returns the size of the font.String
getVar()
Returns the name of the variable under which the font is to be stored in the Jelly context.boolean
isBold()
Returns a flag whether the font has the bold style.boolean
isItalic()
Returns a flag whether the font has the italic style.protected void
process()
Processes this tag.protected void
processBeforeBody()
Performs processing before this tag's body is evaluated.void
setAttributes(String attributes)
Set method of theattributes
attribute.void
setBold(boolean bold)
Set method of thebold
attribute.void
setItalic(boolean italic)
Set method of theitalic
attribute.void
setName(String name)
Set method of thename
attribute.void
setSize(int size)
Set method of thesize
attribute.void
setVar(String var)
Set method of thevar
attribute.-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
canProcess, canProcess, convertToClass, convertToNumberWithUnit, convertToNumberWithUnit, doTag, findContainer, getBuilderData, getBuilderData, getIfName, getResourceText, getResourceText, getUnlessName, setIfName, setUnlessName
-
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
-
-
-
-
Method Detail
-
getName
public String getName()
Returns the name of the font.- Returns:
- the font name
-
setName
public void setName(String name)
Set method of thename
attribute.- Parameters:
name
- the attribute's value
-
getVar
public String getVar()
Returns the name of the variable under which the font is to be stored in the Jelly context.- Returns:
- the variable name
-
setVar
public void setVar(String var)
Set method of thevar
attribute.- Parameters:
var
- the attribute's value
-
getAttributes
public String getAttributes()
Returns the name of a bean with additional attributes for the font to be created.- Returns:
- the name of the bean with additional attributes
-
setAttributes
public void setAttributes(String attributes)
Set method of theattributes
attribute.- Parameters:
attributes
- the attribute's value
-
getSize
public int getSize()
Returns the size of the font.- Returns:
- the font size
-
setSize
public void setSize(int size)
Set method of thesize
attribute.- Parameters:
size
- the attribute's value
-
isBold
public boolean isBold()
Returns a flag whether the font has the bold style.- Returns:
- the bold flag
-
setBold
public void setBold(boolean bold)
Set method of thebold
attribute.- Parameters:
bold
- the attribute's value
-
isItalic
public boolean isItalic()
Returns a flag whether the font has the italic style.- Returns:
- the italic flag
-
setItalic
public void setItalic(boolean italic)
Set method of theitalic
attribute.- Parameters:
italic
- the attribute's value
-
getAttributesMap
public Map<?,?> getAttributesMap()
Returns a (unmodifiable) map with additional attributes of the font to be created. This map is created during processing of the tag. It has to be evaluated by theComponentManager
when the font is to be created.- Returns:
- a map with additional attributes for the font to be created
-
processBeforeBody
protected void processBeforeBody() throws org.apache.commons.jelly.JellyTagException, FormBuilderException
Performs processing before this tag's body is evaluated. This implementation performs some checks of the attributes and obtains the map with additional font attributes.- Overrides:
processBeforeBody
in classFormBaseTag
- Throws:
org.apache.commons.jelly.JellyTagException
- if the tag is used incorrectlyFormBuilderException
- if an error occurs
-
process
protected void process() throws org.apache.commons.jelly.JellyTagException, FormBuilderException
Processes this tag. This implementation delegates to theComponentManager
to actually create the font. Then the new font object is passed to the corresponding receivers.- Specified by:
process
in classFormBaseTag
- Throws:
org.apache.commons.jelly.JellyTagException
- if the tag is used incorrectlyFormBuilderException
- if an error occurs
-
fetchAttributesMap
protected Map<?,?> fetchAttributesMap() throws org.apache.commons.jelly.JellyTagException
Obtains the map with the font's attributes. This method is called before the tag's body is processed. It must return a non-null map. This implementation checks whether theattributes
attribute is provided. If this is the case, the corresponding map bean is retrieved (an exception is thrown if this fails). Otherwise, an empty map is returned.- Returns:
- the map with attributes of the font
- Throws:
org.apache.commons.jelly.JellyTagException
- if the map cannot be retrieved
-
createFont
protected Object createFont(ComponentManager manager) throws FormBuilderException
Calls theComponentManager
to create the font represented by this tag. This method is called byprocess()
.- Parameters:
manager
- theComponentManager
- Returns:
- the font object created by this method
- Throws:
FormBuilderException
- if an error occurs
-
-