コード例 #1
0
ファイル: LocaleTest.java プロジェクト: OzkanCiftci/jdk7u-jdk
  private void doTestDisplayNames(Locale inLocale, int compareIndex, boolean defaultIsFrench) {
    if (defaultIsFrench && !Locale.getDefault().getLanguage().equals("fr"))
      errln(
          "Default locale should be French, but it's really " + Locale.getDefault().getLanguage());
    else if (!defaultIsFrench && !Locale.getDefault().getLanguage().equals("en"))
      errln(
          "Default locale should be English, but it's really " + Locale.getDefault().getLanguage());

    for (int i = 0; i <= MAX_LOCALES; i++) {
      Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
      logln("  Testing " + testLocale + "...");

      String testLang;
      String testCtry;
      String testVar;
      String testName;

      if (inLocale == null) {
        testLang = testLocale.getDisplayLanguage();
        testCtry = testLocale.getDisplayCountry();
        testVar = testLocale.getDisplayVariant();
        testName = testLocale.getDisplayName();
      } else {
        testLang = testLocale.getDisplayLanguage(inLocale);
        testCtry = testLocale.getDisplayCountry(inLocale);
        testVar = testLocale.getDisplayVariant(inLocale);
        testName = testLocale.getDisplayName(inLocale);
      }

      String expectedLang;
      String expectedCtry;
      String expectedVar;
      String expectedName;

      expectedLang = dataTable[compareIndex][i];
      if (expectedLang.equals("") && defaultIsFrench) expectedLang = dataTable[DLANG_EN][i];
      if (expectedLang.equals("")) expectedLang = dataTable[DLANG_ROOT][i];

      expectedCtry = dataTable[compareIndex + 1][i];
      if (expectedCtry.equals("") && defaultIsFrench) expectedCtry = dataTable[DCTRY_EN][i];
      if (expectedCtry.equals("")) expectedCtry = dataTable[DCTRY_ROOT][i];

      expectedVar = dataTable[compareIndex + 2][i];
      if (expectedVar.equals("") && defaultIsFrench) expectedVar = dataTable[DVAR_EN][i];
      if (expectedVar.equals("")) expectedVar = dataTable[DVAR_ROOT][i];

      expectedName = dataTable[compareIndex + 3][i];
      if (expectedName.equals("") && defaultIsFrench) expectedName = dataTable[DNAME_EN][i];
      if (expectedName.equals("")) expectedName = dataTable[DNAME_ROOT][i];

      if (!testLang.equals(expectedLang))
        errln("Display language mismatch: " + testLang + " versus " + expectedLang);
      if (!testCtry.equals(expectedCtry))
        errln("Display country mismatch: " + testCtry + " versus " + expectedCtry);
      if (!testVar.equals(expectedVar))
        errln("Display variant mismatch: " + testVar + " versus " + expectedVar);
      if (!testName.equals(expectedName))
        errln("Display name mismatch: " + testName + " versus " + expectedName);
    }
  }
コード例 #2
0
ファイル: ListFiles.java プロジェクト: sumantmurke/java
  public static void DateFormatWithLocale() {
    Calendar c = Calendar.getInstance();
    c.set(2011, 12, 31);
    Date d = c.getTime();

    Locale l1 = new Locale("en", "US");
    Locale l2 = new Locale("it", "IT");
    Locale l3 = Locale.CHINA;

    DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, l1);
    DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, l2);
    DateFormat df3 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, l3);

    p("df1=", df1.format(d));
    p("df2=", df2.format(d));
    p("df3=", df3.format(d));
    p("l1 ", l1.getDisplayLanguage(), l1.getDisplayCountry());
    p("l1.l2 ", l1.getDisplayLanguage(l2), l1.getDisplayCountry(l2));
    p("l1.l3 ", l1.getDisplayLanguage(l3), l1.getDisplayCountry(l3));

    p("l1.l3 ", l2.getDisplayLanguage(l3), l2.getDisplayCountry(l3));

    p("l3 ", l3.getDisplayLanguage(l3), l3.getDisplayCountry(l3));
    p("l3.l1 ", l3.getDisplayLanguage(l1), l3.getDisplayCountry(l1));
    p("l1.l2 ", l3.getDisplayLanguage(l2), l3.getDisplayCountry(l2));
  }
コード例 #3
0
  @Test
  public void getCountryInformation() {
    Locale locBR = new Locale("pt", "BR");
    assertEquals(locBR.getDisplayCountry(), __);
    assertEquals(locBR.getDisplayCountry(locBR), __);

    Locale locCH = new Locale("it", "CH");
    assertEquals(locCH.getDisplayCountry(), __);
    assertEquals(locCH.getDisplayCountry(locCH), __);
    assertEquals(locCH.getDisplayCountry(new Locale("de", "CH")), __);
  }
コード例 #4
0
ファイル: AboutLocale.java プロジェクト: kl0211/CS410J
  @Koan
  public void getCountryInformation() {
    Locale locBR = new Locale("pt", "BR");
    assertEquals(locBR.getDisplayCountry(), "Brazil");
    assertEquals(locBR.getDisplayCountry(locBR), "Brasil");

    Locale locCH = new Locale("it", "CH");
    assertEquals(locCH.getDisplayCountry(), "Switzerland");
    assertEquals(locCH.getDisplayCountry(locCH), "Svizzera");
    assertEquals(locCH.getDisplayCountry(new Locale("de", "CH")), "Schweiz");
  }
コード例 #5
0
  public static final String getLocaleValue(boolean isRegion) {
    java.util.Locale locale = java.util.Locale.getDefault();

    return isRegion
        ? locale.getDisplayCountry(java.util.Locale.US)
        : locale.getDisplayLanguage(java.util.Locale.US);
  }
コード例 #6
0
ファイル: User.java プロジェクト: aazim/Casper
 /**
  * Returns the country from which the client is from based on the default Locale. If it encounters
  * any errors in retrieving the locale, it will reply with the ISO 3166 2-digit code.
  *
  * @return The language's country.
  */
 public static String getCountry() {
   try {
     return locale.getDisplayCountry();
   } catch (Exception ignored) {
     return System.getProperty("user.country");
   }
 }
コード例 #7
0
  public static List<KeyValue> getCountries() {
    String[] isoCountryCodes = Locale.getISOCountries();
    List<KeyValue> countries = new ArrayList<>();
    for (String countryCode : isoCountryCodes) {
      Locale locale = new Locale("", countryCode);
      String countryName = locale.getDisplayCountry();
      String regionCode = locale.getCountry();
      countries.add(new KeyValue(regionCode, countryName));
    }

    //        Locale[] locales = Locale.getAvailableLocales();
    //        for (Locale locale : locales)
    //        {
    //            String code = locale.getCountry();
    //            String country = locale.getDisplayCountry();
    //            if (code.trim().length() > 0 && !code.contains(code) && country.trim().length() >
    // 0 && !countries.contains(country))
    //            {
    //                countries.add(new KeyValue(code, country));
    //            }
    //        }

    Collections.sort(countries, new KeyValueComparator());
    countries.add(0, new KeyValue("", "Any"));
    return countries;
  }
コード例 #8
0
ファイル: I18nImpl.java プロジェクト: 85625891/freedomotic
  @Override
  public Vector<ComboLanguage> getAvailableLocales() {
    final String bundlename = "freedomotic";
    languages.clear();
    File root = new File(Info.getApplicationPath() + File.separator + "i18n");
    File[] files =
        root.listFiles(
            new FilenameFilter() {
              @Override
              public boolean accept(File dir, String name) {
                return name.matches("^" + bundlename + "(_\\w{2}(_\\w{2})?)?\\.properties$");
              }
            });

    for (File file : files) {
      String value = file.getName().replaceAll("^" + bundlename + "(_)?|\\.properties$", "");

      if (!value.isEmpty()) {
        Locale loc = new Locale(value.substring(0, 2), value.substring(3, 5));
        languages.add(
            new ComboLanguage(
                loc.getDisplayCountry(currentLocale) + " - " + loc.getDisplayLanguage(loc),
                value,
                loc));
      }
    }
    Collections.sort(languages);
    languages.add(new ComboLanguage("Automatic", "auto", Locale.ENGLISH));
    return languages;
  }
コード例 #9
0
ファイル: Localizer.java プロジェクト: Toxic-Lab/DroidG
 public static String getCountryName(String countryCode) {
   String countryName = countryNameCache.get(countryCode);
   if (countryName == null) {
     Locale l = new Locale("", countryCode);
     countryName = l.getDisplayCountry(usedLocale);
     countryNameCache.put(countryCode, countryName);
   }
   return countryName;
 }
コード例 #10
0
 private String getLocaleItemCaption(Locale l) {
   String country = l.getDisplayCountry(getLocale());
   String language = l.getDisplayLanguage(getLocale());
   StringBuilder caption = new StringBuilder(country);
   if (caption.length() != 0) {
     caption.append(", ");
   }
   caption.append(language);
   return caption.toString();
 }
コード例 #11
0
  public List<String> dajVsetkyKrajiny() {
    String[] lokaly = Locale.getISOCountries();
    List<String> krajiny = new ArrayList<String>();
    for (String kodKrajiny : lokaly) {
      Locale lokal = new Locale("", kodKrajiny);
      krajiny.add(lokal.getDisplayCountry());
    }

    return krajiny;
  }
コード例 #12
0
ファイル: LocaleTest.java プロジェクト: ZeerDonker/robovm
  // http://b/2611311; if there's no display language/country/variant, use the raw codes.
  public void test_getDisplayName_unknown() throws Exception {
    Locale unknown = new Locale("xx", "YY", "Traditional");
    assertEquals("xx", unknown.getLanguage());
    assertEquals("YY", unknown.getCountry());
    assertEquals("Traditional", unknown.getVariant());

    assertEquals("xx", unknown.getDisplayLanguage());
    assertEquals("YY", unknown.getDisplayCountry());
    assertEquals("TRADITIONAL", unknown.getDisplayVariant());
    assertEquals("xx (YY,TRADITIONAL)", unknown.getDisplayName());
  }
コード例 #13
0
 @SuppressWarnings("unchecked")
 public static List<SelectItemOption<String>> getLocaleSelectBoxOptions(Locale[] locale) {
   List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>();
   for (Locale local : locale) {
     String country = local.getISO3Country();
     if (country != null && country.trim().length() > 0)
       options.add(
           new SelectItemOption<String>(
               local.getDisplayCountry() + "(" + local.getDisplayLanguage() + ")", country));
   }
   Collections.sort(options, new SelectComparator());
   return options;
 }
コード例 #14
0
ファイル: ProfileComponent.java プロジェクト: RobDaykin/Cuppy
 private void fillCombo(final Combobox combo, final Locale curLocale) {
   if (combo.getItemCount() == 0) {
     final Locale currentLocale = UISessionUtils.getCurrentSession().getLocale();
     for (final Locale locale : getPlayerFacade().getAllCountries()) {
       final Comboitem item = new Comboitem(locale.getDisplayCountry(currentLocale));
       item.setValue(locale);
       combo.appendChild(item);
       if (curLocale.getCountry().equals(locale.getCountry())) {
         combo.setSelectedItem(item);
       }
     }
   }
 }
コード例 #15
0
  /**
   * Available locales
   *
   * @return
   */
  public static List<Locale> getAvailableLocales() {
    List<Locale> locales = new ArrayList<Locale>();

    for (Locale locale : Locale.getAvailableLocales()) {
      if (!StringUtils.isBlank(locale.getDisplayCountry())) {
        locales.add(locale);
      }
    }

    Collections.sort(locales, new LocaleComparator(LocaleComparator.CompareType.COUNTRY));

    return locales;
  }
コード例 #16
0
 @Test
 public void testListAllCountries() {
   for (final Locale aLocale :
       CollectionHelper.getSorted(
           Locale.getAvailableLocales(), new CollatingComparatorLocaleCountry(Locale.US)))
     if (aLocale.getCountry().length() > 0)
       s_aLogger.info(
           aLocale.getCountry()
               + " "
               + aLocale.getDisplayCountry()
               + " ("
               + aLocale.toString()
               + ")");
 }
コード例 #17
0
ファイル: LocaleTest.java プロジェクト: ZeerDonker/robovm
  // http://b/2611311; if there's no display language/country/variant, use the raw codes.
  public void test_getDisplayName_invalid() throws Exception {
    Locale invalid = new Locale("AaBbCc", "DdEeFf", "GgHhIi");

    assertEquals("aabbcc", invalid.getLanguage());
    assertEquals("DDEEFF", invalid.getCountry());
    assertEquals("GgHhIi", invalid.getVariant());

    // Android using icu4c < 49.2 returned empty strings for display language, country,
    // and variant, but a display name made up of the raw strings.
    // Newer releases return slightly different results, but no less unreasonable.
    assertEquals("aabbcc", invalid.getDisplayLanguage());
    assertEquals("", invalid.getDisplayCountry());
    assertEquals("DDEEFF_GGHHII", invalid.getDisplayVariant());
    assertEquals("aabbcc (DDEEFF,DDEEFF_GGHHII)", invalid.getDisplayName());
  }
コード例 #18
0
 @Override
 protected List<ILookupRow<String>> execCreateLookupRows() throws ProcessingException {
   TreeMap<String, ILookupRow<String>> sortMap = new TreeMap<String, ILookupRow<String>>();
   ISpellCheckerService sc = SERVICES.getService(ISpellCheckerService.class);
   if (sc != null) {
     for (String lang : sc.getAvailableLanguages()) {
       Locale loc = NlsUtility.parseLocale(lang);
       sortMap.put(
           lang,
           new LookupRow<String>(
               lang, loc.getDisplayLanguage() + " (" + loc.getDisplayCountry() + ")"));
     }
   }
   return new ArrayList<ILookupRow<String>>(sortMap.values());
 }
コード例 #19
0
 static String a(Address paramAddress) {
   Locale localLocale = paramAddress.getLocale();
   Object localObject2 = paramAddress.getCountryName();
   Object localObject1 = localObject2;
   if (TextUtils.isEmpty((CharSequence) localObject2)) {
     localObject1 = localLocale.getDisplayCountry(localLocale);
   }
   localObject2 = localObject1;
   if (TextUtils.isEmpty((CharSequence) localObject1)) {
     localObject2 = localLocale.getISO3Country();
   }
   localObject1 = localObject2;
   if (TextUtils.isEmpty((CharSequence) localObject2)) {
     localObject1 = paramAddress.getCountryCode();
   }
   return (String) localObject1;
 }
コード例 #20
0
  public void printAvailableLocales(OutputStream os) throws Exception {
    Locale[] locales = Locale.getAvailableLocales();

    String name = null, country = null, lang = null, currencySb = null;
    String countryCd = null, langCd = null, currencyCd = null;
    Currency currency = null;

    PrintWriter pw = null;

    try {
      pw = new PrintWriter(os, true);

      for (Locale locale : locales) {
        name = locale.getDisplayName();
        country = locale.getDisplayCountry();
        countryCd = locale.getISOCountries()[0];
        lang = locale.getDisplayLanguage();
        langCd = locale.getISOLanguages()[0];

        try {
          currency = Currency.getInstance(locale);
          currencySb = currency.getSymbol();
          currencyCd = currency.getCurrencyCode();
        } catch (IllegalArgumentException ex) {
          currencySb = "";
          currencyCd = "";
        }

        pw.print("name : " + name + ", ");
        pw.print("country : " + country + "(" + countryCd + "), ");
        pw.print("lang : " + lang + "(" + langCd + "), ");
        pw.println("currency : " + currencySb + "(" + currencyCd + ")");
      }
    } catch (Exception ex) {
      throw ex;
    } finally {
      if (pw != null && os != (OutputStream) (System.out)) pw.close();
    }
  }
コード例 #21
0
  /**
   * render display string for an ISO3 location name.
   *
   * @param locationName - ISO3 location name
   * @return display string that contains display country name and display language name. For
   *     example, output for "VNM" would be "Vietnam(Vietnamese)".
   */
  public static String getLocationDisplayString(String locationName) {
    Locale[] avai = Locale.getAvailableLocales();
    Locale locale = null;
    for (Locale l : avai) {
      try {
        if (l.getISO3Country().equalsIgnoreCase(locationName)) {
          locale = l;
          break;
        }
      } catch (MissingResourceException ex) {
        log.debug(
            "Three-letter country abbreviation is not available for locale: " + l.getDisplayName(),
            ex);
      }
    }

    if (locale != null) {
      String country = locale.getISO3Country();
      if (country != null && country.trim().length() > 0)
        return locale.getDisplayCountry() + "(" + locale.getDisplayLanguage() + ")";
    }
    return locationName;
  }
コード例 #22
0
ファイル: CountryTag.java プロジェクト: nvchien1407/slapulse
  /**
   * Build a List of LabelValues for all the available countries. Uses the two letter uppercase ISO
   * name of the country as the value and the localized country name as the label.
   *
   * @param locale The Locale used to localize the country names.
   * @return List of LabelValues for all available countries.
   */
  protected List<LabelValue> buildCountryList(Locale locale) {
    final String EMPTY = "";
    final Locale[] available = Locale.getAvailableLocales();

    List<LabelValue> countries = new ArrayList<LabelValue>();

    for (Locale anAvailable : available) {
      final String iso = anAvailable.getCountry();
      final String name = anAvailable.getDisplayCountry(locale);

      if (!EMPTY.equals(iso) && !EMPTY.equals(name)) {
        LabelValue country = new LabelValue(name, iso);

        if (!countries.contains(country)) {
          countries.add(new LabelValue(name, iso));
        }
      }
    }

    Collections.sort(countries, new LabelValueComparator(locale));

    return countries;
  }
コード例 #23
0
  /**
   * Build a List of LabelValues for all the available countries. Uses the two letter uppercase ISO
   * name of the country as the value and the localized country name as the label.
   *
   * @param locale The Locale used to localize the country names.
   * @return List of LabelValues for all available countries.
   */
  @SuppressWarnings("unchecked")
  public Map<String, String> getCountries(Locale locale) {
    if (availableCountries == null) {
      final String EMPTY = "";
      final Locale[] available = Locale.getAvailableLocales();

      List<LabelValue> countries = new ArrayList<LabelValue>();
      countries.add(new LabelValue("", ""));

      for (Locale anAvailable : available) {
        final String iso = anAvailable.getCountry();
        final String name = anAvailable.getDisplayCountry(locale);

        if (!EMPTY.equals(iso) && !EMPTY.equals(name)) {
          LabelValue country = new LabelValue(name, iso);

          if (!countries.contains(country)) {
            countries.add(new LabelValue(name, iso));
          }
        }
      }

      Collections.sort(countries, new LabelValueComparator(locale));

      Map<String, String> options = new LinkedHashMap<String, String>();
      // loop through and convert list to a JSF-Friendly Map for a <select>
      for (Object country : countries) {
        LabelValue option = (LabelValue) country;
        if (!options.containsValue(option.getValue())) {
          options.put(option.getLabel(), option.getValue());
        }
      }
      this.availableCountries = options;
    }

    return availableCountries;
  }
コード例 #24
0
  @ModelAttribute("billingCountries")
  public List<SelectOption> getBillingCountries() {
    final List<SelectOption> countries = new ArrayList<SelectOption>();
    final Locale[] locales = Locale.getAvailableLocales();
    final Map<String, String> countryMap = new HashMap<String, String>();

    for (final Locale locale : locales) {
      final String code = locale.getCountry();
      final String name = locale.getDisplayCountry();

      // putting in a map to remove duplicates
      if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(name)) {
        countryMap.put(code, name);
      }
    }

    for (final String key : countryMap.keySet()) {
      countries.add(new SelectOption(key, countryMap.get(key)));
    }

    Collections.sort(countries, CountryComparator.INSTANCE);

    return countries;
  }
コード例 #25
0
ファイル: TLocale.java プロジェクト: Syn4ck/jdownloader
  public String toString() {
    boolean hasVariant = locale.getVariant().length() > 0;
    boolean hasCountry = locale.getCountry().length() > 0;

    final StringBuilder sb = new StringBuilder();
    sb.append(locale.getDisplayLanguage(Locale.ENGLISH));
    if (hasVariant || hasCountry) {
      sb.append(" (");
    }

    if (hasCountry) {
      sb.append(locale.getDisplayCountry(Locale.ENGLISH));
    }

    if (hasVariant) {
      if (hasCountry) sb.append(", ");
      sb.append(locale.getDisplayVariant(Locale.ENGLISH));
    }

    if (hasVariant || hasCountry) {
      sb.append(")");
    }
    return sb.toString();
  }
コード例 #26
0
  public void main(IWContext iwc) throws Exception {
    // TODO eiki cache countries
    // some caching made by aron
    super.main(iwc);
    // System.out.println( "country dropdown main start "+
    // com.idega.util.IWTimestamp.RightNow().toString());
    List localeCountries = Arrays.asList(Locale.getISOCountries());

    // List locales = Arrays.asList( java.util.Locale.getAvailableLocales());
    // List locales = ICLocaleBusiness.listOfAllLocalesJAVA();
    Locale currentLocale = iwc.getCurrentLocale();

    // Iterator iter = locales.iterator();
    Iterator iter = localeCountries.iterator();

    Country country = null;
    String countryDisplayName = null;
    Map countries = new HashMap();
    String lang = currentLocale.getISO3Language();
    Locale locale;
    List smallCountries = new Vector();
    // CountryHome countryHome = getAddressBusiness(iwc).getCountryHome();
    while (iter.hasNext()) {
      // Locale locale = (Locale) iter.next();

      String ISOCountry = (String) iter.next();
      try {
        locale = new Locale(lang, ISOCountry);

        countryDisplayName = locale.getDisplayCountry(currentLocale);
        // country = countryHome.findByIsoAbbreviation(locale.getCountry());
        country = getCountryByISO(locale.getCountry());

        if (countryDisplayName != null
            && country != null
            && !countries.containsKey(country.getPrimaryKey())) {
          countries.put(country.getPrimaryKey(), country); // cache
          SmallCountry sCountry =
              new SmallCountry(
                  (Integer) country.getPrimaryKey(), countryDisplayName, ISOCountry, currentLocale);
          smallCountries.add(sCountry);
          // addMenuElement(((Integer)country.getPrimaryKey()).intValue(),countryDisplayName);
        }
      } catch (Exception e1) {
        // e1.printStackTrace();
      }
    }
    Collections.sort(smallCountries);

    for (Iterator iterator = smallCountries.iterator(); iterator.hasNext(); ) {
      SmallCountry sCountry = (SmallCountry) iterator.next();
      // we dont want the ISO code into the list
      if (!sCountry.name.equalsIgnoreCase(sCountry.code)) {
        addMenuElement(sCountry.getID().intValue(), sCountry.getName());
      }
    }

    try {
      if (!StringUtil.isEmpty(this.selectedCountryName)) {
        this.selectedCountry =
            getAddressBusiness(iwc).getCountryHome().findByCountryName(this.selectedCountryName);
      }
      // we must ensure no external selected country is set
      else if (this.selectedCountry == null && !StringUtil.isEmpty(currentLocale.getCountry())) {
        this.selectedCountry =
            getAddressBusiness(iwc)
                .getCountryHome()
                .findByIsoAbbreviation(currentLocale.getCountry());
      }
    } catch (RemoteException e) {
      e.printStackTrace();
    } catch (EJBException e) {
      e.printStackTrace();
    } catch (FinderException e) {
      e.printStackTrace();
    }

    if (this.selectedCountry != null) {
      setSelectedElement(((Integer) this.selectedCountry.getPrimaryKey()).intValue());
    }
    // System.out.println( "country dropdown main end "+
    // com.idega.util.IWTimestamp.RightNow().toString());
  }
コード例 #27
0
  private void recreateEditorsPanel() {
    myValuesPanel.removeAll();
    myValuesPanel.setLayout(new CardLayout());

    if (!myProject.isOpen()) return;
    JPanel valuesPanelComponent = new MyJPanel(new GridBagLayout());
    myValuesPanel.add(
        new JBScrollPane(valuesPanelComponent) {
          @Override
          public void updateUI() {
            super.updateUI();
            getViewport().setBackground(UIUtil.getPanelBackground());
          }
        },
        VALUES);
    myValuesPanel.add(myNoPropertySelectedPanel, NO_PROPERTY_SELECTED);

    List<PropertiesFile> propertiesFiles = myResourceBundle.getPropertiesFiles();

    GridBagConstraints gc =
        new GridBagConstraints(
            0,
            0,
            0,
            0,
            0,
            0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0);
    releaseAllEditors();
    myTitledPanels.clear();
    int y = 0;
    Editor previousEditor = null;
    Editor firstEditor = null;
    for (final PropertiesFile propertiesFile : propertiesFiles) {
      final Editor editor = createEditor();
      final Editor oldEditor = myEditors.put(propertiesFile, editor);
      if (firstEditor == null) {
        firstEditor = editor;
      }
      if (previousEditor != null) {
        editor.putUserData(
            ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor);
        previousEditor.putUserData(
            ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, editor);
      }
      previousEditor = editor;
      if (oldEditor != null) {
        EditorFactory.getInstance().releaseEditor(oldEditor);
      }
      ((EditorEx) editor)
          .addFocusListener(
              new FocusChangeListener() {
                @Override
                public void focusGained(final Editor editor) {
                  mySelectedEditor = editor;
                }

                @Override
                public void focusLost(final Editor eventEditor) {
                  writeEditorPropertyValue(editor, propertiesFile, null);
                }
              });
      gc.gridx = 0;
      gc.gridy = y++;
      gc.gridheight = 1;
      gc.gridwidth = GridBagConstraints.REMAINDER;
      gc.weightx = 1;
      gc.weighty = 1;
      gc.anchor = GridBagConstraints.CENTER;

      Locale locale = propertiesFile.getLocale();
      List<String> names = new ArrayList<String>();
      if (!Comparing.strEqual(locale.getDisplayLanguage(), null)) {
        names.add(locale.getDisplayLanguage());
      }
      if (!Comparing.strEqual(locale.getDisplayCountry(), null)) {
        names.add(locale.getDisplayCountry());
      }
      if (!Comparing.strEqual(locale.getDisplayVariant(), null)) {
        names.add(locale.getDisplayVariant());
      }

      String title = propertiesFile.getName();
      if (!names.isEmpty()) {
        title += " (" + StringUtil.join(names, "/") + ")";
      }
      JComponent comp =
          new JPanel(new BorderLayout()) {
            @Override
            public Dimension getPreferredSize() {
              Insets insets = getBorder().getBorderInsets(this);
              return new Dimension(100, editor.getLineHeight() * 4 + insets.top + insets.bottom);
            }
          };
      comp.add(editor.getComponent(), BorderLayout.CENTER);
      comp.setBorder(IdeBorderFactory.createTitledBorder(title, true));
      myTitledPanels.put(propertiesFile, (JPanel) comp);

      valuesPanelComponent.add(comp, gc);
    }
    if (previousEditor != null) {
      previousEditor.putUserData(
          ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, firstEditor);
      firstEditor.putUserData(
          ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor);
    }

    gc.gridx = 0;
    gc.gridy = y;
    gc.gridheight = GridBagConstraints.REMAINDER;
    gc.gridwidth = GridBagConstraints.REMAINDER;
    gc.weightx = 10;
    gc.weighty = 1;

    valuesPanelComponent.add(new JPanel(), gc);
    selectionChanged();
    myValuesPanel.repaint();
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            updateEditorsFromProperties();
          }
        });
  }
コード例 #28
0
  protected void execute(Command cmd) {
    Log.i("TTS: " + cmd.getOriginalCommand());

    if (isMatchingCmd(cmd, "tts")) {
      if (mTtsAvailable) {
        mTts.speak(cmd.getAllArg1(), TextToSpeech.QUEUE_ADD, null);
      } else {
        send(R.string.chat_tts_installation);
        Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        sContext.startActivity(intent);
      }
    } else if (isMatchingCmd(cmd, "tts-engine-list")) {
      if (Build.VERSION.SDK_INT < VERSION_CODES.ICE_CREAM_SANDWICH) {
        send(R.string.android_version_incompatible, "ICE CREAM SANDWICH");
      } else {
        StringBuilder sb = new StringBuilder(getString(R.string.chat_tts_engines));
        for (EngineInfo engine : mTts.getEngines()) {
          sb.append(engine.label).append(" - ").append(engine.name).append("\n");
        }
        send(sb.substring(0, Math.max(0, sb.length() - 1)));
      }
    } else if (isMatchingCmd(cmd, "tts-lang-list")) {
      StringBuilder sb = new StringBuilder(getString(R.string.chat_tts_languages));
      for (Locale locale : Locale.getAvailableLocales()) {
        switch (mTts.isLanguageAvailable(locale)) {
          case TextToSpeech.LANG_AVAILABLE:
            sb.append(locale.getDisplayLanguage());
            if (locale.getDisplayCountry() != null && locale.getDisplayCountry().length() > 0) {
              sb.append(" (").append(locale.getDisplayCountry()).append(")");
            }
            sb.append(" - ").append(locale.getLanguage());

            if (locale.getDisplayCountry() != null && locale.getDisplayCountry().length() > 0) {
              sb.append(":").append(locale.getCountry());
            }
            sb.append("\n");
            break;
        }
      }
      send(sb.substring(0, Math.max(0, sb.length() - 1)));
    } else if (isMatchingCmd(cmd, "tts-engine")) {
      if (Build.VERSION.SDK_INT < VERSION_CODES.ICE_CREAM_SANDWICH) {
        send(R.string.android_version_incompatible, "ICE CREAM SANDWICH");
      } else {
        mTts = new TextToSpeech(sContext, this, cmd.getAllArg1());
        send(getString(R.string.chat_tts_engine) + mTts.getDefaultEngine());
      }
    } else if (isMatchingCmd(cmd, "tts-lang")) {
      String arg1 = cmd.getArg1();
      String arg2 = cmd.getArg2();
      if (!arg1.equals("") && !arg2.equals("")) {
        mLocale = new Locale(arg1, arg2);
        mTts.setLanguage(mLocale);
      } else if (!arg1.equals("")) {
        mLocale = new Locale(arg1);
        mTts.setLanguage(mLocale);
      }
      send(getString(R.string.chat_tts_language) + mTts.getLanguage().getDisplayName());
    }
  }
コード例 #29
0
ファイル: LocaleActivity.java プロジェクト: zieglerm/enh
  static String describeLocale(String name) {
    final StringBuilder result = new StringBuilder();
    result.append("<html>");

    final Locale locale = localeByName(name);

    result.append("<p>");
    append(result, "Display Name", locale.getDisplayName());
    append(result, "Localized Display Name", locale.getDisplayName(locale));

    if (locale.getLanguage().length() > 0) {
      String iso3Language = "(not available)";
      try {
        iso3Language = locale.getISO3Language();
      } catch (MissingResourceException ignored) {
      }

      result.append("<p>");
      append(result, "Display Language", locale.getDisplayLanguage());
      append(result, "Localized Display Language", locale.getDisplayLanguage(locale));
      append(result, "2-Letter Language Code", locale.getLanguage());
      append(result, "3-Letter Language Code", iso3Language);
    }
    if (locale.getCountry().length() > 0) {
      String iso3Country = "(not available)";
      try {
        iso3Country = locale.getISO3Country();
      } catch (MissingResourceException ignored) {
      }

      result.append("<p>");
      append(result, "Display Country", locale.getDisplayCountry());
      append(result, "Localized Display Country", locale.getDisplayCountry(locale));
      append(result, "2-Letter Country Code", locale.getCountry());
      append(result, "3-Letter Country Code", iso3Country);
    }
    if (locale.getVariant().length() > 0) {
      result.append("<p>");
      append(result, "Display Variant", locale.getDisplayVariant());
      append(result, "Localized Display Variant", locale.getDisplayVariant(locale));
      append(result, "Variant Code", locale.getVariant());
    }

    result.append("<p><b>Number Formatting</b>");
    describeNumberFormat(result, "Decimal", NumberFormat.getInstance(locale), 1234.5, -1234.5);
    describeNumberFormat(result, "Integer", NumberFormat.getIntegerInstance(locale), 1234, -1234);
    describeNumberFormat(
        result, "Currency", NumberFormat.getCurrencyInstance(locale), 1234.5, -1234.5);
    describeNumberFormat(result, "Percent", NumberFormat.getPercentInstance(locale), 12.3);

    boolean hasLocaleData = hasLocaleData();

    if (!hasLocaleData) {
      result.append("<p><b>Decimal Format Symbols</b>");
      NumberFormat nf = NumberFormat.getInstance(locale);
      if (nf instanceof DecimalFormat) {
        describeDecimalFormatSymbols(result, ((DecimalFormat) nf).getDecimalFormatSymbols());
      } else {
        result.append("(Didn't expect " + nf.getClass() + ".)");
      }
    }

    Date now =
        new Date(); // FIXME: it might be more useful to always show a time in the afternoon, to
    // make 24-hour patterns more obvious.
    result.append("<p><b>Date/Time Formatting</b>");
    describeDateFormat(
        result, "Full Date", DateFormat.getDateInstance(DateFormat.FULL, locale), now);
    describeDateFormat(
        result, "Long Date", DateFormat.getDateInstance(DateFormat.LONG, locale), now);
    describeDateFormat(
        result, "Medium Date", DateFormat.getDateInstance(DateFormat.MEDIUM, locale), now);
    describeDateFormat(
        result, "Short Date", DateFormat.getDateInstance(DateFormat.SHORT, locale), now);
    result.append("<p>");
    describeDateFormat(
        result, "Full Time", DateFormat.getTimeInstance(DateFormat.FULL, locale), now);
    describeDateFormat(
        result, "Long Time", DateFormat.getTimeInstance(DateFormat.LONG, locale), now);
    describeDateFormat(
        result, "Medium Time", DateFormat.getTimeInstance(DateFormat.MEDIUM, locale), now);
    describeDateFormat(
        result, "Short Time", DateFormat.getTimeInstance(DateFormat.SHORT, locale), now);
    result.append("<p>");
    describeDateFormat(
        result,
        "Full Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale),
        now);
    describeDateFormat(
        result,
        "Long Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale),
        now);
    describeDateFormat(
        result,
        "Medium Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale),
        now);
    describeDateFormat(
        result,
        "Short Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale),
        now);

    if (!hasLocaleData) {
      result.append("<p><b>Date Format Symbols</b><p>");
      DateFormat edf = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
      DateFormatSymbols edfs = ((SimpleDateFormat) edf).getDateFormatSymbols();
      DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, locale);
      DateFormatSymbols dfs = ((SimpleDateFormat) df).getDateFormatSymbols();
      append(result, "Local Pattern Chars", dfs.getLocalPatternChars());
      append(result, "Am/pm", Arrays.toString(dfs.getAmPmStrings()));
      append(result, "Eras", Arrays.toString(dfs.getEras()));
      append(result, "Months", Arrays.toString(dfs.getMonths()));
      append(result, "Short Months", Arrays.toString(dfs.getShortMonths()));
      append(result, "Weekdays", Arrays.toString(dfs.getWeekdays()));
      append(result, "Short Weekdays", Arrays.toString(dfs.getShortWeekdays()));
    }

    result.append("<p><b>Calendar</b><p>");
    Calendar c = Calendar.getInstance(locale);
    int firstDayOfWeek = c.getFirstDayOfWeek();
    String firstDayOfWeekString = new DateFormatSymbols(locale).getWeekdays()[firstDayOfWeek];
    String englishFirstDayOfWeekString =
        new DateFormatSymbols(Locale.US).getWeekdays()[firstDayOfWeek];
    String firstDayOfWeekDetails = firstDayOfWeek + " '" + firstDayOfWeekString + "'";
    if (!englishFirstDayOfWeekString.equals(firstDayOfWeekString)) {
      firstDayOfWeekDetails += " (" + englishFirstDayOfWeekString + ")";
    }
    append(result, "First Day of the Week", firstDayOfWeekDetails);
    append(result, "Minimal Days in First Week", c.getMinimalDaysInFirstWeek());

    // If this locale specifies a country, check out the currency.
    // Languages don't have currencies; countries do.
    if (!locale.getCountry().equals("")) {
      result.append("<p><b>Currency</b><p>");
      try {
        Currency currency = Currency.getInstance(locale);
        append(result, "ISO 4217 Currency Code", currency.getCurrencyCode());
        append(
            result,
            "Currency Symbol",
            unicodeString(currency.getSymbol(locale)) + " (" + currency.getSymbol(Locale.US) + ")");
        append(result, "Default Fraction Digits", currency.getDefaultFractionDigits());
      } catch (IllegalArgumentException ex) {
        result.append(
            "<p>(This version of Android is unable to return a Currency for this Locale.)");
      }
    }

    result.append("<p><b>Data Availability</b><p>");
    appendAvailability(result, locale, "BreakIterator", BreakIterator.class);
    appendAvailability(result, locale, "Calendar", NumberFormat.class);
    appendAvailability(result, locale, "Collator", Collator.class);
    appendAvailability(result, locale, "DateFormat", DateFormat.class);
    appendAvailability(result, locale, "DateFormatSymbols", DateFormatSymbols.class);
    appendAvailability(result, locale, "DecimalFormatSymbols", DecimalFormatSymbols.class);
    appendAvailability(result, locale, "NumberFormat", NumberFormat.class);

    if (hasLocaleData) {
      result.append("<p><b>libcore.icu.LocaleData</b>");
      try {
        Object enUsData = getLocaleDataInstance(Locale.US);
        Object localeData = getLocaleDataInstance(locale);
        String[] previous;

        result.append("<p>");
        describeStringArray(result, "amPm", enUsData, localeData, null);
        describeStringArray(result, "eras", enUsData, localeData, null);

        result.append("<p>");
        previous = describeStringArray(result, "longMonthNames", enUsData, localeData, null);
        describeStringArray(result, "longStandAloneMonthNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "shortMonthNames", enUsData, localeData, null);
        describeStringArray(result, "shortStandAloneMonthNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "tinyMonthNames", enUsData, localeData, null);
        describeStringArray(result, "tinyStandAloneMonthNames", enUsData, localeData, previous);

        result.append("<p>");
        previous = describeStringArray(result, "longWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "longStandAloneWeekdayNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "shortWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "shortStandAloneWeekdayNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "tinyWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "tinyStandAloneWeekdayNames", enUsData, localeData, previous);

        result.append("<p>");
        describeString(result, "yesterday", enUsData, localeData);
        describeString(result, "today", enUsData, localeData);
        describeString(result, "tomorrow", enUsData, localeData);

        result.append("<p>");
        describeString(result, "timeFormat12", enUsData, localeData);
        describeString(result, "timeFormat24", enUsData, localeData);

        result.append("<p>");
        describeChar(result, "zeroDigit", enUsData, localeData);
        describeChar(result, "decimalSeparator", enUsData, localeData);
        describeChar(result, "groupingSeparator", enUsData, localeData);
        describeChar(result, "patternSeparator", enUsData, localeData);
        describeChar(result, "percent", enUsData, localeData);
        describeChar(result, "perMill", enUsData, localeData);
        describeChar(result, "monetarySeparator", enUsData, localeData);
        describeChar(result, "minusSign", enUsData, localeData);
        describeString(result, "exponentSeparator", enUsData, localeData);
        describeString(result, "infinity", enUsData, localeData);
        describeString(result, "NaN", enUsData, localeData);

      } catch (Exception ex) {
        result.append("(" + ex.getClass().getSimpleName() + " thrown: " + ex.getMessage() + ")");
        System.err.println(ex);
      }
    }

    return result.toString();
  }
コード例 #30
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getActivity().setTitle(formField.getLabel());
    final List<FormOption> options = new ArrayList<>();
    final FormOptions formOptions = formField.getOptions();
    final ArrayAdapter<FormOption> adapter =
        new ArrayAdapter<>(getActivity(), R.layout.edx_selectable_list_item, options);
    if (formOptions.getReference() != null) {
      new GetFormOptionsTask(getActivity(), formOptions.getReference()) {
        @Override
        protected void onSuccess(List<FormOption> formOptions) throws Exception {
          options.addAll(formOptions);
          adapter.notifyDataSetChanged();
          selectCurrentOption();
        }
      }.execute();

    } else if (formOptions.getRangeMin() != null && formOptions.getRangeMax() != null) {
      for (int i = formOptions.getRangeMax(); i >= formOptions.getRangeMin(); --i) {
        options.add(new FormOption(String.valueOf(i), String.valueOf(i)));
      }
    } else if (formOptions.getValues() != null && formOptions.getValues().size() > 0) {
      options.addAll(formOptions.getValues());
    }
    if (!TextUtils.isEmpty(formField.getInstructions())) {
      final View instructionsContainer =
          LayoutInflater.from(view.getContext())
              .inflate(R.layout.form_field_instructions_header, listView, false);
      final TextView instructions =
          (TextView) instructionsContainer.findViewById(R.id.instructions);
      final TextView subInstructions =
          (TextView) instructionsContainer.findViewById(R.id.sub_instructions);
      instructions.setText(formField.getInstructions());
      if (TextUtils.isEmpty(formField.getSubInstructions())) {
        subInstructions.setVisibility(View.GONE);
      } else {
        subInstructions.setText(formField.getSubInstructions());
      }
      listView.addHeaderView(instructionsContainer, null, false);
    }
    if (null != formField.getDataType()) {
      switch (formField.getDataType()) {
        case COUNTRY:
          {
            final Locale locale = Locale.getDefault();
            addDetectedValueHeader(
                listView,
                R.string.edit_user_profile_current_location,
                "current_location",
                locale.getDisplayCountry(),
                locale.getCountry(),
                FontAwesomeIcons.fa_map_marker);
            break;
          }
        case LANGUAGE:
          {
            final Locale locale = Locale.getDefault();
            addDetectedValueHeader(
                listView,
                R.string.edit_user_profile_current_language,
                "current_language",
                locale.getDisplayLanguage(),
                locale.getLanguage(),
                FontAwesomeIcons.fa_comment);
            break;
          }
      }
    }
    if (formField.getOptions().isAllowsNone()) {
      final TextView textView =
          (TextView)
              LayoutInflater.from(listView.getContext())
                  .inflate(R.layout.edx_selectable_list_item, listView, false);
      final String label = formField.getOptions().getNoneLabel();
      textView.setText(label);
      listView.addHeaderView(textView, new FormOption(label, null), true);
    }
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final FormOption item = (FormOption) parent.getItemAtPosition(position);
            getActivity()
                .setResult(
                    Activity.RESULT_OK,
                    new Intent()
                        .putExtra(FormFieldActivity.EXTRA_FIELD, formField)
                        .putExtra(FormFieldActivity.EXTRA_VALUE, item.getValue()));
            getActivity().finish();
          }
        });
    selectCurrentOption();
  }