net.databinder.components
Class RenderedLabel

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.markup.html.WebComponent
          extended by org.apache.wicket.markup.html.image.Image
              extended by net.databinder.components.RenderedLabel
All Implemented Interfaces:
java.io.Serializable, org.apache.wicket.IClusterable, org.apache.wicket.IConverterLocator, org.apache.wicket.IRequestListener, org.apache.wicket.IResourceListener
Direct Known Subclasses:
BatikRenderedLabel, FontFormattedRenderedLabel

public class RenderedLabel
extends org.apache.wicket.markup.html.image.Image

Renders its model text into a PNG, using any typeface available to the JVM. The size of the image is determined by the model text and the characteristics of font selected. The default font is 14pt sans, plain black on a white background. The background may be set to null for alpha transparency, which will appear gray in outdated browsers. The image's alt attribute will be set to the model text, and width and height attributes will be set appropriately.

If told to use a shared image resource, RenderedLabel will add its image to the application's shared resources and reference it from a permanent, unique, browser-chacheable URL. Note that if users might request a shared resource before a page containing it has rendered (after a context reload, for example) you should load that resource using loadSharedResources() as the application is starting up.

This class is inspired by, and draws code from, Wicket's DefaultButtonImageResource.

Author:
Nathan Hamblen
See Also:
SharedResources, Serialized Form

Nested Class Summary
static class RenderedLabel.RenderedTextImageResource
          Inner class that renders the model text into an image resource.
 
Nested classes/interfaces inherited from class org.apache.wicket.Component
org.apache.wicket.Component.ComponentModelChange, org.apache.wicket.Component.EnabledChange, org.apache.wicket.Component.IVisitor, org.apache.wicket.Component.VisibilityChange
 
Field Summary
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Fields inherited from interface org.apache.wicket.IResourceListener
INTERFACE
 
Constructor Summary
RenderedLabel(java.lang.String id)
          Constructor to be used if model is derived from a compound property model.
RenderedLabel(java.lang.String id, boolean shareResource)
          Constructor for compound property model and shared resource pool.
RenderedLabel(java.lang.String id, org.apache.wicket.model.IModel model)
          Constructor with explicit model.
RenderedLabel(java.lang.String id, org.apache.wicket.model.IModel model, boolean shareResource)
          Constructor with explicit model.
 
Method Summary
static java.awt.Font fontForResource(org.apache.wicket.Resource fontRes)
          Utility method for creating Font objects from resources.
 java.awt.Color getBackgroundColor()
           
 java.awt.Color getColor()
           
 java.awt.Font getFont()
           
protected  int getLabelHash()
           
protected static int getLabelHash(java.lang.String text, java.awt.Font font, java.awt.Color color, java.awt.Color backgroundColor, java.lang.Integer maxWidth)
           
 java.lang.Integer getMaxWidth()
           
protected  void init()
          Perform generic initialization.
protected  org.apache.wicket.model.IModel initModel()
          Restores compound model resolution that is disabled in the Image superclass.
 boolean isAntiAliased()
           
 boolean isVisible()
           
protected static void loadSharedResources(RenderedLabel.RenderedTextImageResource res, java.lang.String text, java.awt.Font font, java.awt.Color color, java.awt.Color backgroundColor, java.lang.Integer maxWidth)
          Utility method to load a specific instance of a the rendering shared resource.
static void loadSharedResources(java.lang.String text, java.awt.Font font, java.awt.Color color, java.awt.Color backgroundColor, java.lang.Integer maxWidth)
          Load shared resource into pool so it will be available even before a page using the rendered label is first rendered.
protected  RenderedLabel.RenderedTextImageResource newRenderedTextImageResource(boolean isShared)
          Create a new image resource to render this label.
protected  void onBeforeRender()
           
protected  void onComponentTag(org.apache.wicket.markup.ComponentTag tag)
          Adds image-specific attributes including width, height, and alternate text.
 RenderedLabel setAntiAlias(boolean antiAlias)
           
 RenderedLabel setBackgroundColor(java.awt.Color backgroundColor)
          Specify a background color to match the page.
 RenderedLabel setColor(java.awt.Color color)
           
 RenderedLabel setFont(java.awt.Font font)
           
 RenderedLabel setMaxWidth(java.lang.Integer maxWidth)
          Specify a maximum pixel width, causing longer renderings to wrap.
 
Methods inherited from class org.apache.wicket.markup.html.image.Image
getImageResource, getImageResourceReference, getStatelessHint, onComponentTagBody, onResourceRequested, setImageResource, setImageResourceReference, setImageResourceReference, setModel
 
Methods inherited from class org.apache.wicket.markup.html.WebComponent
onRender
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, continueToOriginalDestination, debug, detach, detachBehaviors, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getBehaviors, getBehaviors, getClassRelativePath, getComponentBorder, getConverter, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMetaData, getModel, getModelComparator, getModelObject, getModelObjectAsString, getModelObjectAsString, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageFactory, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, internalAttach, internalDetach, internalOnAttach, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isAttached, isBehaviorAccepted, isEnableAllowed, isEnabled, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, newPage, newPage, onAfterRender, onAttach, onBeginRequest, onDetach, onEndRequest, onModelChanged, onModelChanging, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderHead, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMarkupStream, setMetaData, setModelObject, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, toString, toString, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RenderedLabel

public RenderedLabel(java.lang.String id)
Constructor to be used if model is derived from a compound property model.

Parameters:
id - Wicket id

RenderedLabel

public RenderedLabel(java.lang.String id,
                     boolean shareResource)
Constructor for compound property model and shared resource pool.

Parameters:
id - Wicket id
shareResource - true to add to shared resource pool

RenderedLabel

public RenderedLabel(java.lang.String id,
                     org.apache.wicket.model.IModel model)
Constructor with explicit model.

Parameters:
id - Wicket id
model - model for

RenderedLabel

public RenderedLabel(java.lang.String id,
                     org.apache.wicket.model.IModel model,
                     boolean shareResource)
Constructor with explicit model.

Parameters:
id - Wicket id
model - model for
shareResource - true to add to shared resource pool
Method Detail

init

protected void init()
Perform generic initialization.


onBeforeRender

protected void onBeforeRender()
Overrides:
onBeforeRender in class org.apache.wicket.Component

isVisible

public boolean isVisible()
Overrides:
isVisible in class org.apache.wicket.Component
Returns:
false if set to false or if model string is empty.

onComponentTag

protected void onComponentTag(org.apache.wicket.markup.ComponentTag tag)
Adds image-specific attributes including width, height, and alternate text. A hash is appended to the source URL to trigger a reload whenever drawing attributes change.

Overrides:
onComponentTag in class org.apache.wicket.markup.html.image.Image

getLabelHash

protected int getLabelHash()

getLabelHash

protected static int getLabelHash(java.lang.String text,
                                  java.awt.Font font,
                                  java.awt.Color color,
                                  java.awt.Color backgroundColor,
                                  java.lang.Integer maxWidth)

initModel

protected org.apache.wicket.model.IModel initModel()
Restores compound model resolution that is disabled in the Image superclass.

Overrides:
initModel in class org.apache.wicket.markup.html.image.Image

loadSharedResources

public static void loadSharedResources(java.lang.String text,
                                       java.awt.Font font,
                                       java.awt.Color color,
                                       java.awt.Color backgroundColor,
                                       java.lang.Integer maxWidth)
Load shared resource into pool so it will be available even before a page using the rendered label is first rendered. May be needed if a page is cachable and the context is restarted, for example.

Parameters:
text -
font - uses default if null
color - uses default if null
backgroundColor - uses default if null
maxWidth -

loadSharedResources

protected static void loadSharedResources(RenderedLabel.RenderedTextImageResource res,
                                          java.lang.String text,
                                          java.awt.Font font,
                                          java.awt.Color color,
                                          java.awt.Color backgroundColor,
                                          java.lang.Integer maxWidth)
Utility method to load a specific instance of a the rendering shared resource.


newRenderedTextImageResource

protected RenderedLabel.RenderedTextImageResource newRenderedTextImageResource(boolean isShared)
Create a new image resource to render this label. Override in a subclass to use a different renderer.

Parameters:
isShared - is a shared, cacheable resource
Returns:
new instance of RenderedTextImageResource or subclass

getBackgroundColor

public java.awt.Color getBackgroundColor()

setBackgroundColor

public RenderedLabel setBackgroundColor(java.awt.Color backgroundColor)
Specify a background color to match the page. Specify null for a transparent background blended with the alpha channel, causing IE6 to display a gray background.

Parameters:
backgroundColor - color or null for transparent
Returns:
this for chaining

getColor

public java.awt.Color getColor()

setColor

public RenderedLabel setColor(java.awt.Color color)
Parameters:
color - Color to print text

getFont

public java.awt.Font getFont()

setFont

public RenderedLabel setFont(java.awt.Font font)

getMaxWidth

public java.lang.Integer getMaxWidth()

setMaxWidth

public RenderedLabel setMaxWidth(java.lang.Integer maxWidth)
Specify a maximum pixel width, causing longer renderings to wrap.

Parameters:
maxWidth - maximum width in pixels
Returns:
this, for chaining

fontForResource

public static java.awt.Font fontForResource(org.apache.wicket.Resource fontRes)
Utility method for creating Font objects from resources.

Parameters:
fontRes - Resource containing a TrueType font descriptor.
Returns:
Plain, 16pt font derived from the resource.

isAntiAliased

public boolean isAntiAliased()

setAntiAlias

public RenderedLabel setAntiAlias(boolean antiAlias)


Copyright © 2005-2008 Nathan Hamblen. All Rights Reserved.