diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-05-18 17:29:21 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-05-18 17:29:21 +0000 |
commit | 64089cc9f030d8ef7972adb5d117e0b23f47d62b (patch) | |
tree | 9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/javax/swing/MenuSelectionManager.java | |
parent | 96034e28360d660d7a7708807fcbc4b519574d8e (diff) | |
download | ppe42-gcc-64089cc9f030d8ef7972adb5d117e0b23f47d62b.tar.gz ppe42-gcc-64089cc9f030d8ef7972adb5d117e0b23f47d62b.zip |
Imported GNU Classpath 0.90
* scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale.
* sources.am: Regenerated.
* gcj/javaprims.h: Regenerated.
* Makefile.in: Regenerated.
* gcj/Makefile.in: Regenerated.
* include/Makefile.in: Regenerated.
* testsuite/Makefile.in: Regenerated.
* gnu/java/lang/VMInstrumentationImpl.java: New override.
* gnu/java/net/local/LocalSocketImpl.java: Likewise.
* gnu/classpath/jdwp/VMMethod.java: Likewise.
* gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest
interface.
* java/lang/Thread.java: Add UncaughtExceptionHandler.
* java/lang/reflect/Method.java: Implements GenericDeclaration and
isSynthetic(),
* java/lang/reflect/Field.java: Likewise.
* java/lang/reflect/Constructor.java
* java/lang/Class.java: Implements Type, GenericDeclaration,
getSimpleName() and getEnclosing*() methods.
* java/lang/Class.h: Add new public methods.
* java/lang/Math.java: Add signum(), ulp() and log10().
* java/lang/natMath.cc (log10): New function.
* java/security/VMSecureRandom.java: New override.
* java/util/logging/Logger.java: Updated to latest classpath
version.
* java/util/logging/LogManager.java: New override.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113887 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/javax/swing/MenuSelectionManager.java')
-rw-r--r-- | libjava/classpath/javax/swing/MenuSelectionManager.java | 146 |
1 files changed, 95 insertions, 51 deletions
diff --git a/libjava/classpath/javax/swing/MenuSelectionManager.java b/libjava/classpath/javax/swing/MenuSelectionManager.java index 4e52751065a..df7b42037db 100644 --- a/libjava/classpath/javax/swing/MenuSelectionManager.java +++ b/libjava/classpath/javax/swing/MenuSelectionManager.java @@ -216,28 +216,90 @@ public class MenuSelectionManager public boolean isComponentPartOfCurrentMenu(Component c) { MenuElement[] subElements; - for (int i = 0; i < selectedPath.size(); i++) + boolean ret = false; + for (int i = 0; i < selectedPath.size(); i++) { - subElements = ((MenuElement) selectedPath.get(i)).getSubElements(); - for (int j = 0; j < subElements.length; j++) - { - MenuElement me = subElements[j]; - if (me != null && (me.getComponent()).equals(c)) - return true; - } + // Check first element. + MenuElement first = (MenuElement) selectedPath.get(i); + if (SwingUtilities.isDescendingFrom(c, first.getComponent())) + { + ret = true; + break; + } + else + { + // Check sub elements. + subElements = first.getSubElements(); + for (int j = 0; j < subElements.length; j++) + { + MenuElement me = subElements[j]; + if (me != null + && (SwingUtilities.isDescendingFrom(c, me.getComponent()))) + { + ret = true; + break; + } + } + } } - return false; + return ret; } /** - * DOCUMENT ME! + * Processes key events on behalf of the MenuElements. MenuElement + * instances should always forward their key events to this method and + * get their {@link MenuElement#processKeyEvent(KeyEvent, MenuElement[], + * MenuSelectionManager)} eventually called back. * - * @param e DOCUMENT ME! + * @param e the key event */ public void processKeyEvent(KeyEvent e) { - throw new UnsupportedOperationException("not implemented"); + MenuElement[] selection = (MenuElement[]) + selectedPath.toArray(new MenuElement[selectedPath.size()]); + MenuElement[] path; + for (int index = selection.length - 1; index >= 0; index--) + { + MenuElement el = selection[index]; + // This method's main purpose is to forward key events to the + // relevant menu items, so that they can act in response to their + // mnemonics beeing typed. So we also need to forward the key event + // to all the subelements of the currently selected menu elements + // in the path. + MenuElement[] subEls = el.getSubElements(); + path = null; + for (int subIndex = 0; subIndex < subEls.length; subIndex++) + { + MenuElement sub = subEls[subIndex]; + // Skip elements that are not showing or not enabled. + if (sub == null || ! sub.getComponent().isShowing() + || ! sub.getComponent().isEnabled()) + { + continue; + } + + if (path == null) + { + path = new MenuElement[index + 2]; + System.arraycopy(selection, 0, path, 0, index + 1); + } + path[index + 1] = sub; + sub.processKeyEvent(e, path, this); + if (e.isConsumed()) + break; + } + if (e.isConsumed()) + break; + } + + // Dispatch to first element in selection if it hasn't been consumed. + if (! e.isConsumed()) + { + path = new MenuElement[1]; + path[0] = selection[0]; + path[0].processKeyEvent(e, path, this); + } } /** @@ -303,53 +365,35 @@ public class MenuSelectionManager return; } - int i; - int minSize = path.length; // size of the smaller path. + int minSize = path.length; // size of the smaller path. + int currentSize = selectedPath.size(); + int firstDiff = 0; - if (path.length > selectedPath.size()) + // Search first item that is different in the current and new path. + for (int i = 0; i < minSize; i++) { - minSize = selectedPath.size(); - - // if new selected path contains more elements then current - // selection then first add all elements at - // the indexes > selectedPath.size - for (i = selectedPath.size(); i < path.length; i++) - { - selectedPath.add(path[i]); - path[i].menuSelectionChanged(true); - } + if (i < currentSize && (MenuElement) selectedPath.get(i) == path[i]) + firstDiff++; + else + break; } - else if (path.length < selectedPath.size()) + // Remove items from selection and send notification. + for (int i = currentSize - 1; i >= firstDiff; i--) { - // if new selected path contains less elements then current - // selection then first remove all elements from the selection - // at the indexes > path.length - for (i = selectedPath.size() - 1; i >= path.length; i--) - { - ((MenuElement) selectedPath.get(i)).menuSelectionChanged(false); - selectedPath.remove(i); - } - - minSize = path.length; + MenuElement el = (MenuElement) selectedPath.get(i); + selectedPath.remove(i); + el.menuSelectionChanged(false); } - // Now compare elements in new and current selection path at the - // same location and adjust selection until - // same menu elements will be encountered at the - // same index in both current and new selection path. - MenuElement oldSelectedItem; - - for (i = minSize - 1; i >= 0; i--) + // Add new items to selection and send notification. + for (int i = firstDiff; i < minSize; i++) { - oldSelectedItem = (MenuElement) selectedPath.get(i); - - if (path[i].equals(oldSelectedItem)) - break; - - oldSelectedItem.menuSelectionChanged(false); - path[i].menuSelectionChanged(true); - selectedPath.setElementAt(path[i], i); + if (path[i] != null) + { + selectedPath.add(path[i]); + path[i].menuSelectionChanged(true); + } } fireStateChanged(); |