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
* WinClassicEditorTabDisplayerUI.java
44
* Created on 09 December 2003, 16:53
47
package org.netbeans.swing.tabcontrol.plaf;
49
import java.awt.Component;
50
import java.awt.Container;
51
import java.awt.Dimension;
52
import java.awt.FontMetrics;
53
import java.awt.GradientPaint;
54
import java.awt.Graphics;
55
import java.awt.Graphics2D;
56
import java.awt.Insets;
57
import java.awt.Rectangle;
58
import java.util.HashMap;
60
import javax.swing.Icon;
61
import javax.swing.JComponent;
62
import javax.swing.UIManager;
63
import org.netbeans.swing.tabcontrol.TabDisplayer;
65
import javax.swing.plaf.ComponentUI;
68
* Windows classic impl of tabs ui
70
* @author Tim Boudreau
72
public final class WinClassicEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI {
74
private static final Rectangle scratch5 = new Rectangle();
75
private static Map<Integer, String[]> buttonIconPaths;
77
private static boolean isGenericUI = !"Windows".equals( //NOI18N
78
UIManager.getLookAndFeel().getID());
81
* Creates a new instance of WinClassicEditorTabDisplayerUI
83
public WinClassicEditorTabDisplayerUI(TabDisplayer displayer) {
87
public static ComponentUI createUI(JComponent c) {
88
return new WinClassicEditorTabDisplayerUI ((TabDisplayer) c);
91
public Rectangle getTabRect(int idx, Rectangle rect) {
92
Rectangle r = super.getTabRect (idx, rect);
93
//For win classic, take up the full space, even the insets, to match
96
r.height = displayer.getHeight();
100
public void install() {
103
displayer.setBackground( UIManager.getColor("tab_unsel_fill") );
104
displayer.setOpaque(true);
108
public Dimension getPreferredSize(JComponent c) {
110
Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics();
112
FontMetrics fm = g.getFontMetrics(displayer.getFont());
113
Insets ins = getTabAreaInsets();
114
prefHeight = fm.getHeight() + ins.top + ins.bottom + (isGenericUI ? 5 : 6);
116
return new Dimension(displayer.getWidth(), prefHeight);
119
private void genericPaintAfterTabs (Graphics g) {
120
g.setColor (UIManager.getColor("controlShadow")); //NOI18N
121
Insets ins = displayer.getInsets();
122
Rectangle r = new Rectangle();
123
getTabsVisibleArea(r);
124
r.width = displayer.getWidth();
126
int last = getLastVisibleTab();
128
getTabRect (last, scratch5);
129
g.drawLine (scratch5.x + scratch5.width, displayer.getHeight() -1,
130
displayer.getWidth() - (ins.left + ins.right) - 4,
131
displayer.getHeight() - 1);
132
g.drawLine (0, displayer.getHeight() - 2, 2, displayer.getHeight() -2);
133
//TODO remove when a specific GTK l&f UI class is available
134
if ("GTK".equals(UIManager.getLookAndFeel().getID())) {
135
boolean sel = last == displayer.getSelectionModel().getSelectedIndex();
136
//paint a fading shadow to match the view tabs
137
int x = scratch5.x + scratch5.width;
138
g.setColor (sel ? UIManager.getColor("controlShadow") :
139
ColorUtil.adjustTowards(g.getColor(), 20,
140
UIManager.getColor("control"))); //NOI18N
143
scratch5.y + scratch5.height -2);
144
g.setColor (ColorUtil.adjustTowards(g.getColor(), 20,
145
UIManager.getColor("control"))); //NOI18N
147
scratch5.y + 6, x + 1,
148
scratch5.y + scratch5.height -2);
150
if ((tabState.getState(getFirstVisibleTab()) & TabState.CLIP_LEFT)
151
!=0 && getFirstVisibleTab() !=
152
displayer.getSelectionModel().getSelectedIndex()) {
153
//Draw a small gradient line continuing the left edge of
154
//the displayer up the left side of a left clipped tab
155
GradientPaint gp = ColorUtil.getGradientPaint(
156
0, displayer.getHeight() / 2, UIManager.getColor("control"),
157
0, displayer.getHeight(), UIManager.getColor("controlShadow"));
158
((Graphics2D) g).setPaint(gp);
159
g.drawLine (0, displayer.getHeight() / 2, 0, displayer.getHeight());
161
//Fill the small gap between the top of the content displayer
162
//and the bottom of the tabs, caused by the tab area bottom inset
163
g.setColor (UIManager.getColor("controlShadow"));
164
g.drawLine (0, displayer.getHeight(), 0, displayer.getHeight() - 2);
166
if ((tabState.getState(getLastVisibleTab()) & TabState.CLIP_RIGHT) != 0
167
&& getLastVisibleTab() !=
168
displayer.getSelectionModel().getSelectedIndex()) {
169
GradientPaint gp = ColorUtil.getGradientPaint(
170
0, displayer.getHeight() / 2, UIManager.getColor("control"),
171
0, displayer.getHeight(), UIManager.getColor("controlShadow"));
172
((Graphics2D) g).setPaint(gp);
173
getTabRect (getLastVisibleTab(), scratch5);
174
g.drawLine (scratch5.x + scratch5.width, displayer.getHeight() / 2,
175
scratch5.x + scratch5.width, displayer.getHeight());
179
g.drawLine(r.x, displayer.getHeight() - ins.bottom, r.x + r.width - 4,
180
displayer.getHeight() - ins.bottom);
184
protected void paintAfterTabs(Graphics g) {
186
genericPaintAfterTabs(g);
189
Rectangle r = new Rectangle();
190
getTabsVisibleArea(r);
191
r.width = displayer.getWidth();
192
g.setColor(displayer.isActive() ?
193
defaultRenderer.getSelectedActivatedBackground() :
194
defaultRenderer.getSelectedBackground());
196
Insets ins = getTabAreaInsets();
198
g.fillRect(r.x, r.y + r.height, r.x + r.width,
199
displayer.getHeight() - (r.y + r.height));
201
g.setColor(UIManager.getColor("controlLtHighlight")); //NOI18N
204
int i = selectionModel.getSelectedIndex();
206
getTabRect(i, scratch5);
207
if (scratch5.width != 0) {
208
if (r.x < scratch5.x) {
209
g.drawLine(r.x, displayer.getHeight() - ins.bottom,
211
displayer.getHeight() - ins.bottom);
213
if (scratch5.x + scratch5.width < r.x + r.width) {
214
selEnd = scratch5.x + scratch5.width;
215
//If the last tab is not clipped, the final tab is one
216
//pixel smaller; we need to overwrite one pixel of the
217
//border or there will be a small stub sticking down
218
if (!scroll().isLastTabClipped()) {
221
g.drawLine(selEnd, displayer.getHeight() - ins.bottom,
223
displayer.getHeight() - ins.bottom);
229
g.drawLine(r.x, displayer.getHeight() - ins.bottom, r.x + r.width,
230
displayer.getHeight() - ins.bottom);
233
protected TabCellRenderer createDefaultRenderer() {
234
return new WinClassicEditorTabCellRenderer();
237
private static void initIcons() {
238
if( null == buttonIconPaths ) {
239
buttonIconPaths = new HashMap<Integer, String[]>(7);
242
String[] iconPaths = new String[4];
243
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_scrollleft_enabled.png"; // NOI18N
244
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_scrollleft_disabled.png"; // NOI18N
245
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_scrollleft_rollover.png"; // NOI18N
246
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_scrollleft_pressed.png"; // NOI18N
247
buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths );
250
iconPaths = new String[4];
251
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_scrollright_enabled.png"; // NOI18N
252
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_scrollright_disabled.png"; // NOI18N
253
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_scrollright_rollover.png"; // NOI18N
254
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_scrollright_pressed.png"; // NOI18N
255
buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths );
258
iconPaths = new String[4];
259
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_popup_enabled.png"; // NOI18N
260
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_popup_disabled.png"; // NOI18N
261
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_popup_rollover.png"; // NOI18N
262
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_popup_pressed.png"; // NOI18N
263
buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths );
265
//maximize/restore button
266
iconPaths = new String[4];
267
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_maximize_enabled.png"; // NOI18N
268
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_maximize_disabled.png"; // NOI18N
269
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_maximize_rollover.png"; // NOI18N
270
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_maximize_pressed.png"; // NOI18N
271
buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths );
273
iconPaths = new String[4];
274
iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_restore_enabled.png"; // NOI18N
275
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_restore_disabled.png"; // NOI18N
276
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_restore_rollover.png"; // NOI18N
277
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_restore_pressed.png"; // NOI18N
278
buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths );
282
public Icon getButtonIcon(int buttonId, int buttonState) {
285
String[] paths = buttonIconPaths.get( buttonId );
286
if( null != paths && buttonState >=0 && buttonState < paths.length ) {
287
res = TabControlButtonFactory.getIcon( paths[buttonState] );
292
protected Rectangle getControlButtonsRectangle( Container parent ) {
293
Component c = getControlButtons();
294
return new Rectangle( parent.getWidth()-c.getWidth()-4, 4, c.getWidth(), c.getHeight() );
297
public Insets getTabAreaInsets() {
298
Insets retValue = super.getTabAreaInsets();