de.enough.polish.ui
Class TextEffect

java.lang.Object
  extended by de.enough.polish.ui.TextEffect
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AlienGlowTextEffect, DropShadowTextEffect, FadeTextEffect, FadingAlienGlowTextEffect, FlashTextEffect, LighthouseTextEffect, OutlineTextEffect, RotateTextEffect, RotatingTextEffect, SegmentTextEffect, ShadowTextEffect, SmileyTextEffect, TypeWriterTextEffect, VerticalGradientTextEffect, VerticalMirrorTextEffect, VerticalSplitTextEffect

public abstract class TextEffect
extends java.lang.Object
implements Serializable

Allows text effects for StringItems, IconItems and ChoiceItems.

Copyright (c) Enough Software 2005 - 2008

 history
        16-Nov-2005 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected  Style style
           
 
Constructor Summary
TextEffect()
          Creates a new effect
 
Method Summary
 boolean animate()
          Animates this effect.
 void animate(Item parent, long currentTime, ClippingRegion repaintRegion)
          Animates this effect.
abstract  void drawString(java.lang.String text, int textColor, int x, int y, int orientation, javax.microedition.lcdui.Graphics g)
          Paints the text and applies the text effect.
 void drawStrings(java.lang.String[] textLines, int textColor, int x, int y, int leftBorder, int rightBorder, int lineHeight, int maxWidth, int layout, javax.microedition.lcdui.Graphics g)
          Paints the text and applies the text effect.
protected  javax.microedition.lcdui.Font getFont()
          Retrieves the font that should be used.
 int getFontHeight()
          Retrieves the font height by default.
 int getLeftX(int x, int orientation, int textWidth)
          Retrieves the left start position for a text.
static int[] getRgbData(java.lang.String text, int textColor, javax.microedition.lcdui.Font font)
          Retrieves an RGB integer array in which the text is written on MIDP 2.0 devices.
static int[] getRgbData(java.lang.String text, int textColor, javax.microedition.lcdui.Font font, int x, int y, int width, int height)
          Retrieves an RGB integer array in which the text is written on MIDP 2.0 devices.
static int[] getRgbData(java.lang.String text, int textColor, javax.microedition.lcdui.Font font, int x, int y, int width, int height, int transparentColor)
          Retrieves an RGB integer array in which the text is written on MIDP 2.0 devices.
 int getTopY(int y, int orientation, javax.microedition.lcdui.Font font)
          Retrieves the top y position for a text.
 int getTopY(int y, int orientation, int height, int baseLine)
          Retrieves the top y position for a text.
 void hideNotify()
          Notifies this effect that the corresponding item is to be hidden.
 void releaseResources()
          Releases any resources this effect might contain.
 void setStyle(Style style)
          Sets the style of this item.
 void showNotify()
          Notifies this effect that the corresponding item is to be shown.
 int stringWidth(java.lang.String str)
          Calculates the width of the given text.
 java.lang.String[] wrap(java.lang.String text, javax.microedition.lcdui.Font font, int firstLineWidth, int lineWidth)
          Wraps the text into several lines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

style

protected transient Style style
Constructor Detail

TextEffect

public TextEffect()
Creates a new effect

Method Detail

setStyle

public void setStyle(Style style)
Sets the style of this item. Subclasses can override this method for getting specific settings.

Parameters:
style - the new style for this item.
Throws:
java.lang.NullPointerException - when style is null

animate

public boolean animate()
Animates this effect. Subclasses can override this method to create animations.

Returns:
true when this effect has been animated.

animate

public void animate(Item parent,
                    long currentTime,
                    ClippingRegion repaintRegion)
Animates this effect. Subclasses can override this method to create animations. The default implementation calls the animate() method and adds the full content area to the repaint region.

Parameters:
parent - the parent item
currentTime - the current time in milliseconds
repaintRegion - the repaint area that needs to be updated when this item is animated
See Also:
Item.addRelativeToContentRegion(ClippingRegion, int, int, int, int)

drawStrings

public void drawStrings(java.lang.String[] textLines,
                        int textColor,
                        int x,
                        int y,
                        int leftBorder,
                        int rightBorder,
                        int lineHeight,
                        int maxWidth,
                        int layout,
                        javax.microedition.lcdui.Graphics g)
Paints the text and applies the text effect. The default implementation calls drawText( String, int, int, int, int, int, Graphics)

Parameters:
textLines - the text
textColor - the color of the text
x - horizontal start coordinate
y - vertical start coordinate
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position
lineHeight - the height of a single text line
maxWidth - the width of the longest line
layout - the anchor or the text, e.g. Item.LAYOUT_CENTER or Item.LAYOUT_RIGHT
g - the graphics context
See Also:
drawString( String,int,int,int,int,Graphics)

drawString

public abstract void drawString(java.lang.String text,
                                int textColor,
                                int x,
                                int y,
                                int orientation,
                                javax.microedition.lcdui.Graphics g)
Paints the text and applies the text effect.

Parameters:
text - the text
textColor - the color of the text
x - x coordinate
y - y coordinate
orientation - the orientation, e.g. Graphics.TOP | Graphics.LEFT or Graphics.TOP | Graphics.HCENTER
g - the graphics context

getLeftX

public int getLeftX(int x,
                    int orientation,
                    int textWidth)
Retrieves the left start position for a text.

Parameters:
x - the x position given in drawString()
orientation - the orientation given in drawString()
textWidth - the width of the text given in drawString()
Returns:
the left x position

getTopY

public int getTopY(int y,
                   int orientation,
                   javax.microedition.lcdui.Font font)
Retrieves the top y position for a text.

Parameters:
y - the y position given in drawString()
orientation - the orientation given in drawString()
font - the used font, usually g.getFont()
Returns:
the top y position.

getTopY

public int getTopY(int y,
                   int orientation,
                   int height,
                   int baseLine)
Retrieves the top y position for a text.

Parameters:
y - the y position given in drawString()
orientation - the orientation given in drawString()
height - the height of the used font
baseLine - the base line of the used font
Returns:
the top y position.

getRgbData

public static int[] getRgbData(java.lang.String text,
                               int textColor,
                               javax.microedition.lcdui.Font font)
Retrieves an RGB integer array in which the text is written on MIDP 2.0 devices. NOTE: this method is not available on MIDP 1.0 devices! You can determine the height and width of the produced RGB data with this code:
 int[] rgbData = getRgbData(text, textColor, font);
 int height = font.getHeight();
 int width = rgbData.length / height;
 

Parameters:
text - the text
textColor - the color of the text
font - the font of the text
Returns:
the RGB data that contains the given text

getRgbData

public static int[] getRgbData(java.lang.String text,
                               int textColor,
                               javax.microedition.lcdui.Font font,
                               int x,
                               int y,
                               int width,
                               int height)
Retrieves an RGB integer array in which the text is written on MIDP 2.0 devices. NOTE: this method is not available on MIDP 1.0 devices!

Parameters:
text - the text
textColor - the color of the text
font - the font of the text
x - the left corner of the text in the created rgb data
y - the top corner of the text in the created rgb data
width - the desired width of the data array array, e.g. font.stringWidth(text)
height - the desired height of the data array, e.g. font.getHeight()
Returns:
the RGB data that contains the given text
See Also:
DrawUtil.getComplementaryColor(int)

getRgbData

public static int[] getRgbData(java.lang.String text,
                               int textColor,
                               javax.microedition.lcdui.Font font,
                               int x,
                               int y,
                               int width,
                               int height,
                               int transparentColor)
Retrieves an RGB integer array in which the text is written on MIDP 2.0 devices. NOTE: this method is not available on MIDP 1.0 devices!

Parameters:
text - the text
textColor - the color of the text
font - the font of the text
x - the left corner of the text in the created rgb data
y - the top corner of the text in the created rgb data
width - the desired width of the data array array, e.g. font.stringWidth(text)
height - the desired height of the data array, e.g. font.getHeight()
transparentColor - the color that should be used to flag transparent parts, using DrawUtil.getComplementaryColor( textColor ) might be a good idea
Returns:
the RGB data that contains the given text
See Also:
DrawUtil.getComplementaryColor(int)

showNotify

public void showNotify()
Notifies this effect that the corresponding item is to be shown. The default implementation is empty.


hideNotify

public void hideNotify()
Notifies this effect that the corresponding item is to be hidden. The default implementation is empty.


releaseResources

public void releaseResources()
Releases any resources this effect might contain. For staying future proof subclasses should call super.releaseResources() first, when overriding this method.


stringWidth

public int stringWidth(java.lang.String str)
Calculates the width of the given text. By default getFont().stringWidth(text) is returned.

Parameters:
str - the text of which the width should be determined
Returns:
the width of the text

getFontHeight

public int getFontHeight()
Retrieves the font height by default.

Returns:
the height of the font

getFont

protected javax.microedition.lcdui.Font getFont()
Retrieves the font that should be used.

Returns:
the font

wrap

public java.lang.String[] wrap(java.lang.String text,
                               javax.microedition.lcdui.Font font,
                               int firstLineWidth,
                               int lineWidth)
Wraps the text into several lines.

Parameters:
text - the text
font - used font
firstLineWidth - width of the first line
lineWidth - width of following lines
Returns:
an arrays with strings all fitting into the specified dimensions