de.enough.polish.ui
Class CommandItem

java.lang.Object
  extended by de.enough.polish.ui.Item
      extended by de.enough.polish.ui.StringItem
          extended by de.enough.polish.ui.IconItem
              extended by de.enough.polish.ui.CommandItem
All Implemented Interfaces:
ImageConsumer

public class CommandItem
extends IconItem

Wraps a javax.microedition.lcdui.Command object and allows to add subcommands, specific styles etc to single commands.

Copyright Enough Software 2006 - 2008

 history
        Mar 4, 2006 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected  javax.microedition.lcdui.Command command
           
protected  boolean hasChildren
           
 
Fields inherited from class de.enough.polish.ui.IconItem
horizontalAdjustment, image, imageAlign, imageHeight, imageWidth, isTextVisible, relativeIconX, relativeIconY, scaleData, scaleFinished, verticalAdjustment, yAdjustText
 
Fields inherited from class de.enough.polish.ui.StringItem
animateTextWrap, bitMapFont, bitMapFontViewer, clipText, font, text, textColor, textEffect, textHorizontalAdjustment, textLines, textVerticalAdjustment, textWrapDirection, textWrapSpeed, useSingleLine, 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
CommandItem(javax.microedition.lcdui.Command command, Item parent)
          Creates a new command item.
CommandItem(javax.microedition.lcdui.Command command, Item parent, Style style)
          Creates a new command item.
 
Method Summary
 void addChild(javax.microedition.lcdui.Command childCommand)
          Adds a subcommand to this node.
 void addChild(CommandItem child)
          Adds a subcommand to this node.
 void addChild(javax.microedition.lcdui.Command childCommand, Style childStyle)
          Adds a subcommand to this node.
 void animate(long currentTime, ClippingRegion repaintRegion)
          Animates this item.
 CommandItem getChild(javax.microedition.lcdui.Command parentCommand)
          Retrieves the child item for the specified command.
 CommandItem getChild(int index)
          Retrieves a child item for a given index.
 javax.microedition.lcdui.Command getCommand()
          Returns the command for this item.
 int getLayer()
          Retrieves the layer to which this command item belongs.
protected  boolean handleKeyPressed(int keyCode, int gameAction)
          Handles the key-pressed event.
protected  boolean handleKeyReleased(int keyCode, int gameAction)
          Handles the key-released event.
protected  boolean handlePointerPressed(int x, int y)
          Handles the event when a pointer has been pressed at the specified position.
protected  boolean handlePointerReleased(int x, int y)
          Handles the event when a pointer has been released at the specified position.
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.
protected  boolean isOpen()
          Tells whether this item is open so that the children commands are visible (or not).
protected  void open(boolean open)
          Opens or closes this command item so that the children commands are visible (or not).
 void paintContent(int x, int y, int leftBorder, int rightBorder, javax.microedition.lcdui.Graphics g)
          Paints the content of this item.
 boolean removeChild(javax.microedition.lcdui.Command childCommand)
          Removes a child from this command item.
 void setStyle(Style style)
          Sets the style of this item.
 
Methods inherited from class de.enough.polish.ui.IconItem
createCssSelector, defocus, getImage, isTextVisible, releaseResources, setImage, setImage, setImage, setImage, setImageAlign, setTextVisible, toString
 
Methods inherited from class de.enough.polish.ui.StringItem
getFont, getFontHeight, getText, setFont, setText, setText, setTextColor, showNotify, stringWidth
 
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, handleKeyRepeated, 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

command

protected final javax.microedition.lcdui.Command command

hasChildren

protected boolean hasChildren
Constructor Detail

CommandItem

public CommandItem(javax.microedition.lcdui.Command command,
                   Item parent)
Creates a new command item.

Parameters:
command - the commmand represented by this item.
parent - the parent item

CommandItem

public CommandItem(javax.microedition.lcdui.Command command,
                   Item parent,
                   Style style)
Creates a new command item.

Parameters:
command - the commmand represented by this item.
parent - the parent item
style - the style for this item
Method Detail

addChild

public void addChild(javax.microedition.lcdui.Command childCommand)
Adds a subcommand to this node.

Parameters:
childCommand - the child command

addChild

public void addChild(javax.microedition.lcdui.Command childCommand,
                     Style childStyle)
Adds a subcommand to this node.

Parameters:
childCommand - the child command
childStyle - the style for the child command

addChild

public void addChild(CommandItem child)
Adds a subcommand to this node.

Parameters:
child - the child command item

getLayer

public int getLayer()
Retrieves the layer to which this command item belongs. This method is useful for sub commands.

Returns:
the layer, 0 means this command item belongs to the main commands.

removeChild

public boolean removeChild(javax.microedition.lcdui.Command childCommand)
Removes a child from this command item.

Parameters:
childCommand - the child that should be removed
Returns:
true when the child was found

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.

Overrides:
initContent in class IconItem
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

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.

Overrides:
paintContent in class IconItem
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.

handleKeyPressed

protected boolean handleKeyPressed(int keyCode,
                                   int gameAction)
Description copied from class: Item
Handles the key-pressed event. Please note, that implementation should first try to handle the given key-code, before the game-action is processed. The default implementation just handles the FIRE game-action when a default-command and an item-command-listener have been registered.

Overrides:
handleKeyPressed in class Item
Parameters:
keyCode - the code of the pressed key, e.g. Canvas.KEY_NUM2
gameAction - the corresponding game-action, e.g. Canvas.UP
Returns:
true when the key has been handled / recognized

handleKeyReleased

protected boolean handleKeyReleased(int keyCode,
                                    int gameAction)
Description copied from class: Item
Handles the key-released event. Please note, that implementation should first try to handle the given key-code, before the game-action is processed. The default implementation invokes the default command if one is present

Overrides:
handleKeyReleased in class Item
Parameters:
keyCode - the code of the pressed key, e.g. Canvas.KEY_NUM2
gameAction - the corresponding game-action, e.g. Canvas.UP
Returns:
true when the key has been handled / recognized
See Also:
Item.handleKeyPressed(int, int)

handlePointerPressed

protected boolean handlePointerPressed(int x,
                                       int y)
Description copied from class: Item
Handles the event when a pointer has been pressed at the specified position. The default method discards this event when relX/relY is outside of the item's area. When the event took place inside of the content area, the pointer-event is translated into an artificial FIRE game-action keyPressed event, which is subsequently handled bu the handleKeyPressed(-1, Canvas.FIRE) method. This method needs should be overwritten only when the "polish.hasPointerEvents" preprocessing symbol is defined: "//#ifdef polish.hasPointerEvents".

Overrides:
handlePointerPressed in class Item
Parameters:
x - the x position of the pointer pressing relative to this item's left position
y - the y position of the pointer pressing relative to this item's top position
Returns:
true when the pressing of the pointer was actually handled by this item.
See Also:
this method is used for determining whether the event belongs to this item, for a helper method for determining whether the event took place into the actual content area, Item.handleKeyPressed(int, int), for calculating the horizontal position relative to the content (relX - contentX), for calculating the vertical position relative to the content (relY - contentY)

handlePointerReleased

protected boolean handlePointerReleased(int x,
                                        int y)
Description copied from class: Item
Handles the event when a pointer has been released at the specified position. The default method discards this event when relX/relY is outside of the item's area. When the event took place inside of the content area, the pointer-event is translated into an artificial FIRE game-action keyReleased event, which is subsequently handled bu the handleKeyPressed(-1, Canvas.FIRE) method. This method needs should be overwritten only when the "polish.hasPointerEvents" preprocessing symbol is defined: "//#ifdef polish.hasPointerEvents".

Overrides:
handlePointerReleased in class Item
Parameters:
x - the x position of the pointer pressing relative to this item's left position
y - the y position of the pointer pressing relative to this item's top position
Returns:
true when the pressing of the pointer was actually handled by this item.
See Also:
this method is used for determining whether the event belongs to this item, for a helper method for determining whether the event took place into the actual content area, Item.handleKeyPressed(int, int), for calculating the horizontal position relative to the content (relX - contentX), for calculating the vertical position relative to the content (relY - contentY)

open

protected void open(boolean open)
Opens or closes this command item so that the children commands are visible (or not).

Parameters:
open - true when the children should be visible and the focus is moved to them.

getChild

public CommandItem getChild(javax.microedition.lcdui.Command parentCommand)
Retrieves the child item for the specified command.

Parameters:
parentCommand - the corresponding command
Returns:
the corresponding item or null when the child is not found

setStyle

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

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

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 IconItem
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)

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 StringItem

getCommand

public javax.microedition.lcdui.Command getCommand()
Returns the command for this item.

Returns:
the command

isOpen

protected boolean isOpen()
Tells whether this item is open so that the children commands are visible (or not).

Returns:
true of open, false otherwise

getChild

public CommandItem getChild(int index)
Retrieves a child item for a given index.

Parameters:
index - the index
Returns:
the command item, or null if no child for this index exists