/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A Windows L&F implementation of PopupMenuUI. This implementation
* is a "combined" view/controller.
*
* @author Georges Saab
* @author David Karlton
* @author Arnaud Weber
*/
"javax.swing.plaf.basic.BasicPopupMenuUI.MouseGrabber");
"javax.swing.plaf.basic.BasicPopupMenuUI.MenuKeyboardHelper");
private static boolean checkedUnpostPopup;
private static boolean unpostPopup;
return new BasicPopupMenuUI();
}
public BasicPopupMenuUI() {
BasicLookAndFeel.needsEventHelper = true;
if (laf instanceof BasicLookAndFeel) {
}
}
popupMenu = (JPopupMenu) c;
}
public void installDefaults() {
"PopupMenu.background",
"PopupMenu.foreground",
"PopupMenu.font");
}
protected void installListeners() {
if (popupMenuListener == null) {
popupMenuListener = new BasicPopupMenuListener();
}
if (menuKeyListener == null) {
menuKeyListener = new BasicMenuKeyListener();
}
synchronized (MOUSE_GRABBER_KEY) {
if (mouseGrabber == null) {
mouseGrabber = new MouseGrabber();
}
}
synchronized (MENU_KEYBOARD_HELPER_KEY) {
helper = new MenuKeyboardHelper();
}
}
}
protected void installKeyboardActions() {
}
}
}
}
return windowInputMap;
}
"PopupMenu.actionMap");
}
}
}
protected void uninstallDefaults() {
}
protected void uninstallListeners() {
if (popupMenuListener != null) {
}
if (menuKeyListener != null) {
}
}
protected void uninstallKeyboardActions() {
}
if (p[i] instanceof JPopupMenu)
me = p[i];
}
return me;
}
if (p[i] instanceof JPopupMenu)
popup = (JPopupMenu)p[i];
}
return popup;
}
for (MenuElement element : p) {
if (element instanceof JPopupMenu) {
}
}
return list;
}
}
if (invokerPresent instanceof JPopupMenu) {
}
if (invokerLast instanceof JPopupMenu) {
}
return (invokerPresent == invokerLast);
}
/**
* This Listener fires the Action that provides the correct auditory
* feedback.
*
* @since 1.4
*/
}
}
"PopupMenu.popupSound");
}
}
/**
* Handles mnemonic for children JMenuItems.
* @since 1.5
*/
if (menuToOpen != null) {
// we have a submenu to open
}
e.consume();
}
menuToOpen = null;
}
char keyChar = e.getKeyChar();
// Handle the case for Escape or Enter...
return;
}
int currentIndex = -1;
int matches = 0;
int firstMatch = -1;
continue;
}
if (matches == 0) {
firstMatch = j;
matches++;
} else {
}
}
}
}
}
if (matches == 0) {
// no op
} else if (matches == 1) {
// Invoke the menu action
// submenus are handled in menuKeyTyped
menuToOpen = item;
// we have a menu item
}
e.consume();
} else {
// Select the menu item with the matching mnemonic. If
// the same mnemonic has been invoked then select the next
// menu item in the cycle.
e.consume();
}
}
}
}
}
}
// Types of actions
private static final boolean FORWARD = true;
private static final boolean BACKWARD = false;
private static final boolean PARENT = false;
private static final boolean CHILD = true;
super(key);
}
cancel();
}
else if (key == SELECT_NEXT) {
}
else if (key == SELECT_PREVIOUS) {
}
else if (key == SELECT_PARENT) {
}
else if (key == SELECT_CHILD) {
}
doReturn();
}
}
private void doReturn() {
return;
}
if(lastElement instanceof JMenu) {
} else if(lastElement instanceof JMenuItem) {
}
else {
}
}
}
}
// selecting parent
if (len > 2 &&
// check if we have an open submenu. A submenu item may or
// may not be selected, so submenu popup can be either the
// last or next to the last item.
// we have a submenu, just close it
return;
}
} else {
// selecting child
// we have a submenu, open it
} else {
}
return;
}
}
// check if we have a toplevel menu selected.
// If this is the case, we select another toplevel menu
if (len == 2) {
// menu is selected but its popup not shown
} else {
// menu is selected and its popup is shown
}
}
}
}
return;
}
} else if (len == 2 &&
// a toplevel menu is selected, but its popup not shown.
// Show the popup and select the first item
// an enabled item found -- include it in newPath
} else {
// menu has no enabled items -- still must show the popup
}
// a menu (not necessarily toplevel) is open and its popup
// shown. Select the appropriate menu item
} else {
// all items in the popup are disabled.
// We're going to find the parent popup menu and select
// its next item. If there's no parent popup menu (i.e.
// current menu is toplevel), do nothing
}
}
}
} else {
// just select the next item, no path expansion needed
}
}
}
}
private void cancel() {
// 4234793: This action should call JPopupMenu.firePopupMenuCanceled but it's
// a protected method. The real solution could be to make
// firePopupMenuCanceled public and call it directly.
}
} else {
}
}
private void shortenSelectedPath() {
return;
}
// unselect MenuItem and its Popup by default
int value = 2;
if (lastElement == lastPopup) {
if (previousElement instanceof JMenu) {
// unselect the last visible popup only
value = 1;
} else {
// unselect invisible popup and two visible elements
value = 3;
}
}
}
// clear selection for the topLevelMenu
}
}
}
if (e[i] != null) {
return e[i];
}
}
}
return null;
}
if (e[i] != null) {
return e[i];
}
}
}
return null;
}
boolean forward) {
if (forward) {
} else {
fromIndex+1);
}
return result;
}
for (int i=0; i<e.length; i++) {
if (e[i] == elem) {
return findEnabledChild(e, i, forward);
}
}
return null;
}
public MouseGrabber() {
msm.addChangeListener(this);
grabWindow(this.lastPathSelected);
}
}
void uninstall() {
synchronized (MOUSE_GRABBER_KEY) {
ungrabWindow();
}
}
// A grab needs to be added
return null;
}
}
);
if (invoker instanceof JPopupMenu) {
}
if(grabbedWindow != null) {
} else {
grabbedWindow.addWindowListener(this);
}
}
}
void ungrabWindow() {
// The grab should be removed
return null;
}
}
);
}
void realUngrabWindow() {
if(grabbedWindow != null) {
} else {
}
}
}
grabWindow(p);
}
ungrabWindow();
}
lastPathSelected = p;
}
// Popup should be canceled in case of ungrab event
cancelPopupMenu( );
return;
}
if (!(ev instanceof MouseEvent)) {
// We are interested in MouseEvents only
return;
}
case MouseEvent.MOUSE_PRESSED:
return;
}
if (!(src instanceof JComponent) ||
== BasicComboBoxUI.HIDE_POPUP_KEY)) {
// Cancel popup only if this property was not set.
// If this property is set to TRUE component wants
// to deal with this event by himself.
// Ask UIManager about should we consume event that closes
// popup. This made to match native apps behaviour.
boolean consumeEvent =
// Consume the event so that normal processing stops.
}
}
break;
case MouseEvent.MOUSE_RELEASED:
if(!(src instanceof MenuElement)) {
// Do not forward event to MSM, let component handle it
break;
}
}
}
break;
case MouseEvent.MOUSE_DRAGGED:
if(!(src instanceof MenuElement)) {
// For the MOUSE_DRAGGED event the src is
// the Component in which mouse button was pressed.
// If the src is in popupMenu,
// do not forward event to MSM, let component handle it.
break;
}
}
break;
case MouseEvent.MOUSE_WHEEL:
return;
}
break;
}
}
break;
} else if (c instanceof JPopupMenu) {
return true;
}
}
return false;
}
void cancelPopupMenu() {
// We should ungrab window if a user code throws
// an unexpected runtime exception. See 6495920.
try {
// 4234793: This action should call firePopupMenuCanceled but it's
// a protected method. The real solution could be to make
// firePopupMenuCanceled public and call it directly.
}
} catch (RuntimeException ex) {
throw ex;
throw err;
}
}
}
}
}
}
}
}
}
}
}
/**
* This helper is added to MenuSelectionManager as a ChangeListener to
* listen to menu selection changes. When a menu is activated, it passes
* on that JRootPane. Those maps are necessary in order for menu
* navigation to work. When menu is being deactivated, it restores focus
* to the component that has had it before menu activation, and uninstalls
* the maps.
* This helper is also installed as a KeyListener on root pane when menu
* is active. It forwards key events to MenuSelectionManager for mnemonic
* keys handling.
*/
static class MenuKeyboardHelper
implements ChangeListener, KeyListener {
private boolean focusTraversalKeysEnabled;
/*
* Fix for 4213634
* If this is false, KEY_TYPED and KEY_RELEASED events are NOT
* processed. This is needed to avoid activating a menuitem when
* the menu and menuitem share the same mnemonic.
*/
private boolean receivedKeyPressed = false;
void removeItems() {
if (lastFocused != null) {
if(!lastFocused.requestFocusInWindow()) {
// Workarounr for 4810575.
// If lastFocused is not in currently focused window
// requestFocusInWindow will fail. In this case we must
// request focus by requestFocus() if it was not
// transferred from our popup.
.getFocusedWindow();
}
}
lastFocused = null;
}
if (invokerRootPane != null) {
invokerRootPane.removeKeyListener(this);
}
receivedKeyPressed = false;
}
}
}
};
/**
* Return the last JPopupMenu in <code>path</code>,
* or <code>null</code> if none found
*/
if (elem instanceof JPopupMenu) {
return (JPopupMenu)elem;
}
}
return null;
}
}
} else {
}
}
}
c.setActionMap(map);
} else {
}
}
} else {
}
break;
}
}
}
} else {
}
break;
}
}
}
uninstall();
return;
}
// Do nothing for non-focusable popups
return;
}
removeItems();
}
}
// menu posted
p[1] instanceof JMenu) {
// a menu has been selected but not open
} else {
return;
}
} else {
if(c instanceof JFrame) {
} else if(c instanceof JDialog) {
} else if(c instanceof JApplet) {
} else {
while (!(c instanceof JComponent)) {
if (c == null) {
return;
}
c = c.getParent();
}
invoker = (JComponent)c;
}
}
// remember current focus owner
// request focus on root pane and install keybindings
// used for menu navigation
if (invokerRootPane != null) {
invokerRootPane.requestFocus(true);
invokerRootPane.addKeyListener(this);
}
// menu hidden -- return focus to where it had been before
// and uninstall menu keybindings
removeItems();
} else {
receivedKeyPressed = false;
}
}
// Remember the last path selected
lastPathSelected = p;
}
receivedKeyPressed = true;
}
if (receivedKeyPressed) {
receivedKeyPressed = false;
}
}
if (receivedKeyPressed) {
}
}
void uninstall() {
synchronized (MENU_KEYBOARD_HELPER_KEY) {
}
}
}
}