buoy.widget

Class BPopupMenu

Implemented Interfaces:
MenuWidget

public class BPopupMenu
extends WidgetContainer
implements MenuWidget

A BPopupMenu is a WidgetContainer corresponding to a popup menu. It is typically displayed in response to a WidgetMouseEvent whose isPopupTrigger() method returns true. The exact conditions which represent a popup trigger are platform specific.

The easiest way to add a popup menu to a widget is to invoke

widget.addEventLink(WidgetMouseEvent.class, popup, "show");

on the widget. This will automatically take care of showing the menu whenever the user performs the appropriate action. Alternatively, you can write your own code to listen for the event and call show() on the popup menu. For example, you might want to disable certain menu items before showing it based on the position of the mouse click.

Author:
Peter Eastman

Constructor Summary

BPopupMenu()
Create a new BPopupMenu.

Method Summary

void
add(MenuWidget widget)
Add a MenuWidget (typically a BMenuItem or BMenu) to the end of the menu.
void
add(MenuWidget widget, int index)
Add a MenuWidget (typically a BMenuItem or another BMenu) to the menu.
void
addSeparator()
Add a dividing line (a BSeparator) to the end of the menu.
MenuWidget
getChild(int i)
Get the i'th child of this container.
int
getChildCount()
Get the number of children in this container.
Collection
getChildren()
Get a Collection containing all child Widgets of this container.
void
layoutChildren()
Layout the child Widgets.
void
remove(Widget widget)
Remove a child Widget from this container.
void
removeAll()
Remove all child Widgets from this container.
void
show(WidgetMouseEvent event)
Display the popup menu in response to an event.
void
show(Widget widget, int x, int y)
Display the popup menu over another Widget.

Methods inherited from class buoy.widget.WidgetContainer

getChildCount, getChildren, isOpaque, layoutChildren, remove, removeAll, setOpaque

Methods inherited from class buoy.widget.Widget

addEventLink, dispatchEvent, getBackground, getBounds, getComponent, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible

Methods inherited from class buoy.event.EventSource

addEventLink, addEventLink, addEventLink, dispatchEvent, removeEventLink

Constructor Details

BPopupMenu

public BPopupMenu()
Create a new BPopupMenu.

Method Details

add

public void add(MenuWidget widget)
Add a MenuWidget (typically a BMenuItem or BMenu) to the end of the menu.

add

public void add(MenuWidget widget,
                int index)
Add a MenuWidget (typically a BMenuItem or another BMenu) to the menu.
Parameters:
widget - the MenuWidget to add
index - the position at which to add it

addSeparator

public void addSeparator()
Add a dividing line (a BSeparator) to the end of the menu.

getChild

public MenuWidget getChild(int i)
Get the i'th child of this container.

getChildCount

public int getChildCount()
Get the number of children in this container.
Overrides:
getChildCount in interface WidgetContainer

getChildren

public Collection getChildren()
Get a Collection containing all child Widgets of this container.
Overrides:
getChildren in interface WidgetContainer

layoutChildren

public void layoutChildren()
Layout the child Widgets. This may be invoked whenever something has changed (the size of this WidgetContainer, the preferred size of one of its children, etc.) that causes the layout to no longer be correct. If a child is itself a WidgetContainer, its layoutChildren() method will be called in turn.
Overrides:
layoutChildren in interface WidgetContainer

remove

public void remove(Widget widget)
Remove a child Widget from this container.
Overrides:
remove in interface WidgetContainer

removeAll

public void removeAll()
Remove all child Widgets from this container.
Overrides:
removeAll in interface WidgetContainer

show

public void show(WidgetMouseEvent event)
Display the popup menu in response to an event. If event.isPopupTrigger() returns false, this method returns without doing anything. Otherwise it shows the popup, determining the appropriate location based on information stored in the event.

This version of show() is provided as a convenience. It allows you to very easily add a popup menu to a Widget by invoking

widget.addEventLink(WidgetMouseEvent.class, popup, "show");

Parameters:
event - the user event which is triggering the popup menu

show

public void show(Widget widget,
                 int x,
                 int y)
Display the popup menu over another Widget.
Parameters:
widget - the Widget over which to display the popup menu
x - the x coordinate at which to display the popup menu
y - the y coordinate at which to display the popup menu

Written by Peter Eastman.