home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / FeatureDescriptor.java < prev    next >
Text File  |  1997-05-20  |  7KB  |  216 lines

  1. /*
  2.  * @(#)FeatureDescriptor.java    1.15 97/01/03  
  3.  * 
  4.  * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion bdk_beta
  20.  * 
  21.  */
  22.  
  23. package java.beans;
  24.  
  25. /**
  26.  * The FeatureDescriptor class is the common baseclass for PropertyDescriptor,
  27.  * EventSetDescriptor, and MethodDescriptor, etc.
  28.  * <p>
  29.  * It supports some common information that can be set and retrieved for
  30.  * any of the introspection descriptors.
  31.  * <p>
  32.  * In addition it provides an extension mechanism so that arbitrary
  33.  * attribute/value pairs can be associated with a design feature.
  34.  */
  35.  
  36. public class FeatureDescriptor {
  37.  
  38.  
  39.     public FeatureDescriptor() {
  40.     }
  41.  
  42.     /**
  43.      * @return The programmatic name of the property/method/event
  44.      */
  45.     public String getName() {
  46.     return name;
  47.     }
  48.  
  49.     /**
  50.      * @param name  The programmatic name of the property/method/event
  51.      */
  52.     public void setName(String name) {
  53.     this.name = name;
  54.     }
  55.  
  56.     /**
  57.      * @return The localized display name for the property/method/event.
  58.      *    This defaults to the same as its programmatic name from getName.
  59.      */
  60.     public String getDisplayName() {
  61.     if (displayName == null) {
  62.         return getName();
  63.     }
  64.     return displayName;
  65.     }
  66.  
  67.     /**
  68.      * @param displayName  The localized display name for the
  69.      *        property/method/event.
  70.      */
  71.     public void setDisplayName(String displayName) {
  72.     this.displayName = displayName;
  73.     }
  74.  
  75.     /**
  76.      * The "expert" flag is used to distinguish between those features that are
  77.      * intended for expert users from those that are intended for normal users.
  78.      *
  79.      * @return True if this feature is intended for use by experts only.
  80.      */
  81.     public boolean isExpert() {
  82.     return expert;
  83.     }
  84.  
  85.     /**
  86.      * The "expert" flag is used to distinguish between features that are
  87.      * intended for expert users from those that are intended for normal users.
  88.      *
  89.      * @param expert True if this feature is intended for use by experts only.
  90.      */
  91.     public void setExpert(boolean expert) {
  92.     this.expert = expert;
  93.     }
  94.  
  95.     /**
  96.      * The "hidden" flag is used to identify features that are intended only
  97.      * for tool use, and which should not be exposed to humans.
  98.      *
  99.      * @return True if this feature should be hidden from human users.
  100.      */
  101.     public boolean isHidden() {
  102.     return hidden;
  103.     }
  104.  
  105.     /**
  106.      * The "hidden" flag is used to identify features that are intended only
  107.      * for tool use, and which should not be exposed to humans.
  108.      *
  109.      * @param hidden  True if this feature should be hidden from human users.
  110.      */
  111.     public void setHidden(boolean hidden) {
  112.     this.hidden = hidden;
  113.     }
  114.  
  115.     /**
  116.      * @return  A localized short description associated with this 
  117.      *   property/method/event.  This defaults to be the display name.
  118.      */
  119.     public String getShortDescription() {
  120.     if (shortDescription == null) {
  121.         return getDisplayName();
  122.     }
  123.     return shortDescription;
  124.     }
  125.  
  126.     /**
  127.      * You can associate a short descriptive string with a feature.  Normally
  128.      * these descriptive strings should be less than about 40 characters.
  129.      * @param text  A (localized) short description to be associated with
  130.      * this property/method/event.
  131.      */
  132.     public void setShortDescription(String text) {
  133.     shortDescription = text;
  134.     }
  135.  
  136.     /**
  137.      * Associate a named attribute with this feature.
  138.      * @param attributeName  The locale-independent name of the attribute
  139.      * @param value  The value.
  140.      */
  141.     public void setValue(String attributeName, Object value) {
  142.     if (table == null) {
  143.         table = new java.util.Hashtable();
  144.     }
  145.     table.put(attributeName, value);
  146.     }
  147.  
  148.     /**
  149.      * Retrieve a named attribute with this feature.
  150.      * @param attributeName  The locale-independent name of the attribute
  151.      * @return  The value of the attribute.  May be null if
  152.      *       the attribute is unknown.
  153.      */
  154.     public Object getValue(String attributeName) {
  155.     if (table == null) {
  156.        return null;
  157.     }
  158.     return table.get(attributeName);
  159.     }
  160.  
  161.     /**
  162.      * @return  An enumeration of the locale-independent names of any 
  163.      *    attributes that have been registered with setValue.
  164.      */
  165.     public java.util.Enumeration attributeNames() {
  166.     if (table == null) {
  167.         table = new java.util.Hashtable();
  168.     }
  169.     return table.keys();
  170.     }
  171.  
  172.     /**
  173.      * Package-private constructor,
  174.      * Merge information from two FeatureDescriptors.
  175.      * The merged hidden and expert flags are formed by or-ing the values.
  176.      * In the event of other conflicts, the second argument (y) is
  177.      * given priority over the first argument (x).
  178.      * @param x  The first (lower priority) MethodDescriptor
  179.      * @param y  The second (higher priority) MethodDescriptor
  180.      */
  181.     FeatureDescriptor(FeatureDescriptor x, FeatureDescriptor y) {
  182.     expert = x.expert | y.expert;
  183.     hidden = x.hidden | y.hidden;
  184.     name = y.name;
  185.     shortDescription = x.shortDescription;
  186.     if (y.shortDescription != null) {
  187.         shortDescription = y.shortDescription;
  188.     }
  189.     displayName = x.displayName;
  190.     if (y.displayName != null) {
  191.         displayName = y.displayName;
  192.     }
  193.     addTable(x.table);
  194.     addTable(y.table);
  195.     }
  196.  
  197.     private void addTable(java.util.Hashtable t) {
  198.     if (t == null) {
  199.         return;
  200.     }
  201.     java.util.Enumeration keys = t.keys();
  202.     while (keys.hasMoreElements()) {
  203.         String key = (String)keys.nextElement();
  204.         Object value = t.get(key);
  205.         setValue(key, value);
  206.     }
  207.     }
  208.  
  209.     private boolean expert;
  210.     private boolean hidden;
  211.     private String shortDescription;
  212.     private String name;
  213.     private String displayName;
  214.     private java.util.Hashtable table;
  215. }
  216.