home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / LocaleChooserCollationLocaleEditor.java < prev    next >
Text File  |  1997-07-30  |  3KB  |  88 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 LocaleChooserCollationLocaleEditor extends java.beans.PropertyEditorSupport {
  10.  
  11.   protected Locale collationLocale = null;
  12.  
  13.   public String[] getTags() {
  14.     String [] tags;
  15.     if (collationLocale.equals(LocaleChooser.NULL_LOCALE) ||
  16.     collationLocale.equals(LocaleChooser.DEFAULT_RUNTIME_LOCALE)) {
  17.       tags = new String [] {
  18.     "NULL_LOCALE",
  19.     "DEFAULT_RUNTIME_LOCALE",
  20.       };
  21.     } else {
  22.       tags = new String [] { 
  23.     "NULL_LOCALE",
  24.     "DEFAULT_RUNTIME_LOCALE",
  25.     getJavaInitializationString(),
  26.       };
  27.     }
  28.     return tags;
  29.   }
  30.  
  31.   public String getJavaInitializationString() {
  32.     String localeInitString;
  33.     if (collationLocale.equals(LocaleChooser.NULL_LOCALE)) {
  34.       localeInitString =  "LocaleChooser.NULL_LOCALE";
  35.     } else if (collationLocale.equals(LocaleChooser.DEFAULT_RUNTIME_LOCALE)) {
  36.       localeInitString =  "LocaleChooser.DEFAULT_RUNTIME_LOCALE";
  37.     } else {
  38.       localeInitString = "new java.util.Locale(\"" + collationLocale.getLanguage() + "\", \"";
  39.       if (collationLocale.getCountry().length() == 0) {
  40.     localeInitString += "\")";
  41.       } else {
  42.     localeInitString += collationLocale.getCountry() + "\"";
  43.      if (collationLocale.getVariant().length() == 0) {
  44.       localeInitString += ")";
  45.     } else {
  46.       localeInitString += ",\"" + collationLocale.getVariant() + "\")";
  47.     }
  48.       }
  49.     }
  50.     return localeInitString;
  51.   }
  52.  
  53.   public void setAsText(String text) {
  54.     throw new IllegalArgumentException(text);
  55.   }
  56.  
  57.   public String getAsText() {
  58.     String localeInitString;
  59.     if (collationLocale.equals(LocaleChooser.NULL_LOCALE)) {
  60.       localeInitString =  "NULL_LOCALE";
  61.     } else if (collationLocale.equals(LocaleChooser.DEFAULT_RUNTIME_LOCALE)) {
  62.       localeInitString =  "DEFAULT_RUNTIME_LOCALE";
  63.     } else {
  64.       localeInitString = "new java.util.Locale(\"" + collationLocale.getLanguage() + "\", \"";
  65.       if (collationLocale.getCountry().length() == 0) {
  66.     localeInitString += "\")";
  67.       } else {
  68.     localeInitString += collationLocale.getCountry() + "\"";
  69.      if (collationLocale.getVariant().length() == 0) {
  70.       localeInitString += ")";
  71.     } else {
  72.       localeInitString += ",\"" + collationLocale.getVariant() + "\")";
  73.     }
  74.       }
  75.     }
  76.     return localeInitString;
  77.   }
  78.  
  79.   public void setValue(Object o) {
  80.     collationLocale = (Locale) o;
  81.   }
  82.  
  83.   public Object getValue() {
  84.     return collationLocale;
  85.   }
  86.  
  87. }
  88.