|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbluegammon.gui.menu.Menu
The Menu
class takes care of coordination between
MenuPage
s, PageItem
s and user interaction.
It contains a navigation stack to handle breadcrumb behaviour.
It handles the painting of the menu via a MenuPainter
.
The navigation tree can either be implemented in the PageItem
s
constructor, or via an implementation of ItemAction
that uses
the method gotoPage
in this class.
A common example for using a Menu
:
public class MenuCanvas extends Canvas implements ItemAction { static final int PRINT_1 = 1; static final int PRINT_2 = 2; Menu m_menu; public MenuCanvas() { // Create pages MenuPage mainPage = new MenuPage("STARTPAGE".toCharArray(), null); MenuPage nextPage = new MenuPage("NEXTPAGE".toCharArray(), null); // Create menu items PageItem anItem = new PageItem("Goto next page".toCharArray(), null, null, nextPage); PageItem anotherItem = new PageItem("Print 1".toCharArray(), null, this, null, PRINT_1); PageItem yetAnotherItem = new PageItem("Print 2".toCharArray(), null, this, null, PRINT_2); // Assign items to pages mainPage.addItem(anItem); mainPage.addItem(anotherItem); nextPage.addItem(yetAnotherItem); // Create and setup menu m_menu = new Menu(mainPage, this, new DefaultMenuPainter()); int menuPadding = 16; m_menu.setLocation(0, menuPadding); m_menu.setDimensions(getWidth(), getHeight() - menuPadding * 2); m_menu.setFrameData(10, 20); // 10 frames per transition, 20 ms between each frame m_menu.start(); } protected void paint(Graphics g) { g.setColor(0x000000); g.fillRect(0, 0, getWidth(), getHeight()); m_menu.paint(g); } protected void keyPressed(int keyCode) { m_menu.keyPressed(keyCode); } public void itemAction(MenuPage page, PageItem item) { int id = item.getId(); switch(id) { case PRINT_1: System.out.println("Item 1 is invoked"); break; case PRINT_2: System.out.println("Item 2 is invoked"); break; } } }
Constructor Summary | |
Menu(MenuPage startPage,
javax.microedition.lcdui.Canvas canvas,
MenuPainter painter)
Creates a new menu. |
Method Summary | |
javax.microedition.lcdui.Canvas |
getCanvas()
Returns the canvas this menu is drawn upon. |
MenuPage |
getCurrentPage()
Returns current page. |
long |
getFrameDelay()
Returns the frame delay in milliseconds. |
int |
getFrames()
Returns number of frames in a page switch. |
int |
getHeight()
Returns height of this menu. |
MenuListener |
getListener()
Returns the listener. |
MenuPainter |
getPainter()
Returns the painter used to paint the menu. |
PageItem |
getSelectedItem()
Returns selected item or null if no item is currently selected. |
int |
getSelectedItemIndex()
Returns index of selected item or -1 if no item is currently selected. |
MenuPage |
getStartPage()
Returns start page of this menu. |
int |
getWidth()
Returns width of this menu. |
int |
getX()
Returns x offset of this menu. |
int |
getY()
Returns y offset of this menu. |
void |
goBack()
Steps back to previous page. |
void |
gotoPage(MenuPage newPage)
Steps forward to a new page. |
void |
keyPressed(int keyCode)
Call this from your displayable's keyPressed or keyRepeated method invoke user interaction on the menu. |
void |
paint(javax.microedition.lcdui.Graphics g)
Call this from your displayable's paint method to paint the menu. |
void |
run()
Runnable implementation, invokes
the MenuPainter on transitions. |
void |
setCanvas(javax.microedition.lcdui.Canvas canvas)
Sets the canvas this menu is drawn upon. |
void |
setDimensions(int width,
int height)
Sets the size of this menu. |
void |
setFrameData(int nbrOfFrames,
long frameDelay)
Sets the values used in a transition between to pages. |
void |
setListener(MenuListener listener)
Sets the listener which is reported on menu events. |
void |
setLocation(int x,
int y)
Sets the location of this menu. |
void |
setPainter(MenuPainter painter)
Sets the painter used to paint the menu. |
void |
setSelectedItemIndex(int itemIndex)
Sets index of selected item. |
void |
start()
Activates this menu and jumps to the starting page. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Menu(MenuPage startPage, javax.microedition.lcdui.Canvas canvas, MenuPainter painter)
startPage
- The first page in this menu.canvas
- The canvas that this menu is drawn upon.painter
- The painter used to draw this menu.Method Detail |
public void start()
public void paint(javax.microedition.lcdui.Graphics g)
g
- The graphics context.public void keyPressed(int keyCode)
keyCode
- The keyCode.public void gotoPage(MenuPage newPage)
newPage
- The new page.public void goBack()
public MenuPage getCurrentPage()
public PageItem getSelectedItem()
public int getSelectedItemIndex()
public void setSelectedItemIndex(int itemIndex)
itemIndex
- The index of the item to select.public javax.microedition.lcdui.Canvas getCanvas()
public void setCanvas(javax.microedition.lcdui.Canvas canvas)
canvas
- The canvas drawing this menu.public MenuListener getListener()
public void setListener(MenuListener listener)
listener
- A menu listener.public MenuPainter getPainter()
public void setPainter(MenuPainter painter)
painter
- The painter.public long getFrameDelay()
public int getFrames()
public int getHeight()
public MenuPage getStartPage()
public int getWidth()
public int getX()
public int getY()
public void setLocation(int x, int y)
x
- The x offset.y
- The y offset.public void setDimensions(int width, int height)
width
- The width.height
- The height.public void setFrameData(int nbrOfFrames, long frameDelay)
nbrOfFrames
- Number of frames in a transition.frameDelay
- Delay in milliseconds in each transition.public void run()
Runnable
implementation, invokes
the MenuPainter
on transitions.
run
in interface java.lang.Runnable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |