001 /*
002 * Copyright 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.beans;
027
028 /**
029 * This is a support class to make it easier for people to provide
030 * BeanInfo classes.
031 * <p>
032 * It defaults to providing "noop" information, and can be selectively
033 * overriden to provide more explicit information on chosen topics.
034 * When the introspector sees the "noop" values, it will apply low
035 * level introspection and design patterns to automatically analyze
036 * the target bean.
037 */
038
039 public class SimpleBeanInfo implements BeanInfo {
040
041 /**
042 * Deny knowledge about the class and customizer of the bean.
043 * You can override this if you wish to provide explicit info.
044 */
045 public BeanDescriptor getBeanDescriptor() {
046 return null;
047 }
048
049 /**
050 * Deny knowledge of properties. You can override this
051 * if you wish to provide explicit property info.
052 */
053 public PropertyDescriptor[] getPropertyDescriptors() {
054 return null;
055 }
056
057 /**
058 * Deny knowledge of a default property. You can override this
059 * if you wish to define a default property for the bean.
060 */
061 public int getDefaultPropertyIndex() {
062 return -1;
063 }
064
065 /**
066 * Deny knowledge of event sets. You can override this
067 * if you wish to provide explicit event set info.
068 */
069 public EventSetDescriptor[] getEventSetDescriptors() {
070 return null;
071 }
072
073 /**
074 * Deny knowledge of a default event. You can override this
075 * if you wish to define a default event for the bean.
076 */
077 public int getDefaultEventIndex() {
078 return -1;
079 }
080
081 /**
082 * Deny knowledge of methods. You can override this
083 * if you wish to provide explicit method info.
084 */
085 public MethodDescriptor[] getMethodDescriptors() {
086 return null;
087 }
088
089 /**
090 * Claim there are no other relevant BeanInfo objects. You
091 * may override this if you want to (for example) return a
092 * BeanInfo for a base class.
093 */
094 public BeanInfo[] getAdditionalBeanInfo() {
095 return null;
096 }
097
098 /**
099 * Claim there are no icons available. You can override
100 * this if you want to provide icons for your bean.
101 */
102 public java.awt.Image getIcon(int iconKind) {
103 return null;
104 }
105
106 /**
107 * This is a utility method to help in loading icon images.
108 * It takes the name of a resource file associated with the
109 * current object's class file and loads an image object
110 * from that file. Typically images will be GIFs.
111 * <p>
112 * @param resourceName A pathname relative to the directory
113 * holding the class file of the current class. For example,
114 * "wombat.gif".
115 * @return an image object. May be null if the load failed.
116 */
117 public java.awt.Image loadImage(final String resourceName) {
118 try {
119 final Class c = getClass();
120 java.awt.image.ImageProducer ip = (java.awt.image.ImageProducer) java.security.AccessController
121 .doPrivileged(new java.security.PrivilegedAction() {
122 public Object run() {
123 java.net.URL url;
124 if ((url = c.getResource(resourceName)) == null) {
125 return null;
126 } else {
127 try {
128 return url.getContent();
129 } catch (java.io.IOException ioe) {
130 return null;
131 }
132 }
133 }
134 });
135
136 if (ip == null)
137 return null;
138 java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
139 return tk.createImage(ip);
140 } catch (Exception ex) {
141 return null;
142 }
143 }
144
145 }
|