de.enough.polish.util
Class BitMapFontViewer

java.lang.Object
  extended by de.enough.polish.util.BitMapFontViewer

public class BitMapFontViewer
extends java.lang.Object

Is used for a performant showing of String with a bitmap font.

Copyright Enough Software 2004 - 2008

 history
        09-Nov-2004 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
static int ABSOLUTE_LINE_BREAK
           
static int ARTIFICAL_LINE_BREAK
           
 
Constructor Summary
BitMapFontViewer(javax.microedition.lcdui.Image image, int[] indeces, short[] xPositions, byte[] characterWidths, int fontHeight, int spaceIndex, int verticalPadding)
          Views a specific input string with a specific bitmap font.
 
Method Summary
 int getFontHeight()
          Returns the height of used font.
 int getHeight()
          Retrieves the height needed for this viewer.
 int getNumberOfLines()
          Retrieves the number of lines which are used to display the embedded text.
 byte[] getUsedCharactersWidths()
          Returns the used character widths.
 int getWidth()
          Retrieves the width needed for this viewer.
 void layout(int firstLineWidth, int lineWidth, int paddingVertical, int orientationSetting)
          Layouts this text-viewer.
 void paint(int x, int y, javax.microedition.lcdui.Graphics g)
          Paints this viewer on the screen.
 void setHorizontalOrientation(int orientation)
          Sets the orientation of the text
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ABSOLUTE_LINE_BREAK

public static final int ABSOLUTE_LINE_BREAK
See Also:
Constant Field Values

ARTIFICAL_LINE_BREAK

public static final int ARTIFICAL_LINE_BREAK
See Also:
Constant Field Values
Constructor Detail

BitMapFontViewer

public BitMapFontViewer(javax.microedition.lcdui.Image image,
                        int[] indeces,
                        short[] xPositions,
                        byte[] characterWidths,
                        int fontHeight,
                        int spaceIndex,
                        int verticalPadding)
Views a specific input string with a specific bitmap font.

Parameters:
image - the basic font-image
indeces - array of the x-positions of the to-be-displayed characters
xPositions - array of the x-positions of the to-be-displayed characters
characterWidths - array of the widths of the to-be-displayed characters
fontHeight - the height of the font
spaceIndex - the index of the space character
verticalPadding - the padding between two lines
Method Detail

paint

public void paint(int x,
                  int y,
                  javax.microedition.lcdui.Graphics g)
Paints this viewer on the screen.

Parameters:
x - the x-position for the text. When the orientation is LEFT, x defines the left-border; when the orientation is RIGHT, x defines the rigth border; when the orientation is HCENTER, x defines the middle between left and right border.
y - the top y-position of the first line.
g - the graphics object

getWidth

public int getWidth()
Retrieves the width needed for this viewer.

Returns:
the width in pixels

getHeight

public int getHeight()
Retrieves the height needed for this viewer.

Returns:
the height in pixels

layout

public void layout(int firstLineWidth,
                   int lineWidth,
                   int paddingVertical,
                   int orientationSetting)
Layouts this text-viewer.

Parameters:
firstLineWidth - the available width for the first line
lineWidth - the available width for the following lines
paddingVertical - the space between lines
orientationSetting - the orientation of this viewer, either Grapics.LEFT, Graphics.RIGHT or Graphics.HCENTER
See Also:
getHeight(), getWidth()

setHorizontalOrientation

public void setHorizontalOrientation(int orientation)
Sets the orientation of the text

Parameters:
orientation - the horizontal text orientation like Graphics.LEFT, Graphics.RIGHT or Graphics.HCENTER

getFontHeight

public int getFontHeight()
Returns the height of used font.

Returns:
the height of the bitmap-font in pixels.

getNumberOfLines

public int getNumberOfLines()
Retrieves the number of lines which are used to display the embedded text.

Returns:
the number of lines.

getUsedCharactersWidths

public byte[] getUsedCharactersWidths()
Returns the used character widths. This is usefull to have information about the actual position of each character. You can modify the array because only a copy is returned.

Returns:
a copy of the internal byte array representing the widths of the included characters