diff --git a/make/sun/awt/FILES_export_unix.gmk b/make/sun/awt/FILES_export_unix.gmk index 43637e7c4cbbf66845d39c796998e768352a20be..79246c6bc41bb10de8ec4ce83e7f2a7fa6550f6b 100644 --- a/make/sun/awt/FILES_export_unix.gmk +++ b/make/sun/awt/FILES_export_unix.gmk @@ -1,5 +1,5 @@ # -# Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -107,7 +107,8 @@ FILES_export = \ sun/java2d/x11/X11Renderer.java \ sun/java2d/x11/X11SurfaceData.java \ com/sun/java/swing/plaf/gtk/GTKEngine.java \ - com/sun/java/swing/plaf/gtk/GTKStyle.java + com/sun/java/swing/plaf/gtk/GTKStyle.java \ + sun/awt/ExtendedKeyCodes.java FILES_export2 = \ diff --git a/make/sun/awt/FILES_export_windows.gmk b/make/sun/awt/FILES_export_windows.gmk index 95933ceb396cf7087dfb4b6f582f00d8059b41f9..27627494458aff6ccdb7f496613a210dcfaa8a7f 100644 --- a/make/sun/awt/FILES_export_windows.gmk +++ b/make/sun/awt/FILES_export_windows.gmk @@ -1,5 +1,5 @@ # -# Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -154,7 +154,7 @@ FILES_export2 = \ sun/awt/datatransfer/DataTransferer.java \ sun/awt/datatransfer/SunClipboard.java \ sun/awt/dnd/SunDragSourceContextPeer.java \ - sun/awt/windows/WToolkitThreadBlockedHandler.java + sun/awt/windows/WToolkitThreadBlockedHandler.java FILES_export3 = \ java/awt/CheckboxMenuItem.java \ @@ -214,6 +214,7 @@ FILES_export3 = \ sun/awt/windows/WBufferStrategy.java \ sun/awt/windows/WTrayIconPeer.java \ sun/awt/image/ImagingLib.java \ + sun/awt/ExtendedKeyCodes.java \ sun/java2d/pipe/hw/AccelSurface.java \ sun/java2d/pipe/hw/AccelDeviceEventNotifier.java \ sun/java2d/pipe/hw/ContextCapabilities.java \ diff --git a/make/sun/xawt/mapfile-vers b/make/sun/xawt/mapfile-vers index 2eef2391e8e93e02d7aa32eef5b4588e54cc2692..8aaaef7f260d60bf29113689b81fd5b0d37988bc 100644 --- a/make/sun/xawt/mapfile-vers +++ b/make/sun/xawt/mapfile-vers @@ -1,5 +1,5 @@ # -# Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. +# Copyright 2002-2009 Sun Microsystems, Inc. All Rights Reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -293,16 +293,26 @@ SUNWprivate_1.1 { Java_sun_awt_X11_XlibWrapper_XGetIconSizes; Java_sun_awt_X11_XlibWrapper_XKeycodeToKeysym; Java_sun_awt_X11_XlibWrapper_XKeysymToKeycode; - Java_sun_awt_X11_XlibWrapper_XQueryKeymap; + Java_sun_awt_X11_XlibWrapper_XQueryKeymap; + Java_sun_awt_X11_XlibWrapper_XkbGetEffectiveGroup; + Java_sun_awt_X11_XlibWrapper_XkbSelectEvents; + Java_sun_awt_X11_XlibWrapper_XkbSelectEventDetails; + Java_sun_awt_X11_XlibWrapper_XkbKeycodeToKeysym; + Java_sun_awt_X11_XlibWrapper_XkbLibraryVersion; + Java_sun_awt_X11_XlibWrapper_XkbQueryExtension; + Java_sun_awt_X11_XlibWrapper_XkbGetMap; + Java_sun_awt_X11_XlibWrapper_XkbGetUpdatedMap; + Java_sun_awt_X11_XlibWrapper_XkbFreeKeyboard; + Java_sun_awt_X11_XlibWrapper_XkbTranslateKeyCode; Java_sun_awt_X11_XlibWrapper_XGetModifierMapping; - Java_sun_awt_X11_XlibWrapper_XFreeModifiermap; + Java_sun_awt_X11_XlibWrapper_XFreeModifiermap; Java_sun_awt_X11_XlibWrapper_XChangeActivePointerGrab; Java_sun_awt_X11_XlibWrapper_XNextSecondaryLoopEvent; Java_sun_awt_X11_XlibWrapper_ExitSecondaryLoop; Java_sun_awt_X11_XlibWrapper_XTextPropertyToStringList; Java_sun_awt_X11_XlibWrapper_XGrabServer; Java_sun_awt_X11_XlibWrapper_XUngrabServer; - Java_sun_awt_X11_XlibWrapper_XPutBackEvent; + Java_sun_awt_X11_XlibWrapper_XPutBackEvent; Java_sun_awt_X11_XlibWrapper_XConvertCase; Java_sun_awt_X11_XlibWrapper_XSynchronize; Java_java_awt_FileDialog_initIDs; diff --git a/src/share/classes/java/awt/AWTKeyStroke.java b/src/share/classes/java/awt/AWTKeyStroke.java index 12e43dc0a1448197398aacbbf35a75587f590196..35f57bae358d9637087ecfba9d933ba4e0887526 100644 --- a/src/share/classes/java/awt/AWTKeyStroke.java +++ b/src/share/classes/java/awt/AWTKeyStroke.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -329,6 +329,9 @@ public class AWTKeyStroke implements Serializable { *
java.awt.event.KeyEvent.VK_TAB
* java.awt.event.KeyEvent.VK_SPACE
*
+ * Alternatively, the key code may be obtained by calling
+ * java.awt.event.KeyEvent.getExtendedKeyCodeForChar.
+ *
* The modifiers consist of any combination of:
- * MenuShortcut ms = new MenuShortcut(KeyEvent.VK_A, false);
+ * MenuShortcut ms = new MenuShortcut(KeyEvent.VK_A, false);
+ *
or alternatively + *
+ * MenuShortcut ms = new MenuShortcut(KeyEvent.getExtendedKeyCodeForChar('A'), false);
+ *
+ * Menu shortcuts may also be constructed for a wider set of keycodes
+ * using the java.awt.event.KeyEvent.getExtendedKeyCodeForChar call.
+ * For example, a menu shortcut for "Ctrl+cyrillic ef" is created by
+ *
+ * MenuShortcut ms = new MenuShortcut(KeyEvent.getExtendedKeyCodeForChar('\u0444'), false);
+ *
+ * Note that shortcuts created with a keycode or an extended keycode defined as a constant in KeyEvent
+ * work regardless of the current keyboard layout. However, a shortcut made of
+ * an extended keycode not listed in KeyEvent
+ * only work if the current keyboard layout produces a corresponding letter.
*
* The accelerator key is platform-dependent and may be obtained * via {@link Toolkit#getMenuShortcutKeyMask}. diff --git a/src/share/classes/java/awt/event/KeyEvent.java b/src/share/classes/java/awt/event/KeyEvent.java index 039675702972f64d4446bb0697d8cda02016a25a..1c0d3723d8a4b9e6a68a61546441f37656123235 100644 --- a/src/share/classes/java/awt/event/KeyEvent.java +++ b/src/share/classes/java/awt/event/KeyEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -65,15 +65,16 @@ import java.io.ObjectInputStream; *
* For key pressed and key released events, the getKeyCode method returns * the event's keyCode. For key typed events, the getKeyCode method - * always returns VK_UNDEFINED. + * always returns {@code VK_UNDEFINED}. The {@code getExtendedKeyCode} method + * may also be used with many international keyboard layouts. * *
* "Key pressed" and "key released" events are lower-level and depend * on the platform and keyboard layout. They are generated whenever a key is * pressed or released, and are the only way to find out about keys that don't * generate character input (e.g., action keys, modifier keys, etc.). The key - * being pressed or released is indicated by the getKeyCode method, which returns - * a virtual key code. + * being pressed or released is indicated by the {@code getKeyCode} and {@code getExtendedKeyCode} + * methods, which return a virtual key code. * *
* Virtual key codes are used to report which keyboard key has @@ -111,6 +112,11 @@ import java.io.ObjectInputStream; * platform and keyboard layout. For example, the key that generates VK_Q * when using a U.S. keyboard layout will generate VK_A when using a French * keyboard layout. + *
VK_XXX
* keycodes defined in java.awt.event.KeyEvent.
+ * These codes and the wider array of codes for international
+ * keyboards may be obtained through
+ * java.awt.event.KeyEvent.getExtendedKeyCodeForChar.
* Mnemonics are case-insensitive, therefore a key event
* with the corresponding keycode would cause the button to be
* activated whether or not the Shift modifier was pressed.
diff --git a/src/share/classes/javax/swing/Action.java b/src/share/classes/javax/swing/Action.java
index c996244fd5de1c1df5dab70a9c3f8e58c3198dd3..4a13a42da893dd3ec3e40a84785f7ced70c22a0b 100644
--- a/src/share/classes/javax/swing/Action.java
+++ b/src/share/classes/javax/swing/Action.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -272,7 +272,9 @@ public interface Action extends ActionListener {
* one of the KeyEvent key codes. The value is
* commonly used to specify a mnemonic. For example:
* myAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A)
- * sets the mnemonic of myAction to 'a'.
+ * sets the mnemonic of myAction to 'a', while
+ * myAction.putValue(Action.MNEMONIC_KEY, KeyEvent.getExtendedKeyCodeForChar('\u0444'))
+ * sets the mnemonic of myAction to Cyrillic letter "Ef".
*
* @since 1.3
*/
diff --git a/src/share/classes/javax/swing/JComponent.java b/src/share/classes/javax/swing/JComponent.java
index 831dc717a072bf37ea30fc5d7cb52bc0a57ea09d..ebed19256085a961d3e6c987a4c4f561887b3131 100644
--- a/src/share/classes/javax/swing/JComponent.java
+++ b/src/share/classes/javax/swing/JComponent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -2888,7 +2888,10 @@ public abstract class JComponent extends Container implements Serializable,
return false;
}
// Get the KeyStroke
+ // There may be two keystrokes associated with a low-level key event;
+ // in this case a keystroke made of an extended key code has a priority.
KeyStroke ks;
+ KeyStroke ksE = null;
if (e.getID() == KeyEvent.KEY_TYPED) {
ks = KeyStroke.getKeyStroke(e.getKeyChar());
@@ -2896,9 +2899,18 @@ public abstract class JComponent extends Container implements Serializable,
else {
ks = KeyStroke.getKeyStroke(e.getKeyCode(),e.getModifiers(),
(pressed ? false:true));
+ if (e.getKeyCode() != e.getExtendedKeyCode()) {
+ ksE = KeyStroke.getKeyStroke(e.getExtendedKeyCode(),e.getModifiers(),
+ (pressed ? false:true));
+ }
}
- /* Do we have a key binding for e? */
+ // Do we have a key binding for e?
+ // If we have a binding by an extended code, use it.
+ // If not, check for regular code binding.
+ if(ksE != null && processKeyBinding(ksE, e, WHEN_FOCUSED, pressed)) {
+ return true;
+ }
if(processKeyBinding(ks, e, WHEN_FOCUSED, pressed))
return true;
@@ -2910,6 +2922,9 @@ public abstract class JComponent extends Container implements Serializable,
while (parent != null && !(parent instanceof Window) &&
!(parent instanceof Applet)) {
if(parent instanceof JComponent) {
+ if(ksE != null && ((JComponent)parent).processKeyBinding(ksE, e,
+ WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, pressed))
+ return true;
if(((JComponent)parent).processKeyBinding(ks, e,
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, pressed))
return true;
diff --git a/src/share/classes/javax/swing/JLabel.java b/src/share/classes/javax/swing/JLabel.java
index 417892a83234ead1e849da8512333fe9f1e50436..a9641b9bef108c8129575f5b76ea943ea946292b 100644
--- a/src/share/classes/javax/swing/JLabel.java
+++ b/src/share/classes/javax/swing/JLabel.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -503,10 +503,10 @@ public class JLabel extends JComponent implements SwingConstants, Accessible
* @see #setDisplayedMnemonic(int)
*/
public void setDisplayedMnemonic(char aChar) {
- int vk = (int) aChar;
- if(vk >= 'a' && vk <='z')
- vk -= ('a' - 'A');
- setDisplayedMnemonic(vk);
+ int vk = java.awt.event.KeyEvent.getExtendedKeyCodeForChar(aChar);
+ if (vk != java.awt.event.KeyEvent.VK_UNDEFINED) {
+ setDisplayedMnemonic(vk);
+ }
}
diff --git a/src/share/classes/javax/swing/JTabbedPane.java b/src/share/classes/javax/swing/JTabbedPane.java
index 2c74189fd33e1eaa141d56dade872ea2d9aed23d..e53cde113cded9a0cdc2365a018aef1543989d54 100644
--- a/src/share/classes/javax/swing/JTabbedPane.java
+++ b/src/share/classes/javax/swing/JTabbedPane.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1628,7 +1628,9 @@ public class JTabbedPane extends JComponent
*
* A mnemonic must correspond to a single key on the keyboard
* and should be specified using one of the VK_XXX
- * keycodes defined in java.awt.event.KeyEvent.
+ * keycodes defined in java.awt.event.KeyEvent
+ * or one of the extended keycodes obtained through
+ * java.awt.event.KeyEvent.getExtendedKeyCodeForChar.
* Mnemonics are case-insensitive, therefore a key event
* with the corresponding keycode would cause the button to be
* activated whether or not the Shift modifier was pressed.
diff --git a/src/share/classes/javax/swing/KeyStroke.java b/src/share/classes/javax/swing/KeyStroke.java
index 8a1e860ce298d0d971d7c45909ad7c6dfc928b75..2eb3c41d5dbda3f09e539a47a77628259cd9a12a 100644
--- a/src/share/classes/javax/swing/KeyStroke.java
+++ b/src/share/classes/javax/swing/KeyStroke.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -162,6 +162,9 @@ public class KeyStroke extends AWTKeyStroke {
*
java.awt.event.KeyEvent.getExtendedKeyCodeForChar.
+ *
* The modifiers consist of any combination of:java.awt.event.KeyEvent.getExtendedKeyCodeForChar.
+ *
* The modifiers consist of any combination of:See the dialog box (usually in upper left corner) for instructions
+ + + + diff --git a/test/java/awt/event/KeyEvent/AcceleratorTest/AcceleratorTest.java b/test/java/awt/event/KeyEvent/AcceleratorTest/AcceleratorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d0c71407ca51b286e216fe7e85f3ee180bc82df9 --- /dev/null +++ b/test/java/awt/event/KeyEvent/AcceleratorTest/AcceleratorTest.java @@ -0,0 +1,305 @@ +/* + test + @bug 6680988 + @summary verify that various shortcuts and accelerators work + @author yuri.nesterenko : area=awt.keyboard + @run applet/manual=yesno AcceleratorTest.html +*/ + +/** + * AcceleratorTest.java + * + * summary: + */ + +//import java.applet.Applet; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.Hashtable; + + +public class AcceleratorTest extends JApplet +{ + //Declare things used in the test, like buttons and labels here + static int pressed = 0; + Hashtable