Index: openide/src/org/openide/awt/Actions.java =================================================================== RCS file: /cvs/openide/src/org/openide/awt/Actions.java,v retrieving revision 1.64 diff -c -r1.64 Actions.java *** openide/src/org/openide/awt/Actions.java 9 Jul 2002 14:40:37 -0000 1.64 --- openide/src/org/openide/awt/Actions.java 23 Aug 2002 19:37:48 -0000 *************** *** 200,210 **** } else { item.setText(text.substring(0, i) + text.substring(i + 1)); if (useMnemonic) { ! item.setMnemonic(text.charAt(i + 1)); } } } } /** Replaces the first occurence of &? by ? or (&?? by the empty string * where ? is a wildcard for any character. --- 200,276 ---- } else { item.setText(text.substring(0, i) + text.substring(i + 1)); if (useMnemonic) { ! char ch = text.charAt(i + 1); ! if ((ch>='A' && ch<='Z') || (ch>='a' && ch<='z') || ! (ch>='0' && ch<='9')) { ! // it's latin character or arabic digit, ! // setting it as mnemonics ! item.setMnemonic(ch); ! } else { ! char latinChar = getLatinKeyboardChar(ch); ! item.setMnemonic (latinChar); ! setDisplayedMnemonicIndex(item, i, latinChar); ! } } } } } + + /** 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. + * @param localeChar non-Latin character to be used as mnemonic + * @return character on latin keyboard, corresponding to the locale character. + */ + private static char getLatinKeyboardChar(char localeChar) { + try { + // associated should be a latin character, arabic digit + // or US-keyboard punctuation + return org.openide.util.NbBundle.getBundle(Actions.class) + .getString("MNEMONIC_" + localeChar).charAt(0); // NOI18N + } catch (java.util.MissingResourceException ex) { + // correspondence not found, returning the character itself + return localeChar; + } + } + + /** holds instance of Actions14 or plain object if not on JDK1.4 */ + private static Object actions14; + /** Wrapper for the + * AbstractButton.setDisplayedMnemonicIndex method. + *
  • Under JDK1.4 calls the method on item + *
  • Under JDK1.3 adds the " (<latin character>)" + * to label and sets the latin character as mnemonics + * @param item AbstractButton or it's subclass + * @param index Index of the Character to underline under JDK1.4 + * @param latinChar Latin Character to underline under JDK1.3 + */ + private static void setDisplayedMnemonicIndex (AbstractButton item, int index, char latinChar) { + if (org.openide.modules.Dependency.JAVA_SPEC.compareTo ( + new org.openide.modules.SpecificationVersion("1.4") + ) >= 0) { // NOI18N + if (actions14 == null) { + try { + Class c = Class.forName ("org.openide.awt.Actions14"); + actions14 = c.newInstance (); + } catch (Exception ex) { + ErrorManager.getDefault().notify(ex); + actions14 = ex; + } + } + + if (actions14 instanceof java.util.Map.Entry) { + ((java.util.Map.Entry)actions14).setValue(new Object[] { + item, new Integer (index) + }); + } + } else { + // under JDK 1.3 + item.setText(item.getText()+" ("+latinChar+")"); + item.setMnemonic(latinChar); + } + } /** Replaces the first occurence of &? by ? or (&?? by the empty string * where ? is a wildcard for any character.