Package org.scijava.menu
Class ShadowMenu
- java.lang.Object
-
- org.scijava.AbstractContextual
-
- org.scijava.menu.ShadowMenu
-
- All Implemented Interfaces:
Comparable<ShadowMenu>,Iterable<ModuleInfo>,Runnable,Collection<ModuleInfo>,Contextual,Named
public class ShadowMenu extends AbstractContextual implements Comparable<ShadowMenu>, Collection<ModuleInfo>, Runnable, Named
A tree representing a menu structure independent of any particular user interface.A
ShadowMenuis 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
Collectionof modules (i.e.,ModuleInfoobjects), with the tree structure generated from the modules' menu paths (seeUIDetails.getMenuPath()). The class also implementsRunnable, with each leaf node retaining a link to its correspondingModuleInfo, and executing that module whenrun()is called.- Author:
- Curtis Rueden
- See Also:
MenuCreator,MenuPath,MenuEntry
-
-
Constructor Summary
Constructors Constructor Description ShadowMenu(Context context, Collection<? extends ModuleInfo> modules)Constructs a root menu node populated with the given modules.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(ModuleInfo o)Adds the given module to the menu structure.booleanaddAll(Collection<? extends ModuleInfo> c)Adds the given modules to the menu structure.voidclear()intcompareTo(ShadowMenu c)booleancontains(Object o)booleancontainsAll(Collection<?> c)List<ShadowMenu>getChildren()Gets this node's children, sorted by weight.URLgetIconURL()Gets the URL of the icon associated with this node'sMenuEntry.ShadowMenugetMenu(String path)ShadowMenugetMenu(MenuPath menuPath)Gets the node with the given menu path (relative to this node), or null if no such menu node.intgetMenuDepth()Gets how deep into the menu structure this node is.MenuEntrygetMenuEntry()Gets the menu entry corresponding to this node.ModuleInfogetModuleInfo()Gets the module linked to this node, or null if node is not a leaf.StringgetName()Gets the name of the object.ShadowMenugetParent()Gets this node's parent, or null if it is a root node.booleanisCheckBox()Returns true if this node is a checkbox.booleanisEmpty()booleanisLeaf()Returns true if this node has no children.booleanisRadioButton()Returns true if this node is a radio button.booleanisToggle()Returns true if this node is selectable (checkbox or radio button).ShadowMenuIteratoriterator()booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)voidrun()Executes the module linked to this node.voidsetName(String name)Sets the name of the object.intsize()Object[]toArray()<T> T[]toArray(T[] a)StringtoString()booleanupdate(ModuleInfo module)Updates the menu structure to reflect changes in the given module.booleanupdateAll(Collection<? extends ModuleInfo> c)Updates the menu structure to reflect changes in the given modules.-
Methods inherited from class org.scijava.AbstractContextual
context, getContext
-
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, parallelStream, removeIf, spliterator, stream
-
Methods inherited from interface org.scijava.Contextual
setContext
-
-
-
-
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.
-
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'sMenuEntry.- 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
-
getName
public String getName()
Description copied from interface:NamedGets the name of the object.
-
setName
public void setName(String name)
Description copied from interface:NamedSets the name of the object.
-
compareTo
public int compareTo(ShadowMenu c)
- Specified by:
compareToin interfaceComparable<ShadowMenu>
-
run
public void run()
Executes the module linked to this node. Does nothing for non-leaf nodes.
-
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:
addin interfaceCollection<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:
addAllin interfaceCollection<ModuleInfo>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<ModuleInfo>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<ModuleInfo>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<ModuleInfo>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<ModuleInfo>
-
iterator
public ShadowMenuIterator iterator()
- Specified by:
iteratorin interfaceCollection<ModuleInfo>- Specified by:
iteratorin interfaceIterable<ModuleInfo>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<ModuleInfo>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<ModuleInfo>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<ModuleInfo>
-
size
public int size()
- Specified by:
sizein interfaceCollection<ModuleInfo>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<ModuleInfo>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfaceCollection<ModuleInfo>
-
-