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