PropertyEditor.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* java.beans.PropertyEditor
  2. Copyright (C) 1998 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. /**
  33. ** PropertyEditors are custom GUI editors for specific types of values.
  34. **
  35. ** A PropertyEditor can be used, for example, if you are editing a type of value
  36. ** that can be more easily represented graphically, such as a Point, or one that
  37. ** can be more easily represented by a list, such as a boolean (true/false).<P>
  38. **
  39. ** A PropertyEditor must be able to display its contents when asked to and
  40. ** be able to allow the user to change its underlying field value. However, it
  41. ** is not the PropertyEditor's responsibility to make the change to the
  42. ** underlying Object; in fact, the PropertyEditor does not even know about the
  43. ** Object it is actually editing--only about the property it is currently
  44. ** editing. When a change is made to the property, the PropertyEditor must
  45. ** simply fire a PropertyChangeEvent and allow the RAD tool to actually set
  46. ** the property in the underlying Bean.<P>
  47. **
  48. ** PropertyEditors should not change the Objects they are given by setValue().
  49. ** These Objects may or may not be the actual Objects which are properties of
  50. ** the Bean being edited. Instead, PropertyEditors should create a new Object
  51. ** and fire a PropertyChangeEvent with the old and new values.<P>
  52. **
  53. ** PropertyEditors also must support the ability to return a Java
  54. ** initialization string. See the getJavaInitializationString() method for
  55. ** details.<P>
  56. **
  57. ** There are several different ways a PropertyEditor may display and control
  58. ** editing of its value. When multiple types of input and display are
  59. ** given by a single PropertyEditor, the RAD tool may decide which of the call
  60. ** to support. Some RAD tools may even be text-only, so even if you support
  61. ** a graphical set and get, it may choose the text set and get whenever it can.
  62. ** <OL>
  63. ** <LI>Every PropertyEditor must support getValue() and setValue(). For
  64. ** setValue(), the component must only support it when the argument is
  65. ** the same type that the PropertyEditor supports.</LI>
  66. ** <LI>Every PropertyEditor must support getJavaInitializationString().</LI>
  67. ** <LI>You may support painting the value yourself if you wish. To do this,
  68. ** have isPaintable() return true and implement the paintValue() method.
  69. ** This method does not determine in any way how the value is edited;
  70. ** merely how it is displayed.</LI>
  71. ** <LI>Let the caller of the PropertyEditor give the user a text input. Do
  72. ** this by returning a non-null String from getAsText(). If you support
  73. ** text input, you *must* support setAsText().</LI>
  74. ** <LI>Give the caller a set of possible values, such as "true"/"false", that
  75. ** the user must select from. To do this, return the list of Strings
  76. ** from the getTags() method. The RAD tool may choose to implement the
  77. ** user input any way it wishes, and only guarantees that setAsText() will
  78. ** only be called with one of the Strings returned from getTags().</LI>
  79. ** <LI>You may support a whole custom editing control by supporting
  80. ** getCustomEditor(). To do this, return true from supportsCustomEditor()
  81. ** and return a Component that does the job. It is the component's job,
  82. ** or the PropertyEditor's job, to make sure that when the editor changes
  83. ** its value, the PropertyChangeEvent is thrown.</LI>
  84. ** </OL>
  85. **
  86. ** The PropertyEditor for a particular Bean can be found using the
  87. ** PropertyEditorManager class, which goes through a series of different
  88. ** checks to find the appropriate class.<P>
  89. **
  90. ** A PropertyChangeEvent should be thrown from the PropertyEditor whenever a
  91. ** bound property (a property PropertyDescriptor.isBound() set to true)
  92. ** changes. When this happens, the editor itself should *not* change the value
  93. ** itself, but rather allow the RAD tool to call setValue() or setAsText().
  94. **
  95. ** @author John Keiser
  96. ** @since JDK1.1
  97. ** @version 1.1.0, 30 June 1998
  98. ** @see java.beans.PropertyEditorManager
  99. ** @see java.beans.PropertyEditorSupport
  100. **/
  101. public interface PropertyEditor {
  102. /** Called by the RAD tool to set the value of this property for the PropertyEditor.
  103. ** If the property type is native, it should be wrapped in the appropriate
  104. ** wrapper type.
  105. ** @param value the value to set this property to.
  106. **/
  107. void setValue(Object value);
  108. /** Accessor method to get the current value the PropertyEditor is working with.
  109. ** If the property type is native, it will be wrapped in the appropriate
  110. ** wrapper type.
  111. ** @return the current value of the PropertyEditor.
  112. **/
  113. Object getValue();
  114. /** Set the value of this property using a String.
  115. ** Whether or not this PropertyEditor is editing a String type, this converts
  116. ** the String into the type of the PropertyEditor.
  117. ** @param text the text to set it to.
  118. ** @exception IllegalArgumentException if the String is in the wrong format or setAsText() is not supported.
  119. **/
  120. void setAsText(String text) throws IllegalArgumentException;
  121. /** Get the value of this property in String format.
  122. ** Many times this can simply use Object.toString().<P>
  123. ** Return null if you do not support getAsText()/setAsText().
  124. ** <code>setAsText(getAsText())</code> should be valid; i.e. the stuff you spit out in
  125. ** getAsText() should be able to go into setAsText().
  126. ** @return the value of this property in String format.
  127. **/
  128. String getAsText();
  129. /** Get a list of possible Strings which this property type can have.
  130. ** The value of these will be used by the RAD tool to construct some sort
  131. ** of list box or to check text box input, and the resulting String passed
  132. ** to setAsText() should be one of these. Note, however, that like most things
  133. ** with this mammoth, unwieldy interface, this is not guaranteed. Thus, you
  134. ** must check the value in setAsText() anyway.
  135. ** @return the list of possible String values for this property type.
  136. **/
  137. String[] getTags();
  138. /** The RAD tool calls this to find out whether the PropertyEditor can paint itself.
  139. ** @return true if it can paint itself graphically, false if it cannot.
  140. **/
  141. boolean isPaintable();
  142. /** The RAD tool calls this to paint the actual value of the property.
  143. ** The Graphics context will have the same current font, color, etc. as the
  144. ** parent Container. You may safely change the font, color, etc. and not
  145. ** change them back.<P>
  146. ** This method should do a silent no-op if isPaintable() is false.
  147. ** @param g the Graphics context to paint on
  148. ** @param bounds the rectangle you have reserved to work in
  149. **/
  150. void paintValue(java.awt.Graphics g, java.awt.Rectangle bounds);
  151. /** The RAD tool calls this to find out whether the PropertyEditor supports a custom component to edit and display itself.
  152. ** @return true if getCustomEditor() will return a component, false if not.
  153. **/
  154. boolean supportsCustomEditor();
  155. /** The RAD tool calls this to grab the component that can edit this type.
  156. ** The component may be painted anywhere the RAD tool wants to paint it--
  157. ** even in its own window.<P>
  158. ** The component must hook up with the PropertyEditor and, whenever a
  159. ** change to the value is made, fire a PropertyChangeEvent to the source.<P>
  160. ** @return the custom editor for this property type.
  161. **/
  162. java.awt.Component getCustomEditor();
  163. /** Adds a property change listener to this PropertyEditor.
  164. ** @param listener the listener to add
  165. **/
  166. void addPropertyChangeListener(PropertyChangeListener listener);
  167. /** Removes a property change listener from this PropertyEditor.
  168. ** @param listener the listener to remove
  169. **/
  170. void removePropertyChangeListener(PropertyChangeListener listener);
  171. /** Get a Java language-specific String which could be used to create an Object
  172. ** of the specified type. Every PropertyEditor must support this.<P>
  173. ** The reason for this is that while most RAD tools will serialize the Beans
  174. ** and deserialize them at runtime, some RAD tools will generate code that
  175. ** creates the Beans. Examples of Java initialization strings would be:<P>
  176. ** <OL>
  177. ** <LI><CODE>2</CODE></LI>
  178. ** <LI><CODE>"I am a String"</CODE></LI>
  179. ** <LI><CODE>new MyObject(2, "String", new StringBuffer())</CODE></LI>
  180. ** </OL>
  181. ** @return the initialization string for this object in Java.
  182. **/
  183. String getJavaInitializationString();
  184. }