7129133: [macosx] Accelerators are displayed as Meta instead of the Command symbol
authorleonidr
Thu, 19 Sep 2013 23:46:15 +0400
changeset 20147 78e51d8fcb92
parent 20146 019d103c3e40
child 20148 e197553b4433
7129133: [macosx] Accelerators are displayed as Meta instead of the Command symbol Reviewed-by: anthony, serb
jdk/makefiles/GensrcProperties.gmk
jdk/src/macosx/classes/sun/awt/resources/awtosx.properties
jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
jdk/src/share/classes/java/awt/Toolkit.java
jdk/src/share/classes/sun/awt/AWTAccessor.java
jdk/test/java/awt/Toolkit/ToolkitPropertyTest/bug7129133.java
--- a/jdk/makefiles/GensrcProperties.gmk	Thu Sep 19 22:33:21 2013 +0400
+++ b/jdk/makefiles/GensrcProperties.gmk	Thu Sep 19 23:46:15 2013 +0400
@@ -253,6 +253,13 @@
 	$(call CacheFind,$(JDK_TOPDIR)/src/windows/classes/sun/awt/windows)),\
 	ListResourceBundle,%zh_TW,%zh_HK))
 endif
+# os x specific awt properties
+ifeq ($(OPENJDK_TARGET_OS),macosx)
+$(eval $(call add_properties_to_compile,SUN_AWT,\
+	$(filter $(JDK_TOPDIR)/src/macosx/classes/sun/awt/resources/%.properties,\
+	$(call CacheFind,$(JDK_TOPDIR)/src/macosx/classes/sun/awt/resources)),\
+	ListResourceBundle))
+endif
 
 #sun/launcher/resources
 $(eval $(call add_properties_to_compile,SUN_LAUNCHER,\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/macosx/classes/sun/awt/resources/awtosx.properties	Thu Sep 19 23:46:15 2013 +0400
@@ -0,0 +1,71 @@
+#
+# OS X specific AWT properties
+#
+
+# Modifier names
+AWT.shift=\u21e7
+AWT.control=\u2303
+AWT.alt=\u2325
+AWT.meta=\u2318
+AWT.altGraph=\u2325
+
+# Key names
+AWT.enter=\u23ce
+AWT.backSpace=\u232b
+AWT.tab=\u21e5
+AWT.cancel=\u238b
+AWT.clear=\u2327
+AWT.capsLock=\u21ea
+AWT.escape=\u238b
+AWT.space=\u2423
+AWT.pgup=\u21de
+AWT.pgdn=\u21df
+AWT.end=\u2198
+AWT.home=\u2196
+AWT.left=\u2190
+AWT.up=\u2191
+AWT.right=\u2192
+AWT.down=\u2193
+AWT.comma=,
+AWT.period=.
+AWT.slash=/
+AWT.semicolon=;
+AWT.equals=\u003d
+AWT.openBracket=[
+AWT.backSlash=\\
+AWT.closeBracket=]
+AWT.multiply=\u2328 *
+AWT.add=\u2328 +
+AWT.separator=\u2328 ,
+AWT.separater=\u2328 ,
+AWT.subtract=\u2328 -
+AWT.decimal=\u2328 .
+AWT.divide=\u2328 /
+AWT.delete=\u2326
+AWT.printScreen=\u2399
+AWT.backQuote=`
+AWT.quote='
+AWT.ampersand=&
+AWT.asterisk=*
+AWT.quoteDbl="
+AWT.Less=<
+AWT.greater=>
+AWT.braceLeft=[
+AWT.braceRight=]
+AWT.at=@
+AWT.colon=:
+AWT.circumflex=^
+AWT.dollar=$
+AWT.euro=\u20ac
+AWT.exclamationMark=!
+AWT.invertedExclamationMark=\u00a1
+AWT.leftParenthesis=(
+AWT.numberSign=#
+AWT.plus=+
+AWT.minus=-
+AWT.rightParenthesis=)
+AWT.underscore=_
+
+# Numeric Keypad
+AWT.numpad=\u2328
+
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Thu Sep 19 22:33:21 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Thu Sep 19 23:46:15 2013 +0400
@@ -44,6 +44,8 @@
 import sun.lwawt.LWWindowPeer.PeerType;
 import sun.security.action.GetBooleanAction;
 
+import sun.util.CoreResourceBundleControl;
+
 class NamedCursor extends Cursor {
     NamedCursor(String name) {
         super(name);
@@ -67,13 +69,28 @@
 
     static {
         System.err.flush();
-        java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Object>() {
-            public Object run() {
+
+        ResourceBundle platformResources = java.security.AccessController.doPrivileged(
+                new java.security.PrivilegedAction<ResourceBundle>() {
+            public ResourceBundle run() {
+                ResourceBundle platformResources = null;
+                try {
+                    platformResources =
+                            ResourceBundle.getBundle("sun.awt.resources.awtosx",
+                                    CoreResourceBundleControl.getRBControlInstance());
+                } catch (MissingResourceException e) {
+                    // No resource file; defaults will be used.
+                }
+
                 System.loadLibrary("awt");
                 System.loadLibrary("fontmanager");
-                return null;
+
+                return platformResources;
             }
         });
+
+        AWTAccessor.getToolkitAccessor().setPlatformResources(platformResources);
+
         if (!GraphicsEnvironment.isHeadless()) {
             initIDs();
         }
--- a/jdk/src/share/classes/java/awt/Toolkit.java	Thu Sep 19 22:33:21 2013 +0400
+++ b/jdk/src/share/classes/java/awt/Toolkit.java	Thu Sep 19 23:46:15 2013 +0400
@@ -56,6 +56,7 @@
 import sun.awt.NullComponentPeer;
 import sun.awt.PeerEvent;
 import sun.awt.SunToolkit;
+import sun.awt.AWTAccessor;
 import sun.security.util.SecurityConstants;
 
 import sun.util.CoreResourceBundleControl;
@@ -1599,6 +1600,12 @@
      * here, so that only one copy is maintained.
      */
     private static ResourceBundle resources;
+    private static ResourceBundle platformResources;
+
+    // called by platform toolkit
+    private static void setPlatformResources(ResourceBundle bundle) {
+        platformResources = bundle;
+    }
 
     /**
      * Initialize JNI field and method ids
@@ -1647,6 +1654,14 @@
     }
 
     static {
+        AWTAccessor.setToolkitAccessor(
+                new AWTAccessor.ToolkitAccessor() {
+                    @Override
+                    public void setPlatformResources(ResourceBundle bundle) {
+                        Toolkit.setPlatformResources(bundle);
+                    }
+                });
+
         java.security.AccessController.doPrivileged(
                                  new java.security.PrivilegedAction<Void>() {
             public Void run() {
@@ -1674,6 +1689,15 @@
      * This method returns defaultValue if the property is not found.
      */
     public static String getProperty(String key, String defaultValue) {
+        // first try platform specific bundle
+        if (platformResources != null) {
+            try {
+                return platformResources.getString(key);
+            }
+            catch (MissingResourceException e) {}
+        }
+
+        // then shared one
         if (resources != null) {
             try {
                 return resources.getString(key);
--- a/jdk/src/share/classes/sun/awt/AWTAccessor.java	Thu Sep 19 22:33:21 2013 +0400
+++ b/jdk/src/share/classes/sun/awt/AWTAccessor.java	Thu Sep 19 23:46:15 2013 +0400
@@ -39,6 +39,7 @@
 import java.security.AccessControlContext;
 
 import java.io.File;
+import java.util.ResourceBundle;
 import java.util.Vector;
 
 /**
@@ -705,6 +706,13 @@
     }
 
     /*
+     * An accessor for the Toolkit class
+     */
+    public interface ToolkitAccessor {
+        void setPlatformResources(ResourceBundle bundle);
+    }
+
+    /*
      * Accessor instances are initialized in the static initializers of
      * corresponding AWT classes by using setters defined below.
      */
@@ -731,6 +739,7 @@
     private static TrayIconAccessor trayIconAccessor;
     private static DefaultKeyboardFocusManagerAccessor defaultKeyboardFocusManagerAccessor;
     private static SequencedEventAccessor sequencedEventAccessor;
+    private static ToolkitAccessor toolkitAccessor;
 
     /*
      * Set an accessor object for the java.awt.Component class.
@@ -1124,4 +1133,22 @@
         // (so not a single instance of the event has been created).
         return sequencedEventAccessor;
     }
+
+    /*
+     * Set an accessor object for the java.awt.Toolkit class.
+     */
+    public static void setToolkitAccessor(ToolkitAccessor ta) {
+        toolkitAccessor = ta;
+    }
+
+    /*
+     * Get the accessor object for the java.awt.Toolkit class.
+     */
+    public static ToolkitAccessor getToolkitAccessor() {
+        if (toolkitAccessor == null) {
+            unsafe.ensureClassInitialized(Toolkit.class);
+        }
+
+        return toolkitAccessor;
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Toolkit/ToolkitPropertyTest/bug7129133.java	Thu Sep 19 23:46:15 2013 +0400
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 7129133
+ * @summary [macosx] Accelerators are displayed as Meta instead of the Command symbol
+ * @author leonid.romanov@oracle.com
+ * @run main bug7129133
+ */
+
+import java.awt.*;
+
+public class bug7129133 {
+    public static void main(String[] args) throws Exception {
+        if (sun.awt.OSInfo.getOSType() != sun.awt.OSInfo.OSType.MACOSX) {
+            System.out.println("This test is for MacOS only. Automatically passed on other platforms.");
+            return;
+        }
+
+        Toolkit.getDefaultToolkit();
+
+        String cmdSymbol = "\u2318";
+        String val = Toolkit.getProperty("AWT.meta", "Meta");
+
+        if (!val.equals(cmdSymbol)) {
+           throw new Exception("Wrong property value for AWT.meta. Expected: " + cmdSymbol + ", actual: " + val);
+        }
+    }
+}