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 org.netbeans.modules.welcome.content;
043:
044: import java.awt.Dimension;
045: import java.awt.Graphics;
046: import java.awt.GridBagConstraints;
047: import java.awt.GridBagLayout;
048: import java.awt.Image;
049: import java.awt.Insets;
050: import java.awt.Rectangle;
051: import javax.swing.BorderFactory;
052: import javax.swing.JComponent;
053: import javax.swing.JLabel;
054: import javax.swing.JPanel;
055: import javax.swing.SwingConstants;
056: import org.openide.util.Utilities;
057:
058: /**
059: *
060: * @author S. Aubrecht
061: */
062: public class ContentSection extends JPanel implements Constants {
063:
064: private static final int PANEL_MAX_WIDTH = 800;
065: private int location;
066: private boolean maxSize;
067:
068: private Image center;
069:
070: private JLabel lblTitle;
071:
072: public ContentSection(String title, int location,
073: JComponent content, boolean maxSize) {
074: super (new GridBagLayout());
075: this .location = location;
076: this .maxSize = maxSize;
077:
078: setOpaque(false);
079: lblTitle = new JLabel(title);
080: lblTitle.setFont(SECTION_HEADER_FONT);
081:
082: lblTitle.setHorizontalAlignment(JLabel.RIGHT);
083: lblTitle.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
084: lblTitle.setForeground(Utils.getColor(COLOR_SECTION_HEADER));
085: add(lblTitle, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
086: GridBagConstraints.EAST, GridBagConstraints.NONE,
087: new Insets(0, 0, 0, 0), 0, 0));
088:
089: add(content, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
090: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
091: new Insets(0, 0, 0, 0), 0, 0));
092:
093: setBorder(BorderFactory.createEmptyBorder(8, 12, 6, 12));
094:
095: String centerImageName = null;
096: switch (location) {
097: case SwingConstants.NORTH_EAST:
098: centerImageName = "section_upper_right.png"; //NOI18N
099: break;
100: case SwingConstants.NORTH_WEST:
101: centerImageName = "section_upper_left.png"; //NOI18N
102: break;
103: case SwingConstants.SOUTH_WEST:
104: centerImageName = "section_bottom_left.png"; //NOI18N
105: break;
106: case SwingConstants.SOUTH_EAST:
107: centerImageName = "section_bottom_right.png"; //NOI18N
108: break;
109: }
110: center = Utilities
111: .loadImage("org/netbeans/modules/welcome/resources/"
112: + centerImageName); //NOI18N
113: }
114:
115: @Override
116: protected void paintComponent(Graphics g) {
117: int width = getWidth();
118: int height = getHeight();
119: int centerWidth = center.getWidth(null);
120: int centerHeight = center.getHeight(null);
121: g.setColor(Utils.getColor(COLOR_SECTION_HEADER));
122: switch (location) {
123: case SwingConstants.NORTH_EAST:
124: g.drawImage(center, 1, height - centerHeight - 1, null);
125: g.drawLine(0, height - 1, width - 13, height - 1);
126: g.drawLine(0, 25, 0, height);
127: break;
128: case SwingConstants.NORTH_WEST:
129: g.drawImage(center, width - centerWidth, height
130: - centerHeight - 1, null);
131: g.drawLine(13, height - 1, width, height - 1);
132: break;
133: case SwingConstants.SOUTH_WEST:
134: g.drawImage(center, width - centerWidth, 0, null);
135: break;
136: case SwingConstants.SOUTH_EAST:
137: g.drawImage(center, 1, 0, null);
138: g.drawLine(0, 0, 0, height - 25);
139: break;
140: }
141: }
142:
143: @Override
144: public void setSize(Dimension d) {
145: if (maxSize && d.width > PANEL_MAX_WIDTH) {
146: d = new Dimension(d);
147: d.width = PANEL_MAX_WIDTH;
148: }
149: super .setSize(d);
150: }
151:
152: @Override
153: public void setBounds(Rectangle r) {
154: if (maxSize && r.width > PANEL_MAX_WIDTH) {
155: r = new Rectangle(r);
156: r.width = PANEL_MAX_WIDTH;
157: }
158: super .setBounds(r);
159: }
160:
161: @Override
162: public void setBounds(int x, int y, int w, int h) {
163: if (maxSize && w > PANEL_MAX_WIDTH) {
164: w = PANEL_MAX_WIDTH;
165: }
166: super .setBounds(x, y, w, h);
167: }
168:
169: @Override
170: public Dimension getPreferredSize() {
171: Dimension d = super .getPreferredSize();
172: if (maxSize && d.width > PANEL_MAX_WIDTH) {
173: d = new Dimension(d);
174: d.width = PANEL_MAX_WIDTH;
175: }
176: return d;
177: }
178:
179: public Rectangle getTitleBounds() {
180: Rectangle res = lblTitle.getBounds();
181: res.height -= lblTitle.getInsets().bottom + 7;
182: return res;
183: }
184: }
|