source: trunk/gcc/libjava/java/beans/PropertyEditorSupport.java

Last change on this file was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.6 KB
Line 
1/* java.beans.PropertyEditorSupport
2 Copyright (C) 1998 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.beans;
40
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>
46 **
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.
51 **
52 ** @author John Keiser
53 ** @since JDK1.1
54 ** @version 1.1.0, 29 Jul 1998
55 **/
56
57public class PropertyEditorSupport implements PropertyEditor {
58 Object eventSource;
59 Object val;
60 PropertyChangeSupport pSupport;
61
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);
68 }
69
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);
78 }
79
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);
94 }
95 }
96
97 /** Get the current value of the property.
98 ** @return the current value of the property.
99 **/
100 public Object getValue() {
101 return val;
102 }
103
104 /** Get whether this object is paintable or not.
105 ** @return <CODE>false</CODE>
106 **/
107 public boolean isPaintable() {
108 return false;
109 }
110
111 /** Paint this object. This class does nothing in
112 ** this method.
113 **/
114 public void paintValue(java.awt.Graphics g, java.awt.Rectangle r) {
115 }
116
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.
125 **/
126 public String getJavaInitializationString() {
127 return "@$#^";
128 }
129
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.
135 **/
136 public String getAsText() {
137 return val != null ? val.toString() : "null";
138 }
139
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.
150 **/
151 public void setAsText(String s) throws IllegalArgumentException {
152 if(s.equals("null")) {
153 setValue(null);
154 } else {
155 throw new IllegalArgumentException();
156 }
157 }
158
159 /** Returns a list of possible choices for the value.
160 ** @return <CODE>null</CODE>
161 **/
162 public String[] getTags() {
163 return null;
164 }
165
166 /** Return a custom component to edit the value.
167 ** @return <CODE>null</CODE> in this class.
168 **/
169 public java.awt.Component getCustomEditor() {
170 return null;
171 }
172
173 /** Find out whether this property editor supports a
174 ** custom component to edit its value.
175 ** @return <CODE>false</CODE> in this class.
176 **/
177 public boolean supportsCustomEditor() {
178 return false;
179 }
180
181 /** Add a property change listener to this property editor.
182 ** @param l the listener to add.
183 **/
184 public void addPropertyChangeListener(PropertyChangeListener l) {
185 pSupport.addPropertyChangeListener(l);
186 }
187
188 /** Remove a property change listener from this property editor.
189 ** @param l the listener to remove.
190 **/
191 public void removePropertyChangeListener(PropertyChangeListener l) {
192 pSupport.removePropertyChangeListener(l);
193 }
194
195
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.
201 **/
202 public void firePropertyChange() {
203 pSupport.firePropertyChange(null,null,val);
204 }
205}
206
Note: See TracBrowser for help on using the repository browser.