1 /* java.beans.PropertyEditorManager
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)
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
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
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. */
41 import gnu
.java
.lang
.ClassHelper
;
42 import gnu
.java
.beans
.editors
.ColorEditor
;
43 import gnu
.java
.beans
.editors
.FontEditor
;
44 import gnu
.java
.beans
.editors
.NativeBooleanEditor
;
45 import gnu
.java
.beans
.editors
.NativeByteEditor
;
46 import gnu
.java
.beans
.editors
.NativeDoubleEditor
;
47 import gnu
.java
.beans
.editors
.NativeFloatEditor
;
48 import gnu
.java
.beans
.editors
.NativeIntEditor
;
49 import gnu
.java
.beans
.editors
.NativeLongEditor
;
50 import gnu
.java
.beans
.editors
.NativeShortEditor
;
51 import gnu
.java
.beans
.editors
.StringEditor
;
52 import java
.awt
.Color
;
56 * PropertyEditorManager is used to find property editors
57 * for various types (not necessarily Beans).<P>
59 * It first checks to see if the property editor is
60 * already registered; if it is, that property editor is
61 * used. Next it takes the type's classname and appends
62 * "Editor" to it, and searches first in the class's
63 * package and then in the property editor search path.<P>
65 * Default property editors are provided for:<P>
67 * <LI>boolean, byte, short, int, long, float, and double</LI>
68 * <LI>java.lang.String</LI>
69 * <LI>java.awt.Color</LI>
70 * <LI>java.awt.Font</LI>
73 * <STRONG>Spec Suggestion:</STRONG> Perhaps an editor for
74 * Filename or something like it should be provided. As well
79 * @version 1.1.0, 29 Jul 1998
82 public class PropertyEditorManager
84 static java
.util
.Hashtable editors
= new java
.util
.Hashtable();
85 static String
[] editorSearchPath
= { "gnu.java.beans.editors",
86 "sun.beans.editors" };
90 registerEditor(Boolean
.TYPE
, NativeBooleanEditor
.class);
91 registerEditor(Byte
.TYPE
, NativeByteEditor
.class);
92 registerEditor(Short
.TYPE
, NativeShortEditor
.class);
93 registerEditor(Integer
.TYPE
, NativeIntEditor
.class);
94 registerEditor(Long
.TYPE
, NativeLongEditor
.class);
95 registerEditor(Float
.TYPE
, NativeFloatEditor
.class);
96 registerEditor(Double
.TYPE
, NativeDoubleEditor
.class);
97 registerEditor(String
.class, StringEditor
.class);
98 registerEditor(Color
.class, ColorEditor
.class);
99 registerEditor(Font
.class, FontEditor
.class);
103 * Beats me why this class can be instantiated, but there
106 public PropertyEditorManager()
112 * Register an editor for a class. Replaces old editor
113 * if there was one registered before.
115 * @param editedClass the class that the property editor
117 * @param editorClass the PropertyEditor class.
119 public static void registerEditor(Class editedClass
, Class editorClass
)
121 editors
.put(editedClass
, editorClass
);
125 * Returns a new instance of the property editor for the
128 * @param editedClass the class that the property editor
130 * @return a PropertyEditor instance that can edit the
133 public static PropertyEditor
findEditor(Class editedClass
)
137 Class found
= (Class
)editors
.get(editedClass
);
140 return (PropertyEditor
)found
.newInstance();
143 ClassLoader contextClassLoader
144 = Thread
.currentThread().getContextClassLoader();
148 found
= Class
.forName(editedClass
.getName()+"Editor", true,
150 registerEditor(editedClass
,found
);
151 return (PropertyEditor
)found
.newInstance();
153 catch(ClassNotFoundException E
)
159 + ClassHelper
.getTruncatedClassName(editedClass
)
161 synchronized(editorSearchPath
)
163 for(int i
=0;i
<editorSearchPath
.length
;i
++)
167 found
= Class
.forName(editorSearchPath
[i
] + appendName
,
168 true, contextClassLoader
);
169 registerEditor(editedClass
,found
);
170 return (PropertyEditor
)found
.newInstance();
172 catch(ClassNotFoundException E
)
178 catch(InstantiationException E
)
181 catch(IllegalAccessException E
)
189 * Get the editor search path.
190 * As a minor departure from the spec, the default value
191 * for the editor search path is "gnu.java.beans.editors",
192 * "sun.beans.editors".
194 * @return the editor search path.
196 public static String
[] getEditorSearchPath()
198 return editorSearchPath
;
202 * Set the editor search path.
204 * @param editorSearchPath the new value for the editor search path.
206 public static void setEditorSearchPath(String
[] editorSearchPath
)
208 synchronized(editorSearchPath
)
210 PropertyEditorManager
.editorSearchPath
= editorSearchPath
;