Class GMenu

java.lang.Object
  |
  +--GMenu

public class GMenu
extends java.lang.Object

This class allows a programmer to build a general purpose main menu for the text-based screen console (see Console). In normal usage, the programmer adds a menu title and up to 14 menu items that will be displayed by the displayMenu() method.


Field Summary
static int ITEM_COL
          Default column number where selection items will print.
static int MAX_ITEMS
          Maximum size of menu with one title and 14 selection items.
static int MENU_TITLE_OFFSET
          Default offset from the item column, where the title will print.
static int MENU_TITLE_ROW
          Default row number where menu title will print.
 
Constructor Summary
GMenu()
          Initializes the menu object.
GMenu(int itemCol, int menuTitleRow, int menuTitleOffset, int menuStartRow)
          Initializes the menu object with non-default format parameters.
 
Method Summary
 int addMenuItem(java.lang.String menuItem)
          Adds a menuItem to the menu.
 int addTitle(java.lang.String title)
          Adds a title to the menu object.
 void displayMenu(Console con)
          Constructs the menu in the con screen and displays it on the display device
 int getItemCol()
          Returns the value of the column where selection items will be printed.
 int getMenuStartRow()
          Returns the row number where the first menu selection item will print.
 int getMenuTitleOffset()
          Returns the value of the column offset (from item column) which determines from which column the title will start printing.
 int getMenuTitleRow()
          Returns the value of the row number where the menu title will be printed.
 void setItemCol(int col)
          Sets the column where selection items will be printed on the screen.
 void setMenuStartRow(int row)
          Sets the row number where the first menu selection item will print.
 void setMenuTitleOffset(int off)
          Sets the offset used to determine the column number where the menu title will be printed.
 void setMenuTitleRow(int row)
          Sets the row number where the menu title will be printed.
 java.lang.String toString()
          Overrides Object.toString() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_ITEMS

public static final int MAX_ITEMS
Maximum size of menu with one title and 14 selection items.

ITEM_COL

public static final int ITEM_COL
Default column number where selection items will print.

MENU_TITLE_ROW

public static final int MENU_TITLE_ROW
Default row number where menu title will print.

MENU_TITLE_OFFSET

public static final int MENU_TITLE_OFFSET
Default offset from the item column, where the title will print.
Constructor Detail

GMenu

public GMenu()
Initializes the menu object. The first call to addMenuItem() will start with selection item 1. This constructor sets the menu formatting parameters to default values.

GMenu

public GMenu(int itemCol,
             int menuTitleRow,
             int menuTitleOffset,
             int menuStartRow)
Initializes the menu object with non-default format parameters.

itemCol is the screen column where an item will start.
menuTitleRow is the row number for the title
menuTitleOffset is an offset that determines how far to the right or left of the itemCol the title will print.
menuStartRow is the row where the menu selection items start

itemCol should be between 0 and 50 or the value will be set to the default, ITEM_COL.

menuTitleRow should be between 0 and 12 or the value will be set to the default, MENU_TITLE_ROW.

menuTitleOffset may be negative or positive but should not result in the start column of the title from exceeding the same bounds as the itemCol constraints, otherwise the value will be the default, MENU_TITLE_OFFSET.

menuStartRow should be between 1 and 23 or the value will be set to the default, MENU_START_ROW.

Method Detail

setItemCol

public void setItemCol(int col)
Sets the column where selection items will be printed on the screen. Menu items always start with the selection number, followed by a ')', two spaces and then the selection. The itemCol the column where the first of a two-digit number would be printed on the screen. col must be between 0 and 50 or either the default value, ITEM_COL, or the last set value will still be in effect.

setMenuTitleRow

public void setMenuTitleRow(int row)
Sets the row number where the menu title will be printed. Row must be between 0 (top of screen) and 12 or the method has no effect and either the default value, MENU_TITLE_ROW, or last set value will still be in effect.

setMenuTitleOffset

public void setMenuTitleOffset(int off)
Sets the offset used to determine the column number where the menu title will be printed. The offset is from the item column number set with setItemCol() or the default ITEM_COL. A negative offset will cause the title to print in a column starting to the left of the selection items. If itemCol + off is less than 0 or greater than 50, the value will either remain the default, MENU_TITLE_OFFSET, or the last set value.

setMenuStartRow

public void setMenuStartRow(int row)
Sets the row number where the first menu selection item will print. The row number must be between 1 and 23 or the value will either be the default, MENU_START_ROW, or the last set value.

getItemCol

public int getItemCol()
Returns the value of the column where selection items will be printed. All items will start with a number followed by ')' and two spaces before the selection text will be printed.

getMenuTitleRow

public int getMenuTitleRow()
Returns the value of the row number where the menu title will be printed.

getMenuTitleOffset

public int getMenuTitleOffset()
Returns the value of the column offset (from item column) which determines from which column the title will start printing.

getMenuStartRow

public int getMenuStartRow()
Returns the row number where the first menu selection item will print.

addMenuItem

public int addMenuItem(java.lang.String menuItem)
Adds a menuItem to the menu. Up to 14 items can be added. While there is no restriction on the length of the String, it is best to use short (< 25 characters) strings to avoid screen clutter.

Menu items should be added in the order they are to appear on the screen.

Returns:
an integer representing the selection number of the item just added. If an error occurs while adding an item (e.g., more than 14 items are attempted) the method returns a -1

addTitle

public int addTitle(java.lang.String title)
Adds a title to the menu object. Only one title is allowed. Once a title has been added (set) any subsequent calls to this method will be ignored and a -1 will be returned.
Returns:
0 if the title is added, -1 otherwise.

displayMenu

public void displayMenu(Console con)
Constructs the menu in the con screen and displays it on the display device

toString

public java.lang.String toString()
Overrides Object.toString() method. Concatenates title plus all menu items.
Overrides:
toString in class java.lang.Object