8026929: remove accelerators from policytool resources
authorweijun
Fri, 25 Oct 2013 08:38:20 +0800
changeset 21365 2a7be11ae905
parent 21364 decde35d5139
child 21366 4564a4d5d03d
8026929: remove accelerators from policytool resources Reviewed-by: alexp, weijun Contributed-by: Leif Samuelsson <leif.samuelsson@oracle.com>
jdk/src/share/classes/sun/security/tools/policytool/PolicyTool.java
jdk/src/share/classes/sun/security/tools/policytool/Resources.java
--- a/jdk/src/share/classes/sun/security/tools/policytool/PolicyTool.java	Thu Oct 24 14:13:09 2013 -0700
+++ b/jdk/src/share/classes/sun/security/tools/policytool/PolicyTool.java	Fri Oct 25 08:38:20 2013 +0800
@@ -1092,19 +1092,19 @@
         JMenu menu = new JMenu();
         configureButton(menu, "File");
         ActionListener actionListener = new FileMenuListener(tool, this);
-        addMenuItem(menu, NEW_POLICY_FILE, actionListener);
-        addMenuItem(menu, OPEN_POLICY_FILE, actionListener);
-        addMenuItem(menu, SAVE_POLICY_FILE, actionListener);
-        addMenuItem(menu, SAVE_AS_POLICY_FILE, actionListener);
-        addMenuItem(menu, VIEW_WARNINGS, actionListener);
-        addMenuItem(menu, QUIT, actionListener);
+        addMenuItem(menu, NEW_POLICY_FILE, actionListener, "N");
+        addMenuItem(menu, OPEN_POLICY_FILE, actionListener, "O");
+        addMenuItem(menu, SAVE_POLICY_FILE, actionListener, "S");
+        addMenuItem(menu, SAVE_AS_POLICY_FILE, actionListener, null);
+        addMenuItem(menu, VIEW_WARNINGS, actionListener, null);
+        addMenuItem(menu, QUIT, actionListener, null);
         menuBar.add(menu);
 
         // create a KeyStore menu
         menu = new JMenu();
         configureButton(menu, "KeyStore");
         actionListener = new MainWindowListener(tool, this);
-        addMenuItem(menu, EDIT_KEYSTORE, actionListener);
+        addMenuItem(menu, EDIT_KEYSTORE, actionListener, null);
         menuBar.add(menu);
         setJMenuBar(menuBar);
 
@@ -1220,23 +1220,24 @@
     // Platform specific modifier (control / command).
     private int shortCutModifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
 
-    private void addMenuItem(JMenu menu, String key, ActionListener actionListener) {
+    private void addMenuItem(JMenu menu, String key, ActionListener actionListener, String accelerator) {
         JMenuItem menuItem = new JMenuItem();
         configureButton(menuItem, key);
 
         if (PolicyTool.rb.containsKey(key + ".accelerator")) {
-            String accelerator = PolicyTool.getMessage(key + ".accelerator");
-            if (accelerator != null && !accelerator.isEmpty()) {
-                KeyStroke keyStroke;
-                if (accelerator.matches("^control .$")) {
-                    // Map "control" key to "command" on MacOS
-                    keyStroke = KeyStroke.getKeyStroke(KeyEvent.getExtendedKeyCodeForChar(accelerator.charAt(8)),
-                                                       shortCutModifier);
-                } else {
-                    keyStroke = KeyStroke.getKeyStroke(accelerator);
-                }
-                menuItem.setAccelerator(keyStroke);
+            // Accelerator from resources takes precedence
+            accelerator = PolicyTool.getMessage(key + ".accelerator");
+        }
+
+        if (accelerator != null && !accelerator.isEmpty()) {
+            KeyStroke keyStroke;
+            if (accelerator.length() == 1) {
+                keyStroke = KeyStroke.getKeyStroke(KeyEvent.getExtendedKeyCodeForChar(accelerator.charAt(0)),
+                                                   shortCutModifier);
+            } else {
+                keyStroke = KeyStroke.getKeyStroke(accelerator);
             }
+            menuItem.setAccelerator(keyStroke);
         }
 
         menuItem.addActionListener(actionListener);
--- a/jdk/src/share/classes/sun/security/tools/policytool/Resources.java	Thu Oct 24 14:13:09 2013 -0700
+++ b/jdk/src/share/classes/sun/security/tools/policytool/Resources.java	Fri Oct 25 08:38:20 2013 +0800
@@ -45,11 +45,8 @@
         {".file.file.policy.file.location",
                 "  [-file <file>]    policy file location"},
         {"New", "&New"},
-        {"New.accelerator", "control N"},
         {"Open", "&Open..."},
-        {"Open.accelerator", "control O"},
         {"Save", "&Save"},
-        {"Save.accelerator", "control S"},
         {"Save.As", "Save &As..."},
         {"View.Warning.Log", "View &Warning Log"},
         {"Exit", "E&xit"},
@@ -92,8 +89,6 @@
         {"OK.to.overwrite.existing.file.filename.",
                 "OK to overwrite existing file {0}?"},
         {"Cancel", "Cancel"},
-
-        // Policy Entry Dialog
         {"CodeBase.", "&CodeBase:"},
         {"SignedBy.", "&SignedBy:"},
         {"Add.Principal", "&Add Principal"},
@@ -104,13 +99,10 @@
         {".Edit.Permission", "  Ed&it Permission"},
         {"Remove.Permission", "Re&move Permission"},
         {"Done", "Done"},
-
-        // KeyStore Edit Dialog
         {"KeyStore.URL.", "KeyStore &URL:"},
         {"KeyStore.Type.", "KeyStore &Type:"},
         {"KeyStore.Provider.", "KeyStore &Provider:"},
         {"KeyStore.Password.URL.", "KeyStore Pass&word URL:"},
-
         {"Principals", "Principals"},
         {".Edit.Principal.", "  Edit Principal:"},
         {".Add.New.Principal.", "  Add New Principal:"},