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 22 Aug 2002 12:54:36 -0000 *************** *** 167,172 **** --- 167,243 ---- } } + /** Manages the cache mechanizm for localized mnemonics. + * Useful for Cyrrilic & Greek mnemonic letters. + * Now makes no caching, pending. (mihmax) + * @param localeChar localized mnemonic character + * @return latin accelerator VK, corresponding to the localized character. + */ + private static int getLatinVK(char localeChar) { + char upperLC = Character.toUpperCase(localeChar); + if (upperLC>='A' && upperLC<='Z') { + // it's latin character, returning the character itself + return (int) localeChar; + } + java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(Actions.class); + try { + String s = bundle.getString("MNEMONIC_" + localeChar); // NOI18N + if (s.length() == 1) { + // associated is a character + return (int)(s.charAt(0)); + } else { + // associated should be an integer + return Integer.parseInt(s); + } + } catch (java.util.MissingResourceException ex) { + // correspondence not found, returning the character itself + return (int) localeChar; + } + } + + /** JDK1.3-safe wrapper for the + AbstractButton.setDisplayedMnemonicIndex + method. + * @param item AbstractButton + * @param index Index of the Character to underline + * @param latinChar Latin Character to underline under JDK1.3 + */ + private static void wrapperSetDisplayedMnemonicIndex(AbstractButton item, int index, char latinChar) { + try { + java.lang.reflect.Method setDisplayedMnemonicIndex + = item.getClass(). + getMethod("setDisplayedMnemonicIndex", new Class[] {int.class}); + // JDK 1.4 - invoke + try { + setDisplayedMnemonicIndex.invoke(item, new Object[] {new Integer(index)}); + } + catch (IllegalAccessException x) { + wrapper13SetDisplayedMnemonicIndex(item, latinChar); + } + catch (IllegalArgumentException x) { + wrapper13SetDisplayedMnemonicIndex(item, latinChar); + } + catch (java.lang.reflect.InvocationTargetException x) { + wrapper13SetDisplayedMnemonicIndex(item, latinChar); + } + } + catch (NoSuchMethodException x) { + // if there's no such Method (on JDK 1.3), + // do alternate way + wrapper13SetDisplayedMnemonicIndex(item, latinChar); + } + } + + /** Under JDK 1.3 we add the latin " ()" + * to label and set the character as mnemonics + * @param item AbstractButton + * @param latinChar Latin Character to underline under JDK1.3 + */ + private static void wrapper13SetDisplayedMnemonicIndex(AbstractButton item, char latinChar) { + item.setText(item.getText()+" ("+latinChar+")"); + item.setMnemonic(latinChar); + } + /** Sets the text for the menu item or other subclass of AbstractButton. * Cut from the name '&' char. * @param item AbstractButton *************** *** 200,206 **** } else { item.setText(text.substring(0, i) + text.substring(i + 1)); if (useMnemonic) { ! item.setMnemonic(text.charAt(i + 1)); } } } --- 271,285 ---- } else { item.setText(text.substring(0, i) + text.substring(i + 1)); if (useMnemonic) { ! char ch = text.charAt(i + 1); ! int latinVK = getLatinVK(ch); ! if((int)ch==latinVK) { ! item.setMnemonic(ch); ! } ! else { ! item.setMnemonic (latinVK); ! wrapperSetDisplayedMnemonicIndex(item, i, (char)latinVK); ! } } } }