public class JMenuMerge extends AbstractMenuMerge
Represents a menu merge for a JMenu. This may be a top-level menu (like "file") or a sub-menu. That is, a JMenuMerge can contain a mix of other JMenuMerge children and individual item merges. This class has convenience functions that allow for easily adding menu items based on StateChangeActions and JMenuItems.
To create JMenuMerges that merge items into the main menus, use the constants found in WellKnownMenuConstants
. For example, suppose a module wanted to add a menu item to the File > New menu. You would create a JMenuMerge
using the file menu's name, and add it at the file menu's location. You would create the following MenuBarMerge and
return it from your Designer module hook's DesignerModuleHook.getModuleMenu()
function.
Action myNewAction = new AbstractAction("New Thingamajig") { public void actionPerformed(ActionEvent ae) { System.out.println("Do something here..."); } }; MenuBarMerge menu = new MenuBarMerge("mymodule-id"); JMenuMerge file = new JMenuMerge(WellKnownMenuConstants.FILE_MENU_NAME); JMenuMerge fileNew = new JMenuMerge("new"); fileNew.add(myNewAction); file.add(WellKnownMenuConstants.FILE_OPENSAVE_GROUP, fileNew); menu.add(WellKnownMenuConstants.FILE_MENU_LOCATION, file);
currentImplicitGroup, displayKey, groups, icon, log, menuId, name
Constructor and Description |
---|
JMenuMerge(java.lang.String name) |
JMenuMerge(java.lang.String name,
java.lang.String displayKey) |
JMenuMerge(java.lang.String name,
java.lang.String displayKey,
javax.swing.Icon icon) |
Modifier and Type | Method and Description |
---|---|
void |
add(int separatorGroup,
javax.swing.JMenu menu)
Used to add opaque (non-mergable) menus
|
void |
add(int separatorGroup,
javax.swing.JMenuItem menuItem) |
void |
add(javax.swing.JMenu menu)
Used to add opaque (non-mergable) menus
|
void |
add(javax.swing.JMenuItem menuItem) |
void |
addCheckBox(int separatorGroup,
StateChangeAction action) |
void |
addCheckBox(StateChangeAction action) |
void |
addRadioGroup(int separatorGroup,
StateChangeAction... actions) |
void |
addRadioGroup(StateChangeAction... actions) |
protected void |
addSeparator(javax.swing.JComponent menu)
Subclasses must define how "separator" components get added to the parent menu item.
|
javax.swing.JMenu |
createMenu()
Create the parent menu item represented by this object, that all of its children should be contained in.
|
javax.swing.JComponent |
install(javax.swing.JComponent _menu)
Merges this model into the menu.
|
void |
uninstall(javax.swing.JComponent _menu)
Reverses the merge of this model into the given menu
|
add, add, add, add, addSeparator, getMenuId, getName, iterate, setMenuId
public JMenuMerge(java.lang.String name)
public JMenuMerge(java.lang.String name, java.lang.String displayKey)
public JMenuMerge(java.lang.String name, java.lang.String displayKey, javax.swing.Icon icon)
public void addCheckBox(StateChangeAction action)
public void addRadioGroup(StateChangeAction... actions)
public void add(javax.swing.JMenuItem menuItem)
public void add(javax.swing.JMenu menu)
public void addCheckBox(int separatorGroup, StateChangeAction action)
public void addRadioGroup(int separatorGroup, StateChangeAction... actions)
public void add(int separatorGroup, javax.swing.JMenuItem menuItem)
public void add(int separatorGroup, javax.swing.JMenu menu)
public javax.swing.JComponent install(javax.swing.JComponent _menu)
IMenuMergeModel
install
in interface IMenuMergeModel
install
in class AbstractMenuMerge
public void uninstall(javax.swing.JComponent _menu)
IMenuMergeModel
uninstall
in interface IMenuMergeModel
uninstall
in class AbstractMenuMerge
public javax.swing.JMenu createMenu()
AbstractMenuMerge
createMenu
in class AbstractMenuMerge
protected void addSeparator(javax.swing.JComponent menu)
AbstractMenuMerge
addSeparator
in class AbstractMenuMerge