SimpleBeanInfo.java revision 11769:74e8bd53b31d
1/*
2 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans;
27
28import java.awt.Image;
29import java.awt.Toolkit;
30import java.awt.image.ImageProducer;
31import java.net.URL;
32
33/**
34 * This is a support class to make it easier for people to provide
35 * BeanInfo classes.
36 * <p>
37 * It defaults to providing "noop" information, and can be selectively
38 * overriden to provide more explicit information on chosen topics.
39 * When the introspector sees the "noop" values, it will apply low
40 * level introspection and design patterns to automatically analyze
41 * the target bean.
42 *
43 * @since 1.1
44 */
45
46public class SimpleBeanInfo implements BeanInfo {
47
48    /**
49     * Deny knowledge about the class and customizer of the bean.
50     * You can override this if you wish to provide explicit info.
51     */
52    public BeanDescriptor getBeanDescriptor() {
53        return null;
54    }
55
56    /**
57     * Deny knowledge of properties. You can override this
58     * if you wish to provide explicit property info.
59     */
60    public PropertyDescriptor[] getPropertyDescriptors() {
61        return null;
62    }
63
64    /**
65     * Deny knowledge of a default property. You can override this
66     * if you wish to define a default property for the bean.
67     */
68    public int getDefaultPropertyIndex() {
69        return -1;
70    }
71
72    /**
73     * Deny knowledge of event sets. You can override this
74     * if you wish to provide explicit event set info.
75     */
76    public EventSetDescriptor[] getEventSetDescriptors() {
77        return null;
78    }
79
80    /**
81     * Deny knowledge of a default event. You can override this
82     * if you wish to define a default event for the bean.
83     */
84    public int getDefaultEventIndex() {
85        return -1;
86    }
87
88    /**
89     * Deny knowledge of methods. You can override this
90     * if you wish to provide explicit method info.
91     */
92    public MethodDescriptor[] getMethodDescriptors() {
93        return null;
94    }
95
96    /**
97     * Claim there are no other relevant BeanInfo objects.  You
98     * may override this if you want to (for example) return a
99     * BeanInfo for a base class.
100     */
101    public BeanInfo[] getAdditionalBeanInfo() {
102        return null;
103    }
104
105    /**
106     * Claim there are no icons available.  You can override
107     * this if you want to provide icons for your bean.
108     */
109    public Image getIcon(int iconKind) {
110        return null;
111    }
112
113    /**
114     * This is a utility method to help in loading icon images.
115     * It takes the name of a resource file associated with the
116     * current object's class file and loads an image object
117     * from that file.  Typically images will be GIFs.
118     *
119     * @param resourceName  A pathname relative to the directory
120     *          holding the class file of the current class.  For example,
121     *          "wombat.gif".
122     * @return  an image object.  May be null if the load failed.
123     */
124    public Image loadImage(final String resourceName) {
125        try {
126            final URL url = getClass().getResource(resourceName);
127            if (url != null) {
128                final ImageProducer ip = (ImageProducer) url.getContent();
129                if (ip != null) {
130                    return Toolkit.getDefaultToolkit().createImage(ip);
131                }
132            }
133        } catch (final Exception ignored) {
134        }
135        return null;
136    }
137}
138