Source for java.beans.FeatureDescriptor

   1: /* java.beans.FeatureDescriptor
   2:    Copyright (C) 1998, 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package java.beans;
  40: 
  41: import java.util.Enumeration;
  42: import java.util.Hashtable;
  43: 
  44: /**
  45:  * FeatureDescriptor is the common superclass for all JavaBeans Descriptor
  46:  * classes. JavaBeans descriptors are abstract descriptors of properties,
  47:  * events, methods, beans, etc.<P>
  48:  *
  49:  * <STRONG>Documentation Convention:</STRONG> for proper
  50:  * Internalization of Beans inside an RAD tool, sometimes there
  51:  * are two names for a property or method: a programmatic, or
  52:  * locale-independent name, which can be used anywhere, and a
  53:  * localized, display name, for ease of use.  In the
  54:  * documentation I will specify different String values as
  55:  * either <EM>programmatic</EM> or <EM>localized</EM> to
  56:  * make this distinction clear.
  57:  *
  58:  * @author John Keiser
  59:  * @since 1.1
  60:  */
  61: 
  62: public class FeatureDescriptor
  63: {
  64:   String name;
  65:   String displayName;
  66:   String shortDescription;
  67:   boolean expert;
  68:   boolean hidden;
  69:   boolean preferred;
  70: 
  71:   Hashtable<String,Object> valueHash;
  72: 
  73:   /**
  74:    * Instantiate this FeatureDescriptor with appropriate default values.
  75:    */
  76:   public FeatureDescriptor()
  77:   {
  78:     valueHash = new Hashtable<String,Object>();
  79:   }
  80: 
  81:   /**
  82:    * Get the programmatic name of this feature.
  83:    */
  84:   public String getName()
  85:   {
  86:     return name;
  87:   }
  88: 
  89:   /**
  90:    * Set the programmatic name of this feature.
  91:    *
  92:    * @param name the new name for this feature.
  93:    */
  94:   public void setName(String name)
  95:   {
  96:     this.name = name;
  97:   }
  98: 
  99:   /**
 100:    * Get the localized (display) name of this feature.
 101:    *
 102:    * @returns The localized display name of this feature or falls
 103:    * back to the programmatic name.
 104:    */
 105:   public String getDisplayName()
 106:   {
 107:     return (displayName == null) ? name : displayName;
 108:   }
 109: 
 110:   /**
 111:    * Set the localized (display) name of this feature.
 112:    *
 113:    * @param displayName the new display name for this feature.
 114:    */
 115:   public void setDisplayName(String displayName)
 116:   {
 117:     this.displayName = displayName;
 118:   }
 119: 
 120:   /**
 121:    * Get the localized short description for this feature.
 122:    *
 123:    * @returns A short localized description of this feature or
 124:    * what <code>getDisplayName</code> returns in case, that no short description
 125:    * is available.
 126:    */
 127:   public String getShortDescription()
 128:   {
 129:     return (shortDescription == null) ? getDisplayName() : shortDescription;
 130:   }
 131: 
 132:   /**
 133:    * Set the localized short description for this feature.
 134:    *
 135:    * @param shortDescription the new short description for this feature.
 136:    */
 137:   public void setShortDescription(String shortDescription)
 138:   {
 139:     this.shortDescription = shortDescription;
 140:   }
 141: 
 142:   /**
 143:    * Indicates whether this feature is for expert use only.
 144:    *
 145:    * @return true if for use by experts only,
 146:    * or false if anyone can use it.
 147:    */
 148:   public boolean isExpert()
 149:   {
 150:     return expert;
 151:   }
 152: 
 153:   /**
 154:    * Set whether this feature is for expert use only.
 155:    *
 156:    * @param expert true if for use by experts only,
 157:    * or false if anyone can use it.
 158:    */
 159:   public void setExpert(boolean expert)
 160:   {
 161:     this.expert = expert;
 162:   }
 163: 
 164:   /**
 165:    * Indicates whether this feature is for use by tools only.
 166:    * If it is for use by tools only, then it should not be displayed.
 167:    *
 168:    * @return true if tools only should use it,
 169:    * or false if anyone can see it.
 170:    */
 171:   public boolean isHidden()
 172:   {
 173:     return hidden;
 174:   }
 175: 
 176:   /**
 177:    * Set whether this feature is for use by tools only.
 178:    * If it is for use by tools only, then it should not be displayed.
 179:    *
 180:    * @param hidden true if tools only should use it,
 181:    * or false if anyone can see it.
 182:    */
 183:   public void setHidden(boolean hidden)
 184:   {
 185:     this.hidden = hidden;
 186:   }
 187: 
 188:   public boolean isPreferred ()
 189:   {
 190:     return preferred;
 191:   }
 192: 
 193:   public void setPreferred (boolean preferred)
 194:   {
 195:     this.preferred = preferred;
 196:   }
 197: 
 198:   /**
 199:    * Get an arbitrary value set with setValue().
 200:    *
 201:    * @param name the programmatic name of the key.
 202:    *
 203:    * @return the value associated with this name,
 204:    * or null if there is none.
 205:    */
 206:   public Object getValue(String name)
 207:   {
 208:     return valueHash.get(name);
 209:   }
 210: 
 211:   /**
 212:    * Set an arbitrary string-value pair with this feature.
 213:    *
 214:    * @param name the programmatic name of the key.
 215:    * @param value the value to associate with the name.
 216:    */
 217:   public void setValue(String name, Object value)
 218:   {
 219:     valueHash.put(name, value);
 220:   }
 221: 
 222:   /**
 223:    * Get a list of the programmatic key names set with setValue().
 224:    *
 225:    * @return an Enumerator over all the programmatic key names associated
 226:    * with this feature.
 227:    */
 228:   public Enumeration<String> attributeNames()
 229:   {
 230:     return valueHash.keys();
 231:   }
 232: }