001 // License: GPL. For details, see LICENSE file.
002 package org.openstreetmap.josm.gui.widgets;
003
004 import javax.swing.Action;
005 import javax.swing.JList;
006 import javax.swing.JMenuItem;
007 import javax.swing.JPopupMenu;
008 import javax.swing.event.ListSelectionListener;
009
010 /**
011 * @author Vincent
012 *
013 */
014 public 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 }