Changeset 5884 in josm


Ignore:
Timestamp:
2013-04-19T01:31:16+02:00 (6 years ago)
Author:
Don-vip
Message:

see #4429 - Get popup menu from PopupMenuLauncher + fix javadoc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/widgets/PopupMenuLauncher.java

    r3083 r5884  
    77import javax.swing.JPopupMenu;
    88
     9/**
     10 * Utility class that helps to display popup menus on mouse events.
     11 * @since 2688
     12 */
    913public class PopupMenuLauncher extends MouseAdapter {
    10     private JPopupMenu menu;
     14    private final JPopupMenu menu;
    1115
     16    /**
     17     * Creates a new {@link PopupMenuLauncher} with no defined menu.
     18     * It is then needed to override the {@link #launch} method.
     19     * @see #launch(MouseEvent)
     20     */
    1221    public PopupMenuLauncher() {
    13         menu = null;
     22        this(null);
    1423    }
     24
     25    /**
     26     * Creates a new {@link PopupMenuLauncher} with the given menu.
     27     * @param menu The popup menu to display
     28     */
    1529    public PopupMenuLauncher(JPopupMenu menu) {
    1630        this.menu = menu;
     
    3852    }
    3953
     54    /**
     55     * Launches the popup menu according to the given mouse event.
     56     * This method needs to be overriden if the default constructor has been called.
     57     * @param evt A mouse event
     58     */
    4059    public void launch(MouseEvent evt) {
    4160        if (menu != null) {
    42             menu.show(evt.getComponent(), evt.getX(),evt.getY());
     61            menu.show(evt.getComponent(), evt.getX(), evt.getY());
    4362        }
    4463    }
     64
     65    /**
     66     * @return the popup menu if defined, {@code null} otherwise.
     67     * @since 5884
     68     */
     69    public final JPopupMenu getMenu() {
     70        return menu;
     71    }
    4572}
Note: See TracChangeset for help on using the changeset viewer.