Source Code Cross Referenced for CreationFactory.java in  » IDE-Netbeans » form » org » netbeans » modules » form » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » form » org.netbeans.modules.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.form;
043:
044:        import java.awt.*;
045:        import java.lang.reflect.InvocationTargetException;
046:        import java.util.*;
047:        import javax.swing.*;
048:        import javax.swing.border.Border;
049:        import org.openide.ErrorManager;
050:
051:        import org.netbeans.modules.form.fakepeer.FakePeerSupport;
052:
053:        /**
054:         * Factory class for creating objects, providing java creation code,
055:         * registering CreationDescriptor classes, and related utility methods.
056:         *
057:         * @author Tomas Pavek
058:         */
059:
060:        public class CreationFactory {
061:
062:            private static Map<String, CreationDescriptor> registry;
063:
064:            private static boolean defaultDescriptorsCreated = false;
065:
066:            interface PropertyParameters {
067:
068:                public String getPropertyName();
069:
070:                public String getJavaParametersString(FormProperty prop);
071:
072:                public Object[] getPropertyParametersValues(FormProperty prop);
073:
074:                public Class[] getPropertyParametersTypes();
075:            }
076:
077:            static class Property2ParametersMapper {
078:
079:                private final String propertyName;
080:                private final Class[] propertyType = new Class[1];
081:                private PropertyParameters parameters;
082:
083:                Property2ParametersMapper(Class propertyClass,
084:                        String propertyName) {
085:                    this .propertyType[0] = propertyClass;
086:                    this .propertyName = propertyName;
087:                }
088:
089:                public String getPropertyName() {
090:                    return propertyName;
091:                }
092:
093:                public Class[] getPropertyTypes() {
094:                    if (parameters != null) {
095:                        return parameters.getPropertyParametersTypes();
096:                    }
097:                    return propertyType;
098:                }
099:
100:                public String getJavaParametersString(FormProperty prop) {
101:                    if (parameters != null) {
102:                        return parameters.getJavaParametersString(prop);
103:                    }
104:                    return prop.getJavaInitializationString();
105:                }
106:
107:                public Object[] getPropertyParametersValues(FormProperty prop) {
108:                    if (parameters != null) {
109:                        return parameters.getPropertyParametersValues(prop);
110:                    }
111:                    try {
112:                        return new Object[] { prop.getRealValue() };
113:                    } catch (InvocationTargetException ite) {
114:                        ErrorManager.getDefault().notify(ite);
115:                    } catch (IllegalAccessException iae) {
116:                        ErrorManager.getDefault().notify(iae);
117:                    }
118:                    return new Object[] {};
119:                }
120:
121:                public void setPropertyParameters(PropertyParameters parameters) {
122:                    this .parameters = parameters;
123:                }
124:            }
125:
126:            private CreationFactory() {
127:            }
128:
129:            // -----------
130:            // registry methods
131:
132:            public static CreationDescriptor getDescriptor(Class cls) {
133:                CreationDescriptor cd = getRegistry().get(cls.getName());
134:                if (cd == null && !defaultDescriptorsCreated
135:                        && (cls.getName().startsWith("javax.swing.") // NOI18N
136:                        || cls.getName().startsWith("java.awt."))) { // NOI18N
137:                    createDefaultDescriptors();
138:                    cd = getRegistry().get(cls.getName());
139:                }
140:                if (cd != null) {
141:                    cd.setDescribedClass(cls);
142:                }
143:                return cd;
144:            }
145:
146:            public static void registerDescriptor(CreationDescriptor desc) {
147:                getRegistry().put(desc.getDescribedClassName(), desc);
148:            }
149:
150:            public static void unregisterDescriptor(CreationDescriptor desc) {
151:                if (registry != null)
152:                    registry.remove(desc.getDescribedClassName());
153:            }
154:
155:            // -----------
156:            // creation methods
157:
158:            public static Object createDefaultInstance(final Class cls)
159:                    throws Exception {
160:                CreationDescriptor cd = getDescriptor(cls);
161:                Object cl = UIManager.get("ClassLoader"); // NOI18N
162:                ClassLoader systemCl = org.openide.util.Lookup.getDefault()
163:                        .lookup(ClassLoader.class);
164:                if (cl == systemCl) { // System classloader doesn't help to load user classes like JXLoginPanel
165:                    UIManager.put("ClassLoader", null); // NOI18N
166:                }
167:                Object instance = cd != null ? cd.createDefaultInstance() : cls
168:                        .newInstance();
169:                UIManager.put("ClassLoader", cl); // NOI18N
170:                initAfterCreation(instance);
171:                return instance;
172:            }
173:
174:            public static Object createInstance(Class cls) throws Exception {
175:                Object instance;
176:
177:                CreationDescriptor cd = CreationFactory.getDescriptor(cls);
178:                instance = cd != null ? cd.createDefaultInstance() : cls
179:                        .newInstance();
180:
181:                initAfterCreation(instance);
182:                return instance;
183:            }
184:
185:            public static Object createInstance(Class cls,
186:                    FormProperty[] props, int style) throws Exception {
187:                CreationDescriptor cd = getDescriptor(cls);
188:                if (cd == null)
189:                    return null;
190:
191:                CreationDescriptor.Creator creator = cd.findBestCreator(props,
192:                        style);
193:                if (creator == null)
194:                    return null;
195:
196:                Object instance = creator.createInstance(props);
197:                initAfterCreation(instance);
198:                return instance;
199:            }
200:
201:            public static String getJavaCreationCode(Class cls,
202:                    FormProperty[] props, int style) {
203:                CreationDescriptor cd = getDescriptor(cls);
204:                if (cd != null) {
205:                    CreationDescriptor.Creator creator = cd.findBestCreator(
206:                            props, style);
207:                    if (creator != null) {
208:                        creator.getJavaCreationCode(props, null, null);
209:                    }
210:                }
211:                return null;
212:            }
213:
214:            // ------------
215:            // utility methods
216:
217:            public static FormProperty[] getPropertiesForCreator(
218:                    CreationDescriptor.Creator creator,
219:                    FormProperty[] properties) {
220:
221:                String[] propNames = creator.getPropertyNames();
222:                FormProperty[] crProps = new FormProperty[propNames.length];
223:
224:                for (int i = 0; i < propNames.length; i++) {
225:                    String propName = propNames[i];
226:                    for (int j = 0; j < properties.length; j++)
227:                        if (propName.equals(properties[j].getName())) {
228:                            crProps[i] = properties[j];
229:                            break;
230:                        }
231:                    if (crProps[i] == null)
232:                        return null; // missing property, should not happen
233:                }
234:
235:                return crProps;
236:            }
237:
238:            public static FormProperty[] getRemainingProperties(
239:                    CreationDescriptor.Creator creator,
240:                    FormProperty[] properties) {
241:
242:                String[] propNames = creator.getPropertyNames();
243:                FormProperty[] remProps = new FormProperty[properties.length
244:                        - propNames.length];
245:                if (remProps.length == 0)
246:                    return remProps;
247:
248:                int ii = 0;
249:                for (int i = 0; i < properties.length; i++) {
250:                    String propName = properties[i].getName();
251:                    for (int j = 0; j < propNames.length; j++) {
252:                        if (propName.equals(propNames[j]))
253:                            break;
254:                        if (j + 1 == propNames.length) {
255:                            if (ii > remProps.length)
256:                                return null; // should not happen
257:                            remProps[ii++] = properties[i];
258:                        }
259:                    }
260:                }
261:
262:                return remProps;
263:            }
264:
265:            public static boolean containsProperty(CreationDescriptor desc,
266:                    String propName) {
267:                CreationDescriptor.Creator[] creators = desc.getCreators();
268:                if (creators == null)
269:                    return false;
270:
271:                for (int i = 0; i < creators.length; i++) {
272:                    String[] propNames = creators[i].getPropertyNames();
273:                    for (int j = 0; j < propNames.length; j++)
274:                        if (propNames[j].equals(propName))
275:                            return true;
276:                }
277:                return false;
278:            }
279:
280:            public static boolean containsProperty(
281:                    CreationDescriptor.Creator creator, String propName) {
282:                String[] propNames = creator.getPropertyNames();
283:                for (int j = 0; j < propNames.length; j++)
284:                    if (propNames[j].equals(propName))
285:                        return true;
286:                return false;
287:            }
288:
289:            public static FormProperty findProperty(String propName,
290:                    FormProperty[] properties) {
291:                for (int i = 0; i < properties.length; i++)
292:                    if (properties[i].getName().equals(propName))
293:                        return properties[i];
294:                return null;
295:            }
296:
297:            public static CreationDescriptor.Creator findCreator(
298:                    CreationDescriptor desc, Class[] paramTypes) {
299:                CreationDescriptor.Creator[] creators = desc.getCreators();
300:                for (int i = 0; i < creators.length; i++) {
301:                    CreationDescriptor.Creator cr = creators[i];
302:                    if (cr.getParameterCount() == paramTypes.length) {
303:                        Class[] types = cr.getParameterTypes();
304:                        boolean match = true;
305:                        for (int j = 0; j < types.length; j++)
306:                            if (!types[j].isAssignableFrom(paramTypes[j])) {
307:                                match = false;
308:                                break;
309:                            }
310:                        if (match)
311:                            return cr;
312:                    }
313:                }
314:                return null;
315:            }
316:
317:            /** Evaluates creators for array of properties.
318:             * (Useful for CreationDescriptor.findBestCreator(...) implementation.)
319:             * 
320:             * @param creators creators to consider
321:             * @param properties properties to consider
322:             * @param changedOnly determines whether to consider changed properties only
323:             * @return array of int - for each creator a count of placed properties
324:             */
325:            public static int[] evaluateCreators(
326:                    CreationDescriptor.Creator[] creators,
327:                    FormProperty[] properties, boolean changedOnly) {
328:
329:                if (creators == null || creators.length == 0)
330:                    return null;
331:
332:                int[] placed = new int[creators.length];
333:                for (int i = 0; i < properties.length; i++) {
334:                    if (!changedOnly || properties[i].isChanged()) {
335:                        String name = properties[i].getName();
336:
337:                        for (int j = 0; j < creators.length; j++) {
338:                            String[] crNames = creators[j].getPropertyNames();
339:                            for (int k = 0; k < crNames.length; k++)
340:                                if (name.equals(crNames[k]))
341:                                    placed[j]++;
342:                        }
343:                    }
344:                }
345:                return placed;
346:            }
347:
348:            /** Finds the best creator upon given evaluation.
349:             * (Useful for CreationDescriptor.findBestCreator(...) implementation.)
350:             * 
351:             * @param creators creators to consider.
352:             * @param properties properties to consider.
353:             * @param placed for each creator a count of placed properties
354:             * @param placeAllProps determines whether all properties should be placed
355:             * @return index of most suitable creator
356:             */
357:            public static int getBestCreator(
358:                    CreationDescriptor.Creator[] creators,
359:                    FormProperty[] properties, int[] placed,
360:                    boolean placeAllProps) {
361:                if (creators == null || creators.length == 0)
362:                    return -1;
363:
364:                int best = 0;
365:                int[] sizes = new int[creators.length];
366:                sizes[0] = creators[0].getParameterCount();
367:
368:                if (placeAllProps) {
369:                    // find shortest creator with all properties placed
370:                    for (int i = 1; i < placed.length; i++) {
371:                        sizes[i] = creators[i].getParameterCount();
372:                        if (placed[i] > placed[best]
373:                                || (placed[i] == placed[best] && (sizes[i] < sizes[best] || (sizes[i] == sizes[best] && compareCreatorsAmbiguity(
374:                                        creators[i], creators[best], properties) == 1))))
375:                            best = i;
376:                    }
377:                } else { // find longest creator with all parameters provided by properties
378:                    for (int i = 1; i < placed.length; i++) {
379:                        sizes[i] = creators[i].getParameterCount();
380:                        int iDiff = sizes[i] - placed[i];
381:                        int bestDiff = sizes[best] - placed[best];
382:                        if (iDiff < bestDiff
383:                                || (iDiff == bestDiff && (sizes[i] > sizes[best] || (sizes[i] == sizes[best] && compareCreatorsAmbiguity(
384:                                        creators[i], creators[best], properties) == 1))))
385:                            best = i;
386:                    }
387:                }
388:
389:                return best;
390:            }
391:
392:            // -----------
393:            // non-public methods
394:
395:            /** Compares two creators with equal number of placed properties and equal
396:             * number of all properties. To distinguish which one is better, their
397:             * properties are checked for null values which could cause ambiguity in
398:             * generated code.
399:             * @return 1 if creator1 is better, 2 if creator2 is better, 0 if they
400:             *          are equal
401:             */
402:            static int compareCreatorsAmbiguity(CreationDescriptor.Creator cr1,
403:                    CreationDescriptor.Creator cr2, FormProperty[] properties) {
404:                int nullValues1 = 0;
405:                int nullValues2 = 0;
406:
407:                for (int i = 0, n = cr1.getParameterCount(); i < n; i++) {
408:                    String name1 = cr1.getPropertyNames()[i];
409:                    String name2 = cr2.getPropertyNames()[i];
410:                    if (!name1.equals(name2)) {
411:                        FormProperty prop1 = null;
412:                        FormProperty prop2 = null;
413:                        for (int j = 0; j < properties.length; j++)
414:                            if (prop1 == null
415:                                    && name1.equals(properties[j].getName())) {
416:                                prop1 = properties[j];
417:                                if (prop2 != null)
418:                                    break;
419:                            } else if (prop2 == null
420:                                    && name2.equals(properties[j].getName())) {
421:                                prop2 = properties[j];
422:                                if (prop1 != null)
423:                                    break;
424:                            }
425:
426:                        if (prop1 != null
427:                                && !prop1.getValueType().isPrimitive()) {
428:                            try {
429:                                if (prop1.getRealValue() == null)
430:                                    nullValues1++;
431:                            } catch (Exception ex) {
432:                            } // ignore
433:                        }
434:                        if (prop2 != null
435:                                && !prop2.getValueType().isPrimitive()) {
436:                            try {
437:                                if (prop2.getRealValue() == null)
438:                                    nullValues2++;
439:                            } catch (Exception ex) {
440:                            } // ignore
441:                        }
442:                    }
443:                }
444:
445:                if (nullValues1 == nullValues2)
446:                    return 0;
447:                return nullValues1 < nullValues2 ? 1 : 2;
448:            }
449:
450:            static Map<String, CreationDescriptor> getRegistry() {
451:                if (registry == null)
452:                    registry = new HashMap<String, CreationDescriptor>(40);
453:                return registry;
454:            }
455:
456:            // additional initializations for some components - in fact hacks required
457:            // by using fake peers and remapping L&F...
458:            private static void initAfterCreation(Object instance) {
459:                if (instance instanceof  javax.swing.border.TitledBorder)
460:                    ((javax.swing.border.TitledBorder) instance)
461:                            .setTitleFont(UIManager
462:                                    .getFont("TitledBorder.createDefaultInstancefont")); // NOI18N
463:                else if (instance instanceof  java.awt.Component
464:                        && !(instance instanceof  javax.swing.JComponent)
465:                        && !(instance instanceof  javax.swing.RootPaneContainer)) {
466:                    ((Component) instance).setName(null);
467:                    ((Component) instance).setFont(FakePeerSupport
468:                            .getDefaultAWTFont());
469:                } else if (instance instanceof  MenuComponent) {
470:                    ((MenuComponent) instance).setName(null);
471:                    ((MenuComponent) instance).setFont(FakePeerSupport
472:                            .getDefaultAWTFont());
473:                }
474:            }
475:
476:            // ---------------------------------------------------
477:            // constructors descriptors for some "special" classes...  
478:            private static void createDefaultDescriptors() {
479:                Class[][] constrParamTypes;
480:                String[][] constrPropertyNames;
481:                Object[] defaultConstrParams;
482:                String methodName;
483:                CreationDescriptor cd;
484:                InsetsPropertyParameters[] insetsPropertyParameters = new InsetsPropertyParameters[] { new InsetsPropertyParameters(
485:                        "borderInsets") };
486:
487:                try {
488:                    // borders ------------
489:
490:                    // LineBorder                                       
491:                    constrParamTypes = new Class[][] { { Color.class,
492:                            Integer.TYPE, Boolean.TYPE }
493:
494:                    };
495:                    constrPropertyNames = new String[][] { { "lineColor",
496:                            "thickness", "roundedCorners" } };
497:
498:                    defaultConstrParams = new Object[] { java.awt.Color.black };
499:                    cd = new CreationDescriptor();
500:                    cd.addConstructorCreators(
501:                            javax.swing.border.LineBorder.class,
502:                            constrParamTypes, constrPropertyNames,
503:                            defaultConstrParams);
504:
505:                    constrParamTypes = new Class[][] { { Color.class },
506:                            { Color.class, Integer.TYPE } };
507:                    constrPropertyNames = new String[][] { { "lineColor" },
508:                            { "lineColor", "thickness" }
509:
510:                    };
511:                    methodName = "createLineBorder";
512:
513:                    cd.addMethodCreators(javax.swing.BorderFactory.class,
514:                            javax.swing.border.LineBorder.class, methodName,
515:                            constrParamTypes, constrPropertyNames, null,
516:                            defaultConstrParams);
517:                    registerDescriptor(cd);
518:
519:                    // EtchedBorder
520:                    defaultConstrParams = new Object[] {};
521:                    constrParamTypes = new Class[][] { {},
522:                            { Color.class, Color.class }, { Integer.TYPE },
523:                            { Integer.TYPE, Color.class, Color.class } };
524:                    constrPropertyNames = new String[][] { {},
525:                            { "highlightColor", "shadowColor" },
526:                            { "etchType" },
527:                            { "etchType", "highlightColor", "shadowColor" } };
528:
529:                    methodName = "createEtchedBorder";
530:                    registerDescriptor(new CreationDescriptor(
531:                            javax.swing.BorderFactory.class,
532:                            javax.swing.border.EtchedBorder.class, methodName,
533:                            constrParamTypes, constrPropertyNames, null,
534:                            defaultConstrParams));
535:
536:                    // EmptyBorder     
537:                    constrParamTypes = new Class[][] { { Insets.class } };
538:                    constrPropertyNames = new String[][] { { "borderInsets" } };
539:
540:                    defaultConstrParams = new Object[] { new Integer(1),
541:                            new Integer(1), new Integer(1), new Integer(1) };
542:                    methodName = "createEmptyBorder";
543:
544:                    registerDescriptor(new CreationDescriptor(
545:                            javax.swing.BorderFactory.class,
546:                            javax.swing.border.EmptyBorder.class, methodName,
547:                            constrParamTypes, constrPropertyNames,
548:                            insetsPropertyParameters, defaultConstrParams));
549:
550:                    // TitledBorder              
551:                    constrParamTypes = new Class[][] {
552:                            { String.class },
553:                            { Border.class, String.class },
554:                            { Border.class, String.class, Integer.TYPE,
555:                                    Integer.TYPE },
556:                            { Border.class, String.class, Integer.TYPE,
557:                                    Integer.TYPE, Font.class },
558:                            { Border.class, String.class, Integer.TYPE,
559:                                    Integer.TYPE, Font.class, Color.class },
560:                            { Border.class } };
561:                    constrPropertyNames = new String[][] {
562:                            { "title" },
563:                            { "border", "title" },
564:                            { "border", "title", "titleJustification",
565:                                    "titlePosition" },
566:                            { "border", "title", "titleJustification",
567:                                    "titlePosition", "titleFont" },
568:                            { "border", "title", "titleJustification",
569:                                    "titlePosition", "titleFont", "titleColor" },
570:                            { "border" } };
571:
572:                    defaultConstrParams = new Object[] { null, "",
573:                            new Integer(0), new Integer(0) };
574:                    methodName = "createTitledBorder";
575:                    registerDescriptor(new CreationDescriptor(
576:                            javax.swing.BorderFactory.class,
577:                            javax.swing.border.TitledBorder.class, methodName,
578:                            constrParamTypes, constrPropertyNames, null,
579:                            defaultConstrParams));
580:
581:                    // CompoundBorder          
582:                    constrParamTypes = new Class[][] { {},
583:                            { Border.class, Border.class } };
584:                    constrPropertyNames = new String[][] { {},
585:                            { "outsideBorder", "insideBorder" } };
586:
587:                    defaultConstrParams = new Object[0];
588:                    methodName = "createCompoundBorder";
589:                    registerDescriptor(new CreationDescriptor(
590:                            javax.swing.BorderFactory.class,
591:                            javax.swing.border.CompoundBorder.class,
592:                            methodName, constrParamTypes, constrPropertyNames,
593:                            null, defaultConstrParams));
594:
595:                    // BevelBorder
596:                    constrParamTypes = new Class[][] {
597:                            { Integer.TYPE },
598:                            { Integer.TYPE, Color.class, Color.class },
599:                            { Integer.TYPE, Color.class, Color.class,
600:                                    Color.class, Color.class } };
601:                    constrPropertyNames = new String[][] {
602:                            { "bevelType" },
603:                            { "bevelType", "highlightOuterColor",
604:                                    "shadowOuterColor" },
605:                            { "bevelType", "highlightOuterColor",
606:                                    "highlightInnerColor", "shadowOuterColor",
607:                                    "shadowInnerColor" } };
608:
609:                    defaultConstrParams = new Object[] { new Integer(
610:                            javax.swing.border.BevelBorder.RAISED) };
611:                    methodName = "createBevelBorder";
612:                    registerDescriptor(new CreationDescriptor(
613:                            javax.swing.BorderFactory.class,
614:                            javax.swing.border.BevelBorder.class, methodName,
615:                            constrParamTypes, constrPropertyNames, null,
616:                            defaultConstrParams));
617:
618:                    // SoftBevelBorder
619:                    constrParamTypes = new Class[][] {
620:                            { Integer.TYPE },
621:                            { Integer.TYPE, Color.class, Color.class },
622:                            { Integer.TYPE, Color.class, Color.class,
623:                                    Color.class, Color.class } };
624:                    constrPropertyNames = new String[][] {
625:                            { "bevelType" },
626:                            { "bevelType", "highlightOuterColor",
627:                                    "shadowOuterColor" },
628:                            { "bevelType", "highlightOuterColor",
629:                                    "highlightInnerColor", "shadowOuterColor",
630:                                    "shadowInnerColor" } };
631:                    registerDescriptor(new CreationDescriptor(
632:                            javax.swing.border.SoftBevelBorder.class,
633:                            constrParamTypes, constrPropertyNames,
634:                            defaultConstrParams));
635:
636:                    // MatteBorder              
637:                    cd = new CreationDescriptor();
638:
639:                    constrParamTypes = new Class[][] { { Icon.class } };
640:                    constrPropertyNames = new String[][] { { "tileIcon" } };
641:                    cd.addConstructorCreators(
642:                            javax.swing.border.MatteBorder.class,
643:                            constrParamTypes, constrPropertyNames,
644:                            defaultConstrParams);
645:
646:                    constrParamTypes = new Class[][] {
647:                            { Insets.class, Icon.class },
648:                            { Insets.class, Color.class } };
649:                    constrPropertyNames = new String[][] {
650:                            { "borderInsets", "tileIcon" },
651:                            { "borderInsets", "matteColor" } };
652:                    defaultConstrParams = new Object[] { new Integer(1),
653:                            new Integer(1), new Integer(1), new Integer(1),
654:                            java.awt.Color.black };
655:                    methodName = "createMatteBorder";
656:                    cd.addMethodCreators(javax.swing.BorderFactory.class,
657:                            javax.swing.border.MatteBorder.class, methodName,
658:                            constrParamTypes, constrPropertyNames,
659:                            insetsPropertyParameters, defaultConstrParams);
660:                    registerDescriptor(cd);
661:
662:                    // layouts --------------
663:
664:                    // BorderLayout
665:                    constrParamTypes = new Class[][] { {},
666:                            { Integer.TYPE, Integer.TYPE } };
667:                    constrPropertyNames = new String[][] { {},
668:                            { "hgap", "vgap" } };
669:                    defaultConstrParams = new Object[0];
670:                    registerDescriptor(new CreationDescriptor(
671:                            java.awt.BorderLayout.class, constrParamTypes,
672:                            constrPropertyNames, defaultConstrParams));
673:
674:                    // FlowLayout
675:                    constrParamTypes = new Class[][] { {}, { Integer.TYPE },
676:                            { Integer.TYPE, Integer.TYPE, Integer.TYPE } };
677:                    constrPropertyNames = new String[][] { {}, { "alignment" },
678:                            { "alignment", "hgap", "vgap" }, };
679:                    registerDescriptor(new CreationDescriptor(
680:                            java.awt.FlowLayout.class, constrParamTypes,
681:                            constrPropertyNames, defaultConstrParams));
682:
683:                    // GridBagLayout
684:                    constrParamTypes = new Class[][] { {} };
685:                    constrPropertyNames = new String[][] { {} };
686:                    registerDescriptor(new CreationDescriptor(
687:                            java.awt.GridBagLayout.class, constrParamTypes,
688:                            constrPropertyNames, defaultConstrParams));
689:
690:                    // GridLayout
691:                    constrParamTypes = new Class[][] {
692:                            {},
693:                            { Integer.TYPE, Integer.TYPE },
694:                            { Integer.TYPE, Integer.TYPE, Integer.TYPE,
695:                                    Integer.TYPE } };
696:                    constrPropertyNames = new String[][] { {},
697:                            { "rows", "columns" },
698:                            { "rows", "columns", "hgap", "vgap" } };
699:                    registerDescriptor(new CreationDescriptor(
700:                            java.awt.GridLayout.class, constrParamTypes,
701:                            constrPropertyNames, defaultConstrParams));
702:
703:                    // CardLayout
704:                    constrParamTypes = new Class[][] { {},
705:                            { Integer.TYPE, Integer.TYPE } };
706:                    constrPropertyNames = new String[][] { {},
707:                            { "hgap", "vgap" } };
708:                    registerDescriptor(new CreationDescriptor(
709:                            java.awt.CardLayout.class, constrParamTypes,
710:                            constrPropertyNames, defaultConstrParams));
711:
712:                    // AWT --------
713:
714:                    // Dialog
715:                    constrParamTypes = new Class[][] { { java.awt.Frame.class }, };
716:                    constrPropertyNames = new String[][] { { "owner" }, };
717:                    defaultConstrParams = new Object[] { new java.awt.Frame() };
718:                    registerDescriptor(new CreationDescriptor(
719:                            java.awt.Dialog.class, constrParamTypes,
720:                            constrPropertyNames, defaultConstrParams));
721:
722:                    // other -------
723:
724:                    // JPanel on JDK 1.3 uses one instance of FlowLayout for all instances
725:                    // created by default constructor - this causes problems
726:                    registerDescriptor(new CreationDescriptor(
727:                            javax.swing.JPanel.class) {
728:                        @Override
729:                        public Object createDefaultInstance() {
730:                            return new javax.swing.JPanel(
731:                                    new java.awt.FlowLayout());
732:                        }
733:                    });
734:
735:                    // ----------
736:
737:                    defaultDescriptorsCreated = true;
738:
739:                } catch (NoSuchMethodException ex) { // should not happen
740:                    ex.printStackTrace();
741:                }
742:            }
743:
744:            static class InsetsPropertyParameters implements  PropertyParameters {
745:
746:                private static Class[] parameterTypes = new Class[] {
747:                        Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE };
748:                private final String propertyName;
749:
750:                public InsetsPropertyParameters(String propertyName) {
751:                    this .propertyName = propertyName;
752:                }
753:
754:                public String getPropertyName() {
755:                    return propertyName;
756:                }
757:
758:                public String getJavaParametersString(FormProperty prop) {
759:                    Insets insets = (Insets) getRealValue(prop);
760:                    if (insets != null) {
761:                        return insets.top + ", " + insets.left + ", "
762:                                + insets.bottom + ", " + insets.right;
763:                    } else {
764:                        return "";
765:                    }
766:                }
767:
768:                public Object[] getPropertyParametersValues(FormProperty prop) {
769:                    Insets insets = (Insets) getRealValue(prop);
770:                    if (insets != null) {
771:                        return new Object[] { new Integer(insets.top),
772:                                new Integer(insets.left),
773:                                new Integer(insets.bottom),
774:                                new Integer(insets.right) };
775:                    } else {
776:                        return new Object[] {};
777:                    }
778:                }
779:
780:                public Class[] getPropertyParametersTypes() {
781:                    return parameterTypes;
782:                }
783:
784:                private static Object getRealValue(FormProperty prop) {
785:                    try {
786:                        return prop.getRealValue();
787:                    } catch (InvocationTargetException ite) {
788:                        ErrorManager.getDefault().notify(ite);
789:                    } catch (IllegalAccessException iae) {
790:                        ErrorManager.getDefault().notify(iae);
791:                    }
792:                    return null;
793:                }
794:            }
795:
796:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.