From 484dd4eb1485a39ed1e8393895255a6eae31fd50 Mon Sep 17 00:00:00 2001 From: leonidr Date: Thu, 19 Sep 2013 23:46:15 +0400 Subject: [PATCH] 7129133: [macosx] Accelerators are displayed as Meta instead of the Command symbol Reviewed-by: anthony, serb --- makefiles/GensrcProperties.gmk | 7 ++ .../sun/awt/resources/awtosx.properties | 71 +++++++++++++++++++ .../classes/sun/lwawt/macosx/LWCToolkit.java | 23 +++++- src/share/classes/java/awt/Toolkit.java | 24 +++++++ src/share/classes/sun/awt/AWTAccessor.java | 27 +++++++ .../ToolkitPropertyTest/bug7129133.java | 50 +++++++++++++ 6 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 src/macosx/classes/sun/awt/resources/awtosx.properties create mode 100644 test/java/awt/Toolkit/ToolkitPropertyTest/bug7129133.java diff --git a/makefiles/GensrcProperties.gmk b/makefiles/GensrcProperties.gmk index 3ef3a5384..1e29376f6 100644 --- a/makefiles/GensrcProperties.gmk +++ b/makefiles/GensrcProperties.gmk @@ -253,6 +253,13 @@ ifeq ($(OPENJDK_TARGET_OS),windows) $(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,\ diff --git a/src/macosx/classes/sun/awt/resources/awtosx.properties b/src/macosx/classes/sun/awt/resources/awtosx.properties new file mode 100644 index 000000000..bfc3bd01b --- /dev/null +++ b/src/macosx/classes/sun/awt/resources/awtosx.properties @@ -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 + diff --git a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java index cf395f3ab..d698845e5 100644 --- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java +++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java @@ -44,6 +44,8 @@ import sun.lwawt.*; 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 @@ public final class LWCToolkit extends LWToolkit { static { System.err.flush(); - java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { - public Object run() { + + ResourceBundle platformResources = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + 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(); } diff --git a/src/share/classes/java/awt/Toolkit.java b/src/share/classes/java/awt/Toolkit.java index ac2dc2244..6b669d336 100644 --- a/src/share/classes/java/awt/Toolkit.java +++ b/src/share/classes/java/awt/Toolkit.java @@ -56,6 +56,7 @@ import sun.awt.HeadlessToolkit; 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 @@ public abstract class Toolkit { * 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 @@ public abstract class Toolkit { } static { + AWTAccessor.setToolkitAccessor( + new AWTAccessor.ToolkitAccessor() { + @Override + public void setPlatformResources(ResourceBundle bundle) { + Toolkit.setPlatformResources(bundle); + } + }); + java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Void run() { @@ -1674,6 +1689,15 @@ public abstract class Toolkit { * 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); diff --git a/src/share/classes/sun/awt/AWTAccessor.java b/src/share/classes/sun/awt/AWTAccessor.java index 2b7f73ccd..d604768f5 100644 --- a/src/share/classes/sun/awt/AWTAccessor.java +++ b/src/share/classes/sun/awt/AWTAccessor.java @@ -39,6 +39,7 @@ import java.lang.reflect.InvocationTargetException; import java.security.AccessControlContext; import java.io.File; +import java.util.ResourceBundle; import java.util.Vector; /** @@ -704,6 +705,13 @@ public final class AWTAccessor { boolean isSequencedEvent(AWTEvent event); } + /* + * 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 @@ public final class AWTAccessor { 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 @@ public final class AWTAccessor { // (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; + } } diff --git a/test/java/awt/Toolkit/ToolkitPropertyTest/bug7129133.java b/test/java/awt/Toolkit/ToolkitPropertyTest/bug7129133.java new file mode 100644 index 000000000..457879806 --- /dev/null +++ b/test/java/awt/Toolkit/ToolkitPropertyTest/bug7129133.java @@ -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); + } + } +} -- GitLab