< prev index next >

src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java

Print this page


   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 
  26 package java.beans;
  27 
  28 import java.awt.Image;
  29 import java.awt.Toolkit;
  30 import java.io.InputStream;

  31 import java.security.AccessController;
  32 import java.security.PrivilegedAction;
  33 
  34 /**
  35  * This is a support class to make it easier for people to provide
  36  * BeanInfo classes.
  37  * <p>
  38  * It defaults to providing "noop" information, and can be selectively
  39  * overriden to provide more explicit information on chosen topics.
  40  * When the introspector sees the "noop" values, it will apply low
  41  * level introspection and design patterns to automatically analyze
  42  * the target bean.
  43  *
  44  * @since 1.1
  45  */
  46 public 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.


 165      */
 166     private Image loadImage(final String resourceName, final String suffix) {
 167         final String prefix = "/javax/swing/beaninfo/images/";
 168         final Image image = loadStandardImage(prefix + resourceName + suffix);
 169         return image == null ? loadStandardImage(prefix + "JComponent" + suffix)
 170                              : image;
 171     }
 172 
 173     /**
 174      * This is a utility method to help in loading icon images.
 175      * It takes the name of a resource file associated with the
 176      * current object's class file and loads an image object
 177      * from that file.  Typically images will be GIFs.
 178      *
 179      * @param resourceName  A pathname relative to the directory
 180      *          holding the class file of the current class.  For example,
 181      *          "wombat.gif".
 182      * @return  an image object.  May be null if the load failed.
 183      */
 184     public Image loadImage(final String resourceName) {
 185         try (InputStream in = getClass().getResourceAsStream(resourceName)) {
 186             return Toolkit.getDefaultToolkit().createImage(in.readAllBytes());






 187         } catch (final Exception ignored) {
 188         }
 189         return null;
 190     }
 191 }
   1 /*
   2  * Copyright (c) 1996, 2016, 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 
  26 package java.beans;
  27 
  28 import java.awt.Image;
  29 import java.awt.Toolkit;
  30 import java.awt.image.ImageProducer;
  31 import java.net.URL;
  32 import java.security.AccessController;
  33 import java.security.PrivilegedAction;
  34 
  35 /**
  36  * This is a support class to make it easier for people to provide
  37  * BeanInfo classes.
  38  * <p>
  39  * It defaults to providing "noop" information, and can be selectively
  40  * overriden to provide more explicit information on chosen topics.
  41  * When the introspector sees the "noop" values, it will apply low
  42  * level introspection and design patterns to automatically analyze
  43  * the target bean.
  44  *
  45  * @since 1.1
  46  */
  47 public class SimpleBeanInfo implements BeanInfo {
  48 
  49     /**
  50      * Deny knowledge about the class and customizer of the bean.
  51      * You can override this if you wish to provide explicit info.


 166      */
 167     private Image loadImage(final String resourceName, final String suffix) {
 168         final String prefix = "/javax/swing/beaninfo/images/";
 169         final Image image = loadStandardImage(prefix + resourceName + suffix);
 170         return image == null ? loadStandardImage(prefix + "JComponent" + suffix)
 171                              : image;
 172     }
 173 
 174     /**
 175      * This is a utility method to help in loading icon images.
 176      * It takes the name of a resource file associated with the
 177      * current object's class file and loads an image object
 178      * from that file.  Typically images will be GIFs.
 179      *
 180      * @param resourceName  A pathname relative to the directory
 181      *          holding the class file of the current class.  For example,
 182      *          "wombat.gif".
 183      * @return  an image object.  May be null if the load failed.
 184      */
 185     public Image loadImage(final String resourceName) {
 186         try {
 187             final URL url = getClass().getResource(resourceName);
 188             if (url != null) {
 189                 final ImageProducer ip = (ImageProducer) url.getContent();
 190                 if (ip != null) {
 191                     return Toolkit.getDefaultToolkit().createImage(ip);
 192                 }
 193             }
 194         } catch (final Exception ignored) {
 195         }
 196         return null;
 197     }
 198 }
< prev index next >