org.jrabbit.base.graphics.skins.text
Class RenderedTextSkin

java.lang.Object
  extended by org.jrabbit.base.graphics.skins.text.TextSkin
      extended by org.jrabbit.base.graphics.skins.text.RenderedTextSkin
All Implemented Interfaces:
Renderable, Skin, Dimensioned

public class RenderedTextSkin
extends TextSkin

RenderedTextSkin builds on the functionality provided by TextSkin to render its drawn text onto an image. This provides an immense speed boost over rendering each character in the font. However, there are two limitations in rendering the text like this. Firstly, the text shouldn't be changed that often - doing so will require a re-render of the text, which is slower. If the text to render can change quite often, usually it is better to simply stick with a basic TextSkin. Secondly, a RenderedTextSkin deals with Images outside of the ImageCache, and thus they are not affected by the default, simplified memory management system already in place. However, as Skins are intended to be lightweight, it doesn't make sense for a RenderedTextSkin to need to be manually destroyed. The solution to this problem is relatively simple. As Images are created by RenderedTextSkins, they are added to a list in the static class RenderedText. Thereafter, one can destroy all Image data by using the methods in RenderedText.

Author:
Chris Molini

Field Summary
protected  Image renderSurface
          The Image used to render text.
 
Fields inherited from class org.jrabbit.base.graphics.skins.text.TextSkin
fontPointer, format, formattedText, formatWidth, height, indent, reformat, text, width
 
Constructor Summary
RenderedTextSkin(java.lang.String text)
          Creates a RenderedTextSkin that uses the default font to render the supplied text.
RenderedTextSkin(java.lang.String text, java.lang.String font)
          Creates a RenderedTextSkin that uses the indicated font to render the supplied text.
 
Method Summary
protected  void defaultFormattting()
          RenderedTextSkin overrides the default formatting to ensure that it is formatted and indented within a 512-width paragraph.
protected  void format(Font font)
          Calculates the list of Strings to use for rendering as in TextSprite, and then renders the text to the Image.
 void render()
          Checks to if the rendered text needs to be updated, then draws the Image containing the rendered text.
 Image renderSurface()
          Accesses the RenderedTextSkin's Image.
 
Methods inherited from class org.jrabbit.base.graphics.skins.text.TextSkin
checkFormat, enableFormatting, enableIndent, flagReformat, font, formattedText, formatting, formatWidth, height, indenting, reformat, setFont, setFormatWidth, setText, setToDefaultFont, text, textHeight, textWidth, width
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

renderSurface

protected Image renderSurface
The Image used to render text.

Constructor Detail

RenderedTextSkin

public RenderedTextSkin(java.lang.String text)
Creates a RenderedTextSkin that uses the default font to render the supplied text.

Parameters:
text - The text to render.

RenderedTextSkin

public RenderedTextSkin(java.lang.String text,
                        java.lang.String font)
Creates a RenderedTextSkin that uses the indicated font to render the supplied text.

Parameters:
text - The text to render.
font - The identifier of the Font to render.
Method Detail

defaultFormattting

protected void defaultFormattting()
RenderedTextSkin overrides the default formatting to ensure that it is formatted and indented within a 512-width paragraph.

Overrides:
defaultFormattting in class TextSkin

renderSurface

public Image renderSurface()
Accesses the RenderedTextSkin's Image.

Returns:
The Image used to pre-render text.

format

protected void format(Font font)
Calculates the list of Strings to use for rendering as in TextSprite, and then renders the text to the Image.

Overrides:
format in class TextSkin
Parameters:
font - The Font to use in formatting and rendering.

render

public void render()
Checks to if the rendered text needs to be updated, then draws the Image containing the rendered text.

Specified by:
render in interface Renderable
Overrides:
render in class TextSkin