EnumeratedMetaData.java
资源名称:swingx.zip [点击查看]
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:5k
源码类别:
xml/soap/webservice
开发平台:
Java
- /*
- * $Id: EnumeratedMetaData.java,v 1.3 2005/10/10 17:01:07 rbair Exp $
- *
- * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
- * Santa Clara, California 95054, U.S.A. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- package org.jdesktop.binding.metadata;
- import java.util.List;
- /**
- * <p>
- * Class for representing meta-data for data fields which have a finite
- * set of possible values. The type of each value in the enumeration must
- * match the type ("elementClass" property) of the meta-data object.
- * Example usage:<br>
- * <pre><code>
- * String weekdays[] = {"Sunday","Monday","Tuesday","Wednesday",
- * "Thursday","Friday","Saturday"};
- * EnumeratedMetaData metaData = new EnumeratedMetaData("weekday", String.class,
- * "Day of Week");
- * metaData.setEnumeration(weekdays);
- * </code></pre>
- * </p>
- *
- * @author Amy Fowler
- * @version 1.0
- */
- public class EnumeratedMetaData extends MetaData {
- protected Object[] enumeration;
- /**
- * Instantiates a meta-data object with a default name "enumvalue" and
- * a default field class equal to <code>java.lang.String</code>.
- * This provides the no-argument constructor required for JavaBeans.
- * It is recommended that the program explicitly set a meaningful
- * "name" property.
- */
- public EnumeratedMetaData() {
- this("enumvalue");
- }
- /**
- * Instantiates a meta-data object with the specified name and
- * a default field class equal to <code>java.lang.String</code>.
- * @param name String containing the name of the data field
- */
- public EnumeratedMetaData(String name) {
- super(name);
- }
- /**
- * Instantiates a meta-data object with the specified name and
- * field class.
- * @param name String containing the name of the data field
- * @param klass Class indicating type of data field
- */
- public EnumeratedMetaData(String name, Class klass) {
- super(name, klass);
- }
- /**
- * Instantiates a meta-data object with the specified name,
- * field class, and label.
- * @param name String containing the name of the data field
- * @param klass Class indicating type of data field
- * @param label String containing the user-displayable label for the
- * data field
- */
- public EnumeratedMetaData(String name, Class klass, String label) {
- super(name, klass, label);
- }
- /**
- * Gets the meta-data "enumeration" property which
- * contains the set of possible values for the associated data field.
- * The returned array is a copy, therefore modifications to that array
- * will have no affect on the property.
- * @see #setEnumeration
- * @return array containing 0 or more enumerated values for the data field
- */
- public Object[] getEnumeration() {
- Object[] evalues;
- if (enumeration != null) {
- evalues = new Object[enumeration.length];
- System.arraycopy(enumeration, 0, evalues, 0,
- enumeration.length);
- }
- else {
- evalues = new Object[0];
- }
- return evalues;
- }
- /**
- * Sets the meta-data "enumeration" property by copying
- * the values contained in the specified array to an internal representation.
- * @see #getEnumeration
- * @param enumeration array containing 0 or more enumerated values for the data field
- */
- public void setEnumeration(Object[] enumeration) {
- Object oldEnumeration[] = this.enumeration;
- this.enumeration = new Object[enumeration.length];
- System.arraycopy(enumeration, 0, this.enumeration, 0,
- enumeration.length);
- firePropertyChange("enumeration", oldEnumeration, enumeration);
- }
- /**
- * Sets the meta-data "enumeration" property by copying
- * the values contained in the specified list to an internal representation.
- * @see #getEnumeration
- * @param enumeration list containing 0 or more enumerated values for the data field
- */
- public void setEnumeration(List enumeration) {
- setEnumeration(enumeration.toArray());
- }
- }