当前位置: 首页>>代码示例>>Java>>正文


Java InputMethodDescriptor.getAvailableLocales方法代码示例

本文整理汇总了Java中java.awt.im.spi.InputMethodDescriptor.getAvailableLocales方法的典型用法代码示例。如果您正苦于以下问题:Java InputMethodDescriptor.getAvailableLocales方法的具体用法?Java InputMethodDescriptor.getAvailableLocales怎么用?Java InputMethodDescriptor.getAvailableLocales使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.im.spi.InputMethodDescriptor的用法示例。


在下文中一共展示了InputMethodDescriptor.getAvailableLocales方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addOneInputMethodToMenu

import java.awt.im.spi.InputMethodDescriptor; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:InputMethodPopupMenu.java

示例2: getIMInstance

import java.awt.im.spi.InputMethodDescriptor; //导入方法依赖的package包/类
/**
 * Gets input method instance for the given
 * locale from the given list of descriptors
 * @param descriptors iterator of the list of IM descriptors
 * @param locale the locale to be supported by the IM
 * @return input method instance
 * @throws Exception
 */
private InputMethod getIMInstance(Iterator<InputMethodDescriptor> descriptors,
                                  Locale locale) throws Exception {
    while (descriptors.hasNext()) {
        InputMethodDescriptor desc = descriptors.next();
        Locale[] locs = desc.getAvailableLocales();
        for (Locale element : locs) {
            if (locale.equals(element)) {
                return getIMInstance(desc);
            }
        }
    }
    return null;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:InputMethodContext.java

示例3: putPreferredInputMethod

import java.awt.im.spi.InputMethodDescriptor; //导入方法依赖的package包/类
/**
 * Writes the preferred input method descriptor class name into
 * the user's Preferences tree in accordance with the given locale.
 *
 * @param locator 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;
        }
    }

    // for regions that have only one language, we need to regard
    // "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;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:49,代码来源:ExecutableInputMethodManager.java

示例4: putPreferredInputMethod

import java.awt.im.spi.InputMethodDescriptor; //导入方法依赖的package包/类
/**
 * 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;
        }
    }

    // for regions that have only one language, we need to regard
    // "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;
}
 
开发者ID:JetBrains,项目名称:jdk8u_jdk,代码行数:49,代码来源:ExecutableInputMethodManager.java


注:本文中的java.awt.im.spi.InputMethodDescriptor.getAvailableLocales方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。