bluegammon.gui.menu
Class MenuPage

java.lang.Object
  extended bybluegammon.gui.menu.MenuPage
Direct Known Subclasses:
BluetoothDevicePage

public class MenuPage
extends java.lang.Object

A MenuPage class represents a title and a number of choices in a Menu. The MenuPage's choices are added as PageItems via the addItem method.

Author:
Peter Andersson
See Also:
Menu, PageItem

Field Summary
static int LAYOUT_LEFT
          Left aligned image, right aligned text
static int LAYOUT_RIGHT
          Right aligned image, left aligned text
 
Constructor Summary
MenuPage(char[] title, javax.microedition.lcdui.Image titleImage)
          Creates a new page for a menu.
 
Method Summary
 void addItem(PageItem item)
          Adds an item to this page.
 int getIndex(PageItem item)
          Returns the index of specified item.
 int getLayout()
          Returns the layout of the image, any of LAYOUT_LEFT, LAYOUT_RIGHT.
 int getSelectedIndex()
          Returns the currently selected index in this page.
 char[] getTitle()
          Returns the title of this page.
 javax.microedition.lcdui.Image getTitleImage()
          Returns the title of this page.
 PageItem itemAt(int index)
          Returns item at specified index.
 void removeAllItems()
          Removes all items on this page
 void removeItem(int index)
          Removes the item at specified index from this page.
 void removeItem(PageItem item)
          Removes an item from this page.
 void setLayout(int layout)
          Sets the layout of the image, any of LAYOUT_LEFT, LAYOUT_RIGHT.
 void setSelectedIndex(int index)
          Sets the currently selected index in this page.
 void setTitle(char[] title)
          Sets the title of this page.
 void setTitleImage(javax.microedition.lcdui.Image titleImage)
          Sets the title image of this page.
 int size()
          Returns number of items in this page.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LAYOUT_LEFT

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

See Also:
Constant Field Values

LAYOUT_RIGHT

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

See Also:
Constant Field Values
Constructor Detail

MenuPage

public MenuPage(char[] title,
                javax.microedition.lcdui.Image titleImage)
Creates a new page for a menu.

Parameters:
title - The title of the page or null.
titleImage - The image of the page or null.
Method Detail

setLayout

public void setLayout(int layout)
Sets the layout of the image, any of LAYOUT_LEFT, LAYOUT_RIGHT.

Parameters:
layout - Image layout.

getLayout

public int getLayout()
Returns the layout of the image, any of LAYOUT_LEFT, LAYOUT_RIGHT.

Returns:
Image layout.

getTitle

public char[] getTitle()
Returns the title of this page.

Returns:
The page title.

setTitle

public void setTitle(char[] title)
Sets the title of this page.

Parameters:
title - The page title.

getTitleImage

public javax.microedition.lcdui.Image getTitleImage()
Returns the title of this page.

Returns:
The page title image.

setTitleImage

public void setTitleImage(javax.microedition.lcdui.Image titleImage)
Sets the title image of this page.

Parameters:
titleImage - The page title iamge.

addItem

public void addItem(PageItem item)
Adds an item to this page.

Parameters:
item - The item to add.

removeItem

public void removeItem(PageItem item)
Removes an item from this page.

Parameters:
item - The item to remove.

removeItem

public void removeItem(int index)
Removes the item at specified index from this page.

Parameters:
index - The index of the item to remove.

size

public int size()
Returns number of items in this page.

Returns:
Number of items.

getSelectedIndex

public int getSelectedIndex()
Returns the currently selected index in this page. In special cases this method may return -1, for no selected items.

Returns:
Selected item index.

setSelectedIndex

public void setSelectedIndex(int index)
Sets the currently selected index in this page. If the index is greater than number of items in the page, it is wrapped to the first item. If the index is below zero, it is wrapped to the last item. If correct index is not possible to set index will be set to -1. This happens if there are no items, or all items are disabled.

Parameters:
index - Index of selected item.

itemAt

public PageItem itemAt(int index)
Returns item at specified index.

Parameters:
index - The index of the idem
Returns:
The item at specified index, or null if not found.

getIndex

public int getIndex(PageItem item)
Returns the index of specified item. It this item does not belong to the list, -1 is returned.

Parameters:
item - The item whose index to find.
Returns:
index of the item, or -1 if item is not part of the menu.

removeAllItems

public void removeAllItems()
Removes all items on this page