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-2006 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.vmd.structure.document;
042:
043: import org.netbeans.api.visual.border.Border;
044: import org.netbeans.api.visual.border.BorderFactory;
045: import org.netbeans.api.visual.layout.Layout;
046: import org.netbeans.api.visual.layout.LayoutFactory;
047: import org.netbeans.api.visual.model.ObjectScene;
048: import org.netbeans.api.visual.widget.ImageWidget;
049: import org.netbeans.api.visual.widget.LabelWidget;
050: import org.netbeans.api.visual.widget.SeparatorWidget;
051: import org.netbeans.api.visual.widget.Widget;
052: import org.netbeans.modules.vmd.api.model.*;
053: import org.openide.util.Utilities;
054:
055: import java.awt.*;
056:
057: /**
058: * @author David Kaspar
059: */
060: public class ComponentWidget extends Widget {
061:
062: private static final Layout LAYOUT = LayoutFactory
063: .createHorizontalFlowLayout();
064: private static final Layout LAYOUT_NODES = LayoutFactory
065: .createVerticalFlowLayout(
066: LayoutFactory.SerialAlignment.JUSTIFY, 10);
067: private static final Layout LAYOUT_LABEL = LayoutFactory
068: .createVerticalFlowLayout();
069:
070: private static final Border BORDER_SEPARATOR = BorderFactory
071: .createEmptyBorder(8, 0);
072: private static final Border BORDER_IMAGE = BorderFactory
073: .createEmptyBorder(4, 8, 4, 0);
074: private static final Border BORDER_LABEL = BorderFactory
075: .createEmptyBorder(8, 4);
076:
077: private Widget components;
078: private DesignComponent component;
079:
080: public ComponentWidget(DocumentScene scene,
081: DesignComponent component, boolean selected) {
082: super (scene);
083: this .component = component;
084:
085: ComponentDescriptor descriptor = component
086: .getComponentDescriptor();
087: Color validityColor = descriptor != null ? Color.WHITE
088: : Color.MAGENTA;
089: PaletteDescriptor paletteDescriptor = descriptor != null ? descriptor
090: .getPaletteDescriptor()
091: : null;
092: Image image = paletteDescriptor != null ? Utilities
093: .loadImage(paletteDescriptor.getSmallIcon()) : null;
094:
095: setLayout(org.netbeans.modules.vmd.structure.document.ComponentWidget.LAYOUT);
096:
097: SeparatorWidget separator = new SeparatorWidget(scene,
098: SeparatorWidget.Orientation.VERTICAL);
099: separator.setBorder(BORDER_SEPARATOR);
100: addChild(separator);
101:
102: if (image != null) {
103: ImageWidget imageWidget = new ImageWidget(scene, image);
104: imageWidget.setBorder(BORDER_IMAGE);
105: imageWidget.setOpaque(true);
106: imageWidget
107: .setBackground(selected ? DocumentScene.COLOR_SELECTED
108: : validityColor);
109: addChild(imageWidget);
110: }
111:
112: Widget descriptionWidget = new Widget(scene);
113: descriptionWidget.setBorder(BORDER_LABEL);
114: descriptionWidget.setOpaque(true);
115: descriptionWidget
116: .setBackground(selected ? DocumentScene.COLOR_SELECTED
117: : validityColor);
118: descriptionWidget.setLayout(LAYOUT_LABEL);
119: addChild(descriptionWidget);
120:
121: LabelWidget idWidget = new LabelWidget(scene, component
122: .getComponentID()
123: + " : "
124: + (descriptor != null ? descriptor.getTypeDescriptor()
125: .getThisType().toString() : "<Unknown>")); // NOI18N
126: idWidget.setFont(scene.getDefaultFont().deriveFont(Font.BOLD));
127: descriptionWidget.addChild(idWidget);
128:
129: if (descriptor != null)
130: for (PropertyDescriptor propertyDescriptor : descriptor
131: .getPropertyDescriptors()) {
132: String name = propertyDescriptor.getName();
133: PropertyValue value = component.readProperty(name);
134: descriptionWidget.addChild(new LabelWidget(scene, name
135: + "=" + value.serialize())); // NOI18N
136: }
137:
138: components = new Widget(scene);
139: components.setLayout(LAYOUT_NODES);
140: addChild(components);
141:
142: descriptionWidget.getActions()
143: .addAction(scene.getHoverAction());
144: getActions().addAction(scene.getSelectAction());
145: }
146:
147: public void addChildComponentWidget(ComponentWidget widget) {
148: components.addChild(widget);
149: ((ObjectScene) widget.getScene()).addObject(widget
150: .getComponent(), widget);
151: }
152:
153: public DesignComponent getComponent() {
154: return component;
155: }
156:
157: }
|