com.yospace.yae.yogi
Class AbstractMenu

java.lang.Object
  |
  +--com.yospace.yae.yogi.YogiComponent
        |
        +--com.yospace.yae.yogi.YogiImageComponent
              |
              +--com.yospace.yae.yogi.YogiLabel
                    |
                    +--com.yospace.yae.yogi.AbstractMenu
All Implemented Interfaces:
RendererFactory
Direct Known Subclasses:
YogiDropDownMenu, YogiMenu

public abstract class AbstractMenu
extends YogiLabel

This class provides a basis for menus. Data is stored in an underlying YogiList, and is displayed within a YogiPopup.


Field Summary
protected  YogiList list
          YogiList containing the data items in the menu.
protected  boolean popupMenuVisible
          Visibility of the popup.
static int PROPERTY_LIST
          Constant for the list property.
static int PROPERTY_POPUP_BOUNDS
          Constant for the popup bounds property.
static int PROPERTY_POPUP_MENU_VISIBLE
          Constant for the popup menu visible property.
static int PROPERTY_SELECTION
          Constant for the selection property.
 
Fields inherited from class com.yospace.yae.yogi.YogiLabel
PROPERTY_TEXT, PROPERTY_TEXT_PLACEMENT
 
Fields inherited from class com.yospace.yae.yogi.YogiImageComponent
PROPERTY_IMAGE
 
Fields inherited from class com.yospace.yae.yogi.YogiComponent
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, BORDER_DOTTED, BORDER_NONE, BORDER_PLAIN, BORDER_ROUNDED, BORDER_SOLID, COLOR_BACKGROUND, COLOR_BORDER, COLOR_FOREGROUND, FOCUS_DEFAULT, FOCUS_OFF, FOCUS_ON, PROPERTY_ALIGN, PROPERTY_BORDER_STYLE, PROPERTY_BOUNDS, PROPERTY_COLOR, PROPERTY_CONTEXT_ENABLED, PROPERTY_ENABLED, PROPERTY_FOCUS, PROPERTY_FOCUS_INDEX, PROPERTY_FOCUS_TRAVERSABLE, PROPERTY_FONT, PROPERTY_HOTKEY, PROPERTY_LOCATION, PROPERTY_OPAQUE, PROPERTY_SIZE, PROPERTY_VISIBLE, PROPERTY_X_INSET, PROPERTY_Y_INSET
 
Constructor Summary
AbstractMenu()
          Default constructor which constructs a menu with no text and no image;
AbstractMenu(Image image)
          Constructor taking a menu image.
AbstractMenu(java.lang.String text)
          Constructor taking text for the menu.
AbstractMenu(java.lang.String text, Image image)
          Constructor taking the text and image for the menu.
AbstractMenu(java.lang.String text, java.lang.String imageName)
          Create a AbstractMenu with given text and image.
 
Method Summary
 void add(YogiComponent c)
          Overrides YogiComponent.add(YogiComponent c) to delegate all additions of YogiComponents to the underlying list.
 void addItem(java.lang.Object item)
          Convenience method for adding items to the underlying YogiList of data items.
 void addMenuListener(int index, ActionListener listener)
          Convenience method for adding a ActionListener to a specified item in the menu.
 Rectangle getFocusBounds()
          Finds the bounds of the focussed area by delegating to the underlying YogiList.
 java.lang.Object getItem(int index)
          Convenience method for getting items from the underlying YogiList of data items.
 int getItemCount()
          Convenience method for obtaining the number of elements in the menu.
 YogiList getList()
          Returns the YogiList containing the data items in the menu.
 java.lang.Object getMenuItem(int index)
          Convenience method for obtaining the item at a given index in the menu.
 YogiPopup getPopupMenu()
          This method retrieves the popup associated with the AbstractMenu.
protected  Point getPopupOrigin(YogiComponent c)
          Calculates the location of a component with respect to the nearest popup modal root.
 int getSelectedIndex()
          Convenience method for accessing the current selected item.
protected  void initPopup()
          Initialises the popup menu to its default state.
 boolean isPopupMenuVisible()
          Returns the visibility state of the popup menu.
protected  void popdownMenu()
          This method is called when the popup menu needs to be removed from display.
protected abstract  void popupMenu()
          This method is called by the AbstractMenu before the popup is displayed.
 boolean setFocus(int y)
          Sets the current focus index of an AbstractMenu.
 void setList(YogiList list)
          Sets the underlying list to be used.
 void setPopupBounds(int x, int y, int width, int height)
          Convenience method to set the bounds of the popup menu.
protected  void setPopupMenu(YogiPopup popup)
          Sets the popup menu.
 void setPopupMenuVisible(boolean visible)
          Sets the visibility state of the popup menu to the desired state.
 
Methods inherited from class com.yospace.yae.yogi.YogiLabel
getCellRendererComponent, getText, isTextOnRight, setText, setTextImpl, setTextOnRight
 
Methods inherited from class com.yospace.yae.yogi.YogiImageComponent
getImage, getImageName, setImage, setImage
 
Methods inherited from class com.yospace.yae.yogi.YogiComponent
_debugPrintComponents, addPropertyChangeListener, bringForwards, bringInFrontOf, bringToFront, contains, containsComponent, ensureVisible, ensureVisible, findComponentAt, findCurrentFocus, findFirstFocus, findFocusDomainRoot, findFocusDomainRootImpl, findHotkeyComponent, findNextFocus, fireActionPerformedEvent, firePropertyChangeEvent, getAlign, getBorderStyle, getBounds, getColor, getColors, getComponent, getComponent, getComponentCount, getComponentIndex, getComponents, getFocusIndex, getFont, getGlobalLocation, getHeight, getHotkey, getId, getParent, getParent, getTreeLock, getUI, getWidth, getX, getXInset, getY, getYInset, hasFocus, isActive, isContextEnabled, isEnabled, isFocusDomainRoot, isFocusTraversable, isOpaque, isVisible, keyPressed, keyReleased, keyRepeated, paint, paintBackground, paintBorder, paintForeground, pointerDragged, pointerPressed, pointerReleased, remove, remove, removeAll, removePropertyChangeListener, repaint, repaint, repaintAfterRebounding, requestFocus, requestFocus, sendBackwards, sendBehind, sendToBack, setActionListener, setActive, setAlign, setBorderStyle, setBounds, setColor, setColors, setContextEnabled, setDefaultColor, setEnabled, setFocusDomainRoot, setFocusIndex, setFocusTraversable, setFont, setHotkey, setId, setLocation, setNoFocus, setOpaque, setProperty, setSize, setUI, setVisible, setXInset, setYInset, updateUI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_LIST

public static final int PROPERTY_LIST
Constant for the list property.

PROPERTY_SELECTION

public static final int PROPERTY_SELECTION
Constant for the selection property.

PROPERTY_POPUP_BOUNDS

public static final int PROPERTY_POPUP_BOUNDS
Constant for the popup bounds property.

PROPERTY_POPUP_MENU_VISIBLE

public static final int PROPERTY_POPUP_MENU_VISIBLE
Constant for the popup menu visible property.

popupMenuVisible

protected boolean popupMenuVisible
Visibility of the popup. True = visible, false = not visible.

list

protected YogiList list
YogiList containing the data items in the menu.
Constructor Detail

AbstractMenu

public AbstractMenu()
Default constructor which constructs a menu with no text and no image;

AbstractMenu

public AbstractMenu(Image image)
Constructor taking a menu image.
Parameters:
image - Image to be displayed on the menu.

AbstractMenu

public AbstractMenu(java.lang.String text)
Constructor taking text for the menu.
Parameters:
text - String to be displayed on the menu.

AbstractMenu

public AbstractMenu(java.lang.String text,
                    Image image)
Constructor taking the text and image for the menu.
Parameters:
text - String to be displayed on the menu.
image - Image to be displayed on the menu.

AbstractMenu

public AbstractMenu(java.lang.String text,
                    java.lang.String imageName)
Create a AbstractMenu with given text and image.
Parameters:
text - the text to be displayed.
imageName - the String that defines the name of the resource to create the image to be displayed from.
Method Detail

getList

public YogiList getList()
Returns the YogiList containing the data items in the menu.
Returns:
the list that is the data model for the menu.

getSelectedIndex

public int getSelectedIndex()
Convenience method for accessing the current selected item.
Returns:
the item currently selected in the list. Returns -1 if nothing is selected.

addItem

public void addItem(java.lang.Object item)
Convenience method for adding items to the underlying YogiList of data items.
Parameters:
item - Object to add to the menu.

getItem

public java.lang.Object getItem(int index)
Convenience method for getting items from the underlying YogiList of data items.
Parameters:
index - the index of the item to return.
Returns:
The object at the specified index. Returns null if the list is null or if the list contains nothing at this index.

setFocus

public boolean setFocus(int y)
Sets the current focus index of an AbstractMenu.
Parameters:
y - vertical focus index.
Returns:
True if the focus has changed, False if the specified indexes were already those with focus.

add

public void add(YogiComponent c)
Overrides YogiComponent.add(YogiComponent c) to delegate all additions of YogiComponents to the underlying list. Hence adding a YogiComponent to an AbstractMenu subclass has the same effect as calling {#addItem(java.lang.Object)} and passing in the YogiComponent in question. The only exception is when a YogiList is added, in which case this object becomes the underlying list.
Overrides:
add in class YogiComponent
Parameters:
c - The YogiComponent to add to the underlying list.
See Also:
addItem(Object item)

setList

public void setList(YogiList list)
Sets the underlying list to be used. Also customises the list to make it appropriate for use with menus, by switching off toggleability and setting the selection mode to single. If the list changes, a PROPERTY_LIST change event is fired.
Parameters:
list - YogiList representing the data to be displayed by this menu.

getPopupMenu

public YogiPopup getPopupMenu()
This method retrieves the popup associated with the AbstractMenu. YogiPopups are lazily instantiated to reduce the cost of creating a large number of menus, and so the retrieval process will create a new popup menu if one does not already exist.
Returns:
the YogiPopup used to display the menu.

setPopupBounds

public void setPopupBounds(int x,
                           int y,
                           int width,
                           int height)
Convenience method to set the bounds of the popup menu. X and Y positions are interpreted as follows: for YogiDropDownMenus and YogiMenus which are not sub menus, 0, 0 refers to the point at the same X position and immediately beneath the menu button. for YogiMenus which are sub menus, 0, 0 refers to the point immediately to the right of and at the same Y position as its parent menu. A PROPERTY_POPUP_BOUNDS change event is fired.
Parameters:
x - the desired x value.
y - the desired y value.
width - the desired width.
height - the desired height.

isPopupMenuVisible

public boolean isPopupMenuVisible()
Returns the visibility state of the popup menu.
Returns:
true if the popup menu is currently being shown, false if not.

setPopupMenuVisible

public void setPopupMenuVisible(boolean visible)
Sets the visibility state of the popup menu to the desired state. Setting the popup menu's visibility to true will provoke a call to the AbstractMenu subclass's #popupMenu() method, then show the popup. Setting the popup menu's visibility to false will remove the popup menu from display. If the value changes, the component is repainted and a PROPERTY_POPUP_MENU_VISIBLE change event is fired.
Parameters:
visible - true to display the popup menu, false will hide the popup menu.

getItemCount

public int getItemCount()
Convenience method for obtaining the number of elements in the menu.
Returns:
the number of elements in the menu.

getMenuItem

public java.lang.Object getMenuItem(int index)
Convenience method for obtaining the item at a given index in the menu.
Returns:
the menu item at the specified index.

addMenuListener

public void addMenuListener(int index,
                            ActionListener listener)
Convenience method for adding a ActionListener to a specified item in the menu.
Parameters:
index - The index of the item to which to attach the listener.
listener - The listener

popupMenu

protected abstract void popupMenu()
This method is called by the AbstractMenu before the popup is displayed. Subclasses should implement this method to add the appropriate component(s) to the popup, and provide any other customisation that is required.

popdownMenu

protected void popdownMenu()
This method is called when the popup menu needs to be removed from display.

initPopup

protected void initPopup()
Initialises the popup menu to its default state.

setPopupMenu

protected void setPopupMenu(YogiPopup popup)
Sets the popup menu.
Parameters:
popup - the new popup menu.

getPopupOrigin

protected final Point getPopupOrigin(YogiComponent c)
Calculates the location of a component with respect to the nearest popup modal root. It iterates up through the component hierarchy adding in the successive (x, y) offsets of its ancestors, until the first popup modal root is found.
Parameters:
c - the start component.
Returns:
a Point object containing the location of this component relative to its nearest popup modal root.

getFocusBounds

public Rectangle getFocusBounds()
Finds the bounds of the focussed area by delegating to the underlying YogiList.
Overrides:
getFocusBounds in class YogiComponent
Following copied from class: com.yospace.yae.yogi.YogiComponent
Returns:
the bounding rectangle of this component.

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.