bluegammon.gui.menu
Class PageItem

java.lang.Object
  extended bybluegammon.gui.menu.PageItem
Direct Known Subclasses:
BinaryPageItem

public class PageItem
extends java.lang.Object

The PageItem defines a choice in a MenuPage. An item can have a subpage and/or an ItemAction implementation. When an item is selected by user, the ItemAction implementation is invoked, and/or a transition to the subpage is started.

PageItems can also have key/value pairs typed as int/Object.

When there is both a subpage and an action; pressing fire on such an item will first start a new thread invokinh the action, then the menu will navigate to the subpage. If the user presses right on such an item, the action is not executed but the subpage is navigated to.

Author:
Peter Andersson
See Also:
Menu, MenuPage, ItemAction

Field Summary
static int LAYOUT_ALIGN_LEFT
          Left aligned image, right aligned text
static int LAYOUT_ALIGN_RIGHT
          Right aligned image, left aligned text
static int LAYOUT_CENTERED_LEFT
          Centered item, image to the left of text (Default layout)
static int LAYOUT_CENTERED_RIGHT
          Centered item, image to the right of text
 
Constructor Summary
PageItem(char[] label, javax.microedition.lcdui.Image image, ItemAction action, MenuPage subPage)
          Creates an item that is to be inserted into a MenuPage.
PageItem(char[] label, javax.microedition.lcdui.Image image, ItemAction action, MenuPage subPage, int id)
          Creates an item that is to be inserted into a MenuPage.
 
Method Summary
 void addedToPage()
          Called when this item is added to a page.
 ItemAction getAction()
          Returns action which is called upon item activation.
 int getId()
          Returns ID of this item, or Integer.MIN_VALUE if not set.
 javax.microedition.lcdui.Image getImage()
          Returns image of this item, or null if none set.
 char[] getLabel()
          Returns the label of this item.
 int getLayout()
          Returns the layout of the image, any of LAYOUT_CENTERED_LEFT, LAYOUT_CENTERED_RIGHT, LAYOUT_ALIGN_LEFT, LAYOUT_ALIGN_RIGHT.
 java.lang.Object getProperty(int key)
          Returns value of a generic property on this item or null if not set.
 MenuPage getSubPage()
          Returns the subpage that will be displayed when this item is activated, or null if no such page.
 boolean isEnabled()
          Returns true if this item is enabled, false otherwise.
 void setAction(ItemAction action)
          Sets the action which is called upon item activation.
 void setEnabled(boolean enabled)
          Enables or disables this item.
 void setImage(javax.microedition.lcdui.Image image)
          Sets the image of this item.
 void setLabel(char[] label)
          Sets the text label of this item.
 void setLayout(int layout)
          Sets the layout of the image, any of LAYOUT_CENTERED_LEFT, LAYOUT_CENTERED_RIGHT, LAYOUT_ALIGN_LEFT, LAYOUT_ALIGN_RIGHT.
 void setProperty(int key, java.lang.Object value)
          Sets a value to a generic property on this item, or resets it by giving null as a value.
 void setSubPage(MenuPage page)
          Sets the subpage that will be displayed when this item is activated, or null if no such page.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LAYOUT_CENTERED_LEFT

public static final int LAYOUT_CENTERED_LEFT
Centered item, image to the left of text (Default layout)

See Also:
Constant Field Values

LAYOUT_CENTERED_RIGHT

public static final int LAYOUT_CENTERED_RIGHT
Centered item, image to the right of text

See Also:
Constant Field Values

LAYOUT_ALIGN_LEFT

public static final int LAYOUT_ALIGN_LEFT
Left aligned image, right aligned text

See Also:
Constant Field Values

LAYOUT_ALIGN_RIGHT

public static final int LAYOUT_ALIGN_RIGHT
Right aligned image, left aligned text

See Also:
Constant Field Values
Constructor Detail

PageItem

public PageItem(char[] label,
                javax.microedition.lcdui.Image image,
                ItemAction action,
                MenuPage subPage)
Creates an item that is to be inserted into a MenuPage. Item graphical elements are the label and the image, and logical elements are action and subpage.

Parameters:
label - The text label of this item or null if no text.
image - The image of this item or null if no image.
action - The action that is called when activating this item, or null if no action.
subPage - The page that will be navigated to when activating this item, or null of no such page.

PageItem

public PageItem(char[] label,
                javax.microedition.lcdui.Image image,
                ItemAction action,
                MenuPage subPage,
                int id)
Creates an item that is to be inserted into a MenuPage. Item graphical elements are the label and the image, and logical elements are action and subpage.

Parameters:
label - The text label of this item or null if no text.
image - The image of this item or null if no image.
action - The action that is called when activating this item, or null if no action.
subPage - The page that will be navigated to when activating this item, or null of no such page.
id - The id of this item.
Method Detail

getId

public int getId()
Returns ID of this item, or Integer.MIN_VALUE if not set.

Returns:
The item id

addedToPage

public void addedToPage()
Called when this item is added to a page. Default implementation does nothinhg.


getLabel

public char[] getLabel()
Returns the label of this item.

Returns:
The text label of this item.

setLabel

public void setLabel(char[] label)
Sets the text label of this item.

Parameters:
label - The text label of this item.

getSubPage

public MenuPage getSubPage()
Returns the subpage that will be displayed when this item is activated, or null if no such page.

Returns:
The sub page or null.

setSubPage

public void setSubPage(MenuPage page)
Sets the subpage that will be displayed when this item is activated, or null if no such page.

Parameters:
page - The sub page or null.

getAction

public ItemAction getAction()
Returns action which is called upon item activation.

Returns:
The action of this item.

setAction

public void setAction(ItemAction action)
Sets the action which is called upon item activation.

Parameters:
action - The action of this item.

isEnabled

public boolean isEnabled()
Returns true if this item is enabled, false otherwise.

Returns:
true if enabled, false otherwise

setEnabled

public void setEnabled(boolean enabled)
Enables or disables this item.

Parameters:
enabled - true to enable, false to disable

getImage

public javax.microedition.lcdui.Image getImage()
Returns image of this item, or null if none set.

Returns:
The image or null.

setImage

public void setImage(javax.microedition.lcdui.Image image)
Sets the image of this item.

Parameters:
image - The image or null.

setLayout

public void setLayout(int layout)
Sets the layout of the image, any of LAYOUT_CENTERED_LEFT, LAYOUT_CENTERED_RIGHT, LAYOUT_ALIGN_LEFT, LAYOUT_ALIGN_RIGHT.

Parameters:
layout - Image layout.

getLayout

public int getLayout()
Returns the layout of the image, any of LAYOUT_CENTERED_LEFT, LAYOUT_CENTERED_RIGHT, LAYOUT_ALIGN_LEFT, LAYOUT_ALIGN_RIGHT.

Returns:
Image layout.

getProperty

public java.lang.Object getProperty(int key)
Returns value of a generic property on this item or null if not set.

Parameters:
key - The key of the property.
Returns:
The value of the property or null.

setProperty

public void setProperty(int key,
                        java.lang.Object value)
Sets a value to a generic property on this item, or resets it by giving null as a value.

Parameters:
key - The key of the property.
value - The value of the property, or null to reset it.