SimpleBeanInfo.java revision 12632:58fde919b6c3
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.io.InputStream; 31 32/** 33 * This is a support class to make it easier for people to provide 34 * BeanInfo classes. 35 * <p> 36 * It defaults to providing "noop" information, and can be selectively 37 * overriden to provide more explicit information on chosen topics. 38 * When the introspector sees the "noop" values, it will apply low 39 * level introspection and design patterns to automatically analyze 40 * the target bean. 41 * 42 * @since 1.1 43 */ 44 45public class SimpleBeanInfo implements BeanInfo { 46 47 /** 48 * Deny knowledge about the class and customizer of the bean. 49 * You can override this if you wish to provide explicit info. 50 */ 51 public BeanDescriptor getBeanDescriptor() { 52 return null; 53 } 54 55 /** 56 * Deny knowledge of properties. You can override this 57 * if you wish to provide explicit property info. 58 */ 59 public PropertyDescriptor[] getPropertyDescriptors() { 60 return null; 61 } 62 63 /** 64 * Deny knowledge of a default property. You can override this 65 * if you wish to define a default property for the bean. 66 */ 67 public int getDefaultPropertyIndex() { 68 return -1; 69 } 70 71 /** 72 * Deny knowledge of event sets. You can override this 73 * if you wish to provide explicit event set info. 74 */ 75 public EventSetDescriptor[] getEventSetDescriptors() { 76 return null; 77 } 78 79 /** 80 * Deny knowledge of a default event. You can override this 81 * if you wish to define a default event for the bean. 82 */ 83 public int getDefaultEventIndex() { 84 return -1; 85 } 86 87 /** 88 * Deny knowledge of methods. You can override this 89 * if you wish to provide explicit method info. 90 */ 91 public MethodDescriptor[] getMethodDescriptors() { 92 return null; 93 } 94 95 /** 96 * Claim there are no other relevant BeanInfo objects. You 97 * may override this if you want to (for example) return a 98 * BeanInfo for a base class. 99 */ 100 public BeanInfo[] getAdditionalBeanInfo() { 101 return null; 102 } 103 104 /** 105 * Claim there are no icons available. You can override 106 * this if you want to provide icons for your bean. 107 */ 108 public Image getIcon(int iconKind) { 109 return null; 110 } 111 112 /** 113 * This is a utility method to help in loading icon images. 114 * It takes the name of a resource file associated with the 115 * current object's class file and loads an image object 116 * from that file. Typically images will be GIFs. 117 * 118 * @param resourceName A pathname relative to the directory 119 * holding the class file of the current class. For example, 120 * "wombat.gif". 121 * @return an image object. May be null if the load failed. 122 */ 123 public Image loadImage(final String resourceName) { 124 try (InputStream in = getClass().getResourceAsStream(resourceName)) { 125 return Toolkit.getDefaultToolkit().createImage(in.readAllBytes()); 126 } catch (final Exception ignored) { 127 } 128 return null; 129 } 130} 131