de.enough.polish.ui
Class StringItem

java.lang.Object
  extended by de.enough.polish.ui.Item
      extended by de.enough.polish.ui.StringItem
Direct Known Subclasses:
DateField, IconItem, TextField

public class StringItem
extends Item

An item that can contain a string. A StringItem is display-only; the user cannot edit the contents. Both the label and the textual content of a StringItem may be modified by the application. The visual representation of the label may differ from that of the textual contents.

Author:
Robert Virkus, robert@enough.de

Field Summary
protected  boolean animateTextWrap
           
protected  BitMapFont bitMapFont
           
protected  BitMapFontViewer bitMapFontViewer
           
protected  boolean clipText
           
protected  javax.microedition.lcdui.Font font
           
protected  java.lang.String text
           
protected  int textColor
           
protected  TextEffect textEffect
           
protected  int textHorizontalAdjustment
           
protected  java.lang.String[] textLines
           
protected  int textVerticalAdjustment
           
protected  int textWrapDirection
           
protected  int textWrapSpeed
           
protected  boolean useSingleLine
           
protected  int xOffset
           
 
Fields inherited from class de.enough.polish.ui.Item
_bbField, _bbFieldAdded, appearanceMode, background, backgroundHeight, backgroundWidth, backgroundYOffset, border, borderWidth, BUTTON, colSpan, commands, completeBackground, completeBackgroundPadding, completeBorder, contentHeight, contentWidth, contentX, contentY, cssSelector, defaultCommand, focusedStyle, HORIZONTAL, HYPERLINK, includeLabel, INTERACTIVE, internalHeight, internalWidth, internalX, internalY, isFocused, isInitialized, isInvisible, isLayoutCenter, isLayoutExpand, isLayoutRight, isPressed, isShown, isStyleInitialised, itemCommandListener, itemHeight, itemWidth, label, labelStyle, layout, LAYOUT_2, LAYOUT_BOTTOM, LAYOUT_CENTER, LAYOUT_DEFAULT, LAYOUT_EXPAND, LAYOUT_LEFT, LAYOUT_NEWLINE_AFTER, LAYOUT_NEWLINE_BEFORE, LAYOUT_RIGHT, LAYOUT_SHRINK, LAYOUT_TOP, LAYOUT_VCENTER, LAYOUT_VEXPAND, LAYOUT_VSHRINK, marginBottom, marginLeft, marginRight, marginTop, maximumHeight, maximumWidth, minimumHeight, minimumWidth, NO_POSITION_SET, opacity, opacityPaintNormally, opacityRgbData, paddingBottom, paddingHorizontal, paddingLeft, paddingRight, paddingTop, paddingVertical, parent, PLAIN, preferredHeight, preferredWidth, preserveViewType, relativeX, relativeY, rowSpan, screen, style, TRANSPARENT, useSingleRow, VERTICAL, view
 
Constructor Summary
StringItem(java.lang.String label, java.lang.String text)
          Creates a new StringItem object.
StringItem(java.lang.String label, java.lang.String text, int appearanceMode)
          Creates a new StringItem object with the given label, textual content, and appearance mode.
StringItem(java.lang.String label, java.lang.String text, int appearanceMode, Style style)
          Creates a new StringItem object with the given label, textual content, and appearance mode.
StringItem(java.lang.String label, java.lang.String text, Style style)
          Creates a new StringItem object.
 
Method Summary
 void animate(long currentTime, ClippingRegion repaintRegion)
          Animates this item.
protected  java.lang.String createCssSelector()
          Retrieves the CSS selector for this item.
protected  void defocus(Style originalStyle)
          Removes the focus from this item.
 javax.microedition.lcdui.Font getFont()
          Gets the application's preferred font for rendering this StringItem.
 int getFontHeight()
          Retrieves the height necessary for displaying a row of text without the padding-vertical.
 java.lang.String getText()
          Gets the text contents of the StringItem, or null if the StringItem is empty.
protected  void hideNotify()
          Called by the system to notify the item that it is now completely invisible, when it previously had been at least partially visible.
protected  void initContent(int firstLineWidth, int lineWidth)
          Initialises this item.
 void paintContent(int x, int y, int leftBorder, int rightBorder, javax.microedition.lcdui.Graphics g)
          Paints the content of this item.
 void releaseResources()
          Releases all (memory intensive) resources such as images or RGB arrays of this item.
 void setFont(javax.microedition.lcdui.Font font)
          Sets the application's preferred font for rendering this StringItem.
 void setStyle(Style style)
          Sets the style of this item.
 void setText(java.lang.String text)
          Sets the text contents of the StringItem.
 void setText(java.lang.String text, Style style)
          Sets the text contents of the StringItem along with a style.
 void setTextColor(int color)
          Sets the text color for contents of the StringItem.
protected  void showNotify()
          Called by the system to notify the item that it is now at least partially visible, when it previously had been completely invisible.
 int stringWidth(java.lang.String str)
          Calculates the width of the given text.
 java.lang.String toString()
          Generates a String representation of this item.
 
Methods inherited from class de.enough.polish.ui.Item
addCommand, addCommand, addCommands, addRelativeToBackgroundRegion, addRelativeToBackgroundRegion, addRelativeToContentRegion, animate, containsCommand, focus, getAbsoluteX, getAbsoluteY, getAppearanceMode, getAttribute, getAttributes, getBackgroundHeight, getBackgroundWidth, getBackgroundX, getBackgroundY, getContentHeight, getContentWidth, getContentX, getContentY, getDefaultCommand, getFocusedStyle, getItemAt, getItemCommandListener, getItemCommands, getItemHeight, getItemStateListener, getItemWidth, getLabel, getLabelItem, getLayout, getMinimumHeight, getMinimumWidth, getParent, getPreferredHeight, getPreferredWidth, getScreen, getStyle, handleCommand, handleKeyPressed, handleKeyReleased, handleKeyRepeated, handlePointerPressed, handlePointerReleased, init, initStyle, isInContentArea, isInItemArea, isInItemArea, isInitialized, isVisible, notifyItemPressedEnd, notifyItemPressedStart, notifyStateChanged, paint, paintBackground, paintBackgroundAndBorder, paintBorder, removeCommand, repaint, repaint, repaintFully, requestInit, setAppearanceMode, setAttribute, setDefaultCommand, setItemCommandListener, setItemCommandListener, setItemStateListener, setLabel, setLayout, setParent, setParent, setPreferredSize, setVisible, show, showCommands
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

text

protected java.lang.String text

textLines

protected java.lang.String[] textLines

textColor

protected int textColor

font

protected javax.microedition.lcdui.Font font

bitMapFont

protected BitMapFont bitMapFont

bitMapFontViewer

protected BitMapFontViewer bitMapFontViewer

useSingleLine

protected boolean useSingleLine

clipText

protected boolean clipText

xOffset

protected int xOffset

animateTextWrap

protected boolean animateTextWrap

textWrapDirection

protected int textWrapDirection

textWrapSpeed

protected int textWrapSpeed

textHorizontalAdjustment

protected int textHorizontalAdjustment

textVerticalAdjustment

protected int textVerticalAdjustment

textEffect

protected TextEffect textEffect
Constructor Detail

StringItem

public StringItem(java.lang.String label,
                  java.lang.String text)
Creates a new StringItem object. Calling this constructor is equivalent to calling

 StringItem(label, text, Item.PLAIN, null);     
 

Parameters:
label - the Item label
text - the text contents
See Also:
StringItem(String, String, int, Style)

StringItem

public StringItem(java.lang.String label,
                  java.lang.String text,
                  Style style)
Creates a new StringItem object. Calling this constructor is equivalent to calling

 StringItem(label, text, Item.PLAIN, style);     
 

Parameters:
label - the Item label
text - the text contents
style - the style
See Also:
StringItem(String, String, int, Style)

StringItem

public StringItem(java.lang.String label,
                  java.lang.String text,
                  int appearanceMode)
Creates a new StringItem object with the given label, textual content, and appearance mode. Either label or text may be present or null.

The appearanceMode parameter (see Appearance Modes) is a hint to the platform of the application's intended use for this StringItem. To provide hyperlink- or button-like behavior, the application should associate a default Command with this StringItem and add an ItemCommandListener to this StringItem.

Here is an example showing the use of a StringItem as a button:


 StringItem strItem = new StringItem("Default: ", "Set", Item.BUTTON);
 strItem.setDefaultCommand(
 new Command("Set", Command.ITEM, 1);
 // icl is ItemCommandListener
 strItem.setItemCommandListener(icl);     
 

Parameters:
label - the StringItem's label, or null if no label
text - the StringItem's text contents, or null if the contents are initially empty
appearanceMode - the appearance mode of the StringItem, one of Item.PLAIN, Item.HYPERLINK, or Item.BUTTON
Throws:
java.lang.IllegalArgumentException - if appearanceMode invalid
Since:
MIDP 2.0

StringItem

public StringItem(java.lang.String label,
                  java.lang.String text,
                  int appearanceMode,
                  Style style)
Creates a new StringItem object with the given label, textual content, and appearance mode. Either label or text may be present or null.

The appearanceMode parameter (see Appearance Modes) is a hint to the platform of the application's intended use for this StringItem. To provide hyperlink- or button-like behavior, the application should associate a default Command with this StringItem and add an ItemCommandListener to this StringItem.

Here is an example showing the use of a StringItem as a button:


 StringItem strItem = new StringItem("Default: ", "Set", Item.BUTTON);
 strItem.setDefaultCommand(
 new Command("Set", Command.ITEM, 1);
 // icl is ItemCommandListener
 strItem.setItemCommandListener(icl);     
 

Parameters:
label - the StringItem's label, or null if no label
text - the StringItem's text contents, or null if the contents are initially empty
appearanceMode - the appearance mode of the StringItem, one of Item.PLAIN, Item.HYPERLINK, or Item.BUTTON
style - the style for this item
Throws:
java.lang.IllegalArgumentException - if appearanceMode invalid
Since:
MIDP 2.0
Method Detail

animate

public void animate(long currentTime,
                    ClippingRegion repaintRegion)
Description copied from class: Item
Animates this item. Subclasses can override this method to create animations. The default implementation animates the background and the item view if present.

Overrides:
animate in class Item
Parameters:
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)

defocus

protected void defocus(Style originalStyle)
Description copied from class: Item
Removes the focus from this item.

Overrides:
defocus in class Item
Parameters:
originalStyle - the original style which will be restored.

hideNotify

protected void hideNotify()
Description copied from class: Item
Called by the system to notify the item that it is now completely invisible, when it previously had been at least partially visible. No further paint() calls will be made on this item until after a showNotify() has been called again.

The default implementation of this method sets the isShown field to false and calls hideNotify on style elements.

Overrides:
hideNotify in class Item

showNotify

protected void showNotify()
Description copied from class: Item
Called by the system to notify the item that it is now at least partially visible, when it previously had been completely invisible. The item may receive paint() calls after showNotify() has been called.

The default implementation of this method sets the isShown field to true and calls showNotify on style elements.

Overrides:
showNotify in class Item

getText

public java.lang.String getText()
Gets the text contents of the StringItem, or null if the StringItem is empty.

Returns:
a string with the content of the item
See Also:
setText(java.lang.String)

setText

public void setText(java.lang.String text)
Sets the text contents of the StringItem. If text is null, the StringItem is set to be empty.

Parameters:
text - the new content
See Also:
getText()

setText

public void setText(java.lang.String text,
                    Style style)
Sets the text contents of the StringItem along with a style. If text is null, the StringItem is set to be empty.

Parameters:
text - the new content
style - the new style, is ignored when null
See Also:
getText()

setTextColor

public void setTextColor(int color)
Sets the text color for contents of the StringItem.

Parameters:
color - the new color for the content

setFont

public void setFont(javax.microedition.lcdui.Font font)
Sets the application's preferred font for rendering this StringItem. The font is a hint, and the implementation may disregard the application's preferred font.

The font parameter must be a valid Font object or null. If the font parameter is null, the implementation must use its default font to render the StringItem.

Parameters:
font - - the preferred font to use to render this StringItem
Since:
MIDP 2.0
See Also:
getFont()

getFont

public javax.microedition.lcdui.Font getFont()
Gets the application's preferred font for rendering this StringItem. The value returned is the font that had been set by the application, even if that value had been disregarded by the implementation. If no font had been set by the application, or if the application explicitly set the font to null, the value is the default font chosen by the implementation.

Returns:
the preferred font to use to render this StringItem
Since:
MIDP 2.0
See Also:
setFont(javax.microedition.lcdui.Font)

paintContent

public void paintContent(int x,
                         int y,
                         int leftBorder,
                         int rightBorder,
                         javax.microedition.lcdui.Graphics g)
Description copied from class: Item
Paints the content of this item. The background has already been painted and the border will be added after this method returns.

Specified by:
paintContent in class Item
Parameters:
x - the left start position
y - the upper start position
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position
g - the Graphics on which this item should be painted.

stringWidth

public int stringWidth(java.lang.String str)
Calculates the width of the given text. When a bitmap font is used, the calculation is forwarded to it. When a texteffect is used, the calculation is forwared to it. In other cases font.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 height necessary for displaying a row of text without the padding-vertical.

Returns:
the font height (either from the bitmap, the text-effect or the font used)

initContent

protected void initContent(int firstLineWidth,
                           int lineWidth)
Description copied from class: Item
Initialises this item. The implementation needs to calculate and set the contentWidth and contentHeight fields. The implementation should take the fields preferredWidth and preferredHeight into account.

Specified by:
initContent in class Item
Parameters:
firstLineWidth - the maximum width of the first line
lineWidth - the maximum width of any following lines
See Also:
Item.contentWidth, Item.contentHeight, Item.preferredWidth, Item.preferredHeight

setStyle

public void setStyle(Style style)
Description copied from class: Item
Sets the style of this item.

Overrides:
setStyle in class Item
Parameters:
style - the new style for this item.

createCssSelector

protected java.lang.String createCssSelector()
Description copied from class: Item
Retrieves the CSS selector for this item. The CSS selector is used for the dynamic assignment of styles - that is the styles are assigned by the usage of the item and not by a predefined style-name. With the #style preprocessing command styles are set fix, this method yields in a faster GUI and is recommended. When in a style-sheet dynamic styles are used, e.g. "Form>p", than the selector of the item is needed.
This abstract method needs only be implemented, when dynamic styles are used: #ifdef polish.useDynamicStyles
The returned selector needs to be in lower case.

Specified by:
createCssSelector in class Item
Returns:
the appropriate CSS selector for this item. The selector needs to be in lower case.

toString

public java.lang.String toString()
Description copied from class: Item
Generates a String representation of this item. This method is only implemented when the logging framework is active or the preprocessing variable "polish.keepToString" is set to true.

Overrides:
toString in class Item
Returns:
a String representation of this item.

releaseResources

public void releaseResources()
Description copied from class: Item
Releases all (memory intensive) resources such as images or RGB arrays of this item. The default implementation releases any background resources.

Overrides:
releaseResources in class Item