com.alee.extended.menu
Class WebDynamicMenu

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.alee.laf.panel.WebPanel
                      extended by com.alee.utils.swing.WebHeavyWeightPopup
                          extended by com.alee.extended.menu.WebDynamicMenu
All Implemented Interfaces:
PartialDecoration, LanguageContainerMethods, ShapeProvider, Styleable, SizeMethods<WebPanel>, SwingMethods, WindowMethods<javax.swing.JWindow>, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class WebDynamicMenu
extends WebHeavyWeightPopup

Custom dynamic menu with pretty display/hide animations.

Author:
Mikle Garin
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  double angleRange
          Angle which is available for menu elements.
protected  WebTimer animator
          Animation timer.
protected  boolean clockwise
          Menu animation direction.
protected  float currentProgress
          Menu display progress.
protected  boolean displaying
          Whether menu is being displayed or not.
protected  GlobalFocusListener focusListener
          Custom global focus listener that closes menu.
protected  WindowFollowAdapter followAdapter
          Invoker window follow adapter.
protected  DynamicMenuType hideType
          Menu hide animation type.
protected  boolean hiding
          Whether menu is being hidden or not.
protected  int hidingCause
          Index of menu item that caused menu to close.
protected  java.util.List<WebDynamicMenuItem> items
          Menu items list.
protected  java.lang.Object lsync
          Listeners synchronization object.
protected  java.awt.event.AWTEventListener mouseListener
          Custom global mouse listener that closes menu.
protected  java.util.List<java.lang.Runnable> onFullDisplay
          Actions to perform on full display.
protected  java.util.List<java.lang.Runnable> onFullHide
          Actions to perform on full hide.
protected  int radius
          Radius of the menu background in px.
protected  double startingAngle
          First element position angle in degrees.
protected  float stepProgress
          Single animation step progress.
protected  java.lang.Object sync
          Actions synchronization object.
protected  DynamicMenuType type
          Menu animation type.
 
Fields inherited from class com.alee.utils.swing.WebHeavyWeightPopup
closeOnOuterAction, followInvoker, invoker, invokerWindow, listeners, opacity, opaque, popup, window
 
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
WebDynamicMenu()
          Constructs new dynamic menu.
 
Method Summary
 WebImage addItem(javax.swing.ImageIcon icon)
           
 WebImage addItem(javax.swing.ImageIcon icon, java.awt.event.ActionListener action)
           
 WebImage addItem(WebDynamicMenuItem item)
           
protected  void destroyMenuWindow()
          Disposes old menu window.
protected  void displayMenuWindow(java.awt.Component invoker, java.awt.Point location)
          Creates new menu window.
 void fullyDisplayed()
          Performs actions waiting for menu display animation finish.
 void fullyHidden()
          Performs actions waiting for menu hide animation finish.
 DynamicMenuLayout getActualLayout()
          Returns actual menu layout manager.
 double getAngleRange()
           
 WebTimer getAnimator()
           
 float getCurrentProgress()
           
 DynamicMenuType getHideType()
           
 int getHidingCause()
          Returns index of menu item that caused menu to close.
 double getItemAngle(java.awt.Component item)
          Returns menu item angle relative to vertical axis.
 double getItemAngle(int index)
          Returns menu item angle relative to vertical axis.
 java.util.List<WebDynamicMenuItem> getItems()
           
 int getRadius()
           
 double getStartingAngle()
           
 float getStepProgress()
           
 DynamicMenuType getType()
           
static void hideAllDynamicMenus()
          Hides all visible dynamic menus.
 void hideMenu()
          Hides dynamic menu.
 void hideMenu(int index)
          Hides dynamic menu.
 WebHeavyWeightPopup hidePopup()
          
static boolean isAnyDynamicMenuDisplayed()
          Returns whether any dynamic menu is currently displayed or not.
 boolean isClockwise()
           
 boolean isDisplaying()
           
 boolean isHiding()
           
 void onFullDisplay(java.lang.Runnable action)
          Performs provided action when menu is fully displayed.
 void onFullHide(java.lang.Runnable action)
          Performs provided action when menu is fully hidden.
 void setAngleRange(double angleRange)
           
 void setClockwise(boolean clockwise)
           
 void setHideType(DynamicMenuType hideType)
           
 void setRadius(int radius)
           
 void setStartingAngle(double startingAngle)
           
 void setStepProgress(float stepProgress)
           
 void setType(DynamicMenuType type)
           
 void showMenu(java.awt.Component invoker, java.awt.Point location)
          Displays dynamic menu for the specified invoker location.
 
Methods inherited from class com.alee.utils.swing.WebHeavyWeightPopup
addPopupListener, center, center, center, center, firePopupClosed, firePopupOpened, firePopupWillBeClosed, firePopupWillBeOpened, getInvoker, getInvokerWindow, getPopup, getWindow, getWindowOpacity, installFollowAdapter, isCloseOnOuterAction, isFollowInvoker, isWindowOpaque, packAndCenter, packAndCenter, packToHeight, packToWidth, removePopupListener, setCloseOnOuterAction, setFollowInvoker, setWindowOpacity, setWindowOpaque, showPopup, showPopup, uninstallFollowAdapter, updateOpacity, updateOpaque
 
Methods inherited from class com.alee.laf.panel.WebPanel
add, add, add, add, add, add, getBorderColor, getBorderStroke, getDisabledBorderColor, getFirstComponent, getLanguageContainerKey, getLastComponent, getMargin, getMinimumHeight, getMinimumWidth, getPainter, getPreferredHeight, getPreferredSize, getPreferredWidth, getRound, getShadeTransparency, getShadeWidth, getStyleId, getWebUI, isPaintBackground, isPaintBottom, isPaintBottomLine, isPaintFocus, isPaintLeft, isPaintLeftLine, isPaintRight, isPaintRightLine, isPaintTop, isPaintTopLine, isUndecorated, isWebColoredBackground, provideShape, removeLanguageContainerKey, setBorderColor, setBorderStroke, setDisabledBorderColor, setLanguageContainerKey, setMargin, setMargin, setMargin, setMinimumHeight, setMinimumWidth, setPaintBackground, setPaintBottom, setPaintBottomLine, setPainter, setPaintFocus, setPaintLeft, setPaintLeftLine, setPaintRight, setPaintRightLine, setPaintSideLines, setPaintSides, setPaintTop, setPaintTopLine, setPreferredHeight, setPreferredWidth, setRound, setShadeTransparency, setShadeWidth, setStyleId, setUndecorated, setWebColoredBackground, updateUI
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

radius

protected int radius
Radius of the menu background in px.


startingAngle

protected double startingAngle
First element position angle in degrees. Counted from the circle top-most point.


angleRange

protected double angleRange
Angle which is available for menu elements. It is 360 degress by default (whole circle available).


stepProgress

protected float stepProgress
Single animation step progress. Making this value bigger will speedup the animation, reduce required resources but will also make it less soft.


type

protected DynamicMenuType type
Menu animation type.


hideType

protected DynamicMenuType hideType
Menu hide animation type.


clockwise

protected boolean clockwise
Menu animation direction.


items

protected java.util.List<WebDynamicMenuItem> items
Menu items list.


currentProgress

protected float currentProgress
Menu display progress.


sync

protected final java.lang.Object sync
Actions synchronization object.


animator

protected WebTimer animator
Animation timer.


followAdapter

protected WindowFollowAdapter followAdapter
Invoker window follow adapter.


displaying

protected boolean displaying
Whether menu is being displayed or not.


hiding

protected boolean hiding
Whether menu is being hidden or not.


hidingCause

protected int hidingCause
Index of menu item that caused menu to close. This might affect the hiding animation.


mouseListener

protected java.awt.event.AWTEventListener mouseListener
Custom global mouse listener that closes menu.


focusListener

protected GlobalFocusListener focusListener
Custom global focus listener that closes menu.


lsync

protected final java.lang.Object lsync
Listeners synchronization object.


onFullDisplay

protected final java.util.List<java.lang.Runnable> onFullDisplay
Actions to perform on full display.


onFullHide

protected final java.util.List<java.lang.Runnable> onFullHide
Actions to perform on full hide.

Constructor Detail

WebDynamicMenu

public WebDynamicMenu()
Constructs new dynamic menu.

Method Detail

getRadius

public int getRadius()

setRadius

public void setRadius(int radius)

getStartingAngle

public double getStartingAngle()

setStartingAngle

public void setStartingAngle(double startingAngle)

getAngleRange

public double getAngleRange()

setAngleRange

public void setAngleRange(double angleRange)

getStepProgress

public float getStepProgress()

setStepProgress

public void setStepProgress(float stepProgress)

getType

public DynamicMenuType getType()

setType

public void setType(DynamicMenuType type)

getHideType

public DynamicMenuType getHideType()

setHideType

public void setHideType(DynamicMenuType hideType)

isClockwise

public boolean isClockwise()

setClockwise

public void setClockwise(boolean clockwise)

getItems

public java.util.List<WebDynamicMenuItem> getItems()

addItem

public WebImage addItem(javax.swing.ImageIcon icon)

addItem

public WebImage addItem(javax.swing.ImageIcon icon,
                        java.awt.event.ActionListener action)

addItem

public WebImage addItem(WebDynamicMenuItem item)

getCurrentProgress

public float getCurrentProgress()

getAnimator

public WebTimer getAnimator()

isDisplaying

public boolean isDisplaying()

isHiding

public boolean isHiding()

getHidingCause

public int getHidingCause()
Returns index of menu item that caused menu to close.

Returns:
index of menu item that caused menu to close

showMenu

public void showMenu(java.awt.Component invoker,
                     java.awt.Point location)
Displays dynamic menu for the specified invoker location.

Parameters:
invoker - menu invoker
location - menu location

displayMenuWindow

protected void displayMenuWindow(java.awt.Component invoker,
                                 java.awt.Point location)
Creates new menu window.

Parameters:
invoker - menu invoker
location - menu location

hidePopup

public WebHeavyWeightPopup hidePopup()

Overrides:
hidePopup in class WebHeavyWeightPopup

hideMenu

public void hideMenu()
Hides dynamic menu.


hideMenu

public void hideMenu(int index)
Hides dynamic menu.

Parameters:
index - menu item that forced menu to hide

destroyMenuWindow

protected void destroyMenuWindow()
Disposes old menu window.


onFullDisplay

public void onFullDisplay(java.lang.Runnable action)
Performs provided action when menu is fully displayed. Might be useful to display sub-menus or perform some other actions. Be aware that this action will be performed only once and then removed from the actions list.

Parameters:
action - action to perform

fullyDisplayed

public void fullyDisplayed()
Performs actions waiting for menu display animation finish.


onFullHide

public void onFullHide(java.lang.Runnable action)
Performs provided action when menu is fully hidden. Be aware that this action will be performed only once and then removed from the actions list.

Parameters:
action - action to perform

fullyHidden

public void fullyHidden()
Performs actions waiting for menu hide animation finish.


getItemAngle

public double getItemAngle(java.awt.Component item)
Returns menu item angle relative to vertical axis.

Parameters:
item - menu item
Returns:
menu item center point angle

getItemAngle

public double getItemAngle(int index)
Returns menu item angle relative to vertical axis.

Parameters:
index - menu item index
Returns:
menu item center point angle

getActualLayout

public DynamicMenuLayout getActualLayout()
Returns actual menu layout manager.

Returns:
actual menu layout manager

isAnyDynamicMenuDisplayed

public static boolean isAnyDynamicMenuDisplayed()
Returns whether any dynamic menu is currently displayed or not.

Returns:
true if any dynamic menu is currently displayed, false otherwise

hideAllDynamicMenus

public static void hideAllDynamicMenus()
Hides all visible dynamic menus.