jdk/src/share/classes/javax/swing/plaf/synth/SynthTabbedPaneUI.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 23010 6dadb192ad81
child 25100 d527cc827d7d
permissions -rw-r--r--
8034169: Fix serial lint warnings in javax.swing Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2002, 2014, 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
/**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
    40
 * Provides the Synth L&F UI delegate for
4394
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
7007
36b01e053bd7 6993140: protected constructor in javax.swing.plaf.synth.SynthTabbedPaneUI.SynthTabbedPaneUI is needed
peterz
parents: 6654
diff changeset
   118
     private boolean scrollableTabLayoutEnabled() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   122
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   123
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   124
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   125
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        updateStyle(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private void updateStyle(JTabbedPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // Add properties other than JComponent colors, Borders and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // opacity settings here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            tabRunOverlay =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                style.getInt(context, "TabbedPane.tabRunOverlay", 0);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   139
            tabOverlap = style.getInt(context, "TabbedPane.tabOverlap", 0);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   140
            extendTabsToBase = style.getBoolean(context,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   141
                    "TabbedPane.extendTabsToBase", false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            textIconGap = style.getInt(context, "TabbedPane.textIconGap", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            selectedTabPadInsets = (Insets)style.get(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                "TabbedPane.selectedTabPadInsets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if (selectedTabPadInsets == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                selectedTabPadInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   148
            tabAreaStatesMatchSelectedTab = style.getBoolean(context,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   149
                    "TabbedPane.tabAreaStatesMatchSelectedTab", false);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   150
            nudgeSelectedLabel = style.getBoolean(context,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   151
                    "TabbedPane.nudgeSelectedLabel", true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (tabContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            tabContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        tabContext = getContext(c, Region.TABBED_PANE_TAB, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        this.tabStyle = SynthLookAndFeel.updateStyle(tabContext, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        tabInsets = tabStyle.getInsets(tabContext, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (tabAreaContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            tabAreaContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        tabAreaContext = getContext(c, Region.TABBED_PANE_TAB_AREA, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        this.tabAreaStyle = SynthLookAndFeel.updateStyle(tabAreaContext, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        tabAreaInsets = tabAreaStyle.getInsets(tabAreaContext, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (tabContentContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            tabContentContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        tabContentContext = getContext(c, Region.TABBED_PANE_CONTENT, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.tabContentStyle = SynthLookAndFeel.updateStyle(tabContentContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                                            this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        contentBorderInsets =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            tabContentStyle.getInsets(tabContentContext, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   185
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   186
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   187
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   188
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        tabPane.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   194
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   195
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   196
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   197
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        tabPane.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   203
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   204
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   205
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   206
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        SynthContext context = getContext(tabPane, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        tabStyle.uninstallDefaults(tabContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        tabContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        tabContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        tabStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        tabAreaStyle.uninstallDefaults(tabAreaContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        tabAreaContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        tabAreaContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        tabAreaStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        tabContentStyle.uninstallDefaults(tabContentContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        tabContentContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        tabContentContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        tabContentStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   229
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   230
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   231
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   232
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   234
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   237
    private SynthContext getContext(JComponent c, int state) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    SynthLookAndFeel.getRegion(c),style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    private SynthContext getContext(JComponent c, Region subregion, int state){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        SynthStyle style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Class klass = SynthContext.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (subregion == Region.TABBED_PANE_TAB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            style = tabStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        else if (subregion == Region.TABBED_PANE_TAB_AREA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            style = tabAreaStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        else if (subregion == Region.TABBED_PANE_CONTENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            style = tabContentStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return SynthContext.getContext(klass, c, subregion, style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   258
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   259
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   260
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   261
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    protected JButton createScrollButton(int direction) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   263
        // 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
   264
        // UIManager is queried directly here because this is called before
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   265
        // updateStyle is called so the style can not be queried directly
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   266
        if (UIManager.getBoolean("TabbedPane.useBasicArrows")) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   267
            JButton btn = super.createScrollButton(direction);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   268
            btn.setBorder(BorderFactory.createEmptyBorder());
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   269
            return btn;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   270
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return new SynthScrollableTabButton(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   274
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   275
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   276
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   277
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            updateStyle(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   284
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   285
     * {@inheritDoc}
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   286
     *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   287
     * Overridden to keep track of whether the selected tab is also pressed.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   288
     */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   289
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   290
    protected MouseListener createMouseListener() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   291
        final MouseListener delegate = super.createMouseListener();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   292
        final MouseMotionListener delegate2 = (MouseMotionListener)delegate;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   293
        return new MouseListener() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   294
            public void mouseClicked(MouseEvent e) { delegate.mouseClicked(e); }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   295
            public void mouseEntered(MouseEvent e) { delegate.mouseEntered(e); }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   296
            public void mouseExited(MouseEvent e) { delegate.mouseExited(e); }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   297
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   298
            public void mousePressed(MouseEvent e) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   299
                if (!tabPane.isEnabled()) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   300
                    return;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   301
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   302
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   303
                int tabIndex = tabForCoordinate(tabPane, e.getX(), e.getY());
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   304
                if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   305
                    if (tabIndex == tabPane.getSelectedIndex()) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   306
                        // Clicking on selected tab
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   307
                        selectedTabIsPressed = true;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   308
                        //TODO need to just repaint the tab area!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   309
                        tabPane.repaint();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   310
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   311
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   312
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   313
                //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
   314
                delegate.mousePressed(e);
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
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   317
            public void mouseReleased(MouseEvent e) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   318
                if (selectedTabIsPressed) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   319
                    selectedTabIsPressed = false;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   320
                    //TODO need to just repaint the tab area!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   321
                    tabPane.repaint();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   322
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   323
                //forward the event
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   324
                delegate.mouseReleased(e);
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
                //hack: The super method *should* be setting the mouse-over property correctly
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   327
                //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
   328
                //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
   329
                //move the mouse, this doesn't happen. Hence, forwarding the event.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   330
                delegate2.mouseMoved(e);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   331
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   332
        };
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   333
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   334
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   335
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   336
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   337
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   338
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   339
    protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   340
        if (nudgeSelectedLabel) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   341
            return super.getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   342
        } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   343
            return 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   344
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   345
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   346
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   347
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   348
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   349
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   350
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   351
    protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   352
        if (nudgeSelectedLabel) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   353
            return super.getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   354
        } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   355
            return 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   356
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   357
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   358
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   359
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   360
     * 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
   361
     * 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
   362
     * 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
   363
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   364
     * <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
   365
     * 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
   366
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   367
     * @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
   368
     * @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
   369
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   370
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   371
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        context.getPainter().paintTabbedPaneBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                          g, 0, 0, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   382
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   383
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   384
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   385
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    protected int getBaseline(int tab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (tabPane.getTabComponentAt(tab) != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                getTextViewForTab(tab) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            return super.getBaseline(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        String title = tabPane.getTitleAt(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        Font font = tabContext.getStyle().getFont(tabContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        FontMetrics metrics = getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        Icon icon = getIconForTab(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        textRect.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        iconRect.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        calcRect.setBounds(0, 0, Short.MAX_VALUE, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        tabContext.getStyle().getGraphicsUtils(tabContext).layoutText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                tabContext, metrics, title, icon, SwingUtilities.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                SwingUtilities.CENTER, SwingUtilities.LEADING,
2490
b460fb94812d 6815767: Bad parameter when calling another method in the class SynthTabbedPaneUI
peterz
parents: 2
diff changeset
   401
                SwingUtilities.CENTER, calcRect,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                iconRect, textRect, textIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return textRect.y + metrics.getAscent() + getBaselineOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   406
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   407
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   408
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   409
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        context.getPainter().paintTabbedPaneBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   415
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   416
     * 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
   417
     * <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
   418
     * 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
   419
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   420
     * @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
   421
     * @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
   422
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   423
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   424
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   432
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   433
     * Paints the specified component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   434
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   435
     * @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
   436
     * @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
   437
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   438
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        ensureCurrentLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        // Paint tab area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        // If scrollable tabs are enabled, the tab area will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        // painted by the scrollable tab panel instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            int x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            int y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            int width = tabPane.getWidth() - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            int height = tabPane.getHeight() - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                width = calculateTabAreaWidth(tabPlacement, runCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                              maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                size = calculateTabAreaWidth(tabPlacement, runCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                             maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                x = x + width - size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                width = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                size = calculateTabAreaHeight(tabPlacement, runCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                              maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                y = y + height - size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                height = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                height = calculateTabAreaHeight(tabPlacement, runCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                                maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            tabAreaBounds.setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            if (g.getClipBounds().intersects(tabAreaBounds)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                paintTabArea(tabAreaContext, g, tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                         selectedIndex, tabAreaBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        // Paint content border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        paintContentBorder(tabContentContext, g, tabPlacement, selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
9667
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   491
    protected void paintTabArea(Graphics g, int tabPlacement,
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   492
                                int selectedIndex) {
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   493
        // This can be invoked from ScrollabeTabPanel
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   494
        Insets insets = tabPane.getInsets();
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   495
        int x = insets.left;
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   496
        int y = insets.top;
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   497
        int width = tabPane.getWidth() - insets.left - insets.right;
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   498
        int height = tabPane.getHeight() - insets.top - insets.bottom;
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   499
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   500
        paintTabArea(tabAreaContext, g, tabPlacement, selectedIndex,
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   501
                     new Rectangle(x, y, width, height));
b8c4fd770967 7034619: Scrollable Tabs don't appear with JDK7 Synth based LaF, different from Java 5/6
kizune
parents: 7007
diff changeset
   502
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   504
    private void paintTabArea(SynthContext ss, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                int tabPlacement, int selectedIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                Rectangle tabAreaBounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        Rectangle clipRect = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   509
        //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
   510
        //first update the selected tab's states, then set the state
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   511
        //for the tab area to match
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   512
        //otherwise, restore the tab area's state to ENABLED (which is the
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   513
        //only supported state otherwise).
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   514
        if (tabAreaStatesMatchSelectedTab && selectedIndex >= 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   515
            updateTabContext(selectedIndex, true, selectedTabIsPressed,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   516
                              (getRolloverTab() == selectedIndex),
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   517
                              (getFocusIndex() == selectedIndex));
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   518
            ss.setComponentState(tabContext.getComponentState());
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   519
        } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   520
            ss.setComponentState(SynthConstants.ENABLED);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   521
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   522
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        // Paint the tab area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        SynthLookAndFeel.updateSubregion(ss, g, tabAreaBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        ss.getPainter().paintTabbedPaneTabAreaBackground(ss, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
             tabAreaBounds.x, tabAreaBounds.y, tabAreaBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
             tabAreaBounds.height, tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        ss.getPainter().paintTabbedPaneTabAreaBorder(ss, g, tabAreaBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
             tabAreaBounds.y, tabAreaBounds.width, tabAreaBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
             tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        iconRect.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        textRect.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        // Paint tabRuns of tabs from back to front
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        for (int i = runCount - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            int start = tabRuns[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            int next = tabRuns[(i == runCount - 1)? 0 : i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            int end = (next != 0? next - 1: tabCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            for (int j = start; j <= end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                if (rects[j].intersects(clipRect) && selectedIndex != j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    paintTab(tabContext, g, tabPlacement, rects, j, iconRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                             textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (selectedIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (rects[selectedIndex].intersects(clipRect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                paintTab(tabContext, g, tabPlacement, rects, selectedIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                         iconRect, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   558
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   559
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   560
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   561
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    protected void setRolloverTab(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        int oldRolloverTab = getRolloverTab();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        super.setRolloverTab(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        Rectangle r = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   568
        if (oldRolloverTab != index && tabAreaStatesMatchSelectedTab) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   569
            //TODO need to just repaint the tab area!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   570
            tabPane.repaint();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   571
        } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   572
            if ((oldRolloverTab >= 0) && (oldRolloverTab < tabPane.getTabCount())) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   573
                r = getTabBounds(tabPane, oldRolloverTab);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   574
                if (r != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   575
                    tabPane.repaint(r);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   576
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   579
            if (index >= 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   580
                r = getTabBounds(tabPane, index);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   581
                if (r != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   582
                    tabPane.repaint(r);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   583
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   588
    private void paintTab(SynthContext ss, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                            int tabPlacement, Rectangle[] rects, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                            Rectangle iconRect, Rectangle textRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        Rectangle tabRect = rects[tabIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        boolean isSelected = selectedIndex == tabIndex;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   594
        updateTabContext(tabIndex, isSelected, isSelected && selectedTabIsPressed,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   595
                            (getRolloverTab() == tabIndex),
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   596
                            (getFocusIndex() == tabIndex));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        SynthLookAndFeel.updateSubregion(ss, g, tabRect);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   599
        int x = tabRect.x;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   600
        int y = tabRect.y;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   601
        int height = tabRect.height;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   602
        int width = tabRect.width;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   603
        int placement = tabPane.getTabPlacement();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   604
        if (extendTabsToBase && runCount > 1) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   605
            //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
   606
            //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
   607
            //tab placement, this will cause the bottom of each tab to be
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   608
            //painted even with the bottom of the selected tab. This is because
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   609
            //in each tab placement (TOP, LEFT, BOTTOM, RIGHT) the selected tab
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   610
            //is closest to the base.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   611
            if (selectedIndex >= 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   612
                Rectangle r = rects[selectedIndex];
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   613
                switch (placement) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   614
                    case TOP:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   615
                        int bottomY = r.y + r.height;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   616
                        height = bottomY - tabRect.y;
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 LEFT:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   619
                        int rightX = r.x + r.width;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   620
                        width = rightX - tabRect.x;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   621
                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   622
                    case BOTTOM:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   623
                        int topY = r.y;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   624
                        height = (tabRect.y + tabRect.height) - topY;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   625
                        y = topY;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   626
                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   627
                    case RIGHT:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   628
                        int leftX = r.x;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   629
                        width = (tabRect.x + tabRect.width) - leftX;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   630
                        x = leftX;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   631
                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   632
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   633
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   634
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   635
        tabContext.getPainter().paintTabbedPaneTabBackground(tabContext, g,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   636
                x, y, width, height, tabIndex, placement);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        tabContext.getPainter().paintTabbedPaneTabBorder(tabContext, g,
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   638
                x, y, width, height, tabIndex, placement);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (tabPane.getTabComponentAt(tabIndex) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            String title = tabPane.getTitleAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            Font font = ss.getStyle().getFont(ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            Icon icon = getIconForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            layoutLabel(ss, tabPlacement, metrics, tabIndex, title, icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    tabRect, iconRect, textRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            paintText(ss, g, tabPlacement, font, metrics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    tabIndex, title, textRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   656
    private void layoutLabel(SynthContext ss, int tabPlacement,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                               FontMetrics metrics, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                               String title, Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                               Rectangle tabRect, Rectangle iconRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                               Rectangle textRect, boolean isSelected ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            tabPane.putClientProperty("html", v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        ss.getStyle().getGraphicsUtils(ss).layoutText(ss, metrics, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                         icon, SwingUtilities.CENTER, SwingUtilities.CENTER,
2490
b460fb94812d 6815767: Bad parameter when calling another method in the class SynthTabbedPaneUI
peterz
parents: 2
diff changeset
   670
                         SwingUtilities.LEADING, SwingUtilities.CENTER,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                         tabRect, iconRect, textRect, textIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        tabPane.putClientProperty("html", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        iconRect.x += xNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        iconRect.y += yNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        textRect.x += xNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        textRect.y += yNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   683
    private void paintText(SynthContext ss,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                             Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                             Font font, FontMetrics metrics, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                             String title, Rectangle textRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                             boolean isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        g.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            // html
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            v.paint(g, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            // plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                                  textRect, mnemIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   705
    private void paintContentBorder(SynthContext ss, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                                      int tabPlacement, int selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        int width = tabPane.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        int height = tabPane.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        int x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        int y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        int w = width - insets.right - insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        int h = height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
              x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
              w -= (x - insets.left);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
              w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
              h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
              y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
              h -= (y - insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        SynthLookAndFeel.updateSubregion(ss, g, new Rectangle(x, y, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        ss.getPainter().paintTabbedPaneContentBackground(ss, g, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                                                           w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        ss.getPainter().paintTabbedPaneContentBorder(ss, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    private void ensureCurrentLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if (!tabPane.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            tabPane.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        /* If tabPane doesn't have a peer yet, the validate() call will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * silently fail.  We handle that by forcing a layout if tabPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         * is still invalid.  See bug 4237677.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        if (!tabPane.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            TabbedPaneLayout layout = (TabbedPaneLayout)tabPane.getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            layout.calculateLayoutInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   752
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   753
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   754
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   755
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    protected int calculateMaxTabHeight(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                                             tabContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        for(int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            result = Math.max(calculateTabHeight(tabPlacement, i, fontHeight), result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   768
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   769
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   770
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   771
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    protected int calculateTabWidth(int tabPlacement, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                                    FontMetrics metrics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        Icon icon = getIconForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        int width = tabInsets.left + tabInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        Component tabComponent = tabPane.getTabComponentAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        if (tabComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            width += tabComponent.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                width += icon.getIconWidth() + textIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                // html
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                width += (int) v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                // plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                String title = tabPane.getTitleAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                width += tabContext.getStyle().getGraphicsUtils(tabContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                        computeStringWidth(tabContext, metrics.getFont(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                                metrics, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   799
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   800
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   801
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   802
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    protected int calculateMaxTabWidth(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                                     tabContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        for(int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            result = Math.max(calculateTabWidth(tabPlacement, i, metrics),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                              result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   815
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   816
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   817
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   818
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    protected Insets getTabInsets(int tabPlacement, int tabIndex) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   820
        updateTabContext(tabIndex, false, false, false,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                          (getFocusIndex() == tabIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        return tabInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   825
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   826
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   827
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   828
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    protected FontMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        return getFontMetrics(tabContext.getStyle().getFont(tabContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   833
    private FontMetrics getFontMetrics(Font font) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        return tabPane.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    private void updateTabContext(int index, boolean selected,
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   838
                                  boolean isMouseDown, boolean isMouseOver, boolean hasFocus) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        int state = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        if (!tabPane.isEnabled() || !tabPane.isEnabledAt(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            state |= SynthConstants.DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                state |= SynthConstants.SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        else if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            state |= (SynthConstants.ENABLED | SynthConstants.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            if (isMouseOver && UIManager.getBoolean("TabbedPane.isTabRollover")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                state |= SynthConstants.MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        else if (isMouseOver) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            state |= (SynthConstants.ENABLED | SynthConstants.MOUSE_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            state = SynthLookAndFeel.getComponentState(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            state &= ~SynthConstants.FOCUSED; // don't use tabbedpane focus state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if (hasFocus && tabPane.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            state |= SynthConstants.FOCUSED; // individual tab has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   862
        if (isMouseDown) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   863
            state |= SynthConstants.PRESSED;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   864
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   865
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        tabContext.setComponentState(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   869
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 9667
diff changeset
   870
     * {@inheritDoc}
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   871
     *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   872
     * Overridden to create a TabbedPaneLayout subclass which takes into
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   873
     * account tabOverlap.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   874
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   875
    @Override
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   876
    protected LayoutManager createLayoutManager() {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   877
        if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   878
            return super.createLayoutManager();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   879
        } else { /* WRAP_TAB_LAYOUT */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   880
            return new TabbedPaneLayout() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   881
                @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   882
                public void calculateLayoutInfo() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   883
                    super.calculateLayoutInfo();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   884
                    //shift all the tabs, if necessary
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   885
                    if (tabOverlap != 0) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   886
                        int tabCount = tabPane.getTabCount();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   887
                        //left-to-right/right-to-left only affects layout
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   888
                        //when placement is TOP or BOTTOM
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   889
                        boolean ltr = tabPane.getComponentOrientation().isLeftToRight();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   890
                        for (int i = runCount - 1; i >= 0; i--) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   891
                            int start = tabRuns[i];
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   892
                            int next = tabRuns[(i == runCount - 1)? 0 : i + 1];
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   893
                            int end = (next != 0? next - 1: tabCount - 1);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   894
                            for (int j = start+1; j <= end; j++) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   895
                                // xshift and yshift represent the amount &
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   896
                                // direction to shift the tab in their
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   897
                                // respective axis.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   898
                                int xshift = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   899
                                int yshift = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   900
                                // configure xshift and y shift based on tab
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   901
                                // position and ltr/rtl
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   902
                                switch (tabPane.getTabPlacement()) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   903
                                    case JTabbedPane.TOP:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   904
                                    case JTabbedPane.BOTTOM:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   905
                                        xshift = ltr ? tabOverlap : -tabOverlap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   906
                                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   907
                                    case JTabbedPane.LEFT:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   908
                                    case JTabbedPane.RIGHT:
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   909
                                        yshift = tabOverlap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   910
                                        break;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   911
                                    default: //do nothing
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
                                rects[j].x += xshift;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   914
                                rects[j].y += yshift;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   915
                                rects[j].width += Math.abs(xshift);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   916
                                rects[j].height += Math.abs(yshift);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   917
                            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   918
                        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   919
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   920
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   921
            };
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   922
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   923
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2490
diff changeset
   924
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   925
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    private class SynthScrollableTabButton extends SynthArrowButton implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        public SynthScrollableTabButton(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            super(direction);
6500
129126795742 6915566: Closed swing tests failing with assert errors when run with -ea -esa
malenkov
parents: 5506
diff changeset
   930
            setName("TabbedPane.button");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
}