Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / beans / PropertyEditorSupport.java
blob2ea9aaa4f0b4e613a5c352fabde31db273360518
1 /* java.beans.PropertyEditorSupport
2 Copyright (C) 1998, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
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.
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. */
39 package java.beans;
42 /**
43 * PropertyEditorSupport helps with PropertyEditors,
44 * implementing base functionality that they usually must
45 * have but which is a pain to implement. You may extend
46 * from this class or use it as a standalone.<P>
48 * This class does not do any painting or actual editing.
49 * For that, you must use or extend it. See the
50 * PropertyEditor class for better descriptions of what
51 * the various methods do.
53 * @author John Keiser
54 * @author Robert Schuster
55 * @since 1.1
56 * @status updated to 1.5
58 public class PropertyEditorSupport implements PropertyEditor
60 Object eventSource;
61 Object value;
62 PropertyChangeSupport pSupport;
64 /** Call this constructor when you are deriving from
65 * PropertyEditorSupport.
67 * Using this constructor the event source is this PropertyEditorSupport
68 * instance itself.
70 * @since 1.5
71 * @specnote this was <code>protected</code> prior to 1.5
73 public PropertyEditorSupport()
75 eventSource = this;
76 pSupport = new PropertyChangeSupport(this);
79 /** Call this constructor when you are using
80 * PropertyEditorSupport as a helper object.
82 * This constructor throws a NullPointerException when <code>source</code> is <code>null</code>,
83 * for compatibility reasons with J2SDK 1.5.0 .
85 * @param source The source to use when firing
86 * property change events.
87 * @since 1.5
88 * @specnote this was <code>protected</code> prior to 1.5
90 public PropertyEditorSupport(Object source)
92 // note: constructor rejects source being null for the sake of compatibility
93 // with official 1.5.0 implementation
94 if (source == null)
95 throw new NullPointerException("Event source must not be null.");
97 eventSource = source;
98 pSupport = new PropertyChangeSupport(eventSource);
101 /** Sets the current value of the property and a property change
102 * event is fired to all registered PropertyChangeListener instances.
104 * @param newValue The new value for the property.
106 public void setValue(Object newValue)
108 value = newValue;
110 // specification in java.beans.PropertyChangeEvent says
111 // that without a property name (first argument) the
112 // new and the old value should always be null
113 pSupport.firePropertyChange(null, null, null);
116 /** Gets the current value of the property.
118 * @return the current value of the property.
120 public Object getValue()
122 return value;
125 /** Gets whether this object is paintable or not.
127 * @return <CODE>false</CODE>
129 public boolean isPaintable()
131 return false;
134 /** Paints this object. This class does nothing in
135 * this method.
137 public void paintValue(java.awt.Graphics g, java.awt.Rectangle r)
141 /** Gets the Java initialization String for the current
142 * value of the Object. This class returns gibberish or
143 * null (though the spec does not say which).<P>
144 * <STRONG>Implementation Note:</STRONG> This class
145 * returns the string "@$#^" to make sure the code will
146 * be broken, so that you will know to override it when
147 * you create your own property editor.
149 * @return the Java initialization string.
151 public String getJavaInitializationString()
153 return "@$#^";
156 /** Gets the value as text.
157 * In this class, you cannot count on getAsText() doing
158 * anything useful, although in this implementation I
159 * do toString().
161 * @return the value as text.
163 public String getAsText()
165 return value != null ? value.toString() : "null";
168 /** Sets the value as text.
169 * In this class, you cannot count on setAsText() doing
170 * anything useful across implementations.
171 * <STRONG>Implementation Note:</STRONG> In this
172 * implementation it checks if the String is "null", and
173 * if it is, sets the value to null, otherwise it throws
174 * an IllegalArgumentException.
176 * @param s the text to convert to a new value.
177 * @exception IllegalArgumentException if the text is
178 * malformed.
180 public void setAsText(String s) throws IllegalArgumentException
182 if (s.equals("null"))
183 setValue(null);
184 else
185 throw new IllegalArgumentException();
188 /** Returns a list of possible choices for the value.
190 * @return <CODE>null</CODE>
192 public String[] getTags()
194 return null;
197 /** Returns a custom component to edit the value.
199 * @return <CODE>null</CODE> in this class.
201 public java.awt.Component getCustomEditor()
203 return null;
206 /** Finds out whether this property editor supports a
207 * custom component to edit its value.
209 * @return <CODE>false</CODE> in this class.
211 public boolean supportsCustomEditor()
213 return false;
216 /** Adds a property change listener to this property editor.
218 * @param l the listener to add.
220 public void addPropertyChangeListener(PropertyChangeListener l)
222 pSupport.addPropertyChangeListener(l);
225 /** Removes a property change listener from this property editor.
227 * @param l the listener to remove.
229 public void removePropertyChangeListener(PropertyChangeListener l)
231 pSupport.removePropertyChangeListener(l);
234 /** Notifies people that we've changed, although we don't
235 * tell them just how.
237 public void firePropertyChange()
239 pSupport.firePropertyChange(null, null, null);
242 /** Returns the bean that is used as the source of events.
244 * @return The event source object
245 * @since 1.5
247 public Object getSource()
249 return eventSource;
252 /** Sets the bean that is used as the source of events
253 * when property changes occur.
255 * The event source bean is for informational purposes only
256 * and should not be changed by the <code>PropertyEditor</code>.
258 * @param source
259 * @since 1.5
261 public void setSource(Object source)
263 eventSource = source;