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.screen.resource;
042:
043: import org.netbeans.modules.vmd.api.screen.resource.ScreenResourceCategoryDescriptor;
044: import org.netbeans.modules.vmd.api.screen.resource.ScreenResourceItemPresenter;
045: import org.netbeans.modules.vmd.screen.MainPanel;
046:
047: import javax.swing.*;
048: import java.awt.*;
049: import java.awt.geom.RoundRectangle2D;
050: import java.util.ArrayList;
051:
052: /**
053: *
054: * @author David Kaspar
055: */
056: public class ResourceCategoryPanel extends JPanel {
057:
058: private static final Color LABEL_COLOR = new Color(0x868686);
059: private static final Color BORDER_COLOR = new Color(0xCBC9C1);
060: private static final Color GRADIENT_COLOR = new Color(0xD5D5D5);
061: private static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);
062:
063: private JLabel label;
064:
065: public ResourceCategoryPanel(
066: ScreenResourceCategoryDescriptor category) {
067: setOpaque(false);
068: setLayout(new GridBagLayout());
069: setBackground(MainPanel.BACKGROUND_COLOR);
070: setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
071:
072: label = new JLabel(category.getTitle(), JLabel.CENTER) {
073: public void paint(Graphics g) {
074: Graphics2D gr = (Graphics2D) g;
075: gr.setPaint(new GradientPaint(0.0f, 0.0f, Color.WHITE,
076: 0.0f, getHeight(), GRADIENT_COLOR));
077: gr.fill(new Rectangle(getWidth(), getHeight()));
078: super .paint(g);
079: }
080:
081: public Dimension getPreferredSize() {
082: Dimension dimension = super .getPreferredSize();
083: dimension.width += 8;
084: dimension.height += 8;
085: return dimension;
086: }
087: };
088: label.setBorder(null);
089: label.setFont(getFont().deriveFont(Font.BOLD));
090: label.setToolTipText(category.getToolTip());
091: label.setBackground(null);
092: label.setForeground(LABEL_COLOR);
093: label.setOpaque(false);
094: }
095:
096: public void reload(ArrayList<ScreenResourceItemPresenter> list) {
097: removeAll();
098:
099: GridBagConstraints constraints = new GridBagConstraints();
100: constraints.weightx = 1.0;
101: constraints.weighty = 0.0;
102: constraints.insets = EMPTY_INSETS;
103: constraints.fill = GridBagConstraints.HORIZONTAL;
104: constraints.gridx = GridBagConstraints.REMAINDER;
105: constraints.gridy = GridBagConstraints.RELATIVE;
106: constraints.anchor = GridBagConstraints.NORTHWEST;
107:
108: add(label, constraints);
109:
110: for (ScreenResourceItemPresenter presenter : list) {
111: JPanel filler = new JPanel(); // TODO - cache filler panels
112: Dimension FILLER_SIZE = new Dimension(0, 1);
113: filler.setPreferredSize(FILLER_SIZE);
114: filler.setBackground(BORDER_COLOR);
115: add(filler, constraints);
116:
117: ResourceItemPanel item = new ResourceItemPanel(presenter
118: .getRelatedComponent()); // TODO - cache ResourceItemPanels
119:
120: item.reload();
121:
122: add(item, constraints);
123: }
124: }
125:
126: public void paint(Graphics g) {
127: Graphics2D gr = (Graphics2D) g;
128: Shape previousClip = gr.getClip();
129: gr.clip(new RoundRectangle2D.Float(0, 0, getWidth(),
130: getHeight(), 8, 8));
131:
132: super .paint(g);
133:
134: gr.setClip(previousClip);
135: }
136:
137: protected void paintChildren(Graphics g) {
138: super .paintChildren(g);
139: Graphics2D gr = (Graphics2D) g;
140: gr.setColor(BORDER_COLOR);
141: gr.draw(new RoundRectangle2D.Float(0, 0, getWidth() - 1,
142: getHeight() - 1, 8, 8));
143: }
144:
145: }
|