2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
* MetalEditorTabDisplayerUI.java
44
* Created on December 2, 2003, 9:40 PM
47
package org.netbeans.swing.tabcontrol.plaf;
49
import java.awt.Color;
50
import java.awt.Container;
51
import java.awt.Dimension;
53
import java.awt.FontMetrics;
54
import java.awt.Graphics;
55
import java.awt.Insets;
56
import java.awt.Rectangle;
57
import org.netbeans.swing.tabcontrol.TabDisplayer;
58
import javax.swing.plaf.ComponentUI;
59
import java.util.HashMap;
61
import javax.swing.Icon;
62
import javax.swing.JComponent;
63
import javax.swing.UIManager;
66
* A provisional look and feel for OS-X, round 2, using Java2d to emulate the
69
* @author Tim Boudreau
71
public class AquaEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI {
73
/** Color used in drawing the line behind the tabs */
74
private Color lineMiddleColor = null;
75
/** Color used in drawing the line behind the tabs */
76
private Color lineHlColor = null;
78
private static Map<Integer, String[]> buttonIconPaths;
80
public AquaEditorTabDisplayerUI (TabDisplayer displayer) {
84
public void install() {
86
scroll().setMinimumXposition(9);
89
protected TabCellRenderer createDefaultRenderer() {
90
return new AquaEditorTabCellRenderer();
93
public Insets getTabAreaInsets() {
94
Insets result = super.getTabAreaInsets();
99
public static ComponentUI createUI(JComponent c) {
100
return new AquaEditorTabDisplayerUI ((TabDisplayer) c);
103
protected boolean isAntialiased() {
107
protected Font createFont() {
108
return UIManager.getFont("Label.font"); //NOI18N
111
protected int createRepaintPolicy () {
112
return TabState.REPAINT_SELECTION_ON_ACTIVATION_CHANGE
113
| TabState.REPAINT_ON_SELECTION_CHANGE
114
| TabState.REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA
115
| TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON
116
| TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED
117
| TabState.REPAINT_ON_MOUSE_PRESSED;
120
public Dimension getPreferredSize(JComponent c) {
122
//Never call getGraphics() on the control, it resets in-process
123
//painting on OS-X 1.4.1 and triggers gratuitous repaints
124
Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics();
126
FontMetrics fm = g.getFontMetrics(displayer.getFont());
127
Insets ins = getTabAreaInsets();
128
prefHeight = fm.getHeight() + ins.top + ins.bottom + 7;
130
if (prefHeight % 2 == 0) {
133
return new Dimension(displayer.getWidth(), prefHeight);
136
protected void paintAfterTabs(Graphics g) {
137
//Draw the continuation of the rounded border behind the buttons
140
int centerY = (((displayer.getHeight() -
141
(AquaEditorTabCellRenderer.TOP_INSET + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2)
142
+ AquaEditorTabCellRenderer.TOP_INSET - 1) + getTabAreaInsets().top + 1;
144
if (lineMiddleColor == null) {
145
lineMiddleColor = ColorUtil.getMiddle(UIManager.getColor("controlShadow"),
146
UIManager.getColor("control")); //NOI18N
148
g.setColor (lineMiddleColor);
150
int rightLineStart = getTabsAreaWidth() - 13;
151
int rightLineEnd = displayer.getWidth() - 9;
153
if (displayer.getModel().size() > 0 && !scroll().isLastTabClipped()) {
154
//Extend the line out to the edge of the last visible tab
155
//if none are clipped
156
int idx = scroll().getLastVisibleTab(displayer.getWidth());
157
rightLineStart = scroll().getX(idx) + scroll().getW(idx);
158
} else if (displayer.getModel().size() == 0) {
162
if (scroll().getOffset() >= 0) {
163
//fill the left edge notch
164
g.drawLine(6, centerY, 11, centerY);
166
g.drawLine(rightLineStart, centerY, rightLineEnd, centerY);
168
if (lineHlColor == null) {
169
lineHlColor = ColorUtil.getMiddle (lineMiddleColor,
170
UIManager.getColor("control"));
173
g.setColor (lineHlColor); //NOI18N
174
g.drawLine(rightLineStart, centerY+1, rightLineEnd, centerY+1);
175
if (scroll().getOffset() > 0) {
176
//fill the left edge notch
177
g.drawLine(6, centerY+1, 11, centerY+1);
182
private static void initIcons() {
183
if( null == buttonIconPaths ) {
184
buttonIconPaths = new HashMap<Integer, String[]>(7);
187
String[] iconPaths = new String[4];
188
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_enabled.png"; // NOI18N
189
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_disabled.png"; // NOI18N
190
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_rollover.png"; // NOI18N
191
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_pressed.png"; // NOI18N
192
buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths );
195
iconPaths = new String[4];
196
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_enabled.png"; // NOI18N
197
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_disabled.png"; // NOI18N
198
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_rollover.png"; // NOI18N
199
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_pressed.png"; // NOI18N
200
buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths );
203
iconPaths = new String[4];
204
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_popup_enabled.png"; // NOI18N
205
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_disabled.png"; // NOI18N
206
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_popup_rollover.png"; // NOI18N
207
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_pressed.png"; // NOI18N
208
buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths );
210
//maximize/restore button
211
iconPaths = new String[4];
212
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_enabled.png"; // NOI18N
213
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_disabled.png"; // NOI18N
214
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_rollover.png"; // NOI18N
215
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_pressed.png"; // NOI18N
216
buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths );
218
iconPaths = new String[4];
219
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_restore_enabled.png"; // NOI18N
220
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_disabled.png"; // NOI18N
221
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_restore_rollover.png"; // NOI18N
222
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_pressed.png"; // NOI18N
223
buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths );
227
public Icon getButtonIcon(int buttonId, int buttonState) {
230
String[] paths = buttonIconPaths.get( buttonId );
231
if( null != paths && buttonState >=0 && buttonState < paths.length ) {
232
res = TabControlButtonFactory.getIcon( paths[buttonState] );
237
protected Rectangle getControlButtonsRectangle(Container parent) {
238
int centerY = (((displayer.getHeight() - (AquaEditorTabCellRenderer.TOP_INSET
239
+ AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2) + AquaEditorTabCellRenderer.TOP_INSET)
240
+ getTabAreaInsets().top;
242
int width = parent.getWidth();
243
int height = parent.getHeight();
244
int buttonsWidth = getControlButtons().getWidth();
245
int buttonsHeight = getControlButtons().getHeight();
246
return new Rectangle( width-buttonsWidth-3, centerY-buttonsHeight/2, buttonsWidth, buttonsHeight );