diff --git a/src/org/openide/awt/AbstractMnemonicsAction.java b/src/org/openide/awt/AbstractMnemonicsAction.java
new file mode 100644
index 0000000..e296d8a
--- /dev/null
+++ b/src/org/openide/awt/AbstractMnemonicsAction.java
@@ -0,0 +1,48 @@
+package org.openide.awt;
+
+import javax.swing.*;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * @author Hiroshi Miura
+ */
+public abstract class AbstractMnemonicsAction extends AbstractAction {
+ public AbstractMnemonicsAction() {
+ super();
+ }
+
+ public AbstractMnemonicsAction(String key, ResourceBundle bundle) {
+ super();
+ setText(key, bundle);
+ }
+
+ public AbstractMnemonicsAction(String text, Locale locale) {
+ super();
+ setText(text, locale);
+ }
+
+ public AbstractMnemonicsAction(String text) {
+ super();
+ setText(text);
+ }
+
+ public void setText(String key, ResourceBundle bundle) {
+ setText(bundle.getString(key), bundle.getLocale());
+ }
+
+ public void setText(String text) {
+ setText(text, new Locale("en"));
+ }
+
+ public void setText(String text, Locale locale) {
+ int i = Mnemonics.findMnemonicAmpersand(text);
+ if (i < 0) {
+ putValue(Action.NAME, text);
+ putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, -1);
+ } else {
+ putValue(Action.NAME, text.substring(0, i) + text.substring(i + 1));
+ Mnemonics.setMnemonicAndIndex(this, text.charAt(i + 1), i, locale);
+ }
+ }
+}
diff --git a/src/org/openide/awt/Mnemonics.java b/src/org/openide/awt/Mnemonics.java
index f31f842..02ba0f2 100644
--- a/src/org/openide/awt/Mnemonics.java
+++ b/src/org/openide/awt/Mnemonics.java
@@ -46,6 +46,7 @@
import java.util.regex.Pattern;
import javax.swing.AbstractButton;
+import javax.swing.Action;
import javax.swing.JLabel;
/**
@@ -54,7 +55,7 @@
* @since 3.37
* @see Issue #26640
*/
-public final class Mnemonics extends Object {
+public final class Mnemonics {
private static final Pattern RE_MNEMONIC_END = Pattern.compile("\\s*\\(&[A-Za-z0-9]\\)(?=[.\\uFF1A]*$)");
private static final Pattern RE_MNEMONIC_INSIDE = Pattern.compile("&(\\p{L})");
@@ -194,18 +195,20 @@ public static int findMnemonicAmpersand(String text) {
* @param item AbstractButton/JLabel or subclasses
* @param ch Mnemonic char to set, may be a char in some locale
+ * @param locale locale of the text.
* @param index Index of the Character to underline under JDK1.4
*/
- private static void setMnemonicAndIndex (Object item, char ch, int index, Locale locale) {
+ static void setMnemonicAndIndex(Object item, char ch, int index, Locale locale) {
// OmegaT tweak
// if we're running on non-MacOSX, we don't set any mnemonics
- if (isMacOS()) {
- setMnemonic(item, 0);
+ if (isMacOS() || ch == 0) {
+ setMnemonic(item, 0);
+ setMnemonicIndex(item, -1);
} else {
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')
|| (ch >= '0' && ch <= '9')) {
- // it's latin character or arabic digit,
+ // it's a latin character or arabic digit,
// setting it as mnemonics
setMnemonic(item, ch);
// If it's something like "Save &As", we need to set another
@@ -213,20 +216,23 @@ private static void setMnemonicAndIndex (Object item, char ch, int index, Locale
// see #29676
setMnemonicIndex(item, index);
} else {
- // it's non-latin, getting the latin correspondance
+ // it's non-latin, getting the latin correspondence
int latinCode = getLatinKeycode(ch, locale);
setMnemonic(item, latinCode);
- if( latinCode!=0 )
+ if (latinCode == 0) {
+ setMnemonicIndex(item, -1);
+ } else {
setMnemonicIndex(item, index);
+ }
}
}
}
/**
- * Gets the Latin symbol which corresponds
+ * Gets the Latin symbol, which corresponds
* to some non-Latin symbol on the localized keyboard.
- * The search is done via lookup of Resource bundle
- * for pairs having the form (e.g.) MNEMONIC_\u0424=A
.
+ * The search is done via lookup of a Resource bundle
+ * for pairs having the form (e.g.) MNEMONIC_ะค=A
.
*
* @param localeChar non-Latin character or a punctuator to be used as mnemonic
* @return character on latin keyboard, corresponding to the locale character,
@@ -256,11 +262,13 @@ private static int getLatinKeycode(char localeChar, Locale locale) {
*