001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package com.sun.rave.designtime;
043:
044: import java.beans.FeatureDescriptor;
045:
046: /**
047: * <p>A CategoryDescriptor describes a category for a property. A PropertyDescriptor may include a
048: * CategoryDescriptor using the named attribute: Constants.PropertyDescriptor.CATEGORY, or literally
049: * "category". Properties will be displayed on the property sheet grouped with their associated
050: * category. Use <code>java.beans.PropertyDescriptor.setValue(Constants.PropertyDescriptor.CATEGORY,
051: * someCatDesc)</code> to associate a category with a particular property.</p>
052: *
053: * <p>You can also specify the desired display order of categories on the property sheet by
054: * providing an array of CategoryDescriptors in the BeanDescriptor. Use
055: * <code>java.beans.BeanDescriptor.setValue(Constants.BeanDescriptor.PROPERTY_CATEGORIES,
056: * new CategoryDescriptor[] { ... });</code> to specify the order.</p>
057: *
058: * @author Joe Nuxoll
059: * @version 1.0
060: * @see java.beans.PropertyDescriptor
061: * @see java.beans.BeanDescriptor
062: */
063: public class CategoryDescriptor extends FeatureDescriptor {
064:
065: /**
066: * Constructs a new CategoryDescriptor with no settings.
067: */
068: public CategoryDescriptor() {
069: }
070:
071: /**
072: * Constructs a new CategoryDescriptor with the specified name.
073: *
074: * @param name The String name for the new CategoryDescriptor
075: */
076: public CategoryDescriptor(String name) {
077: setName(name);
078: }
079:
080: /**
081: * Constructs a new CategoryDescriptor with the specified name and description.
082: *
083: * @param name The String name for the new CategoryDescriptor
084: * @param description The String description for the new CategoryDescriptor
085: */
086: public CategoryDescriptor(String name, String description) {
087: setName(name);
088: setShortDescription(description);
089: }
090:
091: /**
092: * Constructs a new CategoryDescriptor with the specified name, description and default expansion
093: * state.
094: *
095: * @param name The String name for the new CategoryDescriptor
096: * @param description The String description for the new CategoryDescriptor
097: * @param expandByDefault The initial state for the 'expandByDefault' property of the new
098: * CategoryDescriptor. If expandByDefault is true, the category will appear expanded
099: * in the property sheet, and collapsed if false.
100: */
101: public CategoryDescriptor(String name, String description,
102: boolean expandByDefault) {
103: setName(name);
104: setShortDescription(description);
105: setExpandByDefault(expandByDefault);
106: }
107:
108: /**
109: * Storage field for the 'expandByDefault' property.
110: */
111: protected boolean expandByDefault = true;
112:
113: /**
114: * Sets the expandByDefault property. If expandByDefault is true, this category will appear
115: * expanded in the property sheet, or collapsed if false.
116: *
117: * @param expandByDefault <code>true</code> to expand the category, <code>false</code> to
118: * collapse it by default.
119: */
120: public void setExpandByDefault(boolean expandByDefault) {
121: this .expandByDefault = expandByDefault;
122: }
123:
124: /**
125: * Returns the state of the expandByDefault property. If expandByDefault is true, this category
126: * will appear expanded in the property sheet, or collapsed if false.
127: *
128: * @return <code>true</code> if the category should be expanded, or <code>false</code> for
129: * collapsed.
130: */
131: public boolean isExpandByDefault() {
132: return expandByDefault;
133: }
134:
135: public boolean equals(Object o) {
136: if (o instanceof CategoryDescriptor) {
137: CategoryDescriptor cd = (CategoryDescriptor) o;
138: return cd == this
139: || (cd.getName() == null && getName() == null || cd
140: .getName() != null
141: && cd.getName().equals(getName()));
142: }
143: return false;
144: }
145: }
|