fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / java / beans / PropertyEditorSupport.java
blob2376867e9d2d399246a03d013f2828159f2ecf34
1 /* java.beans.PropertyEditorSupport
2 Copyright (C) 1998 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;
41 /**
42 ** PropertyEditorSupport helps with PropertyEditors,
43 ** implementing base functionality that they usually must
44 ** have but which is a pain to implement. You may extend
45 ** from this class or use it as a standalone.<P>
47 ** This class does not do any painting or actual editing.
48 ** For that, you must use or extend it. See the
49 ** PropertyEditor class for better descriptions of what
50 ** the various methods do.
52 ** @author John Keiser
53 ** @since JDK1.1
54 ** @version 1.1.0, 29 Jul 1998
55 **/
57 public class PropertyEditorSupport implements PropertyEditor {
58 Object eventSource;
59 Object val;
60 PropertyChangeSupport pSupport;
62 /** Call this constructor when you are deriving from
63 ** PropertyEditorSupport.
64 **/
65 protected PropertyEditorSupport() {
66 this.eventSource = this;
67 this.pSupport = new PropertyChangeSupport(this);
70 /** Call this constructor when you are using
71 ** PropertyEditorSupport as a helper object.
72 ** @param eventSource the source to use when firing
73 ** property change events.
74 **/
75 protected PropertyEditorSupport(Object eventSource) {
76 this.eventSource = eventSource;
77 this.pSupport = new PropertyChangeSupport(this);
80 /** Set the current value of the property.
81 ** <STRONG>Implementation Note</STRONG> Sun does not
82 ** state what exactly this version of the method does.
83 ** Thus, in this implementation, it sets the value, and
84 ** then if the old and new values are different, it
85 ** fires a property change event with no property name
86 ** and the old and new values.
87 ** @param val the new value for the property.
88 **/
89 public void setValue(Object val) {
90 Object oldVal = val;
91 this.val = val;
92 if(!oldVal.equals(val)) {
93 pSupport.firePropertyChange(null,oldVal,val);
97 /** Get the current value of the property.
98 ** @return the current value of the property.
99 **/
100 public Object getValue() {
101 return val;
104 /** Get whether this object is paintable or not.
105 ** @return <CODE>false</CODE>
107 public boolean isPaintable() {
108 return false;
111 /** Paint this object. This class does nothing in
112 ** this method.
114 public void paintValue(java.awt.Graphics g, java.awt.Rectangle r) {
117 /** Get the Java initialization String for the current
118 ** value of the Object. This class returns gibberish or
119 ** null (though the spec does not say which).<P>
120 ** <STRONG>Implementation Note:</STRONG> This class
121 ** returns the string "@$#^" to make sure the code will
122 ** be broken, so that you will know to override it when
123 ** you create your own property editor.
124 ** @return the Java initialization string.
126 public String getJavaInitializationString() {
127 return "@$#^";
130 /** Get the value as text.
131 ** In this class, you cannot count on getAsText() doing
132 ** anything useful, although in this implementation I
133 ** do toString().
134 ** @return the value as text.
136 public String getAsText() {
137 return val != null ? val.toString() : "null";
140 /** Set the value as text.
141 ** In this class, you cannot count on setAsText() doing
142 ** anything useful across implementations.
143 ** <STRONG>Implementation Note:</STRONG> In this
144 ** implementation it checks if the String is "null", and
145 ** if it is, sets the value to null, otherwise it throws
146 ** an IllegalArgumentException.
147 ** @param s the text to convert to a new value.
148 ** @exception IllegalArgumentException if the text is
149 ** malformed.
151 public void setAsText(String s) throws IllegalArgumentException {
152 if(s.equals("null")) {
153 setValue(null);
154 } else {
155 throw new IllegalArgumentException();
159 /** Returns a list of possible choices for the value.
160 ** @return <CODE>null</CODE>
162 public String[] getTags() {
163 return null;
166 /** Return a custom component to edit the value.
167 ** @return <CODE>null</CODE> in this class.
169 public java.awt.Component getCustomEditor() {
170 return null;
173 /** Find out whether this property editor supports a
174 ** custom component to edit its value.
175 ** @return <CODE>false</CODE> in this class.
177 public boolean supportsCustomEditor() {
178 return false;
181 /** Add a property change listener to this property editor.
182 ** @param l the listener to add.
184 public void addPropertyChangeListener(PropertyChangeListener l) {
185 pSupport.addPropertyChangeListener(l);
188 /** Remove a property change listener from this property editor.
189 ** @param l the listener to remove.
191 public void removePropertyChangeListener(PropertyChangeListener l) {
192 pSupport.removePropertyChangeListener(l);
196 /** Notify people that we've changed, although we don't
197 ** tell them just how. The only thing I can think of to
198 ** send in the event is the new value (since the old value
199 ** is unavailable and there is no property name).
200 ** I confess I do not understand the point of this method.
202 public void firePropertyChange() {
203 pSupport.firePropertyChange(null,null,val);