marimba.gui
Class PopupMenu

java.lang.Object
  |
  +--marimba.gui.Widget
        |
        +--marimba.gui.ContainerWidget
              |
              +--marimba.gui.GroupWidget
                    |
                    +--marimba.gui.PopupWidget
                          |
                          +--marimba.gui.PopupMenu
All Implemented Interfaces:
java.awt.image.ImageObserver, PropertyObject, TimerClient, WidgetConstants
Direct Known Subclasses:
DropDownMenu

public class PopupMenu
extends PopupWidget
implements TimerClient

A popup menu, it displays a scrollbar using a scrolling container if necessary. This menu uses the list of PopupMenuItemWidgets, and tracks the current selection via that mechanism, rather than by using an index directly.

Version:
1.49, 05/07/98
Author:
Klaas Waslander
See Also:
PopupMenuItemWidget

Field Summary
protected  ScrollingContainerWidget container
          The popupmenu uses a scrolling container to display the popup menu items.
 PopupMenuItemWidget current
          The currently selected item.
protected  boolean dragged
          Has the user dragged with the mouse?
 boolean itemFocus
          The items can be drawn with or without a focus rectangle around it when they are selected.
 int maxVisible
          The maximum number of visible items, if there are more items a scrollbar is used.
protected  boolean mouseUpPopDown
          Should the menu popdown when the MOUSE_UP event is detected?
 Widget owner
          The owner of this widget.
protected  boolean poppingDown
          indicates whether popdown() is being executed for LOST_FOCUS event
protected  int scrollJump
          Negative is scrolling up, positive is down (unfortunately).
protected  boolean ticking
          Are we currently on the timer's list?
 
Fields inherited from class marimba.gui.PopupWidget
player
 
Fields inherited from class marimba.gui.GroupWidget
editing, fillMode, fillOptions, lineMode, lineOptions, patsrc, pattern, prevtx, prevty
 
Fields inherited from class marimba.gui.ContainerWidget
content
 
Fields inherited from class marimba.gui.Widget
adapter, background, clazz, defaultBackground, defaultFont, defaultForeground, defaultHilite, directGraphics, disabled, east, editor, focus, font, foreground, height, hilite, layoutMgr, name, north, nwidgets, parent, script, south, tip, transparent, tx, ty, valid, visible, wBackground, west, wFont, wForeground, wHilite, widgets, width, wScript, wTip, x, y
 
Fields inherited from interface marimba.gui.WidgetConstants
ALWAYS, ANYWHERE, APPLET, ASCENDING, BLINK, BLUE, BONGO_EVENT, BOTH, BOTTOM, BOXED, BUTTON, CENTER, CHAR, CHECK, COLLAPSE_EVENT, CONTENT, DESCENDING, DETACHED, DIAGONAL, DOWN, DRAG, EXCLUSIVE, EXPAND_EVENT, FILL, FILLED, GREEN, HORIZONTAL, INSIDE, INVISIBLE, JAVA_VERSION, JAVAOS, JDK10, JDK11, LAYERS, LEFT, LOWERED, MAC, MULTIPLE, NETCASTER, NETSCAPE, NEVER, NONE, NT, OPTIONAL, OS_ARCH, OS_NAME, OS_VERSION, OUTLINE, PAGE_DOWN, PAGE_EVENT, PAGE_UP, PATTERN, PC, PICTURE, PLAIN, PROPORTIONAL, RADIO, RAISED, RED, REST_EVENT, RIGHT, ROUNDED, SCALE, SCROLLBAR, SCROLLING, SOLID, SQUARE, TEXT_CHANGED_EVENT, TOP, TOPLEFT, TRUNCATE, UNDERLINE, UNIX, UP, VERTICAL, WAKE_EVENT, WIN95, WINDOWS, WORD
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PopupMenu()
           
 
Method Summary
 void add(PopupMenuItemWidget item)
          Add a menu item by giving the menu item directly.
 void add(java.lang.String label)
          Add a menu item.
 void addSeparator()
          Add a separator to this menu.
 void addSeparator(int index)
          Insert a separator at the specified position.
 void clear()
          Remove all menu items in this menu, the menu will be empty after this.
 void fit()
          Fit the menu in the visible area of the parent window.
 boolean focusInterest()
          Supports input focus.
 PopupMenuItemWidget getCurrentItem()
          The currently selected item.
 PopupMenuItemWidget getItem(int index)
          Get the item at the specified position.
 int getItemCount()
          Get the number of items in this menu.
 boolean getItemFocus()
          Check whether selected items are painted with a focus rectangle around it.
 int getMaxVisible()
          Get the maximum number of visible items.
 Widget getOwner()
          Get the owner.
protected  int getPopupHeight()
          The initial height of the popup menu.
 java.awt.Dimension getPreferredSize()
          Compute the best size for this menu.
 boolean handleEvent(java.awt.Event evt)
          Handle events.
 int indexOf(PopupMenuItemWidget item)
          Return index of given item.
 void insert(PopupMenuItemWidget item, int index)
          Insert a menu item at the given position by giving the item directly.
 void insert(java.lang.String label, int index)
          Insert a menu item at the given position.
 void layout()
          Layout the menu items.
protected  void layoutContainer()
          Set the properties of the container correctly, called by the layout method.
 void nextItem()
          Deprecated. As of Bongo version 1.1.
 void paint(java.awt.Graphics g, int cx, int cy, int cw, int ch)
          Paint the background
 void popdown()
          Hide the PopupMenu.
 void popup(Widget parent, int x, int y)
          Show the menu.
 void popup(Widget parent, int x, int y, int width)
          Show the menu, and force the width to a certain number of pixels.
 java.awt.Dimension preferredSize()
          Deprecated. As of Bongo version 1.1.
 void previousItem()
          Deprecated. As of Bongo version 1.1.
 void remove(int index)
          Remove the menu item at the given position.
 void remove(PopupMenuItemWidget item)
          Remove a menu item by giving the item directly.
 void remove(java.lang.String label)
          Remove the first menu item that has the given label.
 void select(int index)
          Set the current item to the index-th item, with index in [0 ..
 void select(PopupMenuItemWidget item)
          Select an item by giving the item directly.
 void selectNextItem()
          The default always has been to wrap around the bottom.
 void selectNextItem(boolean wrap)
          Select the next item, if there is no current item yet, it will result in the selection of the first item.
 void selectPreviousItem()
          The default always has been to wrap around the bottom.
 void selectPreviousItem(boolean wrap)
          Select previous item, if there is no current item yet, it will result in the selection of the last item.
 void setItemFocus(boolean itemFocus)
          Let the selected item paint with a focus rectangle or not.
 void setMaxVisible(int maxVisible)
          Set the maximum number of visible items.
 void setMouseUpPopDown(boolean popDown)
          Set whether the popupmenu should popdown on the first mouse up event.
 void setOwner(Widget owner)
          Set the owner.
 long tick(long tm, java.lang.Object arg)
          Take care of timer scrolls.
 
Methods inherited from class marimba.gui.PopupWidget
getPlayerPanel, isShowing, paramString, popup, postEvent, repaint, repaint, repaintParent, replace
 
Methods inherited from class marimba.gui.GroupWidget
getEditing, getEditor, getFillMode, getFillOptions, getLineMode, getLineOptions, getPattern, getPatternSource, getProperties, init, setEditing, setFillMode, setLineMode, setPattern, setProperties, update, updateArea, waitForPattern
 
Methods inherited from class marimba.gui.ContainerWidget
findInFocus, findWidget, firstInFocus, getChildProperties, getContent, newContent, nextInFocus, previousInFocus
 
Methods inherited from class marimba.gui.Widget
action, action, add, add, adjustFont, adjustFont, applyProperties, audioLoop, audioLoop, audioPlay, audioPlay, audioStop, audioStop, bounds, clearFocus, clearPopups, clone, contains, contains, createImage, createImage, currentFocus, destroy, disable, disable, enable, firstFocus, getAudioClip, getAudioClipAt, getBackground, getBounds, getCancelButton, getCursor, getDefaultButton, getDescription, getEncoding, getFocusColor, getFont, getFontMetrics, getForeground, getHilite, getImage, getKey, getKey, getKey, getLayoutMgr, getLocale, getLocation, getName, getParent, getPlayerFrame, getPresentation, getSelBackground, getSelFocusColor, getSelForeground, getSize, getText, getText, getTip, getTip, getTipFont, getValue, getValue, getWidget, getWidgetAt, getWidgetAt, getWidgetClass, getWidgetsAt, getWidgetsAt, getWidgetsAt, gotFocus, gotoPage, gotoPage, hasFocus, hide, imageUpdate, inheritFont, inside, inside, invalidate, isDisabled, isTransparent, isVisible, keyDown, keyUp, list, list, locateWidget, locateWidgets, locateWidgets, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, overlap, paint, paintAll, previousFocus, remove, remove, remove, removeAll, repaint, repaint, repaint, replace, replace, requestFocus, resetCursor, reshape, reshape, resize, resize, rmove, rscroll, scroll, setAttach, setBackground, setBounds, setBounds, setCursor, setDisabled, setEditor, setEncoding, setFont, setForeground, setHilite, setLayoutMgr, setLocale, setLocation, setName, setSize, setSize, setText, setText, setTip, setTipFont, setTransparent, setValue, setValue, setVisible, show, show, size, start, stop, sync, toBack, toBack, toFront, toFront, toString, validate
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

current

public PopupMenuItemWidget current
The currently selected item. If no item is selected, current is null.
See Also:
getCurrentItem(), select(int), selectNextItem(), selectPreviousItem()

owner

public Widget owner
The owner of this widget. When the menu is being popped down it will let this widget request focus.
See Also:
getOwner(), setOwner(marimba.gui.Widget)

itemFocus

public boolean itemFocus
The items can be drawn with or without a focus rectangle around it when they are selected.
See Also:
getItemFocus(), setItemFocus(boolean)

maxVisible

public int maxVisible
The maximum number of visible items, if there are more items a scrollbar is used. If this number is zero or smaller the max number of visible items is determined by the size of the menu.
See Also:
getMaxVisible(), setMaxVisible(int)

container

protected ScrollingContainerWidget container
The popupmenu uses a scrolling container to display the popup menu items.

dragged

protected boolean dragged
Has the user dragged with the mouse?

ticking

protected boolean ticking
Are we currently on the timer's list?

scrollJump

protected int scrollJump
Negative is scrolling up, positive is down (unfortunately). The absolute value is the distance from the edge of our space, and is related to the scroll speed.
See Also:
ticking, tick(long, java.lang.Object), handleEvent(java.awt.Event)

mouseUpPopDown

protected boolean mouseUpPopDown
Should the menu popdown when the MOUSE_UP event is detected?
See Also:
setMouseUpPopDown(boolean)

poppingDown

protected boolean poppingDown
indicates whether popdown() is being executed for LOST_FOCUS event
Constructor Detail

PopupMenu

public PopupMenu()
Method Detail

getOwner

public Widget getOwner()
Get the owner.
See Also:
owner

setOwner

public void setOwner(Widget owner)
Set the owner.
See Also:
owner

getItemFocus

public boolean getItemFocus()
Check whether selected items are painted with a focus rectangle around it.
See Also:
itemFocus

setItemFocus

public void setItemFocus(boolean itemFocus)
Let the selected item paint with a focus rectangle or not.
See Also:
itemFocus

getMaxVisible

public int getMaxVisible()
Get the maximum number of visible items.
See Also:
maxVisible

setMaxVisible

public void setMaxVisible(int maxVisible)
Set the maximum number of visible items.
See Also:
maxVisible

getPopupHeight

protected int getPopupHeight()
The initial height of the popup menu.
See Also:
popup(marimba.gui.Widget, int, int)

popup

public void popup(Widget parent,
                  int x,
                  int y)
Show the menu.
Overrides:
popup in class PopupWidget
See Also:
popdown(), getPopupHeight()

popup

public void popup(Widget parent,
                  int x,
                  int y,
                  int width)
Show the menu, and force the width to a certain number of pixels.
See Also:
popdown(), getPopupHeight()

fit

public void fit()
Fit the menu in the visible area of the parent window.
Overrides:
fit in class PopupWidget

addSeparator

public void addSeparator()
Add a separator to this menu. A separator is a grey horizontal line.

addSeparator

public void addSeparator(int index)
Insert a separator at the specified position.

add

public void add(java.lang.String label)
Add a menu item.
See Also:
select(int)

add

public void add(PopupMenuItemWidget item)
Add a menu item by giving the menu item directly.
See Also:
select(int)

insert

public void insert(java.lang.String label,
                   int index)
Insert a menu item at the given position.

insert

public void insert(PopupMenuItemWidget item,
                   int index)
Insert a menu item at the given position by giving the item directly. If null is specified, nothing will happen, if the index is out of range the index is automatically adjusted to the first or last item.

remove

public void remove(java.lang.String label)
Remove the first menu item that has the given label. If there is no menu item with that label, nothing happens.

remove

public void remove(PopupMenuItemWidget item)
Remove a menu item by giving the item directly.

remove

public void remove(int index)
Remove the menu item at the given position. If the index is out of range, it will automatically be adjusted to the first or last item.

clear

public void clear()
Remove all menu items in this menu, the menu will be empty after this.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Compute the best size for this menu.
Overrides:
getPreferredSize in class ContainerWidget

getItemCount

public int getItemCount()
Get the number of items in this menu.

getItem

public PopupMenuItemWidget getItem(int index)
Get the item at the specified position.

getCurrentItem

public PopupMenuItemWidget getCurrentItem()
The currently selected item. If none is selected, null is returned.
See Also:
current

selectNextItem

public void selectNextItem()
The default always has been to wrap around the bottom. Keep this behavior.

selectNextItem

public void selectNextItem(boolean wrap)
Select the next item, if there is no current item yet, it will result in the selection of the first item.
Parameters:
wrap - Wrap back to zero when we go off the end?
See Also:
current

selectPreviousItem

public void selectPreviousItem()
The default always has been to wrap around the bottom. Keep this behavior.

selectPreviousItem

public void selectPreviousItem(boolean wrap)
Select previous item, if there is no current item yet, it will result in the selection of the last item.
Parameters:
wrap - Wrap back to the end of the list if we pass 0?
See Also:
current

indexOf

public int indexOf(PopupMenuItemWidget item)
Return index of given item. Returns -1 if item is not found.
See Also:
select(int)

select

public void select(int index)
Set the current item to the index-th item, with index in [0 .. getItemCount()]. If an invalid number is given, the first item becomes the current one.
See Also:
current, indexOf(marimba.gui.PopupMenuItemWidget), add(java.lang.String)

select

public void select(PopupMenuItemWidget item)
Select an item by giving the item directly.

setMouseUpPopDown

public void setMouseUpPopDown(boolean popDown)
Set whether the popupmenu should popdown on the first mouse up event.
See Also:
mouseUpPopDown

popdown

public void popdown()
Hide the PopupMenu.
Overrides:
popdown in class PopupWidget
See Also:
popup(marimba.gui.Widget, int, int)

layoutContainer

protected void layoutContainer()
Set the properties of the container correctly, called by the layout method.
See Also:
layout()

layout

public void layout()
Layout the menu items.
Overrides:
layout in class ContainerWidget

paint

public void paint(java.awt.Graphics g,
                  int cx,
                  int cy,
                  int cw,
                  int ch)
Paint the background
Overrides:
paint in class GroupWidget

tick

public long tick(long tm,
                 java.lang.Object arg)
Take care of timer scrolls.
Specified by:
tick in interface TimerClient
Overrides:
tick in class Widget
Following copied from class: marimba.gui.Widget
See Also:
TimerClient

handleEvent

public boolean handleEvent(java.awt.Event evt)
Handle events.
Overrides:
handleEvent in class Widget
Following copied from class: marimba.gui.Widget
Parameters:
evt - the event that needs to be handled by the widget
See Also:
Widget.postEvent(java.awt.Event)

focusInterest

public boolean focusInterest()
Supports input focus.
Overrides:
focusInterest in class Widget
Following copied from class: marimba.gui.Widget
See Also:
Widget.focus, Widget.requestFocus()

preferredSize

public java.awt.Dimension preferredSize()
Deprecated. As of Bongo version 1.1.

See Also:
getPreferredSize()

nextItem

public void nextItem()
Deprecated. As of Bongo version 1.1.

See Also:
selectNextItem()

previousItem

public void previousItem()
Deprecated. As of Bongo version 1.1.

See Also:
selectPreviousItem()