Class Menu

java.lang.Object
  extended by Canvas
      extended by Menu

public class Menu
extends Canvas

The Menu class represents a menu that displays items in columns. The constructors compute automatically the preferred number of columns (see getPreferredNumberOfColumns()), but this value can be changed using the setNbCol(int nbCol) method. The fitsOnScreen() method is used to check whether all the items fit on the screen.

Author:
Michel Deriaz

Constructor Summary
Menu(java.lang.String[] items, java.lang.String[] itemsFull, boolean bold, java.lang.String title, MenuListener listener)
          Constructs a menu with the given items.
Menu(java.lang.String[] items, java.lang.String[] itemsFull, MenuListener listener)
          This constructor is a shortcut for the other constructor using bold = false and title = null.
 
Method Summary
 boolean fitsOnScreen()
          Returns whether the items fit on the screen.
 int getMaxNumberOfColumns()
          Computes the maximum number of columns, according to the current device and the values specified in the constructor.
 int getPreferredNumberOfColumns()
          Computes the preferred number of columns, according to the current device and the values specified in the constructor.
 void paint(Graphics g)
           
 void setNbCol(int nbCol)
          Sets the number of columns of the menu.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Menu

public Menu(java.lang.String[] items,
            java.lang.String[] itemsFull,
            boolean bold,
            java.lang.String title,
            MenuListener listener)
Constructs a menu with the given items. The number of columns is computed using the getPreferredNumberOfColumns() method.

Parameters:
items - the items to show in the menu
itemsFull - the full names of the items. These names are displayed on the top of the menu when the corresponding item is selected. This value can be null
bold - determines whether the current selected item must be displayed in bold
title - the title of this menu, or null if there is no title
listener - the listener to fire when an item is selected
See Also:
getPreferredNumberOfColumns()

Menu

public Menu(java.lang.String[] items,
            java.lang.String[] itemsFull,
            MenuListener listener)
This constructor is a shortcut for the other constructor using bold = false and title = null.

See Also:
Menu(String[], String[], boolean, String, MenuListener)
Method Detail

setNbCol

public void setNbCol(int nbCol)
Sets the number of columns of the menu. If the parameter equals 0, the getPreferredNumberOfColumns() method is used to determine the number of columns.

Parameters:
nbCol - the number of columns, or 0 to compute automatically this number
See Also:
getPreferredNumberOfColumns()

getMaxNumberOfColumns

public int getMaxNumberOfColumns()
Computes the maximum number of columns, according to the current device and the values specified in the constructor.

Returns:
the maximum number of columns

getPreferredNumberOfColumns

public int getPreferredNumberOfColumns()
Computes the preferred number of columns, according to the current device and the values specified in the constructor. The preferred number is the one that minimizes the number of key strokes to access any specific item. This method will therefore return a number so that the displayed items form a shape as close as possible of a square.

Returns:
the preferred number of columns

fitsOnScreen

public boolean fitsOnScreen()
Returns whether the items fit on the screen.

Returns:
true if the items fit on the screen, otherwise false

paint

public void paint(Graphics g)