Class 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 the ComponentManager. 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 the ComponentManager. 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, the var attribute must be specified. If a tag is neither nested in a ComponentBaseTag tag nor has the var 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 Detail

      • FontTag

        public FontTag()
    • 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 the name 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 the var 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 the attributes 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 the size 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 the bold 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 the italic 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 the ComponentManager 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 class FormBaseTag
        Throws:
        org.apache.commons.jelly.JellyTagException - if the tag is used incorrectly
        FormBuilderException - if an error occurs
      • process

        protected void process()
                        throws org.apache.commons.jelly.JellyTagException,
                               FormBuilderException
        Processes this tag. This implementation delegates to the ComponentManager to actually create the font. Then the new font object is passed to the corresponding receivers.
        Specified by:
        process in class FormBaseTag
        Throws:
        org.apache.commons.jelly.JellyTagException - if the tag is used incorrectly
        FormBuilderException - 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 the attributes 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