Java Code Examples for java.util.Locale.getISO3Country()

The following are Jave code examples for showing how to use getISO3Country() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Protestr   File: LocaleUtils.java   View Source Code Vote up 6 votes
private static void initIso3Locales() {
    filteredIso3Locales = new HashMap<>();
    for (Locale locale : LOCALES) {
        final String country = locale.getDisplayCountry();
        if (country.length() == 0)
            continue;
        final String iso3Locale;
        try {
            iso3Locale = locale.getISO3Country();
        } catch (MissingResourceException mre) {
            continue;
        }
        filteredIso3Locales.put(iso3Locale, country);
    }
    filteredIso3Locales = sortHashMapByValues(filteredIso3Locales);
}
 
Example 2
Project: jdk8u-jdk   File: LocaleTest.java   View Source Code Vote up 5 votes
/**
 * @bug 4147315
 * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
 * Should throw an exception for unknown locales
 */
public void Test4147315() {
    // Try with codes that are the wrong length but happen to match text
    // at a valid offset in the mapping table
    Locale locale = new Locale("aaa", "CCC");

    try {
        String result = locale.getISO3Country();

        errln("ERROR: getISO3Country() returns: " + result +
            " for locale '" + locale + "' rather than exception" );
    } catch(MissingResourceException e) { }
}
 
Example 3
Project: openjdk-jdk10   File: LocaleTest.java   View Source Code Vote up 5 votes
/**
 * @bug 4147315
 * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
 * Should throw an exception for unknown locales
 */
public void Test4147315() {
    // Try with codes that are the wrong length but happen to match text
    // at a valid offset in the mapping table
    Locale locale = new Locale("aaa", "CCC");

    try {
        String result = locale.getISO3Country();

        errln("ERROR: getISO3Country() returns: " + result
                + " for locale '" + locale + "' rather than exception");
    } catch (MissingResourceException e) {
    }
}
 
Example 4
Project: appinventor-extensions   File: TextToSpeech.java   View Source Code Vote up 5 votes
/**
 * Get list of available languages for TextToSpeech.  Do not call unless the TTS
 * engine is initialized.
 *
 */
private void getLanguageAndCountryLists() {
  // We do compute these lists pre-Donut.  We probably could
  // arrange to also do this in earlier releases, but that would be
  // relying on the use of an external textToSpeech application and those
  // old releases are obsolete anyway.
  if (SdkLevel.getLevel() >= SdkLevel.LEVEL_DONUT) {
    String tempLang;
    String tempCountry;
    for (Locale locale : Locale.getAvailableLocales()) {
      // isLanguageAvailable requires tts to be initialized
      int res = tts.isLanguageAvailable(locale);
      if (!(res == android.speech.tts.TextToSpeech.LANG_NOT_SUPPORTED)){
        tempLang = locale.getLanguage();
        // We record only the ISO3 country codes for now.  We should update the TTS control
        // to use voices, and then we can straighten this out, maybe getting rid of
        // country modifiers in TTS altogether.
        tempCountry = locale.getISO3Country();
        if (!tempLang.equals("") && (!languageList.contains(tempLang))){
          languageList.add(tempLang);
        }
        if (!tempCountry.equals("") && (!countryList.contains(tempCountry))){
          countryList.add(tempCountry);
        }
      }
    }
    Collections.sort(languageList);
    Collections.sort(countryList);
    allLanguages = YailList.makeList(languageList);
    allCountries = YailList.makeList(countryList);
  }
}
 
Example 5
Project: MapAnalyst   File: GUIUtil.java   View Source Code Vote up 4 votes
/**
 * Adds support for plus and minus menu commands, typically for zooming in
 * and out. This is designed for menu items with key accelerators using
 * KeyEvent.VK_ADD and KeyEvent.VK_SUBTRACT (which are typically on the
 * numerical key pad). It adds support for KeyEvent.VK_MINUS and
 * KeyEvent.VK_PLUS, and KeyEvent.VK_EQUALS for keyboard layouts with the
 * plus sign as secondary key for the equals.
 *
 * @param inputMap add key event to this InputMap
 * @param actionMap add action to this ActionMap
 * @param zoomInAction action to call when the + key and the menu shortcut
 * key are pressed
 * @param zoomOutAction action to call when the - key and the menu shortcut
 * key are pressed
 */
public static void zoomMenuCommands(InputMap inputMap, ActionMap actionMap, Action zoomInAction, Action zoomOutAction) {
    int menuKeyMask = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    // add support for minus key
    KeyStroke minusMenueKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_MINUS, menuKeyMask);
    inputMap.put(minusMenueKeyStroke, "zoomOutWithMinusKey");
    actionMap.put("zoomOutWithMinusKey", zoomOutAction);

    // add support for plus key to zoom in. This only works if the keyboard 
    // layout allows access to the plus character without pressing the shift 
    // key, which is not the case for US and UK keyboards.
    KeyStroke plusMenuKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_PLUS, menuKeyMask);
    inputMap.put(plusMenuKeyStroke, "zoomInWithPlusKey");
    actionMap.put("zoomInWithPlusKey", zoomInAction);

    // add support for cases where the plus character is the secondary 
    // character for the equal sign key. That is, plus is accessed by pressing
    // the shift key and the equal key. This is the case for US and UK 
    // keyboard layouts, which are also used in Ireland, India, Australia, Canada,
    // Hong Kong, New Zealand, South Africa, Malaysia, Singapore and Philippines.
    // See https://stackoverflow.com/questions/15605109/java-keybinding-plus-key
    // and https://en.wikipedia.org/wiki/QWERTY
    // The French Canadian keyboard also has = and + on the same key.
    Locale locale = InputContext.getInstance().getLocale();
    String isoCountry = locale.getISO3Country();
    // https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
    if ("USA".equals(isoCountry)
            || "GBR".equals(isoCountry)
            || "IRL".equals(isoCountry)
            || "IND".equals(isoCountry)
            || "AUS".equals(isoCountry)
            || "CAN".equals(isoCountry)
            || "HKG".equals(isoCountry)
            || "NZL".equals(isoCountry)
            || "ZAF".equals(isoCountry)
            || "MYS".equals(isoCountry)
            || "SGP".equals(isoCountry)
            || "PHL".equals(isoCountry)) {
        KeyStroke euqalsMenuKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_EQUALS, menuKeyMask);
        inputMap.put(euqalsMenuKeyStroke, "zoomInWithEqualsKey");
        actionMap.put("zoomInWithEqualsKey", zoomInAction);
    }
}