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.ui;
043:
044: import java.awt.BorderLayout;
045: import java.awt.Dimension;
046: import java.awt.Graphics;
047: import java.awt.Image;
048: import java.awt.Point;
049: import java.awt.Rectangle;
050: import javax.swing.JPanel;
051: import javax.swing.JScrollPane;
052: import javax.swing.Scrollable;
053: import org.netbeans.modules.welcome.content.Constants;
054: import org.openide.util.Utilities;
055:
056: /**
057: * Base class for inner tabs in the Welcome Page
058: *
059: * @author S. Aubrecht
060: */
061: abstract class AbstractTab extends JPanel implements Scrollable,
062: Constants {
063:
064: private boolean initialized = false;
065:
066: private Image imgBottomStripWest;
067: private Image imgBottomStripCenter;
068: private Image imgBottomStripEast;
069:
070: private Image imgTopStripWest;
071: private Image imgTopStripCenter;
072:
073: private Image imgMiddleStripEast;
074: private Image imgMiddleStripCenter;
075:
076: public AbstractTab() {
077: super (new BorderLayout());
078: setOpaque(false);
079:
080: this .imgBottomStripCenter = Utilities
081: .loadImage(IMAGE_STRIP_BOTTOM_CENTER);
082: this .imgBottomStripWest = Utilities
083: .loadImage(IMAGE_STRIP_BOTTOM_WEST);
084: this .imgBottomStripEast = Utilities
085: .loadImage(IMAGE_STRIP_BOTTOM_EAST);
086:
087: this .imgTopStripCenter = Utilities
088: .loadImage(IMAGE_STRIP_TOP_CENTER);
089: this .imgTopStripWest = Utilities
090: .loadImage(IMAGE_STRIP_TOP_WEST);
091:
092: this .imgMiddleStripCenter = Utilities
093: .loadImage(IMAGE_STRIP_MIDDLE_CENTER);
094: this .imgMiddleStripEast = Utilities
095: .loadImage(IMAGE_STRIP_MIDDLE_EAST);
096: }
097:
098: @Override
099: public void addNotify() {
100: super .addNotify();
101: if (!initialized) {
102: buildContent();
103: initialized = true;
104: }
105: }
106:
107: protected abstract void buildContent();
108:
109: protected abstract Point getTopStripOrigin();
110:
111: protected abstract Point getMiddleStripOrigin();
112:
113: protected abstract Point getBottomStripOrigin();
114:
115: @Override
116: public Dimension getPreferredSize() {
117: Dimension d = super .getPreferredSize();
118: if (null != getParent() && getParent().getHeight() > 0
119: && getParent().getHeight() > d.height)
120: d.height = getParent().getHeight();
121: if (null != getParent() && getParent().getWidth() > 0) {
122: if (d.width > getParent().getWidth()) {
123: d.width = Math
124: .max(
125: getParent().getWidth(),
126: START_PAGE_MIN_WIDTH
127: + (int) (((FONT_SIZE - 11) / 11.0) * START_PAGE_MIN_WIDTH));
128: if (getParent().getParent() instanceof JScrollPane) {
129: if (((JScrollPane) getParent().getParent())
130: .getVerticalScrollBar().isVisible())
131: d.width -= ((JScrollPane) getParent()
132: .getParent()).getVerticalScrollBar()
133: .getWidth();
134: }
135: } else if (d.width < getParent().getWidth()) {
136: d.width = getParent().getWidth();
137: }
138: }
139: return d;
140: }
141:
142: public Dimension getPreferredScrollableViewportSize() {
143: return getPreferredSize();
144: }
145:
146: public int getScrollableUnitIncrement(Rectangle visibleRect,
147: int orientation, int direction) {
148: return Constants.FONT_SIZE;
149: }
150:
151: public int getScrollableBlockIncrement(Rectangle visibleRect,
152: int orientation, int direction) {
153: return 30 * Constants.FONT_SIZE;
154: }
155:
156: public boolean getScrollableTracksViewportWidth() {
157: return false;
158: }
159:
160: public boolean getScrollableTracksViewportHeight() {
161: return false;
162: }
163:
164: @Override
165: protected void paintComponent(Graphics g) {
166: int width = getWidth();
167:
168: //top strip
169: Point origin = getTopStripOrigin();
170: g.drawImage(imgTopStripWest, origin.x, origin.y, null);
171: for (int i = origin.x + imgTopStripWest.getWidth(null); i < width; i++) {
172: g.drawImage(imgTopStripCenter, i, origin.y, null);
173: }
174:
175: //middle strip
176: origin = getMiddleStripOrigin();
177: g.drawImage(imgMiddleStripEast, origin.x
178: - imgMiddleStripEast.getWidth(null), origin.y, null);
179: for (int i = origin.x - imgMiddleStripEast.getWidth(null); i >= 0; i--) {
180: g.drawImage(imgMiddleStripCenter, i, origin.y, null);
181: }
182:
183: //bottom strip
184: origin = getBottomStripOrigin();
185: int eastWidth = imgBottomStripEast.getWidth(null);
186: int eastHeight = imgBottomStripEast.getHeight(null);
187: int westWidth = imgBottomStripWest.getWidth(null);
188: int westHeight = imgBottomStripWest.getHeight(null);
189: g.drawImage(imgBottomStripEast, width - eastWidth - 1, origin.y
190: - eastHeight - 1, null);
191: int centerWidth = Math.max(100, width - eastWidth - westWidth
192: - 150);
193:
194: g.drawImage(imgBottomStripWest, width - eastWidth - 1
195: - centerWidth - westWidth, origin.y - westHeight - 1,
196: null);
197: for (int i = 0; i < centerWidth; i++) {
198: g.drawImage(imgBottomStripCenter, width - eastWidth
199: - centerWidth - 1 + i, origin.y - westHeight - 1,
200: null);
201: }
202:
203: }
204: }
|