1/*
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.apple.laf;
27
28import java.awt.Color;
29import java.awt.Font;
30import java.awt.FontMetrics;
31import java.awt.Graphics2D;
32import java.awt.Rectangle;
33import javax.swing.JComponent;
34import javax.swing.UIManager;
35import javax.swing.plaf.ComponentUI;
36import javax.swing.plaf.UIResource;
37import javax.swing.text.View;
38
39import sun.swing.SwingUtilities2;
40
41import apple.laf.JRSUIConstants.*;
42
43public class AquaTabbedPaneContrastUI extends AquaTabbedPaneUI {
44    public static ComponentUI createUI(final JComponent c) {
45        return new AquaTabbedPaneContrastUI();
46    }
47
48    public AquaTabbedPaneContrastUI() { }
49
50    protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
51        final View v = getTextViewForTab(tabIndex);
52        if (v != null) {
53            v.paint(g2d, textRect);
54            return;
55        }
56
57        if (title == null) return;
58
59        final Color color = tabPane.getForegroundAt(tabIndex);
60        if (color instanceof UIResource) {
61            g2d.setColor(getNonSelectedTabTitleColor());
62            if (tabPane.getSelectedIndex() == tabIndex) {
63                boolean pressed = isPressedAt(tabIndex);
64                boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
65                Color textColor = getSelectedTabTitleColor(enabled, pressed);
66                Color shadowColor = getSelectedTabTitleShadowColor(enabled);
67                AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
68                return;
69            }
70        } else {
71            g2d.setColor(color);
72        }
73        g2d.setFont(font);
74        SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
75    }
76
77    protected static Color getSelectedTabTitleColor(boolean enabled, boolean pressed) {
78        if (enabled && pressed) {
79            return UIManager.getColor("TabbedPane.selectedTabTitlePressedColor");
80        } else if (!enabled) {
81            return UIManager.getColor("TabbedPane.selectedTabTitleDisabledColor");
82        } else {
83            return UIManager.getColor("TabbedPane.selectedTabTitleNormalColor");
84        }
85    }
86
87    protected static Color getSelectedTabTitleShadowColor(boolean enabled) {
88        return enabled ? UIManager.getColor("TabbedPane.selectedTabTitleShadowNormalColor") : UIManager.getColor("TabbedPane.selectedTabTitleShadowDisabledColor");
89    }
90
91    protected static Color getNonSelectedTabTitleColor() {
92        return UIManager.getColor("TabbedPane.nonSelectedTabTitleNormalColor");
93    }
94
95    protected boolean isPressedAt(int index) {
96        return ((MouseHandler)mouseListener).trackingTab == index;
97    }
98
99    protected boolean shouldRepaintSelectedTabOnMouseDown() {
100        return true;
101    }
102
103    protected State getState(final int index, final boolean frameActive, final boolean isSelected) {
104        if (!frameActive) return State.INACTIVE;
105        if (!tabPane.isEnabled()) return State.DISABLED;
106        if (pressedTab == index) return State.PRESSED;
107        return State.ACTIVE;
108    }
109
110    protected SegmentTrailingSeparator getSegmentTrailingSeparator(final int index, final int selectedIndex, final boolean isLeftToRight) {
111        if (isTabBeforeSelectedTab(index, selectedIndex, isLeftToRight)) return SegmentTrailingSeparator.NO;
112        return SegmentTrailingSeparator.YES;
113    }
114
115    protected SegmentLeadingSeparator getSegmentLeadingSeparator(final int index, final int selectedIndex, final boolean isLeftToRight) {
116        if (index == selectedIndex) return SegmentLeadingSeparator.YES;
117        return SegmentLeadingSeparator.NO;
118    }
119}
120