Java Code Examples for javax.swing.JMenu#addMenuListener()

The following examples show how to use javax.swing.JMenu#addMenuListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginsManager.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Report the concrete UI menu of all plugins
 *
 * @param menu a preallocated menu instance, or null
 * @return the populated menu entity
 */
public JMenu getMenu (JMenu menu)
{
    if (menu == null) {
        menu = new SeparableMenu();
    }

    for (Plugin plugin : plugins) {
        menu.add(new JMenuItem(new PluginAction(plugin)));
    }

    // Listener to modify attributes on-the-fly
    menu.addMenuListener(new MyMenuListener());

    this.menu = menu;

    return menu;
}
 
Example 2
Source File: PluginsManager.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Report the concrete UI menu of all plugins
 *
 * @param menu a preallocated menu instance, or null
 * @return the populated menu entity
 */
public JMenu getMenu (JMenu menu)
{
    if (menu == null) {
        menu = new SeparableMenu();
    }

    for (Plugin plugin : map.values()) {
        menu.add(new JMenuItem(new PluginAction(plugin)));
    }

    // Listener to modify attributes on-the-fly
    menu.addMenuListener(new MyMenuListener());

    this.menu = menu;

    return menu;
}
 
Example 3
Source File: FigureWidget.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void build(JPopupMenu menu, Figure figure, FigureWidget figureWidget, boolean successors, DiagramScene diagramScene) {
    Set<Figure> set = figure.getPredecessorSet();
    if (successors) {
        set = figure.getSuccessorSet();
    }

    boolean first = true;
    for (Figure f : set) {
        if (f == figure) {
            continue;
        }

        if (first) {
            first = false;
        } else {
            menu.addSeparator();
        }

        Action go = diagramScene.createGotoAction(f);
        menu.add(go);

        JMenu preds = new JMenu("Nodes Above");
        preds.addMenuListener(figureWidget.new NeighborMenuListener(preds, f, false));
        menu.add(preds);

        JMenu succs = new JMenu("Nodes Below");
        succs.addMenuListener(figureWidget.new NeighborMenuListener(succs, f, true));
        menu.add(succs);
    }

    if (figure.getPredecessorSet().isEmpty() && figure.getSuccessorSet().isEmpty()) {
        menu.add("(none)");
    }
}
 
Example 4
Source File: NameSet.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Feed a menu with the dynamic content of this NameSet.
 *
 * @param menu         the menu to be fed, if null it is allocated by this method
 * @param itemListener the listener to be called on item selection
 * @return the menu properly dynamized
 */
public JMenu feedMenu (JMenu menu,
                       final ActionListener itemListener)
{
    final JMenu finalMenu = (menu != null) ? menu : new JMenu(setName);

    MenuListener menuListener = new AbstractMenuListener()
    {
        @Override
        public void menuSelected (MenuEvent e)
        {
            // Clean up the whole menu
            finalMenu.removeAll();

            // Rebuild the whole list of menu items on the fly
            synchronized (NameSet.this) {
                for (String f : names) {
                    JMenuItem menuItem = new JMenuItem(f);
                    menuItem.addActionListener(itemListener);
                    finalMenu.add(menuItem);
                }
            }
        }
    };

    // Listener to menu selection, to modify content on-the-fly
    finalMenu.addMenuListener(menuListener);

    return finalMenu;
}
 
Example 5
Source File: DynamicMenu.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create the dynamic menu.
 *
 * @param menuLabel the label to be used for the menu
 */
public DynamicMenu (String menuLabel)
{
    menu = new JMenu(menuLabel);

    // Listener to menu selection, to modify content on-the-fly
    menu.addMenuListener(listener);
}
 
Example 6
Source File: DynamicMenu.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new DynamicMenu object.
 *
 * @param action related action
 */
public DynamicMenu (Action action)
{
    menu = new JMenu(action);

    // Listener to menu selection, to modify content on-the-fly
    menu.addMenuListener(listener);
}
 
Example 7
Source File: AbstractMenuFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void attachToMenu (JMenu menu) {
    menu.addContainerListener(getMenuListener());
    menu.addComponentListener(getMenuListener());
    menu.addMenuListener(getMenuListener());
}
 
Example 8
Source File: DynamicMenuEnabler.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/** @param menu The {@link JMenu} to add. */
public static void add(JMenu menu) {
    menu.addMenuListener(INSTANCE);
}