jdk/src/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java
author peterz
Tue, 21 Sep 2010 10:04:41 +0400
changeset 6654 0fd919eec405
parent 6500 129126795742
child 7007 36b01e053bd7
permissions -rw-r--r--
6978052: No appropriate CCC request for listed JDK 7 changes in javax.swing.plaf.synth package (b84) Reviewed-by: malenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
6500
129126795742 6915566: Closed swing tests failing with assert errors when run with -ea -esa
malenkov
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5132
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5132
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5132
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5132
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5132
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    40
 * Provides the Synth L&F UI delegate for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    41
 * {@link javax.swing.JTabbedPane}.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    42
 *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    43
 * <p>Looks up the {@code selectedTabPadInsets} property from the Style,
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    44
 * which represents additional insets for the selected tab.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Scott Violet
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    47
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    49
public class SynthTabbedPaneUI extends BasicTabbedPaneUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    50
                               implements PropertyChangeListener, SynthUI {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    51
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    52
    /**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    53
     * <p>If non-zero, tabOverlap indicates the amount that the tab bounds
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    54
     * should be altered such that they would overlap with a tab on either the
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    55
     * leading or trailing end of a run (ie: in TOP, this would be on the left
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    56
     * or right).</p>
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    57
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    58
     * <p>A positive overlap indicates that tabs should overlap right/down,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    59
     * while a negative overlap indicates tha tabs should overlap left/up.</p>
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    60
     *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    61
     * <p>When tabOverlap is specified, it both changes the x position and width
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    62
     * of the tab if in TOP or BOTTOM placement, and changes the y position and
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    63
     * height if in LEFT or RIGHT placement.</p>
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    64
     *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    65
     * <p>This is done for the following reason. Consider a run of 10 tabs.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    66
     * There are 9 gaps between these tabs. If you specified a tabOverlap of
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    67
     * "-1", then each of the tabs "x" values will be shifted left. This leaves
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    68
     * 9 pixels of space to the right of the right-most tab unpainted. So, each
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    69
     * tab's width is also extended by 1 pixel to make up the difference.</p>
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    70
     *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    71
     * <p>This property respects the RTL component orientation.</p>
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    72
     */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    73
    private int tabOverlap = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    74
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    75
    /**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    76
     * When a tabbed pane has multiple rows of tabs, this indicates whether
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    77
     * the tabs in the upper row(s) should extend to the base of the tab area,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    78
     * or whether they should remain at their normal tab height. This does not
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    79
     * affect the bounds of the tabs, only the bounds of area painted by the
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    80
     * tabs. The text position does not change. The result is that the bottom
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    81
     * border of the upper row of tabs becomes fully obscured by the lower tabs,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    82
     * resulting in a cleaner look.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    83
     */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    84
    private boolean extendTabsToBase = false;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
    85
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private SynthContext tabAreaContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private SynthContext tabContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private SynthContext tabContentContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private SynthStyle tabStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private SynthStyle tabAreaStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private SynthStyle tabContentStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
    95
    private Rectangle textRect = new Rectangle();
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
    96
    private Rectangle iconRect = new Rectangle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private Rectangle tabAreaBounds = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   100
    //added for the Nimbus look and feel, where the tab area is painted differently depending on the
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   101
    //state for the selected tab
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   102
    private boolean tabAreaStatesMatchSelectedTab = false;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   103
    //added for the Nimbus LAF to ensure that the labels don't move whether the tab is selected or not
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   104
    private boolean nudgeSelectedLabel = true;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   105
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   106
    private boolean selectedTabIsPressed = false;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   107
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   108
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   109
     * Creates a new UI object for the given component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   110
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   111
     * @param c component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   112
     * @return the UI object
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   113
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return new SynthTabbedPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
6654
0fd919eec405 6978052: No appropriate CCC request for listed JDK 7 changes in javax.swing.plaf.synth package (b84)
peterz
parents: 6500
diff changeset
   118
    private SynthTabbedPaneUI() {
0fd919eec405 6978052: No appropriate CCC request for listed JDK 7 changes in javax.swing.plaf.synth package (b84)
peterz
parents: 6500
diff changeset
   119
    }
0fd919eec405 6978052: No appropriate CCC request for listed JDK 7 changes in javax.swing.plaf.synth package (b84)
peterz
parents: 6500
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private boolean scrollableTabLayoutEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   125
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   126
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   127
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   128
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        updateStyle(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private void updateStyle(JTabbedPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // Add properties other than JComponent colors, Borders and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // opacity settings here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            tabRunOverlay =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                style.getInt(context, "TabbedPane.tabRunOverlay", 0);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   142
            tabOverlap = style.getInt(context, "TabbedPane.tabOverlap", 0);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   143
            extendTabsToBase = style.getBoolean(context,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   144
                    "TabbedPane.extendTabsToBase", false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            textIconGap = style.getInt(context, "TabbedPane.textIconGap", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            selectedTabPadInsets = (Insets)style.get(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                "TabbedPane.selectedTabPadInsets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (selectedTabPadInsets == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                selectedTabPadInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   151
            tabAreaStatesMatchSelectedTab = style.getBoolean(context,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   152
                    "TabbedPane.tabAreaStatesMatchSelectedTab", false);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   153
            nudgeSelectedLabel = style.getBoolean(context,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   154
                    "TabbedPane.nudgeSelectedLabel", true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (tabContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            tabContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        tabContext = getContext(c, Region.TABBED_PANE_TAB, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        this.tabStyle = SynthLookAndFeel.updateStyle(tabContext, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        tabInsets = tabStyle.getInsets(tabContext, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (tabAreaContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            tabAreaContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        tabAreaContext = getContext(c, Region.TABBED_PANE_TAB_AREA, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        this.tabAreaStyle = SynthLookAndFeel.updateStyle(tabAreaContext, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        tabAreaInsets = tabAreaStyle.getInsets(tabAreaContext, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (tabContentContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            tabContentContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        tabContentContext = getContext(c, Region.TABBED_PANE_CONTENT, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        this.tabContentStyle = SynthLookAndFeel.updateStyle(tabContentContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                                            this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        contentBorderInsets =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            tabContentStyle.getInsets(tabContentContext, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   188
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   189
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   190
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   191
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        tabPane.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   197
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   198
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   199
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   200
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        tabPane.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   206
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   207
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   208
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   209
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        SynthContext context = getContext(tabPane, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        tabStyle.uninstallDefaults(tabContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        tabContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        tabContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        tabStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        tabAreaStyle.uninstallDefaults(tabAreaContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        tabAreaContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        tabAreaContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        tabAreaStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        tabContentStyle.uninstallDefaults(tabContentContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        tabContentContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        tabContentContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        tabContentStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   232
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   233
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   234
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   235
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   237
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   240
    private SynthContext getContext(JComponent c, int state) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    SynthLookAndFeel.getRegion(c),style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private SynthContext getContext(JComponent c, Region subregion, int state){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        SynthStyle style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Class klass = SynthContext.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (subregion == Region.TABBED_PANE_TAB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            style = tabStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        else if (subregion == Region.TABBED_PANE_TAB_AREA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            style = tabAreaStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        else if (subregion == Region.TABBED_PANE_CONTENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            style = tabContentStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return SynthContext.getContext(klass, c, subregion, style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   261
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   262
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   263
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   264
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    protected JButton createScrollButton(int direction) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   266
        // added for Nimbus LAF so that it can use the basic arrow buttons
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   267
        // UIManager is queried directly here because this is called before
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   268
        // updateStyle is called so the style can not be queried directly
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   269
        if (UIManager.getBoolean("TabbedPane.useBasicArrows")) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   270
            JButton btn = super.createScrollButton(direction);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   271
            btn.setBorder(BorderFactory.createEmptyBorder());
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   272
            return btn;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   273
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return new SynthScrollableTabButton(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   277
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   278
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   279
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   280
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            updateStyle(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   287
    /**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   288
     * @inheritDoc
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   289
     *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   290
     * Overridden to keep track of whether the selected tab is also pressed.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   291
     */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   292
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   293
    protected MouseListener createMouseListener() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   294
        final MouseListener delegate = super.createMouseListener();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   295
        final MouseMotionListener delegate2 = (MouseMotionListener)delegate;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   296
        return new MouseListener() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   297
            public void mouseClicked(MouseEvent e) { delegate.mouseClicked(e); }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   298
            public void mouseEntered(MouseEvent e) { delegate.mouseEntered(e); }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   299
            public void mouseExited(MouseEvent e) { delegate.mouseExited(e); }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   300
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   301
            public void mousePressed(MouseEvent e) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   302
                if (!tabPane.isEnabled()) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   303
                    return;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   304
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   305
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   306
                int tabIndex = tabForCoordinate(tabPane, e.getX(), e.getY());
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   307
                if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   308
                    if (tabIndex == tabPane.getSelectedIndex()) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   309
                        // Clicking on selected tab
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   310
                        selectedTabIsPressed = true;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   311
                        //TODO need to just repaint the tab area!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   312
                        tabPane.repaint();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   313
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   314
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   315
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   316
                //forward the event (this will set the selected index, or none at all
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   317
                delegate.mousePressed(e);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   318
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   319
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   320
            public void mouseReleased(MouseEvent e) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   321
                if (selectedTabIsPressed) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   322
                    selectedTabIsPressed = false;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   323
                    //TODO need to just repaint the tab area!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   324
                    tabPane.repaint();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   325
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   326
                //forward the event
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   327
                delegate.mouseReleased(e);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   328
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   329
                //hack: The super method *should* be setting the mouse-over property correctly
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   330
                //here, but it doesn't. That is, when the mouse is released, whatever tab is below the
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   331
                //released mouse should be in rollover state. But, if you select a tab and don't
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   332
                //move the mouse, this doesn't happen. Hence, forwarding the event.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   333
                delegate2.mouseMoved(e);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   334
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   335
        };
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   336
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   337
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   338
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   339
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   340
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   341
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   342
    protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   343
        if (nudgeSelectedLabel) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   344
            return super.getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   345
        } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   346
            return 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   347
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   348
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   349
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   350
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   351
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   352
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   353
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   354
    protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   355
        if (nudgeSelectedLabel) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   356
            return super.getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   357
        } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   358
            return 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   359
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   360
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   361
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   362
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   363
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   364
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   365
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   366
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   367
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   368
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   369
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   370
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   371
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   372
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   373
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   374
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        context.getPainter().paintTabbedPaneBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                          g, 0, 0, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   385
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   386
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   387
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   388
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    protected int getBaseline(int tab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (tabPane.getTabComponentAt(tab) != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                getTextViewForTab(tab) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return super.getBaseline(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        String title = tabPane.getTitleAt(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        Font font = tabContext.getStyle().getFont(tabContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        FontMetrics metrics = getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        Icon icon = getIconForTab(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        textRect.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        iconRect.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        calcRect.setBounds(0, 0, Short.MAX_VALUE, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        tabContext.getStyle().getGraphicsUtils(tabContext).layoutText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                tabContext, metrics, title, icon, SwingUtilities.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                SwingUtilities.CENTER, SwingUtilities.LEADING,
2490
b460fb94812d 6815767: Bad parameter when calling another method in the class SynthTabbedPaneUI
peterz
parents: 2
diff changeset
   404
                SwingUtilities.CENTER, calcRect,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                iconRect, textRect, textIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return textRect.y + metrics.getAscent() + getBaselineOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   409
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   410
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   411
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   412
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        context.getPainter().paintTabbedPaneBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   418
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   419
     * Paints the specified component according to the Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   420
     * <p>This method is not used by Synth Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   421
     * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   422
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   423
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   424
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   425
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   426
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   427
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   435
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   436
     * Paints the specified component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   437
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   438
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   439
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   440
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   441
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        ensureCurrentLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        // Paint tab area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        // If scrollable tabs are enabled, the tab area will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // painted by the scrollable tab panel instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            int x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            int y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            int width = tabPane.getWidth() - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            int height = tabPane.getHeight() - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                width = calculateTabAreaWidth(tabPlacement, runCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                              maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                size = calculateTabAreaWidth(tabPlacement, runCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                             maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                x = x + width - size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                width = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                size = calculateTabAreaHeight(tabPlacement, runCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                                              maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                y = y + height - size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                height = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                height = calculateTabAreaHeight(tabPlacement, runCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                                                maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            tabAreaBounds.setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            if (g.getClipBounds().intersects(tabAreaBounds)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                paintTabArea(tabAreaContext, g, tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                         selectedIndex, tabAreaBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        // Paint content border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        paintContentBorder(tabContentContext, g, tabPlacement, selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   495
    private void paintTabArea(SynthContext ss, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                int tabPlacement, int selectedIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                Rectangle tabAreaBounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        Rectangle clipRect = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   500
        //if the tab area's states should match that of the selected tab, then
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   501
        //first update the selected tab's states, then set the state
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   502
        //for the tab area to match
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   503
        //otherwise, restore the tab area's state to ENABLED (which is the
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   504
        //only supported state otherwise).
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   505
        if (tabAreaStatesMatchSelectedTab && selectedIndex >= 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   506
            updateTabContext(selectedIndex, true, selectedTabIsPressed,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   507
                              (getRolloverTab() == selectedIndex),
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   508
                              (getFocusIndex() == selectedIndex));
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   509
            ss.setComponentState(tabContext.getComponentState());
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   510
        } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   511
            ss.setComponentState(SynthConstants.ENABLED);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   512
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   513
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        // Paint the tab area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        SynthLookAndFeel.updateSubregion(ss, g, tabAreaBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        ss.getPainter().paintTabbedPaneTabAreaBackground(ss, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
             tabAreaBounds.x, tabAreaBounds.y, tabAreaBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
             tabAreaBounds.height, tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        ss.getPainter().paintTabbedPaneTabAreaBorder(ss, g, tabAreaBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
             tabAreaBounds.y, tabAreaBounds.width, tabAreaBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
             tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        iconRect.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        textRect.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        // Paint tabRuns of tabs from back to front
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        for (int i = runCount - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            int start = tabRuns[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            int next = tabRuns[(i == runCount - 1)? 0 : i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            int end = (next != 0? next - 1: tabCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            for (int j = start; j <= end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                if (rects[j].intersects(clipRect) && selectedIndex != j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    paintTab(tabContext, g, tabPlacement, rects, j, iconRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                             textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (selectedIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            if (rects[selectedIndex].intersects(clipRect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                paintTab(tabContext, g, tabPlacement, rects, selectedIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                         iconRect, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   549
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   550
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   551
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   552
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    protected void setRolloverTab(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        int oldRolloverTab = getRolloverTab();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        super.setRolloverTab(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        Rectangle r = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   559
        if (oldRolloverTab != index && tabAreaStatesMatchSelectedTab) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   560
            //TODO need to just repaint the tab area!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   561
            tabPane.repaint();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   562
        } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   563
            if ((oldRolloverTab >= 0) && (oldRolloverTab < tabPane.getTabCount())) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   564
                r = getTabBounds(tabPane, oldRolloverTab);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   565
                if (r != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   566
                    tabPane.repaint(r);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   567
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   570
            if (index >= 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   571
                r = getTabBounds(tabPane, index);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   572
                if (r != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   573
                    tabPane.repaint(r);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   574
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   579
    private void paintTab(SynthContext ss, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                            int tabPlacement, Rectangle[] rects, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                            Rectangle iconRect, Rectangle textRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        Rectangle tabRect = rects[tabIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        boolean isSelected = selectedIndex == tabIndex;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   585
        updateTabContext(tabIndex, isSelected, isSelected && selectedTabIsPressed,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   586
                            (getRolloverTab() == tabIndex),
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   587
                            (getFocusIndex() == tabIndex));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        SynthLookAndFeel.updateSubregion(ss, g, tabRect);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   590
        int x = tabRect.x;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   591
        int y = tabRect.y;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   592
        int height = tabRect.height;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   593
        int width = tabRect.width;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   594
        int placement = tabPane.getTabPlacement();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   595
        if (extendTabsToBase && runCount > 1) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   596
            //paint this tab such that its edge closest to the base is equal to
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   597
            //edge of the selected tab closest to the base. In terms of the TOP
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   598
            //tab placement, this will cause the bottom of each tab to be
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   599
            //painted even with the bottom of the selected tab. This is because
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   600
            //in each tab placement (TOP, LEFT, BOTTOM, RIGHT) the selected tab
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   601
            //is closest to the base.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   602
            if (selectedIndex >= 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   603
                Rectangle r = rects[selectedIndex];
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   604
                switch (placement) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   605
                    case TOP:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   606
                        int bottomY = r.y + r.height;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   607
                        height = bottomY - tabRect.y;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   608
                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   609
                    case LEFT:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   610
                        int rightX = r.x + r.width;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   611
                        width = rightX - tabRect.x;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   612
                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   613
                    case BOTTOM:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   614
                        int topY = r.y;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   615
                        height = (tabRect.y + tabRect.height) - topY;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   616
                        y = topY;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   617
                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   618
                    case RIGHT:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   619
                        int leftX = r.x;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   620
                        width = (tabRect.x + tabRect.width) - leftX;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   621
                        x = leftX;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   622
                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   623
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   624
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   625
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   626
        tabContext.getPainter().paintTabbedPaneTabBackground(tabContext, g,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   627
                x, y, width, height, tabIndex, placement);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        tabContext.getPainter().paintTabbedPaneTabBorder(tabContext, g,
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   629
                x, y, width, height, tabIndex, placement);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        if (tabPane.getTabComponentAt(tabIndex) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            String title = tabPane.getTitleAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            Font font = ss.getStyle().getFont(ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            Icon icon = getIconForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            layoutLabel(ss, tabPlacement, metrics, tabIndex, title, icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    tabRect, iconRect, textRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            paintText(ss, g, tabPlacement, font, metrics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    tabIndex, title, textRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   647
    private void layoutLabel(SynthContext ss, int tabPlacement,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                               FontMetrics metrics, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                               String title, Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                               Rectangle tabRect, Rectangle iconRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                               Rectangle textRect, boolean isSelected ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            tabPane.putClientProperty("html", v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        ss.getStyle().getGraphicsUtils(ss).layoutText(ss, metrics, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                         icon, SwingUtilities.CENTER, SwingUtilities.CENTER,
2490
b460fb94812d 6815767: Bad parameter when calling another method in the class SynthTabbedPaneUI
peterz
parents: 2
diff changeset
   661
                         SwingUtilities.LEADING, SwingUtilities.CENTER,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                         tabRect, iconRect, textRect, textIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        tabPane.putClientProperty("html", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        iconRect.x += xNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        iconRect.y += yNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        textRect.x += xNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        textRect.y += yNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   674
    private void paintText(SynthContext ss,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                             Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                             Font font, FontMetrics metrics, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                             String title, Rectangle textRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                             boolean isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        g.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            // html
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            v.paint(g, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            // plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                  textRect, mnemIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   696
    private void paintContentBorder(SynthContext ss, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                                      int tabPlacement, int selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        int width = tabPane.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        int height = tabPane.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        int x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        int y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        int w = width - insets.right - insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        int h = height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
              x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
              w -= (x - insets.left);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
              w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
              h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
              y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
              h -= (y - insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        SynthLookAndFeel.updateSubregion(ss, g, new Rectangle(x, y, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        ss.getPainter().paintTabbedPaneContentBackground(ss, g, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                                                           w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        ss.getPainter().paintTabbedPaneContentBorder(ss, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    private void ensureCurrentLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        if (!tabPane.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            tabPane.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        /* If tabPane doesn't have a peer yet, the validate() call will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
         * silently fail.  We handle that by forcing a layout if tabPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
         * is still invalid.  See bug 4237677.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        if (!tabPane.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            TabbedPaneLayout layout = (TabbedPaneLayout)tabPane.getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            layout.calculateLayoutInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   743
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   744
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   745
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   746
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    protected int calculateMaxTabHeight(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                                             tabContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        for(int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            result = Math.max(calculateTabHeight(tabPlacement, i, fontHeight), result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   759
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   760
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   761
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   762
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    protected int calculateTabWidth(int tabPlacement, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                                    FontMetrics metrics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        Icon icon = getIconForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        int width = tabInsets.left + tabInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        Component tabComponent = tabPane.getTabComponentAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        if (tabComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            width += tabComponent.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                width += icon.getIconWidth() + textIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                // html
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                width += (int) v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                // plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                String title = tabPane.getTitleAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                width += tabContext.getStyle().getGraphicsUtils(tabContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                        computeStringWidth(tabContext, metrics.getFont(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                                metrics, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   790
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   791
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   792
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   793
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    protected int calculateMaxTabWidth(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                                     tabContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        for(int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            result = Math.max(calculateTabWidth(tabPlacement, i, metrics),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                              result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   806
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   807
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   808
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   809
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    protected Insets getTabInsets(int tabPlacement, int tabIndex) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   811
        updateTabContext(tabIndex, false, false, false,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                          (getFocusIndex() == tabIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        return tabInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   816
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   817
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   818
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   819
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    protected FontMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return getFontMetrics(tabContext.getStyle().getFont(tabContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   824
    private FontMetrics getFontMetrics(Font font) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        return tabPane.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    private void updateTabContext(int index, boolean selected,
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   829
                                  boolean isMouseDown, boolean isMouseOver, boolean hasFocus) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        int state = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        if (!tabPane.isEnabled() || !tabPane.isEnabledAt(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            state |= SynthConstants.DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                state |= SynthConstants.SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        else if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            state |= (SynthConstants.ENABLED | SynthConstants.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            if (isMouseOver && UIManager.getBoolean("TabbedPane.isTabRollover")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                state |= SynthConstants.MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        else if (isMouseOver) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            state |= (SynthConstants.ENABLED | SynthConstants.MOUSE_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            state = SynthLookAndFeel.getComponentState(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            state &= ~SynthConstants.FOCUSED; // don't use tabbedpane focus state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        if (hasFocus && tabPane.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            state |= SynthConstants.FOCUSED; // individual tab has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   853
        if (isMouseDown) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   854
            state |= SynthConstants.PRESSED;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   855
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   856
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        tabContext.setComponentState(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   860
    /**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   861
     * @inheritDoc
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   862
     *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   863
     * Overridden to create a TabbedPaneLayout subclass which takes into
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   864
     * account tabOverlap.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   865
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   866
    @Override
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   867
    protected LayoutManager createLayoutManager() {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   868
        if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   869
            return super.createLayoutManager();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   870
        } else { /* WRAP_TAB_LAYOUT */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   871
            return new TabbedPaneLayout() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   872
                @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   873
                public void calculateLayoutInfo() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   874
                    super.calculateLayoutInfo();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   875
                    //shift all the tabs, if necessary
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   876
                    if (tabOverlap != 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   877
                        int tabCount = tabPane.getTabCount();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   878
                        //left-to-right/right-to-left only affects layout
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   879
                        //when placement is TOP or BOTTOM
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   880
                        boolean ltr = tabPane.getComponentOrientation().isLeftToRight();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   881
                        for (int i = runCount - 1; i >= 0; i--) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   882
                            int start = tabRuns[i];
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   883
                            int next = tabRuns[(i == runCount - 1)? 0 : i + 1];
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   884
                            int end = (next != 0? next - 1: tabCount - 1);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   885
                            for (int j = start+1; j <= end; j++) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   886
                                // xshift and yshift represent the amount &
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   887
                                // direction to shift the tab in their
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   888
                                // respective axis.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   889
                                int xshift = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   890
                                int yshift = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   891
                                // configure xshift and y shift based on tab
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   892
                                // position and ltr/rtl
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   893
                                switch (tabPane.getTabPlacement()) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   894
                                    case JTabbedPane.TOP:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   895
                                    case JTabbedPane.BOTTOM:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   896
                                        xshift = ltr ? tabOverlap : -tabOverlap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   897
                                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   898
                                    case JTabbedPane.LEFT:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   899
                                    case JTabbedPane.RIGHT:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   900
                                        yshift = tabOverlap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   901
                                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   902
                                    default: //do nothing
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   903
                                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   904
                                rects[j].x += xshift;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   905
                                rects[j].y += yshift;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   906
                                rects[j].width += Math.abs(xshift);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   907
                                rects[j].height += Math.abs(yshift);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   908
                            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   909
                        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   910
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   911
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   912
            };
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   913
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   914
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   915
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    private class SynthScrollableTabButton extends SynthArrowButton implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        public SynthScrollableTabButton(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            super(direction);
6500
129126795742 6915566: Closed swing tests failing with assert errors when run with -ea -esa
malenkov
parents: 5506
diff changeset
   920
            setName("TabbedPane.button");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
}