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: package org.netbeans.modules.visual.experimental.widget.general;
042:
043: import org.netbeans.api.visual.widget.*;
044: import org.netbeans.api.visual.laf.LookFeel;
045: import org.netbeans.api.visual.border.BorderFactory;
046: import org.netbeans.api.visual.layout.LayoutFactory;
047: import org.netbeans.api.visual.model.ObjectState;
048:
049: import java.awt.*;
050:
051: /**
052: * This class represents a general list widget which is rendered as a rectangle with a header on top and list item widgets
053: * underneath.
054: *
055: * @author David Kaspar
056: */
057: public class ListWidget extends Widget {
058:
059: private Widget header;
060: private ImageWidget imageWidget;
061: private LabelWidget labelWidget;
062:
063: /**
064: * Creates a list widget.
065: * @param scene the scene
066: */
067: public ListWidget(Scene scene) {
068: super (scene);
069:
070: LookFeel lookFeel = scene.getLookFeel();
071: setOpaque(true);
072: setBackground(lookFeel.getBackground());
073: setBorder(BorderFactory.createLineBorder());
074: setLayout(LayoutFactory.createVerticalFlowLayout());
075:
076: header = new Widget(scene);
077: header.setLayout(LayoutFactory.createHorizontalFlowLayout(
078: LayoutFactory.SerialAlignment.CENTER, 0));
079: header.addChild(imageWidget = new ImageWidget(scene));
080: header.addChild(labelWidget = new LabelWidget(scene));
081: addChild(header);
082:
083: addChild(new SeparatorWidget(scene,
084: SeparatorWidget.Orientation.HORIZONTAL));
085:
086: setState(ObjectState.createNormal());
087: }
088:
089: /**
090: * Implements the widget-state specific look of the widget.
091: * @param previousState the previous state
092: * @param state the new state
093: */
094: public void notifyStateChanged(ObjectState previousState,
095: ObjectState state) {
096: LookFeel lookFeel = getScene().getLookFeel();
097: header.setBorder(BorderFactory.createCompositeBorder(
098: BorderFactory.createEmptyBorder(2), lookFeel
099: .getBorder(state)));
100: labelWidget.setForeground(lookFeel.getForeground(state));
101: }
102:
103: /**
104: * Sets an image used in the list header.
105: * @param image the image
106: */
107: public final void setImage(Image image) {
108: imageWidget.setImage(image);
109: }
110:
111: /**
112: * Sets a label used in the list header.
113: * @param label the label
114: */
115: public final void setLabel(String label) {
116: labelWidget.setLabel(label);
117: }
118:
119: /**
120: * Returns a header widget.
121: * @return the header widget
122: */
123: public final Widget getHeader() {
124: return header;
125: }
126:
127: /**
128: * Returns an image widget in the header.
129: * @return the image widget
130: */
131: public final ImageWidget getImageWidget() {
132: return imageWidget;
133: }
134:
135: /**
136: * Returns a label widget in the header.
137: * @return the label widget
138: */
139: public final LabelWidget getLabelWidget() {
140: return labelWidget;
141: }
142:
143: }
|