Java 类javax.swing.event.MenuListener 实例源码

项目:cn1    文件:JMenuTest.java   
public void testAddGetRemoveMenuListener() {
    MenuListener listener1 = new ConcreteMenuListener();
    MenuListener listener2 = new ConcreteMenuListener();
    MenuListener listener3 = new ConcreteMenuListener();
    EventListener[] listenersArray = null;
    listenersArray = menu.getMenuListeners();
    int initialValue = listenersArray.length;
    menu.addMenuListener(listener1);
    menu.addMenuListener(listener2);
    menu.addMenuListener(listener2);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 3, listenersArray.length);
    menu.removeMenuListener(listener1);
    menu.addMenuListener(listener3);
    menu.addMenuListener(listener3);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 4, listenersArray.length);
    menu.removeMenuListener(listener3);
    menu.removeMenuListener(listener3);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 2, listenersArray.length);
    menu.removeMenuListener(listener2);
    menu.removeMenuListener(listener2);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue, listenersArray.length);
}
项目:freeVM    文件:JMenuTest.java   
public void testAddGetRemoveMenuListener() {
    MenuListener listener1 = new ConcreteMenuListener();
    MenuListener listener2 = new ConcreteMenuListener();
    MenuListener listener3 = new ConcreteMenuListener();
    EventListener[] listenersArray = null;
    listenersArray = menu.getMenuListeners();
    int initialValue = listenersArray.length;
    menu.addMenuListener(listener1);
    menu.addMenuListener(listener2);
    menu.addMenuListener(listener2);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 3, listenersArray.length);
    menu.removeMenuListener(listener1);
    menu.addMenuListener(listener3);
    menu.addMenuListener(listener3);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 4, listenersArray.length);
    menu.removeMenuListener(listener3);
    menu.removeMenuListener(listener3);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 2, listenersArray.length);
    menu.removeMenuListener(listener2);
    menu.removeMenuListener(listener2);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue, listenersArray.length);
}
项目:freeVM    文件:JMenuTest.java   
public void testAddGetRemoveMenuListener() {
    MenuListener listener1 = new ConcreteMenuListener();
    MenuListener listener2 = new ConcreteMenuListener();
    MenuListener listener3 = new ConcreteMenuListener();
    EventListener[] listenersArray = null;
    listenersArray = menu.getMenuListeners();
    int initialValue = listenersArray.length;
    menu.addMenuListener(listener1);
    menu.addMenuListener(listener2);
    menu.addMenuListener(listener2);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 3, listenersArray.length);
    menu.removeMenuListener(listener1);
    menu.addMenuListener(listener3);
    menu.addMenuListener(listener3);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 4, listenersArray.length);
    menu.removeMenuListener(listener3);
    menu.removeMenuListener(listener3);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 2, listenersArray.length);
    menu.removeMenuListener(listener2);
    menu.removeMenuListener(listener2);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue, listenersArray.length);
}
项目:jaer    文件:BiasgenFrame.java   
@Override
public void dispose() {
    MenuListener[] listeners = PotGUIControl.viewMenu.getMenuListeners();
    for (MenuListener listener : listeners) {
        PotGUIControl.viewMenu.removeMenuListener(listener);
    }
    super.dispose();
}
项目:jdk8u-jdk    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:openjdk-jdk10    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:openjdk-jdk10    文件:JMenuOperator.java   
/**
 * Maps {@code JMenu.addMenuListener(MenuListener)} through queue
 */
public void addMenuListener(final MenuListener menuListener) {
    runMapping(new MapVoidAction("addMenuListener") {
        @Override
        public void map() {
            ((JMenu) getSource()).addMenuListener(menuListener);
        }
    });
}
项目:openjdk-jdk10    文件:JMenuOperator.java   
/**
 * Maps {@code JMenu.removeMenuListener(MenuListener)} through queue
 */
public void removeMenuListener(final MenuListener menuListener) {
    runMapping(new MapVoidAction("removeMenuListener") {
        @Override
        public void map() {
            ((JMenu) getSource()).removeMenuListener(menuListener);
        }
    });
}
项目:openjdk9    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:openjdk9    文件:JMenuOperator.java   
/**
 * Maps {@code JMenu.addMenuListener(MenuListener)} through queue
 */
public void addMenuListener(final MenuListener menuListener) {
    runMapping(new MapVoidAction("addMenuListener") {
        @Override
        public void map() {
            ((JMenu) getSource()).addMenuListener(menuListener);
        }
    });
}
项目:openjdk9    文件:JMenuOperator.java   
/**
 * Maps {@code JMenu.removeMenuListener(MenuListener)} through queue
 */
public void removeMenuListener(final MenuListener menuListener) {
    runMapping(new MapVoidAction("removeMenuListener") {
        @Override
        public void map() {
            ((JMenu) getSource()).removeMenuListener(menuListener);
        }
    });
}
项目:audiveris    文件:NameSet.java   
/**
 * 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;
}
项目:jdk8u_jdk    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:lookaside_java-1.8.0-openjdk    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:javify    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was selected.
 */
protected void fireMenuSelected()
{
  MenuListener[] listeners = getMenuListeners();

  for (int index = 0; index < listeners.length; ++index)
    listeners[index].menuSelected(menuEvent);
}
项目:javify    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuDeselected() method of MenuListeners is called to indicated that the menu
 * was deselected.
 */
protected void fireMenuDeselected()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuDeselected(menuEvent);
}
项目:javify    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was cancelled. The menu is cancelled when it's popup menu is close without selection.
 */
protected void fireMenuCanceled()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuCanceled(menuEvent);
}
项目:jvm-stm    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was selected.
 */
protected void fireMenuSelected()
{
  MenuListener[] listeners = getMenuListeners();

  for (int index = 0; index < listeners.length; ++index)
    listeners[index].menuSelected(menuEvent);
}
项目:jvm-stm    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuDeselected() method of MenuListeners is called to indicated that the menu
 * was deselected.
 */
protected void fireMenuDeselected()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuDeselected(menuEvent);
}
项目:jvm-stm    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was cancelled. The menu is cancelled when it's popup menu is close without selection.
 */
protected void fireMenuCanceled()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuCanceled(menuEvent);
}
项目:infobip-open-jdk-8    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:jdk8u-dev-jdk    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:flower-platform-arduino-ide-plugin    文件:SetOptionsCommand.java   
public Object run() {
    Editor editor = FlowerPlatformPlugin.getInstance().getEditor();
    JMenuBar menuBar = editor.getJMenuBar();
    JMenu toolsMenu = menuBar.getMenu(3);
    toolsMenu.getListeners(MenuListener.class)[0].menuSelected(null);
    toolsMenu.getListeners(MenuListener.class)[1].menuSelected(null);

    // set menu options
    for (Component c : toolsMenu.getMenuComponents()) {
        if ((c instanceof JMenu) && c.isVisible()) {
            JMenu menu = (JMenu) c;
            String option = menu.getText();
            if (option == null) {
                continue;
            }
            int index = option.indexOf(':');
            if (index > 0) {
                option = option.substring(0, index);
            }
            String newValue = options.get(option);
            for (int i = 0; i < menu.getItemCount(); i++) {
                JMenuItem item = menu.getItem(i);
                if (item != null && item.isVisible() && item.getText().equals(newValue)) {
                    item.setSelected(true);
                }
            }
        }
    }


    return null;
}
项目:flower-platform-arduino-ide-plugin    文件:GetBoardsCommand.java   
public Object run() {
        Editor editor = FlowerPlatformPlugin.getInstance().getEditor();
        JMenuBar menuBar = editor.getJMenuBar();
        JMenu toolsMenu = menuBar.getMenu(3);
        toolsMenu.getListeners(MenuListener.class)[0].menuSelected(null);

        JMenu boardsMenu = null;
        for (Component c : toolsMenu.getMenuComponents()) {
            if (!(c instanceof JMenu) || !c.isVisible()) {
                continue;
            }
            JMenu menu = (JMenu) c;
            if (menu.getText().startsWith("Board")) {
                boardsMenu = menu;
                break;
            }
        }
        List<String> boards = new ArrayList<>();
        // start from 1 (skip first entry - "Boards manager")
        for (int i = 1; i < boardsMenu.getItemCount(); i++) {
            JMenuItem item = boardsMenu.getItem(i);
            if (item != null && item.isEnabled()) {
//              System.out.println(item.getText());
                boards.add(item.getText());
            }
        }

        return boards;
    }
项目:OLD-OpenJDK8    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:freemind_1.0.0_20140624_214725    文件:FreeMindPopupMenu.java   
protected void firePopupMenuWillBecomeVisible() {
    super.firePopupMenuWillBecomeVisible();
    logger.fine("Popup firePopupMenuWillBecomeVisible called.");
    for (Iterator i = listeners.iterator(); i.hasNext();) {
        MenuListener listener = (MenuListener) i.next();
        listener.menuSelected(null);
    }
}
项目:freemind_1.0.0_20140624_214725    文件:FreeMindPopupMenu.java   
protected void firePopupMenuCanceled() {
    super.firePopupMenuCanceled();
    // logger.info("Popup firePopupMenuCanceled called.");
    for (Iterator i = listeners.iterator(); i.hasNext();) {
        MenuListener listener = (MenuListener) i.next();
        listener.menuCanceled(null);
    }
}
项目:freemind_1.0.0_20140624_214725    文件:FreeMindPopupMenu.java   
protected void firePopupMenuWillBecomeInvisible() {
    super.firePopupMenuWillBecomeInvisible();
    // logger.info("Popup firePopupMenuWillBecomeInvisible called.");
    for (Iterator i = listeners.iterator(); i.hasNext();) {
        MenuListener listener = (MenuListener) i.next();
        listener.menuDeselected(null);
    }
}
项目:JamVM-PH    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was selected.
 */
protected void fireMenuSelected()
{
  MenuListener[] listeners = getMenuListeners();

  for (int index = 0; index < listeners.length; ++index)
    listeners[index].menuSelected(menuEvent);
}
项目:JamVM-PH    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuDeselected() method of MenuListeners is called to indicated that the menu
 * was deselected.
 */
protected void fireMenuDeselected()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuDeselected(menuEvent);
}
项目:JamVM-PH    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was cancelled. The menu is cancelled when it's popup menu is close without selection.
 */
protected void fireMenuCanceled()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuCanceled(menuEvent);
}
项目:openjdk-jdk7u-jdk    文件:bug4983388.java   
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
项目:classpath    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was selected.
 */
protected void fireMenuSelected()
{
  MenuListener[] listeners = getMenuListeners();

  for (int index = 0; index < listeners.length; ++index)
    listeners[index].menuSelected(menuEvent);
}
项目:classpath    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuDeselected() method of MenuListeners is called to indicated that the menu
 * was deselected.
 */
protected void fireMenuDeselected()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuDeselected(menuEvent);
}
项目:classpath    文件:JMenu.java   
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was cancelled. The menu is cancelled when it's popup menu is close without selection.
 */
protected void fireMenuCanceled()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuCanceled(menuEvent);
}
项目:freeVM    文件:JMenu.java   
protected void fireMenuCanceled() {
    final MenuListener[] listeners = getMenuListeners();
    if (listeners.length == 0) {
        return;
    }
    if (menuEvent == null) {
        menuEvent = new MenuEvent(this);
    }
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].menuCanceled(menuEvent);
    }
}
项目:freeVM    文件:JMenu.java   
protected void fireMenuDeselected() {
    final MenuListener[] listeners = getMenuListeners();
    if (listeners.length == 0) {
        return;
    }
    if (menuEvent == null) {
        menuEvent = new MenuEvent(this);
    }
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].menuDeselected(menuEvent);
    }
}
项目:freeVM    文件:JMenu.java   
protected void fireMenuSelected() {
    final MenuListener[] listeners = getMenuListeners();
    if (listeners.length == 0) {
        return;
    }
    if (menuEvent == null) {
        menuEvent = new MenuEvent(this);
    }
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].menuSelected(menuEvent);
    }
}
项目:freeVM    文件:JMenu.java   
protected void fireMenuCanceled() {
    final MenuListener[] listeners = getMenuListeners();
    if (listeners.length == 0) {
        return;
    }
    if (menuEvent == null) {
        menuEvent = new MenuEvent(this);
    }
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].menuCanceled(menuEvent);
    }
}
项目:freeVM    文件:JMenu.java   
protected void fireMenuDeselected() {
    final MenuListener[] listeners = getMenuListeners();
    if (listeners.length == 0) {
        return;
    }
    if (menuEvent == null) {
        menuEvent = new MenuEvent(this);
    }
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].menuDeselected(menuEvent);
    }
}