UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.satin.widgets
Class PieMenu

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--edu.berkeley.guir.lib.satin.widgets.PieMenu
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, MenuElement, Serializable

public class PieMenu
extends JPanel
implements MenuElement

A Pie Menu widget.



Introduction

A Pie Menu is a circular menu that lets people choose items by dragging the pointing device in the direction of the menu item. Pie Menus work well with pen devices, and also take advantage of muscle-memory, as it seems that people remember angles better than they remember the position of items in linear lists.

See Don Hopkins' page on Pie Menus for more information.

For a short description of how to use this particular Pie Menu implementation, see the Java PieMenu page.


Application Programming Interface

Here's a short overview of the API. There are a collection of static class methods that let you set global behavior. Some, like {@link #setAllToMouseMode()} and {@link #setAllDragOpen()}, deal with the global look and feel of all pie menus. These kind of class methods are named setAllXXX().

There are other class methods that let you set the default for all pie menus created after they are set. For example, {@link #setDefaultFillColor(Color)} lets you set the color of all pie menus created after the method is called. These kind of class methods are named setDefaultXXX().

There are also instance methods that let you set values for individual instances of pie menus. For example, {@link #setLineColor(Color)} lets you set the color of lines in one instance of a pie menu, without affecting any others.

Here's an overview of the setAllXXX() methods:

Code Example

To add items to the PieMenu, just use the various add() methods. You'll need to add an ActionListener on each of the items you add, which will be called when the menu item is activated. For example:
    PieMenu pieMain = new PieMenu();
    PieMenu pieFile = new PieMenu("File");

    pieMain.add(pieFile);       // add a submenu
    pieMain.add("Edit").addActionListener(new PieSliceListener());
    pieMain.add("View").addActionListener(new PieSliceListener());
    pieMain.add("Help").addActionListener(new PieSliceListener());

    pieFile.add("Open").addActionListener(new PieSliceListener());
    ...

    class PieSliceListener
       implements ActionListener {
 
       public actionPerformed(ActionEvent evt) {
          System.out.println("Activating " + evt.getActionCommand());
       } // of actionPerformed

    } // of PieSliceListener
 
Of course, you'd probably have different ActionListeners instead of just going to one.

To add this pie menu to a component, just do:

    PieMenu pm = new PieMenu();
    JComponent c = new JPanel();
    pm.addPieMenuTo(c);
 
Currently, the PieMenu only works with JComponents.


Other Notes

Pie Menus are a more sophisticated form of {@link javax.swing.JPopupMenu}. Although most of the interface is implemented, this PieMenu isn't a full JPopupMenu yet (but that's on the list for things to do later on).

Please note that this Pie Menu widget does not clip to the circular boundaries of the Pie Menu for performance reasons. It does, however, clip to the rectangular bounds of the Pie Menu. The system response time felt a little sluggish, so I turned it rectangular clipping by default.

Lastly, this version of Pie Menu only works with Java Swing. It does not currently work with AWT heavyweight widgets.


Known Problems

Don't do something like this:
 PieMenu   pieMain = new PieMenu();
 JMenuItem item    = new JMenuItem("File");
 
 pieMain.add(item);
 item.setEnabled(false);
 
Although this should work, it doesn't, due to a quirk in this implementation. However, you can do the following instead:
 PieMenu   pieMain = new PieMenu();
 JMenuItem item    = pieMain.add("File");
 item.setEnabled(false);
 


Sample Code

Here is what some sample code would look like. It creates a hierarchy of pie menus. The parts that have action listeners would actually work. The parts that don't would be displayed but would take no action.
 private void setupPieMenu() {
    PieMenu pieMain      = new PieMenu();
    PieMenu pieFile      = new PieMenu("File");
    PieMenu pieEdit      = new PieMenu("Edit");
    PieMenu pieHelp      = new PieMenu("Help");
    PieMenu pieTransform = new PieMenu("Rotate /\nZoom");

    //// 1. Pie menu layout.
    pieMain.add(pieFile);
       pieFile.add("Open\nImages").addActionListener(new OpenImageListener());
       pieFile.add("Open\nPoster");
       pieFile.add("Save\nPoster");
    pieMain.add("Undo");
    pieMain.add(pieHelp);
       pieHelp.add("About");
       pieHelp.add("Search");
       pieHelp.add(pieDebug);
       pieHelp.add(pieTransform);
          pieTransform.add("Zoom\nIn");
          pieTransform.add("Rotate\nLeft");
          pieTransform.add("Zoom\nOut");
          pieTransform.add("Rotate\nRight");
    pieMain.add("Color").addActionListener(new ColorListener());
    pieMain.add("Redo").addActionListener(new RedoListener());
    pieMain.add(pieEdit);
       pieEdit.add("Cut").addActionListener(new CutListener());
       pieEdit.add("Copy").addActionListener(new CopyListener());
       pieEdit.add("Paste").addActionListener(new PasteListener());
       pieEdit.add("Delete").addActionListener(new DeleteListener());

    //// 2. Other pie menu initializations.
    pieMain.addPieMenuTo(this);
    pieMain.setLineNorth(true);
    pieMain.setAllTapHoldOpen();
 } // of setupPieMenu
 


This software is distributed under the Berkeley Software License.

 Revisions:  - SATIN-v1.0-1.0.0, Mar 16 1999, JH
               Created class
             - SATIN-v2.1-1.0.1, Aug 11 2000, JH
               Touched for SATIN release
 

Since:
JDK 1.2
Version:
SATIN-v2.1-1.0.1, Aug 11 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )
See Also:
JPopupMenu, Serialized Form

Inner classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
Field Summary
static boolean DEFAULT_AUTO_OPEN
          Default value for auto-open is false.
static int DEFAULT_BIG_RADIUS
          Default radius size for the pie menu, currently 100.
static boolean DEFAULT_CLIP_FLAG
          Default value for clipping is false.
static Color DEFAULT_FILL_COLOR
          The default color of the pie menu, currently light gray.
static Font DEFAULT_FONT
          The default font, currently sans serif plain, 16 point.
static Color DEFAULT_FONT_COLOR
          The default color of fonts, currently black.
static long DEFAULT_INITIAL_DELAY
          The default delay (msec) before pie menus initially pop up, currently 200ms.
static Color DEFAULT_LINE_COLOR
          The default color of the lines in the pie menu, currently black.
static float DEFAULT_LINE_WIDTH
          Default line width for drawing lines in the Pie Menu, currently 0.5.
static double DEFAULT_SCALING_FACTOR
          The default scaling factor for where to draw objects.
static Color DEFAULT_SELECTED_COLOR
          The default color of the selected item in the pie menu, currently gray.
static int DEFAULT_SMALL_RADIUS
          The radius of the small inner circle, currently 20.
static double DEFAULT_START
          Where the first pie slice is rendered.
static long DEFAULT_SUBMENU_DELAY
          The default delay (msec) before pie submenus pop up, currently 500ms.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PieMenu()
          Create a pie menu on the specified applet.
PieMenu(int radius)
           
PieMenu(String str)
           
PieMenu(String str, Icon icon)
           
PieMenu(String str, Icon icon, int radius)
          Create a pie menu with the specified parameters.
PieMenu(String str, int radius)
           
 
Method Summary
 JMenuItem add(Icon icon)
          Add an Icon as a menu element.
 JMenuItem add(Icon icon, int index)
          Add an Icon as a menu element at the given position.
 JMenuItem add(JMenuItem menuItem)
           
 JMenuItem add(JMenuItem menuItem, int index)
           
 void add(PieMenu menu)
          Adds a pie menu as a menu element.
 void add(PieMenu menu, int index)
          Adds a pie menu as a menu element at the given position.
 JMenuItem add(String str)
          Add a String as a menu element.
 JMenuItem add(String str, Icon icon)
          Add a String and Icon as a menu element.
 JMenuItem add(String str, Icon icon, int index)
          Add a String and Icon as a menu element at the given position.
 JMenuItem add(String str, int index)
          Add a String as a menu element at the given position.
 void addPieMenuTo(Component c)
          A convenience method to have the pie menu listen on the specified component.
 void addPopupMenuListener(PopupMenuListener l)
           
 boolean contains(int x, int y)
           
 boolean contains(Point pt)
           
 boolean doesActivateMenu(MouseEvent evt)
          Specify what triggers the popup of this pie menu.
protected  void firePopupMenuCanceled()
          This is never really called, as firePopupMenuCanceled is never really used in JPopupMenu either.
protected  void firePopupMenuWillBecomeInvisible()
           
protected  void firePopupMenuWillBecomeVisible()
           
static boolean getAllAutoOpen()
          Check whether we can auto-open pie menus or not.
static boolean getAllClipping()
          Get the default for whether or not pie menus should be clipped to circular bounds for all new pie menus created.
static long getAllInitialDelay()
          Get the default appearance delay for the initial pie menu.
static boolean getAllRelocateSubmenus()
          Get the default for whether or not pie menus should appear wherever the cursor happens to be, or if it should appear in a standardized location.
static long getAllSubmenuDelay()
          Get the default appearance delay for all pie submenus.
 int getBigRadius()
          Get the radius for the pie menu.
 Component getComponent()
           
static int getDefaultBigRadius()
          Get the default radius for all new pie menus created.
static Color getDefaultFillColor()
          Get the default fill color for all new pie menus created.
static Font getDefaultFont()
          Get the default font for all new pie menus created.
static Color getDefaultFontColor()
          Get the default font color for all new pie menus created.
static Color getDefaultLineColor()
          Get the default line color for all new pie menus created.
static boolean getDefaultLineNorth()
          Get the default for whether or not the first line drawn should be north or if the first pie slice should be drawn north.
static float getDefaultLineWidth()
          Get the default line width for all new pie menus created.
static double getDefaultScalingFactor()
          Get the default scaling factor for all new pie menus created.
static Color getDefaultSelectedColor()
          Get the default selected color for all new pie menus created.
 int getDefaultSelectedItem()
           
static int getDefaultSmallRadius()
          Get the default radius of the inner circle for all new pie menus created.
static Image getDefaultSubmenuIcon()
          Get what the default image should be for submenus.
 Color getFillColor()
          Get the color of the pie menu items.
 Font getFont()
          Get the font the pie menu will use.
 Color getFontColor()
          Get the color text is rendered in.
 Icon getIcon()
           
 JMenuItem getItem(int pos)
           
 int getItemCount()
           
 Color getLineColor()
          Get the color lines are rendered in.
 boolean getLineNorth()
          Get whether we draw a line to north, or draw the first slice such that it is centered on north.
 double getScalingFactor()
          Get the scaling factor for the pie menu.
 Color getSelectedColor()
          Get the color of the selected item.
 int getSelectedItem()
          Get the menu item that is currently selected.
 int getSmallRadius()
          Get the radius of the inner circle for the pie menu.
 MenuElement[] getSubElements()
           
protected  Image getSubmenuIcon()
          Get the image to add for submenus.
 String getText()
           
static boolean isAllMouseMode()
          See if all of the pie menus are in mouse mode.
static boolean isAllPenMode()
          See if all of the pie menus are in pen mode.
static boolean isDragOpen()
          Check if the sequence {button-down} opens up the pie menu.
static boolean isTapHoldOpen()
          Check if the sequence {button-down, hold without moving} opens up the pie menu.
static boolean isTapOpen()
          Check if the sequence {button-down, button-up} opens up the pie menu.
 void menuSelectionChanged(boolean isIncluded)
           
 void paintComponent(Graphics g)
           
 void processKeyEvent(KeyEvent evt, MenuElement[] path, MenuSelectionManager manager)
           
 void processMouseEvent(MouseEvent evt, MenuElement[] path, MenuSelectionManager manager)
           
 void remove(int pos)
          Removes the menu item at the specified index from this menu.
 void removePopupMenuListener(PopupMenuListener l)
           
protected  void renderIcon(Graphics2D gg, int xx, int yy, Icon icon, double angle, double radius, boolean enabled)
          Render a menu icon at the given angle and maximum radius.
protected  void renderString(Graphics2D gg, int xx, int yy, String str, double angle, double radius, boolean enabled)
          Render a String at the given angle and maximum radius.
protected  void renderSubmenuIcon(Graphics2D gg, int xx, int yy, Image img, double angle, double radius)
          Draw the submenu icon.
static void setAllAutoOpen(boolean flag)
          Set whether we can auto-open pie menus or not.
static void setAllClipping(boolean flag)
          Set the default for whether or not pie menus should be clipped to circular bounds for all new pie menus created.
static void setAllDragOpen()
          Set that the sequence {button-down} opens up the pie menu.
static void setAllInitialDelay(long newDelay)
          Set the default appearance delay for the initial pie menu.
static void setAllRelocateSubmenus(boolean flag)
          Set the default for whether or not pie menus should appear wherever the cursor happens to be, or if it should appear in a standardized location.
static void setAllSubmenuDelay(long newDelay)
          Set the default appearance delay all pie submenus.
static void setAllTapHoldOpen()
          Set that the sequence {button-down, hold without moving} opens up the pie menu.
static void setAllTapOpen()
          Set that the sequence {button-down, button-up} opens up the pie menu.
static void setAllToMouseMode()
          Set all of the pie menus to be used with mouse mode.
static void setAllToPenMode()
          Set all of the pie menus to be used with pen mode.
 void setBigRadius(int radius)
          Set the radius for the pie menu.
static void setDefaultBigRadius(int newRadius)
          Set the default radius for all new pie menus created after this value is set.
static void setDefaultFillColor(Color newColor)
          Set the default fill color for all new pie menus created after this value is set.
static void setDefaultFont(Font newFont)
          Set the default font for all new pie menus created after this value is set.
static void setDefaultFontColor(Color newColor)
          Set the default font color for all new pie menus created after this value is set.
static void setDefaultLineColor(Color newColor)
          Set the default line color for all new pie menus created after this value is set.
static void setDefaultLineNorth(boolean flag)
          Set the default for whether or not the first line drawn should be north or if the first pie slice should be drawn north.
static void setDefaultLineWidth(float newLineWidth)
          Set the default line width for all new pie menus created after this value is set.
static void setDefaultScalingFactor(double newScalingFactor)
          Set the default scaling factor for all new pie menus created after this value is set.
static void setDefaultSelectedColor(Color newColor)
          Set the default selected color for all new pie menus created after this value is set.
 void setDefaultSelectedItem(int pos)
          Set what the selected item is by default when the pie menu is opened.
static void setDefaultSmallRadius(int newRadius)
          Set the default radius of the inner circle for all new pie menus created after this value is set.
static void setDefaultSubmenuIcon(Image newImage)
          Set what the default image should be for submenus created after this value is set.
 void setFillColor(Color newColor)
          Set the color of the pie menu items.
 void setFont(Font newFont)
          Set the font the pie menu will use.
 void setFontColor(Color newColor)
          Set the color text is rendered in.
 void setIcon(Icon icon)
           
 void setLineColor(Color newColor)
          Set the color lines are rendered in.
 void setLineNorth(boolean flag)
          Set whether we draw a line to north, or draw the first slice such that it is centered on north.
 void setLineWidth(float newWidth)
          Set the line width for the pie menu.
 void setLocation(int x, int y)
           
 void setLocation(Point pt)
           
 void setScalingFactor(double newScalingFactor)
          Set the scaling factor for the pie menu.
 void setSelectedColor(Color newColor)
          Set the color of the selected item.
 void setSelectedItem(int index)
          Set which menu item is currently selected.
 void setSmallRadius(int newRadius)
          Set the radius of the inner circle for the pie menu.
 void setText(String str)
           
 void setVisible(boolean flag)
          Hide immediately.
 void show(Component invoker, int x, int y)
          Show the pie menu.
 void showNow(Component invoker, int x, int y)
           
 String toString()
           
protected  void updateShape()
          Update the shape of this PieMenu whenever the location or radius is changed.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setName, setSize, setSize, show, show, size, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_START

public static final double DEFAULT_START
Where the first pie slice is rendered. Currently North.

DEFAULT_BIG_RADIUS

public static final int DEFAULT_BIG_RADIUS
Default radius size for the pie menu, currently 100.

DEFAULT_SMALL_RADIUS

public static final int DEFAULT_SMALL_RADIUS
The radius of the small inner circle, currently 20.

DEFAULT_INITIAL_DELAY

public static final long DEFAULT_INITIAL_DELAY
The default delay (msec) before pie menus initially pop up, currently 200ms. Don't make this too small, or you'll get strange errors.

DEFAULT_SUBMENU_DELAY

public static final long DEFAULT_SUBMENU_DELAY
The default delay (msec) before pie submenus pop up, currently 500ms.

DEFAULT_AUTO_OPEN

public static final boolean DEFAULT_AUTO_OPEN
Default value for auto-open is false.

DEFAULT_CLIP_FLAG

public static final boolean DEFAULT_CLIP_FLAG
Default value for clipping is false.

DEFAULT_SCALING_FACTOR

public static final double DEFAULT_SCALING_FACTOR
The default scaling factor for where to draw objects. This scaling factor is multiplied with the radius to determine where to draw things. Currently 0.65.

DEFAULT_FILL_COLOR

public static final Color DEFAULT_FILL_COLOR
The default color of the pie menu, currently light gray.

DEFAULT_LINE_COLOR

public static final Color DEFAULT_LINE_COLOR
The default color of the lines in the pie menu, currently black.

DEFAULT_SELECTED_COLOR

public static final Color DEFAULT_SELECTED_COLOR
The default color of the selected item in the pie menu, currently gray.

DEFAULT_FONT_COLOR

public static final Color DEFAULT_FONT_COLOR
The default color of fonts, currently black.

DEFAULT_FONT

public static final Font DEFAULT_FONT
The default font, currently sans serif plain, 16 point.

DEFAULT_LINE_WIDTH

public static final float DEFAULT_LINE_WIDTH
Default line width for drawing lines in the Pie Menu, currently 0.5.
Constructor Detail

PieMenu

public PieMenu()
Create a pie menu on the specified applet.

PieMenu

public PieMenu(int radius)

PieMenu

public PieMenu(String str)

PieMenu

public PieMenu(String str,
               Icon icon)

PieMenu

public PieMenu(String str,
               int radius)

PieMenu

public PieMenu(String str,
               Icon icon,
               int radius)
Create a pie menu with the specified parameters.
Parameters:
str - is the name of this pie menu.
icon - is the icon for this pie menu.
radius - is the intiial radius of the pie menu.
Method Detail

setAllAutoOpen

public static void setAllAutoOpen(boolean flag)
Set whether we can auto-open pie menus or not.

getAllAutoOpen

public static boolean getAllAutoOpen()
Check whether we can auto-open pie menus or not.

isTapOpen

public static boolean isTapOpen()
Check if the sequence {button-down, button-up} opens up the pie menu.

isTapHoldOpen

public static boolean isTapHoldOpen()
Check if the sequence {button-down, hold without moving} opens up the pie menu.

isDragOpen

public static boolean isDragOpen()
Check if the sequence {button-down} opens up the pie menu.

setAllTapOpen

public static void setAllTapOpen()
Set that the sequence {button-down, button-up} opens up the pie menu.

setAllTapHoldOpen

public static void setAllTapHoldOpen()
Set that the sequence {button-down, hold without moving} opens up the pie menu.

setAllDragOpen

public static void setAllDragOpen()
Set that the sequence {button-down} opens up the pie menu.

setAllRelocateSubmenus

public static void setAllRelocateSubmenus(boolean flag)
Set the default for whether or not pie menus should appear wherever the cursor happens to be, or if it should appear in a standardized location. This is a global behavior for all pie menus.

getAllRelocateSubmenus

public static boolean getAllRelocateSubmenus()
Get the default for whether or not pie menus should appear wherever the cursor happens to be, or if it should appear in a standardized location.

setAllToPenMode

public static void setAllToPenMode()
Set all of the pie menus to be used with pen mode. This is a global behavior for all pie menus.

setAllToMouseMode

public static void setAllToMouseMode()
Set all of the pie menus to be used with mouse mode. This is a global behavior for all pie menus.

isAllPenMode

public static boolean isAllPenMode()
See if all of the pie menus are in pen mode.

isAllMouseMode

public static boolean isAllMouseMode()
See if all of the pie menus are in mouse mode.

setAllInitialDelay

public static void setAllInitialDelay(long newDelay)
Set the default appearance delay for the initial pie menu. This is a global behavior for all pie menus.

getAllInitialDelay

public static long getAllInitialDelay()
Get the default appearance delay for the initial pie menu.

setAllSubmenuDelay

public static void setAllSubmenuDelay(long newDelay)
Set the default appearance delay all pie submenus. This is a global behavior for all pie menus.

getAllSubmenuDelay

public static long getAllSubmenuDelay()
Get the default appearance delay for all pie submenus.

setAllClipping

public static void setAllClipping(boolean flag)
Set the default for whether or not pie menus should be clipped to circular bounds for all new pie menus created. Clipping ensures that images and text are drawn entirely within the Pie Menu, but at the cost of performance. The Pie Menu feels a little sluggish when clipping is turned on. By default, it is off.

getAllClipping

public static boolean getAllClipping()
Get the default for whether or not pie menus should be clipped to circular bounds for all new pie menus created.

setDefaultSubmenuIcon

public static void setDefaultSubmenuIcon(Image newImage)
Set what the default image should be for submenus created after this value is set.

getDefaultSubmenuIcon

public static Image getDefaultSubmenuIcon()
Get what the default image should be for submenus.

setDefaultFillColor

public static void setDefaultFillColor(Color newColor)
Set the default fill color for all new pie menus created after this value is set.

getDefaultFillColor

public static Color getDefaultFillColor()
Get the default fill color for all new pie menus created.

setDefaultLineColor

public static void setDefaultLineColor(Color newColor)
Set the default line color for all new pie menus created after this value is set.

getDefaultLineColor

public static Color getDefaultLineColor()
Get the default line color for all new pie menus created.

setDefaultSelectedColor

public static void setDefaultSelectedColor(Color newColor)
Set the default selected color for all new pie menus created after this value is set.

getDefaultSelectedColor

public static Color getDefaultSelectedColor()
Get the default selected color for all new pie menus created.

setDefaultFontColor

public static void setDefaultFontColor(Color newColor)
Set the default font color for all new pie menus created after this value is set.

getDefaultFontColor

public static Color getDefaultFontColor()
Get the default font color for all new pie menus created.

setDefaultFont

public static void setDefaultFont(Font newFont)
Set the default font for all new pie menus created after this value is set.

getDefaultFont

public static Font getDefaultFont()
Get the default font for all new pie menus created.

setDefaultLineWidth

public static void setDefaultLineWidth(float newLineWidth)
Set the default line width for all new pie menus created after this value is set.

getDefaultLineWidth

public static float getDefaultLineWidth()
Get the default line width for all new pie menus created.

setDefaultBigRadius

public static void setDefaultBigRadius(int newRadius)
Set the default radius for all new pie menus created after this value is set.

getDefaultBigRadius

public static int getDefaultBigRadius()
Get the default radius for all new pie menus created.

setDefaultSmallRadius

public static void setDefaultSmallRadius(int newRadius)
Set the default radius of the inner circle for all new pie menus created after this value is set.

getDefaultSmallRadius

public static int getDefaultSmallRadius()
Get the default radius of the inner circle for all new pie menus created.

setDefaultScalingFactor

public static void setDefaultScalingFactor(double newScalingFactor)
Set the default scaling factor for all new pie menus created after this value is set.

getDefaultScalingFactor

public static double getDefaultScalingFactor()
Get the default scaling factor for all new pie menus created.

setDefaultLineNorth

public static void setDefaultLineNorth(boolean flag)
Set the default for whether or not the first line drawn should be north or if the first pie slice should be drawn north. Only takes effect for new pie menus created after this value is set.

getDefaultLineNorth

public static boolean getDefaultLineNorth()
Get the default for whether or not the first line drawn should be north or if the first pie slice should be drawn north.

getSubElements

public MenuElement[] getSubElements()
Specified by:
getSubElements in interface MenuElement

menuSelectionChanged

public void menuSelectionChanged(boolean isIncluded)
Specified by:
menuSelectionChanged in interface MenuElement

processKeyEvent

public void processKeyEvent(KeyEvent evt,
                            MenuElement[] path,
                            MenuSelectionManager manager)
Specified by:
processKeyEvent in interface MenuElement

processMouseEvent

public void processMouseEvent(MouseEvent evt,
                              MenuElement[] path,
                              MenuSelectionManager manager)
Specified by:
processMouseEvent in interface MenuElement

setFillColor

public void setFillColor(Color newColor)
Set the color of the pie menu items.

getFillColor

public Color getFillColor()
Get the color of the pie menu items.

setLineColor

public void setLineColor(Color newColor)
Set the color lines are rendered in.

getLineColor

public Color getLineColor()
Get the color lines are rendered in.

setSelectedColor

public void setSelectedColor(Color newColor)
Set the color of the selected item.

getSelectedColor

public Color getSelectedColor()
Get the color of the selected item.

setFontColor

public void setFontColor(Color newColor)
Set the color text is rendered in.

getFontColor

public Color getFontColor()
Get the color text is rendered in.

setFont

public void setFont(Font newFont)
Set the font the pie menu will use.
Overrides:
setFont in class JComponent

getFont

public Font getFont()
Get the font the pie menu will use.
Overrides:
getFont in class Component

setLineWidth

public void setLineWidth(float newWidth)
Set the line width for the pie menu.

setBigRadius

public void setBigRadius(int radius)
Set the radius for the pie menu.
Parameters:
radius - is the radius of the pie menu from the center.

getBigRadius

public int getBigRadius()
Get the radius for the pie menu.

setSmallRadius

public void setSmallRadius(int newRadius)
Set the radius of the inner circle for the pie menu.

getSmallRadius

public int getSmallRadius()
Get the radius of the inner circle for the pie menu.

setScalingFactor

public void setScalingFactor(double newScalingFactor)
Set the scaling factor for the pie menu.

getScalingFactor

public double getScalingFactor()
Get the scaling factor for the pie menu.

setLineNorth

public void setLineNorth(boolean flag)
Set whether we draw a line to north, or draw the first slice such that it is centered on north.
Parameters:
flag - is true if a line is to be drawn to north, false otherwise.

getLineNorth

public boolean getLineNorth()
Get whether we draw a line to north, or draw the first slice such that it is centered on north.

setSelectedItem

public void setSelectedItem(int index)
Set which menu item is currently selected.
Parameters:
index - is the index of the selected item. It has a value less than 0 to select the center circle.

getSelectedItem

public int getSelectedItem()
Get the menu item that is currently selected.
Returns:
the index of the currently selected item (0 based), or -1 if the small center circle is selected.

setDefaultSelectedItem

public void setDefaultSelectedItem(int pos)
Set what the selected item is by default when the pie menu is opened. Be sure to set this AFTER adding items to the pie menu, as it ignores invalid values.
Parameters:
pos - is the index of the menu item to be selected by default. Pass in a negative value to specify the little circle. Ignores values that are too large, defaults to the little circle.

getDefaultSelectedItem

public int getDefaultSelectedItem()

doesActivateMenu

public boolean doesActivateMenu(MouseEvent evt)
Specify what triggers the popup of this pie menu. Currently, looks for right mouse button, since the isPopupTrigger() method in MouseEvent doesn't seem to work correctly.

Override this method to be what you want.


addPieMenuTo

public void addPieMenuTo(Component c)
A convenience method to have the pie menu listen on the specified component. By default, this makes the pie menu listen for right mouse clicks. If any are received, then the pie menu will pop open.
Parameters:
c - is the component to attach the pie menu to. Right now, PieMenu only works with Java Swing components.

updateShape

protected void updateShape()
Update the shape of this PieMenu whenever the location or radius is changed.

contains

public boolean contains(int x,
                        int y)
Overrides:
contains in class JComponent

contains

public boolean contains(Point pt)
Overrides:
contains in class Component

setText

public void setText(String str)

getText

public String getText()

setIcon

public void setIcon(Icon icon)

getIcon

public Icon getIcon()

getComponent

public Component getComponent()
Specified by:
getComponent in interface MenuElement

getItemCount

public int getItemCount()

add

public JMenuItem add(JMenuItem menuItem,
                     int index)

add

public JMenuItem add(JMenuItem menuItem)

add

public JMenuItem add(Icon icon,
                     int index)
Add an Icon as a menu element at the given position. If index equals -1, the component will be appended to the end.

add

public JMenuItem add(Icon icon)
Add an Icon as a menu element.

add

public JMenuItem add(String str,
                     int index)
Add a String as a menu element at the given position. If index equals -1, the component will be appended to the end.

add

public JMenuItem add(String str)
Add a String as a menu element.

add

public JMenuItem add(String str,
                     Icon icon,
                     int index)
Add a String and Icon as a menu element at the given position. If index equals -1, the component will be appended to the end.

add

public JMenuItem add(String str,
                     Icon icon)
Add a String and Icon as a menu element.

add

public void add(PieMenu menu,
                int index)
Adds a pie menu as a menu element at the given position. If index equals -1, the component will be appended to the end.

add

public void add(PieMenu menu)
Adds a pie menu as a menu element. This is to allow multi-level pie menus. In later releases, Pie Menus will also be JMenuItems, so everything will be consistent.

remove

public void remove(int pos)
Removes the menu item at the specified index from this menu.
Overrides:
remove in class Container

getItem

public JMenuItem getItem(int pos)

addPopupMenuListener

public void addPopupMenuListener(PopupMenuListener l)

removePopupMenuListener

public void removePopupMenuListener(PopupMenuListener l)

firePopupMenuWillBecomeVisible

protected void firePopupMenuWillBecomeVisible()

firePopupMenuWillBecomeInvisible

protected void firePopupMenuWillBecomeInvisible()

firePopupMenuCanceled

protected void firePopupMenuCanceled()
This is never really called, as firePopupMenuCanceled is never really used in JPopupMenu either.

setVisible

public void setVisible(boolean flag)
Hide immediately.
Overrides:
setVisible in class JComponent

show

public void show(Component invoker,
                 int x,
                 int y)
Show the pie menu.
Parameters:
invoker - is the Component to show the pie menu in.
x - is the x-coordinate in the invoker's coordinate space.
y - is the y-coordinate in the invoker's coordinate space.
ms - is the delay (msec) before showing the pie menu.

showNow

public void showNow(Component invoker,
                    int x,
                    int y)

setLocation

public void setLocation(Point pt)
Overrides:
setLocation in class Component

setLocation

public void setLocation(int x,
                        int y)
Overrides:
setLocation in class Component

renderString

protected void renderString(Graphics2D gg,
                            int xx,
                            int yy,
                            String str,
                            double angle,
                            double radius,
                            boolean enabled)
Render a String at the given angle and maximum radius.
Parameters:
gg - is the Graphics context to render on.
xx - is the origin for the angle and radius.
yy - is the origin for the angle and radius.
str - is the String to render.
angle - is the angle to render the String str at.
radius - is the largest radius to render the String str at. The pie menu scaling factor will be used.
enabled - specifies whether the menu item is enabled or not.

renderIcon

protected void renderIcon(Graphics2D gg,
                          int xx,
                          int yy,
                          Icon icon,
                          double angle,
                          double radius,
                          boolean enabled)
Render a menu icon at the given angle and maximum radius.
Parameters:
gg - is the Graphics context to render on.
xx - is the origin for the angle and radius.
yy - is the origin for the angle and radius.
icon - is the icon to render.
angle - is the angle to render the icon at.
radius - is the largest radius to render the String str at. The pie menu scaling factor will be used.
enabled - specifies whether the item is enabled or not.

renderSubmenuIcon

protected void renderSubmenuIcon(Graphics2D gg,
                                 int xx,
                                 int yy,
                                 Image img,
                                 double angle,
                                 double radius)
Draw the submenu icon.

paintComponent

public void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

getSubmenuIcon

protected Image getSubmenuIcon()
Get the image to add for submenus. This image should be drawn such that it is pointing up. We'll do the rotation automatically for you.

toString

public String toString()
Overrides:
toString in class Component

Copyright Information