source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/ListPopupMenu.java@ 12304

Last change on this file since 12304 was 12304, checked in by michael2402, 7 years ago

Javadoc for public methods / classes in gui.util and gui.widgets

  • Property svn:eol-style set to native
File size: 990 bytes
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import javax.swing.Action;
5import javax.swing.JList;
6import javax.swing.JMenuItem;
7import javax.swing.JPopupMenu;
8import javax.swing.event.ListSelectionListener;
9
10/**
11 * A popup menu for one or more lists. If actions are added to this menu, a ListSelectionListener is registered automatically.
12 * @author Vincent
13 */
14public class ListPopupMenu extends JPopupMenu {
15
16 private final JList<?>[] lists;
17
18 /**
19 * Create a new ListPopupMenu
20 * @param lists The lists to which listeners should be appended
21 */
22 public ListPopupMenu(JList<?>... lists) {
23 this.lists = lists;
24 }
25
26 @Override
27 public JMenuItem add(Action a) {
28 if (lists != null && a instanceof ListSelectionListener) {
29 for (JList<?> list : lists) {
30 list.addListSelectionListener((ListSelectionListener) a);
31 }
32 }
33 return super.add(a);
34 }
35}
Note: See TracBrowser for help on using the repository browser.