1 // JTEM - Java Tools for Experimental Mathematics
\r
2 // GPL Copyright (C) 2002 JTEM-Group
\r
4 // This program is free software; you can redistribute it and/or modify
\r
5 // it under the terms of the GNU General Public License as published by
\r
6 // the Free Software Foundation; either version 2 of the License, or
\r
7 // any later version.
\r
9 // This program is distributed in the hope that it will be useful,
\r
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 // GNU General Public License for more details.
\r
14 // You should have received a copy of the GNU General Public License
\r
15 // along with this program; if not, write to the Free Software
\r
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
18 String beanInfoMaker(){ return beanInfoMaker(self);}
\r
21 String beanInfoMaker(String fullClassName){
\r
22 import java.beans.BeanInfo;
\r
23 import java.beans.MethodDescriptor;
\r
24 import java.beans.PropertyDescriptor;
\r
25 import java.beans.Introspector;
\r
27 final int lastP = fullClassName.lastIndexOf('.');
\r
28 final String packageName = fullClassName.substring(0,lastP);
\r
29 final String myClassName = fullClassName.substring
\r
30 (lastP+((lastP==0)?0:1));
\r
32 // final String myclassName = myClassName.substring(0,1).toLowerCase()
\r
33 // + myClassName.substring(1);
\r
35 final BeanInfo bI= Introspector.getBeanInfo
\r
36 (Class.forName(fullClassName));
\r
38 // final MethodDescriptor[] mDA = bI.getMethodDescriptors();
\r
39 final PropertyDescriptor[] pDA = bI.getPropertyDescriptors();
\r
40 final StringBuffer pDS = new StringBuffer(500*pDA.length);
\r
42 for (int i=0; i<pDA.length; i++) {
\r
43 final PropertyDescriptor pDAi = pDA[i];
\r
44 final String mGetName = pDAi.getReadMethod().getName();
\r
45 // final java.lang.reflect.Method mSetMethod = pDAig.getWriteMethod();
\r
46 // final String mSetName = (mSetMethod==null)?"":mSetMethod.getName();
\r
47 final String pName = mGetName.substring(3);
\r
48 final String pname = pName.substring(0,1).toLowerCase()
\r
49 + pName.substring(1);
\r
50 // final String pTypeUnreadable = pDAi.getPropertyType().getName();
\r
54 " pD=new PropertyDescriptor(\""+pname+"\",myClass);\n"+
\r
55 " pD.setDisplayName(\""+pName+"\");\n"+
\r
56 " pD.setPropertyEditorClass("+pName+"Editor.class);\n"+
\r
57 " pD.setBound(false);\n"+
\r
58 " pD.setConstrained(false);\n"+
\r
59 " pD.setHidden(false);\n"+
\r
60 " pD.setPreferred(true);\n"+
\r
61 " pD.setShortDescription(\""+pName+"\");\n"+
\r
62 " pD.setExpert(false);\n"+
\r
63 " properties[i++]=pD;\n");
\r
66 return (// Sorry not to respect usual identation here.
\r
67 "// Brought to you by JTEM - JavaTtools for Experimental Mathematics\n"+
\r
68 "// http://www.jtem.de\n"+
\r
69 "// BeanInfo Maker GPL Copyright (C) 2002 JTEM-Group\n"+
\r
71 "// This program is free software; you can redistribute it and/or modify\n"+
\r
72 "// it under the terms of the GNU General Public License as published by\n"+
\r
73 "// the Free Software Foundation; either version 2 of the License, or\n"+
\r
74 "// any later version.\n"+
\r
76 "// This program is distributed in the hope that it will be useful,\n"+
\r
77 "// but WITHOUT ANY WARRANTY; without even the implied warranty of\n"+
\r
78 "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"+
\r
79 "// GNU General Public License for more details.\n"+
\r
81 "// You should have received a copy of the GNU General Public License\n"+
\r
82 "// along with this program; if not, write to the Free Software\n"+
\r
83 "// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"+
\r
85 ((packageName=="")?"": // Unknown package.
\r
86 "package "+packageName+";\n")+
\r
89 "import java.beans.*;\n"+
\r
92 " * Bean support class for {@link "+myClassName+"}\n"+
\r
94 " * @see BeanInfo\n"+
\r
96 "public class "+myClassName+"BeanInfo implements BeanInfo\n"+
\r
98 " private static final BeanDescriptor BD\n"+
\r
99 " =new BeanDescriptor("+myClassName+".class);\n"+
\r
100 " private static final PropertyDescriptor[] properties\n"+
\r
101 " =new PropertyDescriptor["+pDA.length+"];\n"+
\r
102 " private static IntrospectionException initialError=null;\n"+
\r
107 " Class myClass="+myClassName+".class;\n"+
\r
108 " BD.setDisplayName(\""+myClassName+" nice name\");\n"+
\r
109 " PropertyDescriptor pD;\n"+
\r
113 " catch(IntrospectionException ex)\n"+
\r
115 " initialError=ex;\n"+
\r
116 " ex.printStackTrace();\n"+
\r
119 " public "+myClassName+"BeanInfo() throws IntrospectionException\n"+
\r
121 " if(initialError!=null) throw initialError;\n"+
\r
123 " public BeanDescriptor getBeanDescriptor()\n"+
\r
127 " public EventSetDescriptor[] getEventSetDescriptors()\n"+
\r
131 " public int getDefaultEventIndex()\n"+
\r
135 " public PropertyDescriptor[] getPropertyDescriptors()\n"+
\r
137 "// System.out.println(\"providing good PropertyDescriptors\");\n"+
\r
138 " return properties;\n"+
\r
140 " public int getDefaultPropertyIndex()\n"+
\r
144 " public MethodDescriptor[] getMethodDescriptors()\n"+
\r
148 " public BeanInfo[] getAdditionalBeanInfo()\n"+
\r
152 " public java.awt.Image getIcon(int iconKind)\n"+
\r
162 String beanInfoMaker(Object o){
\r
164 final String fullClassName;
\r
165 if (o.getClass()==Class) {
\r
166 fullClassName = o.getName();
\r
168 fullClassName = o.getClass().getName();
\r
170 return beanInfoMaker(fullClassName);
\r
173 void beanInfoMaker(Object o, String fileName) // throws IOException
\r
176 File outputFile = new File(fileName);
\r
178 FileWriter out = new FileWriter(outputFile);
\r
179 out.write( beanInfoMaker(o));
\r
181 if (!fileName.endsWith("BeanInfo.java")) {
\r
182 System.out.println("Name it \"MyClassBeanInfo.java\"");
\r