home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / beans / FeatureDescriptor.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  6.8 KB  |  243 lines

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