org.scijava.menu
Class ShadowMenu

java.lang.Object
  extended by org.scijava.AbstractContextual
      extended by org.scijava.menu.ShadowMenu
All Implemented Interfaces:
Comparable<ShadowMenu>, Iterable<ModuleInfo>, Runnable, Collection<ModuleInfo>, Contextual

public class ShadowMenu
extends AbstractContextual
implements Comparable<ShadowMenu>, Collection<ModuleInfo>, Runnable

A tree representing a menu structure independent of any particular user interface.

A ShadowMenu is a tree node with links to other tree nodes. It is possible to traverse the entire menu structure from any given node, though by convention the root node is used to represent the menu as a whole.

The class is implemented as a Collection of modules (i.e., ModuleInfo objects), with the tree structure generated from the modules' menu paths (see UIDetails.getMenuPath()). The class also implements Runnable, with each leaf node retaining a link to its corresponding ModuleInfo, and executing that module when run() is called.

Author:
Curtis Rueden
See Also:
MenuCreator, MenuPath, MenuEntry

Constructor Summary
ShadowMenu(Context context, Collection<? extends ModuleInfo> modules)
          Constructs a root menu node populated with the given modules.
 
Method Summary
 boolean add(ModuleInfo o)
          Adds the given module to the menu structure.
 boolean addAll(Collection<? extends ModuleInfo> c)
          Adds the given modules to the menu structure.
 void clear()
           
 int compareTo(ShadowMenu c)
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 List<ShadowMenu> getChildren()
          Gets this node's children, sorted by weight.
 URL getIconURL()
          Gets the URL of the icon associated with this node's MenuEntry.
 ShadowMenu getMenu(MenuPath menuPath)
          Gets the node with the given menu path (relative to this node), or null if no such menu node.
 ShadowMenu getMenu(String path)
           
 int getMenuDepth()
          Gets how deep into the menu structure this node is.
 MenuEntry getMenuEntry()
          Gets the menu entry corresponding to this node.
 ModuleInfo getModuleInfo()
          Gets the module linked to this node, or null if node is not a leaf.
 String getName()
          Gets the name of the menu.
 ShadowMenu getParent()
          Gets this node's parent, or null if it is a root node.
 boolean isCheckBox()
          Returns true if this node is a checkbox.
 boolean isEmpty()
           
 boolean isLeaf()
          Returns true if this node has no children.
 boolean isRadioButton()
          Returns true if this node is a radio button.
 boolean isToggle()
          Returns true if this node is selectable (checkbox or radio button).
 ShadowMenuIterator iterator()
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 void run()
          Executes the module linked to this node.
 int size()
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 String toString()
           
 boolean update(ModuleInfo module)
          Updates the menu structure to reflect changes in the given module.
 boolean updateAll(Collection<? extends ModuleInfo> c)
          Updates the menu structure to reflect changes in the given modules.
 
Methods inherited from class org.scijava.AbstractContextual
context, getContext, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

ShadowMenu

public ShadowMenu(Context context,
                  Collection<? extends ModuleInfo> modules)
Constructs a root menu node populated with the given modules.

Method Detail

getModuleInfo

public ModuleInfo getModuleInfo()
Gets the module linked to this node, or null if node is not a leaf.


getMenu

public ShadowMenu getMenu(MenuPath menuPath)
Gets the node with the given menu path (relative to this node), or null if no such menu node.

For example, asking for "File > New > Image..." from the root application menu node would retrieve the node for "Image...", as would asking for "New > Image..." from the "File" node.


getMenu

public ShadowMenu getMenu(String path)

getMenuEntry

public MenuEntry getMenuEntry()
Gets the menu entry corresponding to this node. May be a non-leaf menu (e.g., "File") or a leaf item (e.g., "Exit").


getMenuDepth

public int getMenuDepth()
Gets how deep into the menu structure this node is. For example, "File" would be at depth 1, whereas "Exit" (of "File>Exit") would be at depth 2.


getName

public String getName()
Gets the name of the menu.


getParent

public ShadowMenu getParent()
Gets this node's parent, or null if it is a root node.


getChildren

public List<ShadowMenu> getChildren()
Gets this node's children, sorted by weight.


isLeaf

public boolean isLeaf()
Returns true if this node has no children.


isToggle

public boolean isToggle()
Returns true if this node is selectable (checkbox or radio button).


isCheckBox

public boolean isCheckBox()
Returns true if this node is a checkbox.


isRadioButton

public boolean isRadioButton()
Returns true if this node is a radio button.


getIconURL

public URL getIconURL()
Gets the URL of the icon associated with this node's MenuEntry.

See Also:
PluginInfo.getIconURL()

update

public boolean update(ModuleInfo module)
Updates the menu structure to reflect changes in the given module. Does nothing unless the module is already in the menu structure.

Returns:
true if the module was successfully updated

updateAll

public boolean updateAll(Collection<? extends ModuleInfo> c)
Updates the menu structure to reflect changes in the given modules. Does nothing unless at least one of the modules is already in the menu structure.

Returns:
true if at least one module was successfully updated

compareTo

public int compareTo(ShadowMenu c)
Specified by:
compareTo in interface Comparable<ShadowMenu>

toString

public String toString()
Overrides:
toString in class Object

run

public void run()
Executes the module linked to this node. Does nothing for non-leaf nodes.

Specified by:
run in interface Runnable

add

public boolean add(ModuleInfo o)
Adds the given module to the menu structure. If the module is not visible (i.e., UIDetails.isVisible() returns false), it is ignored.

Specified by:
add in interface Collection<ModuleInfo>

addAll

public boolean addAll(Collection<? extends ModuleInfo> c)
Adds the given modules to the menu structure. If a module is not visible (i.e., UIDetails.isVisible() returns false), it is ignored.

Specified by:
addAll in interface Collection<ModuleInfo>

clear

public void clear()
Specified by:
clear in interface Collection<ModuleInfo>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<ModuleInfo>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<ModuleInfo>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<ModuleInfo>

iterator

public ShadowMenuIterator iterator()
Specified by:
iterator in interface Iterable<ModuleInfo>
Specified by:
iterator in interface Collection<ModuleInfo>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<ModuleInfo>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<ModuleInfo>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<ModuleInfo>

size

public int size()
Specified by:
size in interface Collection<ModuleInfo>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<ModuleInfo>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<ModuleInfo>


Copyright © 2009–2014 SciJava. All rights reserved.