001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.widgets;
003
004import javax.swing.Action;
005import javax.swing.JList;
006import javax.swing.JMenuItem;
007import javax.swing.JPopupMenu;
008import javax.swing.event.ListSelectionListener;
009
010/**
011 * @author Vincent
012 *
013 */
014public class ListPopupMenu extends JPopupMenu {
015
016    private JList[] lists;
017
018    public ListPopupMenu(JList ... lists) {
019        this.lists = lists;
020    }
021
022    /* (non-Javadoc)
023     * @see javax.swing.JPopupMenu#add(javax.swing.Action)
024     */
025    @Override
026    public JMenuItem add(Action a) {
027        if (lists != null && a instanceof ListSelectionListener) {
028            for (JList list : lists) {
029                list.addListSelectionListener((ListSelectionListener) a);
030            }
031        }
032        return super.add(a);
033    }
034}