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:
042: package org.netbeans.swing.tabcontrol.plaf;
043:
044: import java.awt.Dimension;
045: import java.awt.FontMetrics;
046: import java.awt.Graphics;
047: import java.awt.Insets;
048: import java.awt.Rectangle;
049: import java.util.HashMap;
050: import java.util.Map;
051: import javax.swing.Icon;
052: import javax.swing.JComponent;
053: import org.netbeans.swing.tabcontrol.TabDisplayer;
054:
055: import javax.swing.plaf.ComponentUI;
056:
057: /**
058: * Windows Vista impl of tabs ui
059: *
060: * @author S. Aubrecht
061: */
062: public final class WinVistaEditorTabDisplayerUI extends
063: BasicScrollingTabDisplayerUI {
064:
065: private static final Rectangle scratch5 = new Rectangle();
066: private static Map<Integer, String[]> buttonIconPaths;
067:
068: public WinVistaEditorTabDisplayerUI(TabDisplayer displayer) {
069: super (displayer);
070: }
071:
072: public static ComponentUI createUI(JComponent c) {
073: return new WinVistaEditorTabDisplayerUI((TabDisplayer) c);
074: }
075:
076: public Dimension getPreferredSize(JComponent c) {
077: int prefHeight = 22;
078: Graphics g = BasicScrollingTabDisplayerUI
079: .getOffscreenGraphics();
080: if (g != null) {
081: FontMetrics fm = g.getFontMetrics(displayer.getFont());
082: Insets ins = getTabAreaInsets();
083: prefHeight = fm.getHeight() + ins.top + ins.bottom + 6;
084: }
085: return new Dimension(displayer.getWidth(), prefHeight);
086: }
087:
088: public void paintBackground(Graphics g) {
089: g.setColor(displayer.getBackground());
090: g.fillRect(0, 0, displayer.getWidth(), displayer.getHeight());
091: }
092:
093: protected void paintAfterTabs(Graphics g) {
094: Rectangle r = new Rectangle();
095: getTabsVisibleArea(r);
096: r.width = displayer.getWidth();
097:
098: Insets ins = getTabAreaInsets();
099:
100: int y = displayer.getHeight()
101: - WinVistaEditorTabCellRenderer.BOTTOM_INSET;
102: int tabsWidth = getTabsAreaWidth();
103:
104: g.setColor(WinVistaEditorTabCellRenderer.getBorderColor());
105:
106: //Draw a line tracking the bottom of the tabs under the control
107: //buttons, out to the right edge of the control
108:
109: //Find the last visible tab
110: int last = scroll().getLastVisibleTab(tabsWidth);
111: int l = 0;
112: if (last >= 0) {
113: //If it's onscreen (usually will be unless there are no tabs,
114: //find the edge of the last tab - it may be scrolled)
115: getTabRect(last, scratch5);
116: last = scratch5.x + scratch5.width;
117: }
118: //Draw the dark line under the controls button area that closes the
119: //tabs bottom margin on top
120: g.drawLine(last, y - 1, displayer.getWidth(), y - 1);
121: }
122:
123: protected TabCellRenderer createDefaultRenderer() {
124: return new WinVistaEditorTabCellRenderer();
125: }
126:
127: protected Rectangle getTabRectForRepaint(int tab, Rectangle rect) {
128: Rectangle res = super .getTabRectForRepaint(tab, rect);
129: //we need to repaint extra vertical lines on both sides when mouse-over
130: //or selection changes
131: res.x--;
132: res.width += 2;
133: return res;
134: }
135:
136: private static void initIcons() {
137: if (null == buttonIconPaths) {
138: buttonIconPaths = new HashMap<Integer, String[]>(7);
139:
140: //left button
141: String[] iconPaths = new String[4];
142: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_enabled.png"; // NOI18N
143: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_disabled.png"; // NOI18N
144: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_rollover.png"; // NOI18N
145: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_pressed.png"; // NOI18N
146: buttonIconPaths.put(TabControlButton.ID_SCROLL_LEFT_BUTTON,
147: iconPaths);
148:
149: //right button
150: iconPaths = new String[4];
151: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_enabled.png"; // NOI18N
152: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_disabled.png"; // NOI18N
153: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_rollover.png"; // NOI18N
154: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_pressed.png"; // NOI18N
155: buttonIconPaths.put(
156: TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths);
157:
158: //drop down button
159: iconPaths = new String[4];
160: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_popup_enabled.png"; // NOI18N
161: iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT];
162: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_popup_rollover.png"; // NOI18N
163: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_popup_pressed.png"; // NOI18N
164: buttonIconPaths.put(TabControlButton.ID_DROP_DOWN_BUTTON,
165: iconPaths);
166:
167: //maximize/restore button
168: iconPaths = new String[4];
169: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_enabled.png"; // NOI18N
170: iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT];
171: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_rollover.png"; // NOI18N
172: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_pressed.png"; // NOI18N
173: buttonIconPaths.put(TabControlButton.ID_MAXIMIZE_BUTTON,
174: iconPaths);
175:
176: iconPaths = new String[4];
177: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_restore_enabled.png"; // NOI18N
178: iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT];
179: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_restore_rollover.png"; // NOI18N
180: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_restore_pressed.png"; // NOI18N
181: buttonIconPaths.put(TabControlButton.ID_RESTORE_BUTTON,
182: iconPaths);
183: }
184: }
185:
186: public Icon getButtonIcon(int buttonId, int buttonState) {
187: Icon res = null;
188: initIcons();
189: String[] paths = buttonIconPaths.get(buttonId);
190: if (null != paths && buttonState >= 0
191: && buttonState < paths.length) {
192: res = TabControlButtonFactory.getIcon(paths[buttonState]);
193: }
194: return res;
195: }
196: }
|