Example usage for javax.swing JMenuItem removeActionListener

List of usage examples for javax.swing JMenuItem removeActionListener

Introduction

In this page you can find the example usage for javax.swing JMenuItem removeActionListener.

Prototype

public void removeActionListener(ActionListener l) 

Source Link

Document

Removes an ActionListener from the button.

Usage

From source file:javazoom.jlgui.player.amp.equalizer.ui.EqualizerUI.java

public void loadUI() {
    log.info("Load EqualizerUI (EDT=" + SwingUtilities.isEventDispatchThread() + ")");
    removeAll();/*from w  w  w. ja v  a  2s  .  c o m*/
    // Background
    ImageBorder border = new ImageBorder();
    border.setImage(ui.getEqualizerImage());
    setBorder(border);
    // On/Off
    add(ui.getAcEqOnOff(), ui.getAcEqOnOff().getConstraints());
    ui.getAcEqOnOff().removeActionListener(this);
    ui.getAcEqOnOff().addActionListener(this);
    // Auto
    add(ui.getAcEqAuto(), ui.getAcEqAuto().getConstraints());
    ui.getAcEqAuto().removeActionListener(this);
    ui.getAcEqAuto().addActionListener(this);
    // Sliders
    add(ui.getAcEqPresets(), ui.getAcEqPresets().getConstraints());
    for (int i = 0; i < ui.getAcEqSliders().length; i++) {
        add(ui.getAcEqSliders()[i], ui.getAcEqSliders()[i].getConstraints());
        ui.getAcEqSliders()[i].setValue(maxGain - gainValue[i]);
        ui.getAcEqSliders()[i].removeChangeListener(this);
        ui.getAcEqSliders()[i].addChangeListener(this);
    }
    if (ui.getSpline() != null) {
        ui.getSpline().setValues(gainValue);
        add(ui.getSpline(), ui.getSpline().getConstraints());
    }
    // Popup menu on TitleBar
    mainpopup = new JPopupMenu();
    String[] presets = { "Normal", "Classical", "Club", "Dance", "Full Bass", "Full Bass & Treble",
            "Full Treble", "Laptop", "Live", "Party", "Pop", "Reggae", "Rock", "Techno" };
    JMenuItem mi;
    for (int p = 0; p < presets.length; p++) {
        mi = new JMenuItem(presets[p]);
        mi.removeActionListener(this);
        mi.addActionListener(this);
        mainpopup.add(mi);
    }
    ui.getAcEqPresets().removeActionListener(this);
    ui.getAcEqPresets().addActionListener(this);
    validate();
}

From source file:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java

public void loadUI() {
    removeAll();/*w w w. j  a va  2  s .c  o  m*/
    ui.getPlaylistPanel().setParent(this);
    add(ui.getAcPlSlider(), ui.getAcPlSlider().getConstraints());
    ui.getAcPlSlider().setValue(100);
    ui.getAcPlSlider().removeChangeListener(this);
    ui.getAcPlSlider().addChangeListener(this);
    add(ui.getAcPlUp(), ui.getAcPlUp().getConstraints());
    ui.getAcPlUp().removeActionListener(this);
    ui.getAcPlUp().addActionListener(this);
    add(ui.getAcPlDown(), ui.getAcPlDown().getConstraints());
    ui.getAcPlDown().removeActionListener(this);
    ui.getAcPlDown().addActionListener(this);
    // Add menu
    add(ui.getAcPlAdd(), ui.getAcPlAdd().getConstraints());
    ui.getAcPlAdd().removeActionListener(this);
    ui.getAcPlAdd().addActionListener(this);
    add(ui.getAcPlAddPopup(), ui.getAcPlAddPopup().getConstraints());
    ui.getAcPlAddPopup().setVisible(false);
    ActiveJButton[] items = ui.getAcPlAddPopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].addActionListener(this);
    }
    // Remove menu
    add(ui.getAcPlRemove(), ui.getAcPlRemove().getConstraints());
    ui.getAcPlRemove().removeActionListener(this);
    ui.getAcPlRemove().addActionListener(this);
    add(ui.getAcPlRemovePopup(), ui.getAcPlRemovePopup().getConstraints());
    ui.getAcPlRemovePopup().setVisible(false);
    items = ui.getAcPlRemovePopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].removeActionListener(this);
        items[i].addActionListener(this);
    }
    // Select menu
    add(ui.getAcPlSelect(), ui.getAcPlSelect().getConstraints());
    ui.getAcPlSelect().removeActionListener(this);
    ui.getAcPlSelect().addActionListener(this);
    add(ui.getAcPlSelectPopup(), ui.getAcPlSelectPopup().getConstraints());
    ui.getAcPlSelectPopup().setVisible(false);
    items = ui.getAcPlSelectPopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].removeActionListener(this);
        items[i].addActionListener(this);
    }
    // Misc menu
    add(ui.getAcPlMisc(), ui.getAcPlMisc().getConstraints());
    ui.getAcPlMisc().removeActionListener(this);
    ui.getAcPlMisc().addActionListener(this);
    add(ui.getAcPlMiscPopup(), ui.getAcPlMiscPopup().getConstraints());
    ui.getAcPlMiscPopup().setVisible(false);
    items = ui.getAcPlMiscPopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].removeActionListener(this);
        items[i].addActionListener(this);
    }
    // List menu
    add(ui.getAcPlList(), ui.getAcPlList().getConstraints());
    ui.getAcPlList().removeActionListener(this);
    ui.getAcPlList().addActionListener(this);
    add(ui.getAcPlListPopup(), ui.getAcPlListPopup().getConstraints());
    ui.getAcPlListPopup().setVisible(false);
    items = ui.getAcPlListPopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].removeActionListener(this);
        items[i].addActionListener(this);
    }
    // Popup menu
    fipopup = new JPopupMenu();
    JMenuItem mi = new JMenuItem(ui.getResource("playlist.popup.info"));
    mi.setActionCommand(PlayerActionEvent.ACPLINFO);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    fipopup.add(mi);
    fipopup.addSeparator();
    mi = new JMenuItem(ui.getResource("playlist.popup.play"));
    mi.setActionCommand(PlayerActionEvent.ACPLPLAY);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    fipopup.add(mi);
    fipopup.addSeparator();
    mi = new JMenuItem(ui.getResource("playlist.popup.remove"));
    mi.setActionCommand(PlayerActionEvent.ACPLREMOVE);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    fipopup.add(mi);
    validate();
    repaint();
}

From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java

/**
 * Re maps help links for a couple items on iReport Help menu
 *///w ww . j  a  v  a2  s  .  c  o m
public void fixUpHelpLinks() {
    int helpMenuIdx = 9;
    int homePageItemIdx = 0;
    int helpItemIdx = 1;
    final String jasperHomePage = "http://jasperforge.org/";

    JMenuBar mb = getJMenuBar();
    JMenu hm = mb.getMenu(helpMenuIdx);
    homePageItem = hm.getItem(homePageItemIdx);
    //remove original listener linked to bad url
    ActionListener[] als = homePageItem.getActionListeners();
    for (int l = 0; l < als.length; l++) {
        homePageItem.removeActionListener(als[l]);
    }
    //add new listener
    homePageItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            openUrl(jasperHomePage);
        }

    });

    JMenuItem helpPageItem = hm.getItem(helpItemIdx);
    als = helpPageItem.getActionListeners();
    //remove original listener linked to bad url
    for (int l = 0; l < als.length; l++) {
        helpPageItem.removeActionListener(als[l]);
    }
    HelpMgr.registerComponent(helpPageItem, "iReport");

    setIconImage(IconManager.getIcon("SPIReports", IconManager.IconSize.NonStd).getImage());

}

From source file:javazoom.jlgui.player.amp.PlayerUI.java

public void loadSkin() {
    log.info("Load PlayerUI (EDT=" + SwingUtilities.isEventDispatchThread() + ")");
    removeAll();//from  w w w .  j av  a 2 s .c o m
    // Load skin specified in args
    if (ui.getPath() != null) {
        log.info("Load default skin from " + ui.getPath());
        ui.loadSkin(ui.getPath());
        config.setDefaultSkin(ui.getPath());
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        ui.loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        ClassLoader cl = getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        ui.loadSkin(sis);
    }
    // Background
    ImageBorder border = new ImageBorder();
    border.setImage(ui.getMainImage());
    setBorder(border);
    // Buttons        
    add(ui.getAcPrevious(), ui.getAcPrevious().getConstraints());
    ui.getAcPrevious().removeActionListener(this);
    ui.getAcPrevious().addActionListener(this);
    add(ui.getAcPlay(), ui.getAcPlay().getConstraints());
    ui.getAcPlay().removeActionListener(this);
    ui.getAcPlay().addActionListener(this);
    add(ui.getAcPause(), ui.getAcPause().getConstraints());
    ui.getAcPause().removeActionListener(this);
    ui.getAcPause().addActionListener(this);
    add(ui.getAcStop(), ui.getAcStop().getConstraints());
    ui.getAcStop().removeActionListener(this);
    ui.getAcStop().addActionListener(this);
    add(ui.getAcNext(), ui.getAcNext().getConstraints());
    ui.getAcNext().removeActionListener(this);
    ui.getAcNext().addActionListener(this);
    add(ui.getAcEject(), ui.getAcEject().getConstraints());
    ui.getAcEject().removeActionListener(this);
    ui.getAcEject().addActionListener(this);
    // EqualizerUI toggle
    add(ui.getAcEqualizer(), ui.getAcEqualizer().getConstraints());
    ui.getAcEqualizer().removeActionListener(this);
    ui.getAcEqualizer().addActionListener(this);
    // Playlist toggle
    add(ui.getAcPlaylist(), ui.getAcPlaylist().getConstraints());
    ui.getAcPlaylist().removeActionListener(this);
    ui.getAcPlaylist().addActionListener(this);
    // Shuffle toggle
    add(ui.getAcShuffle(), ui.getAcShuffle().getConstraints());
    ui.getAcShuffle().removeActionListener(this);
    ui.getAcShuffle().addActionListener(this);
    // Repeat toggle
    add(ui.getAcRepeat(), ui.getAcRepeat().getConstraints());
    ui.getAcRepeat().removeActionListener(this);
    ui.getAcRepeat().addActionListener(this);
    // Volume
    add(ui.getAcVolume(), ui.getAcVolume().getConstraints());
    ui.getAcVolume().removeChangeListener(this);
    ui.getAcVolume().addChangeListener(this);
    // Balance
    add(ui.getAcBalance(), ui.getAcBalance().getConstraints());
    ui.getAcBalance().removeChangeListener(this);
    ui.getAcBalance().addChangeListener(this);
    // Seek bar
    add(ui.getAcPosBar(), ui.getAcPosBar().getConstraints());
    ui.getAcPosBar().removeChangeListener(this);
    ui.getAcPosBar().addChangeListener(this);
    // Mono
    add(ui.getAcMonoIcon(), ui.getAcMonoIcon().getConstraints());
    // Stereo
    add(ui.getAcStereoIcon(), ui.getAcStereoIcon().getConstraints());
    // Title label
    add(ui.getAcTitleLabel(), ui.getAcTitleLabel().getConstraints());
    // Sample rate label
    add(ui.getAcSampleRateLabel(), ui.getAcSampleRateLabel().getConstraints());
    // Bit rate label
    add(ui.getAcBitRateLabel(), ui.getAcBitRateLabel().getConstraints());
    // Play icon
    add(ui.getAcPlayIcon(), ui.getAcPlayIcon().getConstraints());
    // Time icon
    add(ui.getAcTimeIcon(), ui.getAcTimeIcon().getConstraints());
    // MinuteH number
    add(ui.getAcMinuteH(), ui.getAcMinuteH().getConstraints());
    // MinuteL number
    add(ui.getAcMinuteL(), ui.getAcMinuteL().getConstraints());
    // SecondH number
    add(ui.getAcSecondH(), ui.getAcSecondH().getConstraints());
    // SecondL number
    add(ui.getAcSecondL(), ui.getAcSecondL().getConstraints());
    // TitleBar
    add(ui.getAcTitleBar(), ui.getAcTitleBar().getConstraints());
    add(ui.getAcMinimize(), ui.getAcMinimize().getConstraints());
    ui.getAcMinimize().removeActionListener(this);
    ui.getAcMinimize().addActionListener(this);
    add(ui.getAcExit(), ui.getAcExit().getConstraints());
    ui.getAcExit().removeActionListener(this);
    ui.getAcExit().addActionListener(this);
    // DSP
    if (ui.getAcAnalyzer() != null) {
        add(ui.getAcAnalyzer(), ui.getAcAnalyzer().getConstraints());
    }
    // Popup menu
    mainpopup = new JPopupMenu(ui.getResource("popup.title"));
    JMenuItem mi = new JMenuItem(Skin.TITLETEXT + "- JavaZOOM");
    //mi.removeActionListener(this);
    //mi.addActionListener(this);
    mainpopup.add(mi);
    mainpopup.addSeparator();
    JMenu playSubMenu = new JMenu(ui.getResource("popup.play"));
    miPlayFile = new JMenuItem(ui.getResource("popup.play.file"));
    miPlayFile.setActionCommand(PlayerActionEvent.MIPLAYFILE);
    miPlayFile.removeActionListener(this);
    miPlayFile.addActionListener(this);
    miPlayLocation = new JMenuItem(ui.getResource("popup.play.location"));
    miPlayLocation.setActionCommand(PlayerActionEvent.MIPLAYLOCATION);
    miPlayLocation.removeActionListener(this);
    miPlayLocation.addActionListener(this);
    playSubMenu.add(miPlayFile);
    playSubMenu.add(miPlayLocation);
    mainpopup.add(playSubMenu);
    mainpopup.addSeparator();
    miPlaylist = new JCheckBoxMenuItem(ui.getResource("popup.playlist"));
    miPlaylist.setActionCommand(PlayerActionEvent.MIPLAYLIST);
    if (config.isPlaylistEnabled())
        miPlaylist.setState(true);
    miPlaylist.removeActionListener(this);
    miPlaylist.addActionListener(this);
    mainpopup.add(miPlaylist);
    miEqualizer = new JCheckBoxMenuItem(ui.getResource("popup.equalizer"));
    miEqualizer.setActionCommand(PlayerActionEvent.MIEQUALIZER);
    if (config.isEqualizerEnabled())
        miEqualizer.setState(true);
    miEqualizer.removeActionListener(this);
    miEqualizer.addActionListener(this);
    mainpopup.add(miEqualizer);
    mainpopup.addSeparator();
    mi = new JMenuItem(ui.getResource("popup.preferences"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK, false));
    mi.setActionCommand(PlayerActionEvent.MIPREFERENCES);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    mainpopup.add(mi);
    JMenu skinsSubMenu = new JMenu(ui.getResource("popup.skins"));
    mi = new JMenuItem(ui.getResource("popup.skins.browser"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK, false));
    mi.setActionCommand(PlayerActionEvent.MISKINBROWSER);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    skinsSubMenu.add(mi);
    mi = new JMenuItem(ui.getResource("popup.skins.load"));
    mi.setActionCommand(PlayerActionEvent.MILOADSKIN);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    skinsSubMenu.add(mi);
    mainpopup.add(skinsSubMenu);
    JMenu playbackSubMenu = new JMenu(ui.getResource("popup.playback"));
    mi = new JMenuItem(ui.getResource("popup.playback.jump"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, 0, false));
    mi.setActionCommand(PlayerActionEvent.MIJUMPFILE);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    playbackSubMenu.add(mi);
    mi = new JMenuItem(ui.getResource("popup.playback.stop"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, 0, false));
    mi.setActionCommand(PlayerActionEvent.MISTOP);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    playbackSubMenu.add(mi);
    mainpopup.add(playbackSubMenu);
    mainpopup.addSeparator();
    mi = new JMenuItem(ui.getResource("popup.exit"));
    mi.setActionCommand(PlayerActionEvent.ACEXIT);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    mainpopup.add(mi);
    // Popup menu on TitleBar
    ui.getAcTitleBar().removeMouseListener(popupAdapter);
    popupAdapter = new PopupAdapter(mainpopup);
    ui.getAcTitleBar().addMouseListener(popupAdapter);
    // Popup menu on Eject button
    ejectpopup = new JPopupMenu();
    mi = new JMenuItem(ui.getResource("popup.eject.openfile"));
    mi.setActionCommand(PlayerActionEvent.MIPLAYFILE);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    ejectpopup.add(mi);
    mi = new JMenuItem(ui.getResource("popup.eject.openlocation"));
    mi.setActionCommand(PlayerActionEvent.MIPLAYLOCATION);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    ejectpopup.add(mi);
    ui.getAcEject().removeMouseListener(ejectpopupAdapter);
    ejectpopupAdapter = new PopupAdapter(ejectpopup);
    ui.getAcEject().addMouseListener(ejectpopupAdapter);
    // EqualizerUI
    if (equalizerUI != null)
        equalizerUI.loadUI();
    if (playlistUI != null)
        playlistUI.loadUI();
    validate();
    loader.loaded();
}

From source file:org.omegat.gui.scripting.ScriptingWindow.java

private void removeAllQuickScriptActionListenersFrom(JMenuItem menu) {
    if (menu == null) {
        return;/*w ww. jav a2 s .co  m*/
    }

    for (ActionListener l : menu.getActionListeners()) {
        if (l instanceof QuickScriptActionListener) {
            menu.removeActionListener(l);
        }
    }
}

From source file:org.xulux.swing.widgets.Table.java

/**
 * Initializes the popupmenus of the table.
 *
 * @return if initialize update did some work
 *//*from www .ja v  a  2 s.c o  m*/
protected boolean initializeUpdateButtons() {
    if (this.menu != null) {
        return false;
    }
    String buttons = getProperty("updatebuttons");
    if (buttons != null) {
        String updateAction = getProperty("updateaction");
        List list = new ArrayList();
        List strList = NyxCollectionUtils.getListFromCSV(buttons);
        Iterator it = strList.iterator();
        while (it.hasNext()) {
            String wName = (String) it.next();
            Widget widget = getPart().getWidget(wName);
            if (widget == null) {
                if (log.isWarnEnabled()) {
                    log.warn("Button " + wName + " does not exist, check your part xml");
                    continue;
                }
            }
            if (updateAction != null) {
                widget.setProperty("action", updateAction);
                widget.addNyxListener(new UpdateButtonsListener(this, widget));
            }
            list.add(widget);
        }
        menu = WidgetFactory.getPopupFromButtons(list, "Popup:" + getName());
        if (menu == null) {
            return false;
        }
        menu.setParent(this);
        menu.setPart(getPart());
        List children = menu.getChildWidgets();
        if (children != null) {
            for (Iterator cit = children.iterator(); cit.hasNext();) {
                Widget cw = (Widget) cit.next();
                // we must clear the prepostfieldlistener...
                JMenuItem jcomp = (JMenuItem) cw.getNativeWidget();
                EventListener[] evs = jcomp.getListeners(ActionListener.class);
                if (evs != null && evs.length > 0) {
                    jcomp.removeActionListener((ActionListener) evs[0]);
                }
                cw.addNyxListener(new UpdateButtonsListener(this, cw));
            }
        }
        addChildWidget(menu);
        table.addMouseListener(new PopupListener(this.menu, this));
        if (this.lockedTable != null) {
            this.lockedTable.addMouseListener(new PopupListener(this.menu, this));
        }
    }
    // we also add UpdateButtonsListener here..
    if (!childPopupsChecked) {
        childPopupsChecked = true;
        List list = getChildWidgets();
        if (list != null && list.size() > 0) {
            for (Iterator it = getChildWidgets().iterator(); it.hasNext();) {
                Widget cw = (Widget) it.next();
                if (cw instanceof MenuItem) {
                    hasChildPopups = true;
                    break;
                }
            }
        }
    }
    if (hasChildPopups && buttons != null) {
        // just add a seperator by default
        Widget item = WidgetFactory.getWidget("menuitem", "Separator:" + getName());
        item.setProperty("type", "separator");
        item.setParent(menu);
        menu.addChildWidget(item);
    }
    if (hasChildPopups) {
        if (menu == null) {
            menu = WidgetFactory.getWidget("popupmenu", "PopupMenu:" + getName());
        }
        if (getChildWidgets() != null) {
            for (Iterator it = getChildWidgets().iterator(); it.hasNext();) {
                Widget cw = (Widget) it.next();
                if (cw instanceof MenuItem) {
                    cw.addNyxListener(new UpdateButtonsListener(this, cw));
                    cw.setParent(menu);
                    menu.addChildWidget(cw);
                }
            }
        }
    }
    if (menu != null) {
        if (menu.getParent() == null) {
            menu.setParent(this);
        }
        menu.initialize();
    }
    return true;
}