Last change
on this file since 9249 was 9249, checked in by Don-vip, 8 years ago |
see #11390 - resolve last javadoc warnings with Java 8. "ant javadoc" now produces 0 warning \o/
|
-
Property svn:eol-style
set to
native
|
File size:
1.3 KB
|
Rev | Line | |
---|
[5094] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[5088] | 2 | package org.openstreetmap.josm.gui.util;
|
---|
| 3 |
|
---|
| 4 | import javax.swing.Action;
|
---|
| 5 | import javax.swing.JCheckBoxMenuItem;
|
---|
| 6 | import javax.swing.MenuElement;
|
---|
| 7 | import javax.swing.MenuSelectionManager;
|
---|
| 8 | import javax.swing.event.ChangeEvent;
|
---|
| 9 | import javax.swing.event.ChangeListener;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * An extension of JCheckBoxMenuItem that doesn't close the menu when selected.
|
---|
| 13 | *
|
---|
[6920] | 14 | * @author Darryl https://tips4java.wordpress.com/2010/09/12/keeping-menus-open/
|
---|
[5088] | 15 | */
|
---|
| 16 | public class StayOpenCheckBoxMenuItem extends JCheckBoxMenuItem {
|
---|
| 17 |
|
---|
[8126] | 18 | private static volatile MenuElement[] path;
|
---|
[5088] | 19 |
|
---|
| 20 | {
|
---|
| 21 | getModel().addChangeListener(new ChangeListener() {
|
---|
| 22 |
|
---|
| 23 | @Override
|
---|
| 24 | public void stateChanged(ChangeEvent e) {
|
---|
| 25 | if (getModel().isArmed() && isShowing()) {
|
---|
| 26 | path = MenuSelectionManager.defaultManager().getSelectedPath();
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 | });
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
[9249] | 33 | * Contructs a new {@code StayOpenCheckBoxMenuItem} whose properties are taken from the Action supplied.
|
---|
| 34 | * @param a action
|
---|
[5088] | 35 | */
|
---|
| 36 | public StayOpenCheckBoxMenuItem(Action a) {
|
---|
| 37 | super(a);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * Overridden to reopen the menu.
|
---|
| 42 | *
|
---|
| 43 | * @param pressTime the time to "hold down" the button, in milliseconds
|
---|
| 44 | */
|
---|
| 45 | @Override
|
---|
| 46 | public void doClick(int pressTime) {
|
---|
| 47 | super.doClick(pressTime);
|
---|
| 48 | MenuSelectionManager.defaultManager().setSelectedPath(path);
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.