|
Java example source code file (BeanInfoUtils.java)
The BeanInfoUtils.java Java example source code
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.swing;
import java.beans.*;
import java.lang.reflect.Method;
public class BeanInfoUtils
{
/* The values of these createPropertyDescriptor() and
* createBeanDescriptor() keywords are the names of the
* properties they're used to set.
*/
public static final String BOUND = "bound";
public static final String CONSTRAINED = "constrained";
public static final String PROPERTYEDITORCLASS = "propertyEditorClass";
public static final String READMETHOD = "readMethod";
public static final String WRITEMETHOD = "writeMethod";
public static final String DISPLAYNAME = "displayName";
public static final String EXPERT = "expert";
public static final String HIDDEN = "hidden";
public static final String PREFERRED = "preferred";
public static final String SHORTDESCRIPTION = "shortDescription";
public static final String CUSTOMIZERCLASS = "customizerClass";
static private void initFeatureDescriptor(FeatureDescriptor fd, String key, Object value)
{
if (DISPLAYNAME.equals(key)) {
fd.setDisplayName((String)value);
}
if (EXPERT.equals(key)) {
fd.setExpert(((Boolean)value).booleanValue());
}
if (HIDDEN.equals(key)) {
fd.setHidden(((Boolean)value).booleanValue());
}
if (PREFERRED.equals(key)) {
fd.setPreferred(((Boolean)value).booleanValue());
}
else if (SHORTDESCRIPTION.equals(key)) {
fd.setShortDescription((String)value);
}
/* Otherwise assume that we have an arbitrary FeatureDescriptor
* "attribute".
*/
else {
fd.setValue(key, value);
}
}
/**
* Create a beans PropertyDescriptor given an of keyword/value
* arguments. The following sample call shows all of the supported
* keywords:
*<pre>
* createPropertyDescriptor("contentPane", new Object[] {
* BOUND, Boolean.TRUE,
* CONSTRAINED, Boolean.TRUE,
* PROPERTYEDITORCLASS, package.MyEditor.class,
* READMETHOD, "getContentPane",
* WRITEMETHOD, "setContentPane",
* DISPLAYNAME, "contentPane",
* EXPERT, Boolean.FALSE,
* HIDDEN, Boolean.FALSE,
* PREFERRED, Boolean.TRUE,
* SHORTDESCRIPTION, "A top level window with a window manager border",
* "random attribute","random object value"
* }
* );
* </pre>
* The keywords correspond to <code>java.beans.PropertyDescriptor and
* <code>java.beans.FeatureDescriptor properties, e.g. providing a value
* for displayName is comparable to <code>FeatureDescriptor.setDisplayName().
* Using createPropertyDescriptor instead of the PropertyDescriptor
* constructor and set methods is preferrable in that it regularizes
* the code in a <code>java.beans.BeanInfo.getPropertyDescriptors()
* method implementation. One can use <code>createPropertyDescriptor
* to set <code>FeatureDescriptor attributes, as in "random attribute"
* "random object value".
* <p>
* All properties should provide a reasonable value for the
* <code>SHORTDESCRIPTION keyword and should set
Other Java examples (source code examples)Here is a short list of links related to this Java BeanInfoUtils.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.