buoy.widget
Class BPopupMenu

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.WidgetContainer
              extended by buoy.widget.BPopupMenu
All 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.
 java.util.Collection<Widget> getChildren()
          Get a Collection containing all child Widgets of this container.
 javax.swing.JPopupMenu getComponent()
          Get the java.awt.Component corresponding to this Widget.
 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(Widget widget, int x, int y)
          Display the popup menu over another Widget.
 void show(WidgetMouseEvent event)
          Display the popup menu in response to an event.
 
Methods inherited from class buoy.widget.WidgetContainer
isOpaque, setOpaque
 
Methods inherited from class buoy.widget.Widget
addEventLink, dispatchEvent, getBackground, getBounds, 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, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BPopupMenu

public BPopupMenu()
Create a new BPopupMenu.

Method Detail

getComponent

public javax.swing.JPopupMenu getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

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

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

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.


getChildCount

public int getChildCount()
Get the number of children in this container.

Specified by:
getChildCount in class WidgetContainer

getChild

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


getChildren

public java.util.Collection<Widget> getChildren()
Get a Collection containing all child Widgets of this container.

Specified by:
getChildren in class WidgetContainer

remove

public void remove(Widget widget)
Remove a child Widget from this container.

Specified by:
remove in class WidgetContainer

removeAll

public void removeAll()
Remove all child Widgets from this container.

Specified by:
removeAll in class 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.

Specified by:
layoutChildren in class WidgetContainer


Written by Peter Eastman.