FeatureDescriptor.java 6.2 KB

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