< prev index next >
src/share/classes/sun/print/ServiceDialog.java
Print this page
rev 1477 : 7013850: Please change the mnemonic assignment system to avoid translation issue
Reviewed-by: prr, mfang
@@ -70,10 +70,11 @@
import javax.swing.event.PopupMenuListener;
import javax.swing.text.NumberFormatter;
import sun.print.SunPageSelection;
import java.awt.event.KeyEvent;
import java.net.URISyntaxException;
+import java.lang.reflect.Field;
/**
* A class which implements a cross-platform print dialog.
*
@@ -477,38 +478,74 @@
/**
* Returns message string from resource
*/
public static String getMsg(String key) {
try {
- return messageRB.getString(key);
+ return removeMnemonics(messageRB.getString(key));
} catch (java.util.MissingResourceException e) {
throw new Error("Fatal: Resource for ServiceUI is broken; " +
"there is no " + key + " key in resource");
}
}
+ private static String removeMnemonics(String s) {
+ int i = s.indexOf('&');
+ int len = s.length();
+ if (i < 0 || i == (len - 1)) {
+ return s;
+ }
+ int j = s.indexOf('&', i+1);
+ if (j == i+1) {
+ if (j+1 == len) {
+ return s.substring(0, i+1); // string ends with &&
+ } else {
+ return s.substring(0, i+1) + removeMnemonics(s.substring(j+1));
+ }
+ }
+ // ok first & not double &&
+ if (i == 0) {
+ return removeMnemonics(s.substring(1));
+ } else {
+ return (s.substring(0, i) + removeMnemonics(s.substring(i+1)));
+ }
+ }
+
+
/**
* Returns mnemonic character from resource
*/
private static char getMnemonic(String key) {
- String str = getMsg(key + ".mnemonic");
- if ((str != null) && (str.length() > 0)) {
- return str.charAt(0);
+ String str = messageRB.getString(key).replace("&&", "");
+ int index = str.indexOf('&');
+ if (0 <= index && index < str.length() - 1) {
+ char c = str.charAt(index + 1);
+ return Character.toUpperCase(c);
} else {
return (char)0;
}
}
/**
* Returns the mnemonic as a KeyEvent.VK constant from the resource.
*/
+ static Class _keyEventClazz = null;
private static int getVKMnemonic(String key) {
- String str = getMsg(key + ".vkMnemonic");
- if ((str != null) && (str.length() > 0)) {
+ String s = String.valueOf(getMnemonic(key));
+ if ( s == null || s.length() != 1) {
+ return 0;
+ }
+ String vkString = "VK_" + s.toUpperCase();
+
try {
- return Integer.parseInt(str);
- } catch (NumberFormatException nfe) {}
+ if (_keyEventClazz == null) {
+ _keyEventClazz= Class.forName("java.awt.event.KeyEvent",
+ true, (ServiceDialog.class).getClassLoader());
+ }
+ Field field = _keyEventClazz.getDeclaredField(vkString);
+ int value = field.getInt(null);
+ return value;
+ } catch (Exception e) {
}
return 0;
}
/**
< prev index next >