com.jmex.bui.text
Class AWTTextFactory

java.lang.Object
  extended by com.jmex.bui.text.BTextFactory
      extended by com.jmex.bui.text.AWTTextFactory
All Implemented Interfaces:
BConstants

public class AWTTextFactory
extends BTextFactory

Formats text by using the AWT to render runs of text into a bitmap and then texturing a quad with the result. This text factory handles a simple styled text syntax:

 @=b(this text would be bold)
 @=i(this text would be italic)
 @=s(this text would be striked-through)
 @=u(this text would be underlined)
 @=bi(this text would be bold and italic)
 @=bi#FFCC99(this text would be bold, italic and pink)
 


Nested Class Summary
protected static class AWTTextFactory.GlowKey
           
protected static class AWTTextFactory.StyleRun
           
 
Field Summary
protected  boolean _antialias
           
protected  Map<TextAttribute,Font> _attrs
           
protected  Map<AWTTextFactory.GlowKey,BufferedImage> _cachedGlowBGs
           
protected  Map<AWTTextFactory.GlowKey,BufferedImage> _cachedGlowFGs
           
protected  AWTTextFactory.GlowKey _gkey
           
protected  int _height
           
protected static boolean _isMacOS
           
protected  BufferedImage _stub
           
protected static char BOLD
           
protected static char COLOR
           
protected static char ITALIC
           
protected static char NONE
           
protected static char STRIKE
           
protected static char UNDERLINE
           
 
Fields inherited from interface com.jmex.bui.BConstants
BOTTOM, CENTER, DEFAULT_SIZE, DEFAULT_SPACING, GLOW, HORIZONTAL, LEFT, NORMAL, OUTLINE, OVERLAPPING, PLAIN, RIGHT, SHADOW, TOP, VERTICAL
 
Constructor Summary
AWTTextFactory(Font font, boolean antialias)
          Creates an AWT text factory with the supplied font.
 
Method Summary
protected  int computeWidth(char c)
          Helper function.
 BText createText(String text, ColorRGBA color, int effect, int effectSize, ColorRGBA effectColor, boolean useAdvance)
          Creates a text instance using our the font configuration associated with this text factory and the foreground color, text effect and text effect color specified.
protected  BText createText(String origText, TextLayout layout, ColorRGBA color, int effect, int effectSize, ColorRGBA effectColor, int length, boolean useAdvance)
          Helper function.
protected  BufferedImage getGlowBackground(char c, int height, ColorRGBA color, int effectSize)
          Helper function.
protected  BufferedImage getGlowForeground(char c, int height, ColorRGBA color, int effectSize)
          Helper function.
 int getHeight()
          Returns the height of our text.
protected  AttributedString parseStyledText(String text, Map<TextAttribute,Font> attrs, String[] bare, boolean style)
          Parses our simple styled text formatting codes and creates an attributed string to render them.
 BText[] wrapText(String text, ColorRGBA color, int effect, int effectSize, ColorRGBA effectColor, int maxWidth)
          Wraps a string into a set of text objects that do not exceed the specified width.
 
Methods inherited from class com.jmex.bui.text.BTextFactory
createText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_antialias

protected boolean _antialias

_height

protected int _height

_stub

protected BufferedImage _stub

_attrs

protected Map<TextAttribute,Font> _attrs

_cachedGlowBGs

protected Map<AWTTextFactory.GlowKey,BufferedImage> _cachedGlowBGs

_cachedGlowFGs

protected Map<AWTTextFactory.GlowKey,BufferedImage> _cachedGlowFGs

_gkey

protected AWTTextFactory.GlowKey _gkey

_isMacOS

protected static boolean _isMacOS

NONE

protected static final char NONE
See Also:
Constant Field Values

BOLD

protected static final char BOLD
See Also:
Constant Field Values

ITALIC

protected static final char ITALIC
See Also:
Constant Field Values

UNDERLINE

protected static final char UNDERLINE
See Also:
Constant Field Values

STRIKE

protected static final char STRIKE
See Also:
Constant Field Values

COLOR

protected static final char COLOR
See Also:
Constant Field Values
Constructor Detail

AWTTextFactory

public AWTTextFactory(Font font,
                      boolean antialias)
Creates an AWT text factory with the supplied font.

Method Detail

getHeight

public int getHeight()
Description copied from class: BTextFactory
Returns the height of our text.

Specified by:
getHeight in class BTextFactory

createText

public BText createText(String text,
                        ColorRGBA color,
                        int effect,
                        int effectSize,
                        ColorRGBA effectColor,
                        boolean useAdvance)
Description copied from class: BTextFactory
Creates a text instance using our the font configuration associated with this text factory and the foreground color, text effect and text effect color specified.

Specified by:
createText in class BTextFactory
useAdvance - if true, the advance to the next insertion point will be included in the bounds of the created text (this is needed by editable text displays).

wrapText

public BText[] wrapText(String text,
                        ColorRGBA color,
                        int effect,
                        int effectSize,
                        ColorRGBA effectColor,
                        int maxWidth)
Description copied from class: BTextFactory
Wraps a string into a set of text objects that do not exceed the specified width.

Specified by:
wrapText in class BTextFactory

createText

protected BText createText(String origText,
                           TextLayout layout,
                           ColorRGBA color,
                           int effect,
                           int effectSize,
                           ColorRGBA effectColor,
                           int length,
                           boolean useAdvance)
Helper function.


getGlowBackground

protected BufferedImage getGlowBackground(char c,
                                          int height,
                                          ColorRGBA color,
                                          int effectSize)
Helper function.


getGlowForeground

protected BufferedImage getGlowForeground(char c,
                                          int height,
                                          ColorRGBA color,
                                          int effectSize)
Helper function.


computeWidth

protected int computeWidth(char c)
Helper function.


parseStyledText

protected AttributedString parseStyledText(String text,
                                           Map<TextAttribute,Font> attrs,
                                           String[] bare,
                                           boolean style)
Parses our simple styled text formatting codes and creates an attributed string to render them.



Copyright © 2008 Michael Bayne. All Rights Reserved.