home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / LocaleChooserMultipleLocaleSelector.java < prev    next >
Text File  |  1997-07-30  |  2KB  |  65 lines

  1. package borland.samples.intl.beans;
  2.  
  3. import java.beans.*;
  4. import java.util.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import borland.jbcl.model.*;
  8.  
  9. public class LocaleChooserMultipleLocaleSelector extends LocaleChooserLocaleSelector {
  10.  
  11.   public LocaleChooserMultipleLocaleSelector() {
  12.     localeChooser.setAllowMultiSelect(true);
  13.   }
  14.  
  15.   public String getJavaInitializationString() {
  16.     Locale [] locale = localeChooser.getSelectedLocales();
  17.  
  18.     String localeInitString = "new java.util.Locale [] {\n";
  19.     for (int i = 0; i < locale.length; i++) {
  20.       localeInitString += "new java.util.Locale(\"" + locale[i].getLanguage() + "\", \"";
  21.       if (locale[i].getCountry().length() == 0) {
  22.     localeInitString += "\")";
  23.       } else {
  24.     localeInitString += locale[i].getCountry() + "\"";
  25.      if (locale[i].getVariant().length() == 0) {
  26.       localeInitString += ")";
  27.     } else {
  28.       localeInitString += ",\"" + locale[i].getVariant() + "\")";
  29.     }
  30.       }
  31.       localeInitString += ",\n";
  32.     }
  33.     localeInitString += " } ";
  34.     System.out.println(localeInitString + "\n:" + this.getClass().getName() + ".getJavaInitializationString()");
  35.     return localeInitString;
  36.   }
  37.  
  38.   public void setValue(Object o) {
  39.     try {
  40.       Locale [] locale = (Locale []) ((Locale []) o).clone();
  41.       for (int i = 0; i < locale.length; i++) {
  42.     System.out.print(locale[i]+";");
  43.       }
  44.       System.out.println(":" + this.getClass().getName() +".setValue()");
  45.       localeChooser.setSelectedLocales(locale);
  46.     } catch (Exception e) {
  47.       e.printStackTrace();
  48.     }
  49.   }
  50.  
  51.   public Object getValue() {
  52.     Locale [] l = localeChooser.getSelectedLocales();
  53.     for (int i = 0; i < l.length; i++) {
  54.       System.out.println(l[i]);
  55.     }
  56.     System.out.println(":" + this.getClass().getName() + ".getValue()");
  57.     return localeChooser.getSelectedLocales();
  58.   }
  59.  
  60.   public String getAsText() {
  61.     System.out.println(this.getClass().getName() + ".getAsText():");
  62.     return getJavaInitializationString();
  63.   }
  64. }
  65.