use of java.awt.im.spi.InputMethodDescriptor in project jdk8u_jdk by JetBrains.
the class ExecutableInputMethodManager method putPreferredInputMethod.
/**
* Writes the preferred input method descriptor class name into
* the user's Preferences tree in accordance with the given locale.
*
* @param inputMethodLocator input method locator to remember.
*/
private synchronized void putPreferredInputMethod(InputMethodLocator locator) {
InputMethodDescriptor descriptor = locator.getDescriptor();
Locale preferredLocale = locator.getLocale();
if (preferredLocale == null) {
// check available locales of the input method
try {
Locale[] availableLocales = descriptor.getAvailableLocales();
if (availableLocales.length == 1) {
preferredLocale = availableLocales[0];
} else {
// there is no way to know which locale is the preferred one, so do nothing.
return;
}
} catch (AWTException ae) {
// do nothing here, either.
return;
}
}
// "xx_YY" as "xx" when putting the preference into tree
if (preferredLocale.equals(Locale.JAPAN)) {
preferredLocale = Locale.JAPANESE;
}
if (preferredLocale.equals(Locale.KOREA)) {
preferredLocale = Locale.KOREAN;
}
if (preferredLocale.equals(new Locale("th", "TH"))) {
preferredLocale = new Locale("th");
}
// obtain node
String path = preferredIMNode + "/" + createLocalePath(preferredLocale);
// write in the preference tree
writePreferredInputMethod(path, descriptor.getClass().getName());
preferredLocatorCache.put(preferredLocale.toString().intern(), locator.deriveLocator(preferredLocale));
return;
}
use of java.awt.im.spi.InputMethodDescriptor in project jdk8u_jdk by JetBrains.
the class ExecutableInputMethodManager method getPreferredInputMethod.
/**
* Returns a InputMethodLocator object that the
* user prefers for the given locale.
*
* @param locale Locale for which the user prefers the input method.
*/
private synchronized InputMethodLocator getPreferredInputMethod(Locale locale) {
InputMethodLocator preferredLocator = null;
if (!hasMultipleInputMethods()) {
// No need to look for a preferred Java input method
return null;
}
// look for the cached preference first.
preferredLocator = preferredLocatorCache.get(locale.toString().intern());
if (preferredLocator != null) {
return preferredLocator;
}
// look for the preference in the user preference tree
String nodePath = findPreferredInputMethodNode(locale);
String descriptorName = readPreferredInputMethod(nodePath);
Locale advertised;
// get the locator object
if (descriptorName != null) {
// check for the host adapter first
if (hostAdapterLocator != null && hostAdapterLocator.getDescriptor().getClass().getName().equals(descriptorName)) {
advertised = getAdvertisedLocale(hostAdapterLocator, locale);
if (advertised != null) {
preferredLocator = hostAdapterLocator.deriveLocator(advertised);
preferredLocatorCache.put(locale.toString().intern(), preferredLocator);
}
return preferredLocator;
}
// look for Java input methods
for (int i = 0; i < javaInputMethodLocatorList.size(); i++) {
InputMethodLocator locator = javaInputMethodLocatorList.get(i);
InputMethodDescriptor descriptor = locator.getDescriptor();
if (descriptor.getClass().getName().equals(descriptorName)) {
advertised = getAdvertisedLocale(locator, locale);
if (advertised != null) {
preferredLocator = locator.deriveLocator(advertised);
preferredLocatorCache.put(locale.toString().intern(), preferredLocator);
}
return preferredLocator;
}
}
// maybe preferred input method information is bogus.
writePreferredInputMethod(nodePath, null);
}
return null;
}
use of java.awt.im.spi.InputMethodDescriptor in project jdk8u_jdk by JetBrains.
the class AWTInputMethodPopupMenu method addOneInputMethodToMenu.
void addOneInputMethodToMenu(InputMethodLocator locator, String currentSelection) {
InputMethodDescriptor descriptor = locator.getDescriptor();
String label = descriptor.getInputMethodDisplayName(null, Locale.getDefault());
String command = locator.getActionCommandString();
Locale[] locales = null;
int localeCount;
try {
locales = descriptor.getAvailableLocales();
localeCount = locales.length;
} catch (AWTException e) {
// ??? should have better error handling -
// tell user what happened, then remove this input method from the list.
// For the time being, just show it disabled.
localeCount = 0;
}
if (localeCount == 0) {
// could be IIIMP adapter which has lost its connection
addMenuItem(label, null, currentSelection);
} else if (localeCount == 1) {
if (descriptor.hasDynamicLocaleList()) {
// try to make sure that what the user sees and what
// we eventually select is consistent even if the locale
// list changes in the meantime
label = descriptor.getInputMethodDisplayName(locales[0], Locale.getDefault());
command = locator.deriveLocator(locales[0]).getActionCommandString();
}
addMenuItem(label, command, currentSelection);
} else {
Object submenu = createSubmenu(label);
add(submenu);
for (int j = 0; j < localeCount; j++) {
Locale locale = locales[j];
String subLabel = getLocaleName(locale);
String subCommand = locator.deriveLocator(locale).getActionCommandString();
addMenuItem(submenu, subLabel, subCommand, currentSelection);
}
}
}
Aggregations