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: * MetalEditorTabDisplayerUI.java
043: *
044: * Created on December 2, 2003, 9:40 PM
045: */
046:
047: package org.netbeans.swing.tabcontrol.plaf;
048:
049: import java.awt.Color;
050: import java.awt.Container;
051: import java.awt.Dimension;
052: import java.awt.Font;
053: import java.awt.FontMetrics;
054: import java.awt.Graphics;
055: import java.awt.Insets;
056: import java.awt.Rectangle;
057: import org.netbeans.swing.tabcontrol.TabDisplayer;
058: import javax.swing.plaf.ComponentUI;
059: import java.util.HashMap;
060: import java.util.Map;
061: import javax.swing.Icon;
062: import javax.swing.JComponent;
063: import javax.swing.UIManager;
064:
065: /**
066: * A provisional look and feel for OS-X, round 2, using Java2d to emulate the
067: * aqua look.
068: *
069: * @author Tim Boudreau
070: */
071: public class AquaEditorTabDisplayerUI extends
072: BasicScrollingTabDisplayerUI {
073:
074: /** Color used in drawing the line behind the tabs */
075: private Color lineMiddleColor = null;
076: /** Color used in drawing the line behind the tabs */
077: private Color lineHlColor = null;
078:
079: private static Map<Integer, String[]> buttonIconPaths;
080:
081: public AquaEditorTabDisplayerUI(TabDisplayer displayer) {
082: super (displayer);
083: }
084:
085: public void install() {
086: super .install();
087: scroll().setMinimumXposition(9);
088: }
089:
090: protected TabCellRenderer createDefaultRenderer() {
091: return new AquaEditorTabCellRenderer();
092: }
093:
094: public Insets getTabAreaInsets() {
095: Insets result = super .getTabAreaInsets();
096: result.bottom = 2;
097: return result;
098: }
099:
100: public static ComponentUI createUI(JComponent c) {
101: return new AquaEditorTabDisplayerUI((TabDisplayer) c);
102: }
103:
104: protected boolean isAntialiased() {
105: return true;
106: }
107:
108: protected Font createFont() {
109: return UIManager.getFont("Label.font"); //NOI18N
110: }
111:
112: protected int createRepaintPolicy() {
113: return TabState.REPAINT_SELECTION_ON_ACTIVATION_CHANGE
114: | TabState.REPAINT_ON_SELECTION_CHANGE
115: | TabState.REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA
116: | TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON
117: | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED
118: | TabState.REPAINT_ON_MOUSE_PRESSED;
119: }
120:
121: public Dimension getPreferredSize(JComponent c) {
122: int prefHeight = 28;
123: //Never call getGraphics() on the control, it resets in-process
124: //painting on OS-X 1.4.1 and triggers gratuitous repaints
125: Graphics g = BasicScrollingTabDisplayerUI
126: .getOffscreenGraphics();
127: if (g != null) {
128: FontMetrics fm = g.getFontMetrics(displayer.getFont());
129: Insets ins = getTabAreaInsets();
130: prefHeight = fm.getHeight() + ins.top + ins.bottom + 7;
131: }
132: if (prefHeight % 2 == 0) {
133: prefHeight += 1;
134: }
135: return new Dimension(displayer.getWidth(), prefHeight);
136: }
137:
138: protected void paintAfterTabs(Graphics g) {
139: //Draw the continuation of the rounded border behind the buttons
140: //and tabs
141:
142: int centerY = (((displayer.getHeight() - (AquaEditorTabCellRenderer.TOP_INSET + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2)
143: + AquaEditorTabCellRenderer.TOP_INSET - 1)
144: + getTabAreaInsets().top + 1;
145:
146: if (lineMiddleColor == null) {
147: lineMiddleColor = ColorUtil.getMiddle(UIManager
148: .getColor("controlShadow"), UIManager
149: .getColor("control")); //NOI18N
150: }
151: g.setColor(lineMiddleColor);
152:
153: int rightLineStart = getTabsAreaWidth() - 13;
154: int rightLineEnd = displayer.getWidth() - 9;
155:
156: if (displayer.getModel().size() > 0
157: && !scroll().isLastTabClipped()) {
158: //Extend the line out to the edge of the last visible tab
159: //if none are clipped
160: int idx = scroll().getLastVisibleTab(displayer.getWidth());
161: rightLineStart = scroll().getX(idx) + scroll().getW(idx);
162: } else if (displayer.getModel().size() == 0) {
163: rightLineStart = 6;
164: }
165:
166: if (scroll().getOffset() >= 0) {
167: //fill the left edge notch
168: g.drawLine(6, centerY, 11, centerY);
169: }
170: g.drawLine(rightLineStart, centerY, rightLineEnd, centerY);
171:
172: if (lineHlColor == null) {
173: lineHlColor = ColorUtil.getMiddle(lineMiddleColor,
174: UIManager.getColor("control"));
175: }
176:
177: g.setColor(lineHlColor); //NOI18N
178: g.drawLine(rightLineStart, centerY + 1, rightLineEnd,
179: centerY + 1);
180: if (scroll().getOffset() > 0) {
181: //fill the left edge notch
182: g.drawLine(6, centerY + 1, 11, centerY + 1);
183: }
184: }
185:
186: private static void initIcons() {
187: if (null == buttonIconPaths) {
188: buttonIconPaths = new HashMap<Integer, String[]>(7);
189:
190: //left button
191: String[] iconPaths = new String[4];
192: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_enabled.png"; // NOI18N
193: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_disabled.png"; // NOI18N
194: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_rollover.png"; // NOI18N
195: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_pressed.png"; // NOI18N
196: buttonIconPaths.put(TabControlButton.ID_SCROLL_LEFT_BUTTON,
197: iconPaths);
198:
199: //right button
200: iconPaths = new String[4];
201: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_enabled.png"; // NOI18N
202: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_disabled.png"; // NOI18N
203: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_rollover.png"; // NOI18N
204: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_pressed.png"; // NOI18N
205: buttonIconPaths.put(
206: TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths);
207:
208: //drop down button
209: iconPaths = new String[4];
210: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_popup_enabled.png"; // NOI18N
211: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_disabled.png"; // NOI18N
212: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_popup_rollover.png"; // NOI18N
213: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_pressed.png"; // NOI18N
214: buttonIconPaths.put(TabControlButton.ID_DROP_DOWN_BUTTON,
215: iconPaths);
216:
217: //maximize/restore button
218: iconPaths = new String[4];
219: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_enabled.png"; // NOI18N
220: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_disabled.png"; // NOI18N
221: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_rollover.png"; // NOI18N
222: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_pressed.png"; // NOI18N
223: buttonIconPaths.put(TabControlButton.ID_MAXIMIZE_BUTTON,
224: iconPaths);
225:
226: iconPaths = new String[4];
227: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_restore_enabled.png"; // NOI18N
228: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_disabled.png"; // NOI18N
229: iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_restore_rollover.png"; // NOI18N
230: iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_pressed.png"; // NOI18N
231: buttonIconPaths.put(TabControlButton.ID_RESTORE_BUTTON,
232: iconPaths);
233: }
234: }
235:
236: public Icon getButtonIcon(int buttonId, int buttonState) {
237: Icon res = null;
238: initIcons();
239: String[] paths = buttonIconPaths.get(buttonId);
240: if (null != paths && buttonState >= 0
241: && buttonState < paths.length) {
242: res = TabControlButtonFactory.getIcon(paths[buttonState]);
243: }
244: return res;
245: }
246:
247: protected Rectangle getControlButtonsRectangle(Container parent) {
248: int centerY = (((displayer.getHeight() - (AquaEditorTabCellRenderer.TOP_INSET + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2) + AquaEditorTabCellRenderer.TOP_INSET)
249: + getTabAreaInsets().top;
250:
251: int width = parent.getWidth();
252: int height = parent.getHeight();
253: int buttonsWidth = getControlButtons().getWidth();
254: int buttonsHeight = getControlButtons().getHeight();
255: return new Rectangle(width - buttonsWidth - 3, centerY
256: - buttonsHeight / 2, buttonsWidth, buttonsHeight);
257: }
258: }
|