src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java
author pbansal
Mon, 25 Jun 2018 12:50:25 +0530
changeset 50837 86897f8a6598
parent 47216 71c04702a3d5
child 50917 55a43beaa529
permissions -rw-r--r--
8194873: right ALT key hotkeys no longer work in Swing components Reviewed-by: serb, psadhukhan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
     2
 * Copyright (c) 1997, 2015, 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: 2658
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: 2658
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: 2658
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
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.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 20151
diff changeset
    46
 * A Basic L&F implementation of TabbedPaneUI.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author Dave Moore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
// Instance variables initialized at installation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    59
    /** The tab pane */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected JTabbedPane tabPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    62
    /** Highlight color */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected Color highlight;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    64
    /** Light highlight color */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected Color lightHighlight;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    66
    /** Shadow color */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected Color shadow;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    68
    /** Dark shadow color */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected Color darkShadow;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    70
    /** Focus color */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected Color focus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private   Color selectedColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    74
    /** Text icon gap */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected int textIconGap;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    76
    /** Tab run overlay */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected int tabRunOverlay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    79
    /** Tab insets */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected Insets tabInsets;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    81
    /** Selected tab insets */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    protected Insets selectedTabPadInsets;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    83
    /** Tab area insets */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected Insets tabAreaInsets;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
    85
    /** Content border insets */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected Insets contentBorderInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private boolean tabsOverlapBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private boolean tabsOpaque = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private boolean contentOpaque = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected KeyStroke upKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    protected KeyStroke downKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    protected KeyStroke leftKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected KeyStroke rightKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
// Transient variables (recalculated each time TabbedPane is layed out)
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   134
    /** Tab runs */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    protected int tabRuns[] = new int[10];
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   136
    /** Run count */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected int runCount = 0;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   138
    /** Selected run */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected int selectedRun = -1;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   140
    /** Tab rects */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    protected Rectangle rects[] = new Rectangle[0];
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   142
    /** Maximum tab height */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    protected int maxTabHeight;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   144
    /** Maximum tab width */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected int maxTabWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
// Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   149
    /** Tab change listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    protected ChangeListener tabChangeListener;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   151
    /** Property change listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    protected PropertyChangeListener propertyChangeListener;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   153
    /** Mouse change listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected MouseListener mouseListener;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   155
    /** Focus change listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected FocusListener focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
// Private instance data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private Insets currentPadInsets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private Insets currentTabAreaInsets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private Component visibleComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    // PENDING(api): See comment for ContainerHandler
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   165
    private Vector<View> htmlViews;
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   166
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   167
    private Hashtable<Integer, Integer> mnemonicToIndexMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * InputMap used for mnemonics. Only non-null if the JTabbedPane has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * mnemonics associated with it. Lazily created in initMnemonics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private InputMap mnemonicInputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    // For use when tabLayoutPolicy = SCROLL_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private ScrollableTabSupport tabScroller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private TabContainer tabContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * A rectangle used for general layout calculations in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * to avoid constructing many new Rectangles on the fly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected transient Rectangle calcRect = new Rectangle(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Tab that has focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private int focusIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Combined listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Index of the tab the mouse is over.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private int rolloverTabIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * This is set to true when a component is added/removed from the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * pane and set to false when layout happens.  If true it indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * tabRuns is not valid and shouldn't be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private boolean isRunsDirty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private boolean calculatedBaseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    private int baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
// UI creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   213
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   214
     * Create a UI.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   215
     * @param c a component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   216
     * @return a UI
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   217
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return new BasicTabbedPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        map.put(new Actions(Actions.NEXT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        map.put(new Actions(Actions.PREVIOUS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        map.put(new Actions(Actions.RIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        map.put(new Actions(Actions.LEFT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        map.put(new Actions(Actions.UP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        map.put(new Actions(Actions.DOWN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        map.put(new Actions(Actions.PAGE_UP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        map.put(new Actions(Actions.PAGE_DOWN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        map.put(new Actions(Actions.REQUEST_FOCUS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        map.put(new Actions(Actions.REQUEST_FOCUS_FOR_VISIBLE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        map.put(new Actions(Actions.SET_SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        map.put(new Actions(Actions.SELECT_FOCUSED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        map.put(new Actions(Actions.SCROLL_FORWARD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        map.put(new Actions(Actions.SCROLL_BACKWARD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
// UI Installation/De-installation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        this.tabPane = (JTabbedPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        calculatedBaseline = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        rolloverTabIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        focusIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        c.setLayout(createLayoutManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        installComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        uninstallComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        c.setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        this.tabPane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Invoked by <code>installUI</code> to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * a layout manager object to manage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * the <code>JTabbedPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return a layout manager object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see TabbedPaneLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @see javax.swing.JTabbedPane#getTabLayoutPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    protected LayoutManager createLayoutManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return new TabbedPaneScrollLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else { /* WRAP_TAB_LAYOUT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return new TabbedPaneLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /* In an attempt to preserve backward compatibility for programs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * which have extended BasicTabbedPaneUI to do their own layout, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * UI uses the installed layoutManager (and not tabLayoutPolicy) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * determine if scrollTabLayout is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private boolean scrollableTabLayoutEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return (tabPane.getLayout() instanceof TabbedPaneScrollLayout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Creates and installs any required subcomponents for the JTabbedPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Invoked by installUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    protected void installComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if (tabScroller == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                tabScroller = new ScrollableTabSupport(tabPane.getTabPlacement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                tabPane.add(tabScroller.viewport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        installTabContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private void installTabContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         for (int i = 0; i < tabPane.getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
             Component tabComponent = tabPane.getTabComponentAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
             if (tabComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                 if(tabContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                     tabContainer = new TabContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                 tabContainer.add(tabComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         if(tabContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         if (scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
             tabScroller.tabPanel.add(tabContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
             tabPane.add(tabContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Creates and returns a JButton that will provide the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * with a way to scroll the tabs in a particular direction. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * returned JButton must be instance of UIResource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param direction One of the SwingConstants constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * SOUTH, NORTH, EAST or WEST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @return Widget for user to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @see javax.swing.JTabbedPane#setTabPlacement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see javax.swing.SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @throws IllegalArgumentException if direction is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *         NORTH, SOUTH, EAST or WEST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    protected JButton createScrollButton(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (direction != SOUTH && direction != NORTH && direction != EAST &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                  direction != WEST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            throw new IllegalArgumentException("Direction must be one of: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                               "SOUTH, NORTH, EAST or WEST");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return new ScrollableTabButton(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Removes any installed subcomponents from the JTabbedPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Invoked by uninstallUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    protected void uninstallComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        uninstallTabContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            tabPane.remove(tabScroller.viewport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            tabPane.remove(tabScroller.scrollForwardButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            tabPane.remove(tabScroller.scrollBackwardButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            tabScroller = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    private void uninstallTabContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         if(tabContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         // Remove all the tabComponents, making sure not to notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         // the tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         tabContainer.notifyTabbedPane = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         tabContainer.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         if(scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
             tabContainer.remove(tabScroller.croppedEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
             tabScroller.tabPanel.remove(tabContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
           tabPane.remove(tabContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         tabContainer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   383
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   384
     * Install the defaults.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   385
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        LookAndFeel.installColorsAndFont(tabPane, "TabbedPane.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                                    "TabbedPane.foreground", "TabbedPane.font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        highlight = UIManager.getColor("TabbedPane.light");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        lightHighlight = UIManager.getColor("TabbedPane.highlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        shadow = UIManager.getColor("TabbedPane.shadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        darkShadow = UIManager.getColor("TabbedPane.darkShadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        focus = UIManager.getColor("TabbedPane.focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        selectedColor = UIManager.getColor("TabbedPane.selected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        textIconGap = UIManager.getInt("TabbedPane.textIconGap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        tabInsets = UIManager.getInsets("TabbedPane.tabInsets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        selectedTabPadInsets = UIManager.getInsets("TabbedPane.selectedTabPadInsets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        tabsOverlapBorder = UIManager.getBoolean("TabbedPane.tabsOverlapBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        contentBorderInsets = UIManager.getInsets("TabbedPane.contentBorderInsets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        tabRunOverlay = UIManager.getInt("TabbedPane.tabRunOverlay");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        tabsOpaque = UIManager.getBoolean("TabbedPane.tabsOpaque");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        contentOpaque = UIManager.getBoolean("TabbedPane.contentOpaque");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        Object opaque = UIManager.get("TabbedPane.opaque");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (opaque == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            opaque = Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        LookAndFeel.installProperty(tabPane, "opaque", opaque);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   410
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   411
        // Fix for 6711145 BasicTabbedPanuUI should not throw a NPE if these
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   412
        // keys are missing. So we are setting them to there default values here
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   413
        // if the keys are missing.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   414
        if (tabInsets == null) tabInsets = new Insets(0,4,1,4);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   415
        if (selectedTabPadInsets == null) selectedTabPadInsets = new Insets(2,2,2,1);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   416
        if (tabAreaInsets == null) tabAreaInsets = new Insets(3,2,0,2);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   417
        if (contentBorderInsets == null) contentBorderInsets = new Insets(2,2,3,3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   420
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   421
     * Uninstall the defaults.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   422
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        highlight = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        lightHighlight = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        shadow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        darkShadow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        focus = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        tabInsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        selectedTabPadInsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        tabAreaInsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        contentBorderInsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   435
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   436
     * Install the listeners.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   437
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if ((propertyChangeListener = createPropertyChangeListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            tabPane.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if ((tabChangeListener = createChangeListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            tabPane.addChangeListener(tabChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if ((mouseListener = createMouseListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            tabPane.addMouseListener(mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        tabPane.addMouseMotionListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if ((focusListener = createFocusListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            tabPane.addFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        tabPane.addContainerListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (tabPane.getTabCount()>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            htmlViews = createHTMLVector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   458
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   459
     * Uninstall the listeners.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   460
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (mouseListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            tabPane.removeMouseListener(mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            mouseListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        tabPane.removeMouseMotionListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (focusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            tabPane.removeFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            focusListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        tabPane.removeContainerListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (htmlViews!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            htmlViews.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            htmlViews = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (tabChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            tabPane.removeChangeListener(tabChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            tabChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (propertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            tabPane.removePropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            propertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   488
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   489
     * Creates a mouse listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   490
     * @return a mouse listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   491
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    protected MouseListener createMouseListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   496
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   497
     * Creates a focus listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   498
     * @return a focus listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   499
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    protected FocusListener createFocusListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   504
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   505
     * Creates a change listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   506
     * @return a change listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   507
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    protected ChangeListener createChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   512
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   513
     * Creates a property change listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   514
     * @return a property change listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   515
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   527
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   528
     * Installs the keyboard actions.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   529
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        InputMap km = getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        SwingUtilities.replaceUIInputMap(tabPane, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                         km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        km = getInputMap(JComponent.WHEN_FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        LazyActionMap.installLazyActionMap(tabPane, BasicTabbedPaneUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                           "TabbedPane.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        updateMnemonics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            return (InputMap)DefaultLookup.get(tabPane, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                               "TabbedPane.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        else if (condition == JComponent.WHEN_FOCUSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            return (InputMap)DefaultLookup.get(tabPane, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                               "TabbedPane.focusInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   557
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   558
     * Uninstalls the keyboard actions.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   559
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    protected void uninstallKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        SwingUtilities.replaceUIActionMap(tabPane, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        SwingUtilities.replaceUIInputMap(tabPane, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                         null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                         null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        SwingUtilities.replaceUIInputMap(tabPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                         JComponent.WHEN_IN_FOCUSED_WINDOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                         null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        mnemonicToIndexMap = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        mnemonicInputMap = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Reloads the mnemonics. This should be invoked when a memonic changes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * when the title of a mnemonic changes, or when tabs are added/removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    private void updateMnemonics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        resetMnemonics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        for (int counter = tabPane.getTabCount() - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
             counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            int mnemonic = tabPane.getMnemonicAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            if (mnemonic > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                addMnemonic(counter, mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Resets the mnemonics bindings to an empty state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    private void resetMnemonics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if (mnemonicToIndexMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            mnemonicToIndexMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            mnemonicInputMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Adds the specified mnemonic at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    private void addMnemonic(int index, int mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (mnemonicToIndexMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            initMnemonics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11661
diff changeset
   607
        mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, BasicLookAndFeel.getFocusAcceleratorKeyMask()),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                             "setSelectedIndex");
50837
86897f8a6598 8194873: right ALT key hotkeys no longer work in Swing components
pbansal
parents: 47216
diff changeset
   609
        mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic,
86897f8a6598 8194873: right ALT key hotkeys no longer work in Swing components
pbansal
parents: 47216
diff changeset
   610
                SwingUtilities2.setAltGraphMask(
86897f8a6598 8194873: right ALT key hotkeys no longer work in Swing components
pbansal
parents: 47216
diff changeset
   611
                        BasicLookAndFeel.getFocusAcceleratorKeyMask())),
86897f8a6598 8194873: right ALT key hotkeys no longer work in Swing components
pbansal
parents: 47216
diff changeset
   612
                "setSelectedIndex");
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   613
        mnemonicToIndexMap.put(Integer.valueOf(mnemonic), Integer.valueOf(index));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Installs the state needed for mnemonics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    private void initMnemonics() {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   620
        mnemonicToIndexMap = new Hashtable<Integer, Integer>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        mnemonicInputMap = new ComponentInputMapUIResource(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                              JComponent.WHEN_IN_FOCUSED_WINDOW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        SwingUtilities.replaceUIInputMap(tabPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                              JComponent.WHEN_IN_FOCUSED_WINDOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                         mnemonicInputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Sets the tab the mouse is over by location. This is a cover method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * for <code>setRolloverTab(tabForCoordinate(x, y, false))</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    private void setRolloverTab(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        // NOTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        // This calls in with false otherwise it could trigger a validate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // which should NOT happen if the user is only dragging the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        // mouse around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        setRolloverTab(tabForCoordinate(tabPane, x, y, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Sets the tab the mouse is currently over to <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <code>index</code> will be -1 if the mouse is no longer over any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * tab. No checking is done to ensure the passed in index identifies a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * valid tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @param index Index of the tab the mouse is over.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    protected void setRolloverTab(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        rolloverTabIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Returns the tab the mouse is currently over, or {@code -1} if the mouse is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * longer over any tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @return the tab the mouse is currently over, or {@code -1} if the mouse is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * longer over any tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    protected int getRolloverTab() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        return rolloverTabIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        // Default to LayoutManager's minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        // Default to LayoutManager's maximumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        int baseline = calculateBaselineIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (baseline != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            int placement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            Insets tabAreaInsets = getTabAreaInsets(placement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            switch(placement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            case JTabbedPane.TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                baseline += insets.top + tabAreaInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                return baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            case JTabbedPane.BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                baseline = height - insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    tabAreaInsets.bottom - maxTabHeight + baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                return baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            case JTabbedPane.LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            case JTabbedPane.RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                baseline += insets.top + tabAreaInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                return baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        super.getBaselineResizeBehavior(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        switch(tabPane.getTabPlacement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        case JTabbedPane.LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        case JTabbedPane.RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        case JTabbedPane.TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        case JTabbedPane.BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            return Component.BaselineResizeBehavior.CONSTANT_DESCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return Component.BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * Returns the baseline for the specified tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * @param tab index of tab to get baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @exception IndexOutOfBoundsException if index is out of range
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 20151
diff changeset
   735
     *            (index &lt; 0 || index &gt;= tab count)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * @return baseline or a value &lt; 0 indicating there is no reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *                  baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    protected int getBaseline(int tab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if (tabPane.getTabComponentAt(tab) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            int offset = getBaselineOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            if (offset != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                // The offset is not applied to the tab component, and so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                // in general we can't get good alignment like with components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                // in the tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            Component c = tabPane.getTabComponentAt(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            Dimension pref = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            Insets tabInsets = getTabInsets(tabPane.getTabPlacement(), tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            int cellHeight = maxTabHeight - tabInsets.top - tabInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            return c.getBaseline(pref.width, pref.height) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    (cellHeight - pref.height) / 2 + tabInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            View view = getTextViewForTab(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                int viewHeight = (int)view.getPreferredSpan(View.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                int baseline = BasicHTML.getHTMLBaseline(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    view, (int)view.getPreferredSpan(View.X_AXIS), viewHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                if (baseline >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                    return maxTabHeight / 2 - viewHeight / 2 + baseline +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                        getBaselineOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        FontMetrics metrics = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        int fontBaseline = metrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        return maxTabHeight / 2 - fontHeight / 2 + fontBaseline +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                getBaselineOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * Returns the amount the baseline is offset by.  This is typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * the same as <code>getTabLabelShiftY</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @return amount to offset the baseline by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    protected int getBaselineOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        switch(tabPane.getTabPlacement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        case JTabbedPane.TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            if (tabPane.getTabCount() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        case JTabbedPane.BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            if (tabPane.getTabCount() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        default: // RIGHT|LEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            return (maxTabHeight % 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    private int calculateBaselineIfNecessary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if (!calculatedBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            calculatedBaseline = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            baseline = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            if (tabPane.getTabCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                calculateBaseline();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        return baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    private void calculateBaseline() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        maxTabHeight = calculateMaxTabHeight(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        baseline = getBaseline(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        if (isHorizontalTabPlacement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            for(int i = 1; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                if (getBaseline(i) != baseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                    baseline = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            // left/right, tabs may be different sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            FontMetrics fontMetrics = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            int fontHeight = fontMetrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            int height = calculateTabHeight(tabPlacement, 0, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            for(int i = 1; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                int newHeight = calculateTabHeight(tabPlacement, i,fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                if (height != newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    // assume different baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                    baseline = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
// UI Rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        ensureCurrentLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        // Paint content border and tab area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        if (tabsOverlapBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            paintContentBorder(g, tabPlacement, selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        // If scrollable tabs are enabled, the tab area will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        // painted by the scrollable tab panel instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            paintTabArea(g, tabPlacement, selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        if (!tabsOverlapBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            paintContentBorder(g, tabPlacement, selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * Paints the tabs in the tab area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * Invoked by paint().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * The graphics parameter must be a valid <code>Graphics</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * object.  Tab placement may be either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * The selected index must be a valid tabbed pane tab index (0 to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * tab count - 1, inclusive) or -1 if no tab is currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * The handling of invalid parameters is unspecified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @param g the graphics object to use for rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @param tabPlacement the placement for the tabs within the JTabbedPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @param selectedIndex the tab index of the selected component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        Rectangle iconRect = new Rectangle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                  textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        Rectangle clipRect = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        // Paint tabRuns of tabs from back to front
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        for (int i = runCount - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            int start = tabRuns[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            int next = tabRuns[(i == runCount - 1)? 0 : i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            int end = (next != 0? next - 1: tabCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            for (int j = start; j <= end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                if (j != selectedIndex && rects[j].intersects(clipRect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                    paintTab(g, tabPlacement, rects, j, iconRect, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        // Paint selected tab if its in the front run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        // since it may overlap other tabs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        if (selectedIndex >= 0 && rects[selectedIndex].intersects(clipRect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            paintTab(g, tabPlacement, rects, selectedIndex, iconRect, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   910
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   911
     * Paints a tab.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   912
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   913
     * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   914
     * @param rects rectangles
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   915
     * @param tabIndex the tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   916
     * @param iconRect the icon rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   917
     * @param textRect the text rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
   918
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    protected void paintTab(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                            Rectangle[] rects, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                            Rectangle iconRect, Rectangle textRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        Rectangle tabRect = rects[tabIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        boolean isSelected = selectedIndex == tabIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        if (tabsOpaque || tabPane.isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    tabRect.width, tabRect.height, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                       tabRect.width, tabRect.height, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        String title = tabPane.getTitleAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        Font font = tabPane.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        Icon icon = getIconForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        layoutLabel(tabPlacement, metrics, tabIndex, title, icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    tabRect, iconRect, textRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if (tabPane.getTabComponentAt(tabIndex) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            String clippedTitle = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            if (scrollableTabLayoutEnabled() && tabScroller.croppedEdge.isParamsSet() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                    tabScroller.croppedEdge.getTabIndex() == tabIndex && isHorizontalTabPlacement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                int availTextWidth = tabScroller.croppedEdge.getCropline() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                        (textRect.x - tabRect.x) - tabScroller.croppedEdge.getCroppedSideWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics, title, availTextWidth);
12279
a88bb2d86435 4310381: Text in multi-row/col JTabbedPane tabs can be truncated/clipped
rupashka
parents: 12047
diff changeset
   950
            } else if (!scrollableTabLayoutEnabled() && isHorizontalTabPlacement()) {
a88bb2d86435 4310381: Text in multi-row/col JTabbedPane tabs can be truncated/clipped
rupashka
parents: 12047
diff changeset
   951
                clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics, title, textRect.width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            paintText(g, tabPlacement, font, metrics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    tabIndex, clippedTitle, textRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        paintFocusIndicator(g, tabPlacement, rects, tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                  iconRect, textRect, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    private boolean isHorizontalTabPlacement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        return tabPane.getTabPlacement() == TOP || tabPane.getTabPlacement() == BOTTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    /* This method will create and return a polygon shape for the given tab rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * which has been cropped at the specified cropline with a torn edge visual.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * e.g. A "File" tab which has cropped been cropped just after the "i":
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     *             -------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     *             |  .....     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     *             |  .          |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *             |  ...  .    |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     *             |  .    .   |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     *             |  .    .    |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *             |  .    .     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     *             --------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * The x, y arrays below define the pattern used to create a "torn" edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * segment which is repeated to fill the edge of the tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * For tabs placed on TOP and BOTTOM, this righthand torn edge is created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * line segments which are defined by coordinates obtained by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * subtracting xCropLen[i] from (tab.x + tab.width) and adding yCroplen[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * to (tab.y).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * For tabs placed on LEFT or RIGHT, the bottom torn edge is created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * subtracting xCropLen[i] from (tab.y + tab.height) and adding yCropLen[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * to (tab.x).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    private static int xCropLen[] = {1,1,0,0,1,1,2,2};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    private static int yCropLen[] = {0,3,3,6,6,9,9,12};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    private static final int CROP_SEGMENT = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    private static Polygon createCroppedTabShape(int tabPlacement, Rectangle tabRect, int cropline) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   994
        int rlen;
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   995
        int start;
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   996
        int end;
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   997
        int ostart;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
              rlen = tabRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
              start = tabRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
              end = tabRect.x + tabRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
              ostart = tabRect.y + tabRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
             rlen = tabRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
             start = tabRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
             end = tabRect.y + tabRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
             ostart = tabRect.x + tabRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        int rcnt = rlen/CROP_SEGMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (rlen%CROP_SEGMENT > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            rcnt++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        int npts = 2 + (rcnt*8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        int xp[] = new int[npts];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        int yp[] = new int[npts];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        int pcnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        xp[pcnt] = ostart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        yp[pcnt++] = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        xp[pcnt] = ostart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        yp[pcnt++] = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        for(int i = 0; i < rcnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            for(int j = 0; j < xCropLen.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                xp[pcnt] = cropline - xCropLen[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                yp[pcnt] = start + (i*CROP_SEGMENT) + yCropLen[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                if (yp[pcnt] >= end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    yp[pcnt] = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    pcnt++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                pcnt++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        if (tabPlacement == JTabbedPane.TOP || tabPlacement == JTabbedPane.BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
           return new Polygon(xp, yp, pcnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        } else { // LEFT or RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
           return new Polygon(yp, xp, pcnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    /* If tabLayoutPolicy == SCROLL_TAB_LAYOUT, this method will paint an edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * indicating the tab is cropped in the viewport display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    private void paintCroppedTabEdge(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        int tabIndex = tabScroller.croppedEdge.getTabIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        int cropline = tabScroller.croppedEdge.getCropline();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        int x,y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        switch(tabPane.getTabPlacement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            x = rects[tabIndex].x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            y = cropline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            int xx = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            while(xx <= x+rects[tabIndex].width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                for (int i=0; i < xCropLen.length; i+=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                    g.drawLine(xx+yCropLen[i],y-xCropLen[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                               xx+yCropLen[i+1]-1,y-xCropLen[i+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                xx+=CROP_SEGMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            x = cropline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            y = rects[tabIndex].y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            int yy = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            while(yy <= y+rects[tabIndex].height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                for (int i=0; i < xCropLen.length; i+=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    g.drawLine(x-xCropLen[i],yy+yCropLen[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                               x-xCropLen[i+1],yy+yCropLen[i+1]-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                yy+=CROP_SEGMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1087
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1088
     * Laysout a label.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1089
     * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1090
     * @param metrics the font metric
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1091
     * @param tabIndex the tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1092
     * @param title the title
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1093
     * @param icon the icon
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1094
     * @param tabRect the tab rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1095
     * @param iconRect the icon rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1096
     * @param textRect the text rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1097
     * @param isSelected selection status
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1098
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    protected void layoutLabel(int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                               FontMetrics metrics, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                               String title, Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                               Rectangle tabRect, Rectangle iconRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                               Rectangle textRect, boolean isSelected ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            tabPane.putClientProperty("html", v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  1111
        SwingUtilities.layoutCompoundLabel(tabPane,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                                           metrics, title, icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                                           SwingUtilities.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                                           SwingUtilities.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                                           SwingUtilities.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                                           SwingUtilities.TRAILING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                                           tabRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                                           iconRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                                           textRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                                           textIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        tabPane.putClientProperty("html", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        iconRect.x += xNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        iconRect.y += yNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        textRect.x += xNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        textRect.y += yNudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1132
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1133
     * Paints an icon.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1134
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1135
     * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1136
     * @param tabIndex the tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1137
     * @param icon the icon
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1138
     * @param iconRect the icon rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1139
     * @param isSelected selection status
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1140
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    protected void paintIcon(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                             int tabIndex, Icon icon, Rectangle iconRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                             boolean isSelected ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        if (icon != null) {
47139
0cbe21f1eb04 8075918: The regression-swing case failed as the long Tab titles are not clipped with dots at the end with NimbusLookAndFeel
psadhukhan
parents: 32865
diff changeset
  1145
            // Clip the icon within iconRect bounds
0cbe21f1eb04 8075918: The regression-swing case failed as the long Tab titles are not clipped with dots at the end with NimbusLookAndFeel
psadhukhan
parents: 32865
diff changeset
  1146
            Shape oldClip = g.getClip();
0cbe21f1eb04 8075918: The regression-swing case failed as the long Tab titles are not clipped with dots at the end with NimbusLookAndFeel
psadhukhan
parents: 32865
diff changeset
  1147
            ((Graphics2D)g).clip(iconRect);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            icon.paintIcon(tabPane, g, iconRect.x, iconRect.y);
47139
0cbe21f1eb04 8075918: The regression-swing case failed as the long Tab titles are not clipped with dots at the end with NimbusLookAndFeel
psadhukhan
parents: 32865
diff changeset
  1149
            g.setClip(oldClip);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1153
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1154
     * Paints text.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1155
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1156
     * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1157
     * @param font the font
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1158
     * @param metrics the font metrics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1159
     * @param tabIndex the tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1160
     * @param title the title
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1161
     * @param textRect the text rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1162
     * @param isSelected selection status
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1163
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    protected void paintText(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                             Font font, FontMetrics metrics, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                             String title, Rectangle textRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                             boolean isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        g.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            // html
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            v.paint(g, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            // plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                Color fg = tabPane.getForegroundAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                if (isSelected && (fg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                    Color selectedFG = UIManager.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                                  "TabbedPane.selectedForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                    if (selectedFG != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                        fg = selectedFG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                g.setColor(fg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                             title, mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                             textRect.x, textRect.y + metrics.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            } else { // tab disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                             title, mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                             textRect.x, textRect.y + metrics.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                             title, mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                             textRect.x - 1, textRect.y + metrics.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1207
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1208
     * Returns the tab label shift x.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1209
     * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1210
     * @param tabIndex the tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1211
     * @param isSelected selection status
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1212
     * @return the tab label shift x
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1213
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        Rectangle tabRect = rects[tabIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        String propKey = (isSelected ? "selectedLabelShift" : "labelShift");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        int nudge = DefaultLookup.getInt(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                tabPane, this, "TabbedPane." + propKey, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        switch (tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                return nudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                return -nudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                return tabRect.width % 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1232
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1233
     * Returns the tab label shift y.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1234
     * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1235
     * @param tabIndex the tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1236
     * @param isSelected selection status
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1237
     * @return the tab label shift y
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1238
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        Rectangle tabRect = rects[tabIndex];
11661
b508c9f2009d 7010561: Tab text position with Synth based LaF is different to Java 5/6
rupashka
parents: 7668
diff changeset
  1241
        int nudge = (isSelected ? DefaultLookup.getInt(tabPane, this, "TabbedPane.selectedLabelShift", -1) :
b508c9f2009d 7010561: Tab text position with Synth based LaF is different to Java 5/6
rupashka
parents: 7668
diff changeset
  1242
                DefaultLookup.getInt(tabPane, this, "TabbedPane.labelShift", 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        switch (tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                return -nudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                return tabRect.height % 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                return nudge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1256
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1257
     * Paints the focus indicator.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1258
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1259
     * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1260
     * @param rects rectangles
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1261
     * @param tabIndex the tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1262
     * @param iconRect the icon rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1263
     * @param textRect the text rectangle
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1264
     * @param isSelected selection status
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1265
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    protected void paintFocusIndicator(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                                       Rectangle[] rects, int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                                       Rectangle iconRect, Rectangle textRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                                       boolean isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        Rectangle tabRect = rects[tabIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        if (tabPane.hasFocus() && isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            int x, y, w, h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            g.setColor(focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
              case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                  x = tabRect.x + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                  y = tabRect.y + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                  w = tabRect.width - 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                  h = tabRect.height - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
              case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                  x = tabRect.x + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                  y = tabRect.y + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                  w = tabRect.width - 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                  h = tabRect.height - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
              case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                  x = tabRect.x + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                  y = tabRect.y + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                  w = tabRect.width - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                  h = tabRect.height - 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
              case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                  x = tabRect.x + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                  y = tabRect.y + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                  w = tabRect.width - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                  h = tabRect.height - 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
      * this function draws the border around each tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
      * note that this function does now draw the background of the tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
      * that is done elsewhere
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1308
      *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1309
      * @param g             the graphics context in which to paint
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1310
      * @param tabPlacement  the placement (left, right, bottom, top) of the tab
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1311
      * @param tabIndex      the index of the tab with respect to other tabs
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1312
      * @param x             the x coordinate of tab
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1313
      * @param y             the y coordinate of tab
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1314
      * @param w             the width of the tab
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1315
      * @param h             the height of the tab
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1316
      * @param isSelected    a {@code boolean} which determines whether or not
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 23697
diff changeset
  1317
      * the tab is selected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    protected void paintTabBorder(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                                  int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                                  int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                                  boolean isSelected ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        g.setColor(lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        switch (tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
              g.drawLine(x+1, y+h-2, x+1, y+h-2); // bottom-left highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
              g.drawLine(x, y+2, x, y+h-3); // left highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
              g.drawLine(x+1, y+1, x+1, y+1); // top-left highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
              g.drawLine(x+2, y, x+w-1, y); // top highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
              g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
              g.drawLine(x+2, y+h-2, x+w-1, y+h-2); // bottom shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
              g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
              g.drawLine(x+2, y+h-1, x+w-1, y+h-1); // bottom dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
              g.drawLine(x, y, x+w-3, y); // top highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
              g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
              g.drawLine(x, y+h-2, x+w-3, y+h-2); // bottom shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
              g.drawLine(x+w-2, y+2, x+w-2, y+h-3); // right shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
              g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
              g.drawLine(x+w-2, y+1, x+w-2, y+1); // top-right dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
              g.drawLine(x+w-2, y+h-2, x+w-2, y+h-2); // bottom-right dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
              g.drawLine(x+w-1, y+2, x+w-1, y+h-3); // right dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
              g.drawLine(x, y+h-1, x+w-3, y+h-1); // bottom dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
              g.drawLine(x, y, x, y+h-3); // left highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
              g.drawLine(x+1, y+h-2, x+1, y+h-2); // bottom-left highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
              g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
              g.drawLine(x+2, y+h-2, x+w-3, y+h-2); // bottom shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
              g.drawLine(x+w-2, y, x+w-2, y+h-3); // right shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
              g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
              g.drawLine(x+2, y+h-1, x+w-3, y+h-1); // bottom dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
              g.drawLine(x+w-2, y+h-2, x+w-2, y+h-2); // bottom-right dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
              g.drawLine(x+w-1, y, x+w-1, y+h-3); // right dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
              g.drawLine(x, y+2, x, y+h-1); // left highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
              g.drawLine(x+1, y+1, x+1, y+1); // top-left highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
              g.drawLine(x+2, y, x+w-3, y); // top highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
              g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
              g.drawLine(x+w-2, y+2, x+w-2, y+h-1); // right shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
              g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
              g.drawLine(x+w-1, y+2, x+w-1, y+h-1); // right dark-shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
              g.drawLine(x+w-2, y+1, x+w-2, y+1); // top-right shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1379
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1380
     * Paints the tab background.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1381
     * @param g             the graphics context in which to paint
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1382
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1383
     * @param tabIndex      the index of the tab with respect to other tabs
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1384
     * @param x             the x coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1385
     * @param y             the y coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1386
     * @param w             the width of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1387
     * @param h             the height of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1388
     * @param isSelected    a {@code boolean} which determines whether or not
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1389
     * the tab is selected
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1390
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    protected void paintTabBackground(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                                      int tabIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                                      int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                                      boolean isSelected ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        g.setColor(!isSelected || selectedColor == null?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                   tabPane.getBackgroundAt(tabIndex) : selectedColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
              g.fillRect(x+1, y+1, w-1, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
              g.fillRect(x, y+1, w-2, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
              g.fillRect(x+1, y, w-3, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
              g.fillRect(x+1, y+1, w-3, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1413
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1414
     * Paints the content border.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1415
     * @param g             the graphics context in which to paint
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1416
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1417
     * @param selectedIndex the tab index of the selected component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1418
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        int width = tabPane.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        int height = tabPane.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        int x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        int y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        int w = width - insets.right - insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        int h = height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
              x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
              if (tabsOverlapBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                  x -= tabAreaInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
              w -= (x - insets.left);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
              w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
              if (tabsOverlapBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                  w += tabAreaInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
              h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
              if (tabsOverlapBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                  h += tabAreaInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
              y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
              if (tabsOverlapBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                  y -= tabAreaInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
              h -= (y - insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            if ( tabPane.getTabCount() > 0 && (contentOpaque || tabPane.isOpaque()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
            // Fill region behind content area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            Color color = UIManager.getColor("TabbedPane.contentAreaColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            if (color != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            else if ( selectedColor == null || selectedIndex == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                g.setColor(tabPane.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                g.setColor(selectedColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            g.fillRect(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1481
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1482
     * Paints the content border top edge.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1483
     * @param g             the graphics context in which to paint
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1484
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1485
     * @param selectedIndex the tab index of the selected component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1486
     * @param x             the x coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1487
     * @param y             the y coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1488
     * @param w             the width of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1489
     * @param h             the height of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1490
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                                         int selectedIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                                         int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        Rectangle selRect = selectedIndex < 0? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                               getTabBounds(selectedIndex, calcRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        g.setColor(lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        // Draw unbroken line if tabs are not on TOP, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        // selected tab is not in run adjacent to content, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        // selected tab is not visible (SCROLL_TAB_LAYOUT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        if (tabPlacement != TOP || selectedIndex < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            (selRect.y + selRect.height + 1 < y) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            (selRect.x < x || selRect.x > x + w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            g.drawLine(x, y, x+w-2, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            // Break line to show visual connection to selected tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            g.drawLine(x, y, selRect.x - 1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            if (selRect.x + selRect.width < x + w - 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                g.drawLine(selRect.x + selRect.width, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                           x+w-2, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                g.drawLine(x+w-2, y, x+w-2, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1520
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1521
     * Paints the content border left edge.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1522
     * @param g             the graphics context in which to paint
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1523
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1524
     * @param selectedIndex the tab index of the selected component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1525
     * @param x             the x coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1526
     * @param y             the y coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1527
     * @param w             the width of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1528
     * @param h             the height of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1529
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                                               int selectedIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        Rectangle selRect = selectedIndex < 0? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                               getTabBounds(selectedIndex, calcRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        g.setColor(lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        // Draw unbroken line if tabs are not on LEFT, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        // selected tab is not in run adjacent to content, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        // selected tab is not visible (SCROLL_TAB_LAYOUT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        if (tabPlacement != LEFT || selectedIndex < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            (selRect.x + selRect.width + 1 < x) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            (selRect.y < y || selRect.y > y + h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            g.drawLine(x, y, x, y+h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            // Break line to show visual connection to selected tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            g.drawLine(x, y, x, selRect.y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            if (selRect.y + selRect.height < y + h - 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                g.drawLine(x, selRect.y + selRect.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                           x, y+h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1556
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1557
     * Paints the content border bottom edge.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1558
     * @param g             the graphics context in which to paint
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1559
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1560
     * @param selectedIndex the tab index of the selected component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1561
     * @param x             the x coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1562
     * @param y             the y coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1563
     * @param w             the width of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1564
     * @param h             the height of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1565
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                                               int selectedIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        Rectangle selRect = selectedIndex < 0? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                               getTabBounds(selectedIndex, calcRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        // Draw unbroken line if tabs are not on BOTTOM, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        // selected tab is not in run adjacent to content, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        // selected tab is not visible (SCROLL_TAB_LAYOUT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        if (tabPlacement != BOTTOM || selectedIndex < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
             (selRect.y - 1 > h) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
             (selRect.x < x || selRect.x > x + w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            g.drawLine(x+1, y+h-2, x+w-2, y+h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
            g.drawLine(x, y+h-1, x+w-1, y+h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
            // Break line to show visual connection to selected tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            g.drawLine(x+1, y+h-2, selRect.x - 1, y+h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
            g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            g.drawLine(x, y+h-1, selRect.x - 1, y+h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            if (selRect.x + selRect.width < x + w - 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                g.drawLine(selRect.x + selRect.width, y+h-2, x+w-2, y+h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                g.drawLine(selRect.x + selRect.width, y+h-1, x+w-1, y+h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1599
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1600
     * Paints the content border right edge.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1601
     * @param g             the graphics context in which to paint
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1602
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1603
     * @param selectedIndex the tab index of the selected component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1604
     * @param x             the x coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1605
     * @param y             the y coordinate of tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1606
     * @param w             the width of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1607
     * @param h             the height of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1608
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                                               int selectedIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        Rectangle selRect = selectedIndex < 0? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                               getTabBounds(selectedIndex, calcRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        // Draw unbroken line if tabs are not on RIGHT, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        // selected tab is not in run adjacent to content, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        // selected tab is not visible (SCROLL_TAB_LAYOUT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        if (tabPlacement != RIGHT || selectedIndex < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
             (selRect.x - 1 > w) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
             (selRect.y < y || selRect.y > y + h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            g.drawLine(x+w-2, y+1, x+w-2, y+h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            g.drawLine(x+w-1, y, x+w-1, y+h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            // Break line to show visual connection to selected tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
            g.drawLine(x+w-2, y+1, x+w-2, selRect.y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            g.drawLine(x+w-1, y, x+w-1, selRect.y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            if (selRect.y + selRect.height < y + h - 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                g.drawLine(x+w-2, selRect.y + selRect.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                           x+w-2, y+h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                g.drawLine(x+w-1, selRect.y + selRect.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                           x+w-1, y+h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    private void ensureCurrentLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        if (!tabPane.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            tabPane.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        /* If tabPane doesn't have a peer yet, the validate() call will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
         * silently fail.  We handle that by forcing a layout if tabPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
         * is still invalid.  See bug 4237677.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        if (!tabPane.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            TabbedPaneLayout layout = (TabbedPaneLayout)tabPane.getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            layout.calculateLayoutInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
// TabbedPaneUI methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     * Returns the bounds of the specified tab index.  The bounds are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * with respect to the JTabbedPane's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    public Rectangle getTabBounds(JTabbedPane pane, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        ensureCurrentLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        Rectangle tabRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
        return getTabBounds(i, tabRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
    public int getTabRunCount(JTabbedPane pane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        ensureCurrentLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        return runCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     * Returns the tab index which intersects the specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     * in the JTabbedPane's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    public int tabForCoordinate(JTabbedPane pane, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        return tabForCoordinate(pane, x, y, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    private int tabForCoordinate(JTabbedPane pane, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                                 boolean validateIfNecessary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        if (validateIfNecessary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            ensureCurrentLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        if (isRunsDirty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            // We didn't recalculate the layout, runs and tabCount may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            // line up, bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        Point p = new Point(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        if (scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            translatePointToTabPanel(x, y, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            Rectangle viewRect = tabScroller.viewport.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
            if (!viewRect.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        for (int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            if (rects[i].contains(p.x, p.y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * Returns the bounds of the specified tab in the coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * of the JTabbedPane component.  This is required because the tab rects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * are by default defined in the coordinate space of the component where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * they are rendered, which could be the JTabbedPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * (for WRAP_TAB_LAYOUT) or a ScrollableTabPanel (SCROLL_TAB_LAYOUT).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * This method should be used whenever the tab rectangle must be relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * to the JTabbedPane itself and the result should be placed in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * designated Rectangle object (rather than instantiating and returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * a new Rectangle each time). The tab index parameter must be a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * tabbed pane tab index (0 to tab count - 1, inclusive).  The destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * rectangle parameter must be a valid <code>Rectangle</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * The handling of invalid parameters is unspecified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * @param tabIndex the index of the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * @param dest the rectangle where the result should be placed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * @return the resulting rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    protected Rectangle getTabBounds(int tabIndex, Rectangle dest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        dest.width = rects[tabIndex].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        dest.height = rects[tabIndex].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        if (scrollableTabLayoutEnabled()) { // SCROLL_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
            // Need to translate coordinates based on viewport location &
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            // view position
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            Point vpp = tabScroller.viewport.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            Point viewp = tabScroller.viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            dest.x = rects[tabIndex].x + vpp.x - viewp.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            dest.y = rects[tabIndex].y + vpp.y - viewp.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        } else { // WRAP_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            dest.x = rects[tabIndex].x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            dest.y = rects[tabIndex].y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        return dest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * Returns the index of the tab closest to the passed in location, note
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * that the returned tab may not contain the location x,y.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
    private int getClosestTab(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        int min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        int tabCount = Math.min(rects.length, tabPane.getTabCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        int max = tabCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        boolean useX = (tabPlacement == TOP || tabPlacement == BOTTOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        int want = (useX) ? x : y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        while (min != max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
            int current = (max + min) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
            int minLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            int maxLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            if (useX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                minLoc = rects[current].x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                maxLoc = minLoc + rects[current].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                minLoc = rects[current].y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                maxLoc = minLoc + rects[current].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
            if (want < minLoc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                max = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                if (min == max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                    return Math.max(0, current - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            else if (want >= maxLoc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                min = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                if (max - min <= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                    return Math.max(current + 1, tabCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                return current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        return min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     * Returns a point which is translated from the specified point in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     * JTabbedPane's coordinate space to the coordinate space of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * ScrollableTabPanel.  This is used for SCROLL_TAB_LAYOUT ONLY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    private Point translatePointToTabPanel(int srcx, int srcy, Point dest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
        Point vpp = tabScroller.viewport.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        Point viewp = tabScroller.viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
        dest.x = srcx - vpp.x + viewp.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        dest.y = srcy - vpp.y + viewp.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
        return dest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
// BasicTabbedPaneUI methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1810
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1811
     * Returns the visible component.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1812
     * @return the visible component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1813
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
    protected Component getVisibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        return visibleComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1818
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1819
     * Sets the visible component.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1820
     * @param component the component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1821
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
    protected void setVisibleComponent(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        if (visibleComponent != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                && visibleComponent != component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                && visibleComponent.getParent() == tabPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                && visibleComponent.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            visibleComponent.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        if (component != null && !component.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            component.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        visibleComponent = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1836
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1837
     * Assure the rectangles are created.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1838
     * @param tabCount the tab count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1839
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    protected void assureRectsCreated(int tabCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        int rectArrayLen = rects.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
        if (tabCount != rectArrayLen ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            Rectangle[] tempRectArray = new Rectangle[tabCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            System.arraycopy(rects, 0, tempRectArray, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                             Math.min(rectArrayLen, tabCount));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
            rects = tempRectArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
            for (int rectIndex = rectArrayLen; rectIndex < tabCount; rectIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                rects[rectIndex] = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1854
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1855
     * Expands the tab runs array.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1856
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
    protected void expandTabRunsArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
        int rectLen = tabRuns.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
        int[] newArray = new int[rectLen+10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
        System.arraycopy(tabRuns, 0, newArray, 0, runCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        tabRuns = newArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1864
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1865
     * Returns the run for a tab.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1866
     * @param tabCount the tab count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1867
     * @param tabIndex the tab index.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1868
     * @return the run for a tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1869
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
    protected int getRunForTab(int tabCount, int tabIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        for (int i = 0; i < runCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            int first = tabRuns[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
            int last = lastTabInRun(tabCount, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
            if (tabIndex >= first && tabIndex <= last) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1881
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1882
     * Returns the last tab in a run.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1883
     * @param tabCount the tab count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1884
     * @param run the run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1885
     * @return the last tab in a run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1886
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
    protected int lastTabInRun(int tabCount, int run) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
        if (runCount == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            return tabCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        int nextRun = (run == runCount - 1? 0 : run + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        if (tabRuns[nextRun] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            return tabCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        return tabRuns[nextRun]-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1898
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1899
     * Returns the tab run overlay.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1900
     * @param tabPlacement the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1901
     * @return the tab run overlay
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1902
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    protected int getTabRunOverlay(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
        return tabRunOverlay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1907
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1908
     * Returns the tab run indent.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1909
     * @param tabPlacement the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1910
     * @param run the tab run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1911
     * @return the tab run indent
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1912
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
    protected int getTabRunIndent(int tabPlacement, int run) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1917
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1918
     * Returns whether or not the tab run should be padded.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1919
     * @param tabPlacement the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1920
     * @param run the tab run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1921
     * @return whether or not the tab run should be padded
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1922
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
    protected boolean shouldPadTabRun(int tabPlacement, int run) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        return runCount > 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1927
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1928
     * Returns whether or not the tab run should be rotated.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1929
     * @param tabPlacement the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1930
     * @return whether or not the tab run should be rotated
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1931
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
    protected boolean shouldRotateTabRuns(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1936
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1937
     * Returns the icon for a tab.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1938
     * @param tabIndex the index of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1939
     * @return the icon for a tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1940
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
    protected Icon getIconForTab(int tabIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
        return (!tabPane.isEnabled() || !tabPane.isEnabledAt(tabIndex))?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                          tabPane.getDisabledIconAt(tabIndex) : tabPane.getIconAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * Returns the text View object required to render stylized text (HTML) for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * the specified tab or null if no specialized text rendering is needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * for this tab. This is provided to support html rendering inside tabs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * @param tabIndex the index of the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * @return the text view to render the tab's text or null if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     *         specialized rendering is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
    protected View getTextViewForTab(int tabIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        if (htmlViews != null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  1959
            return htmlViews.elementAt(tabIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1964
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1965
     * Calculates the tab height.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1966
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1967
     * @param tabIndex      the index of the tab with respect to other tabs
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1968
     * @param fontHeight    the font height
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1969
     * @return the tab height
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1970
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        int height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        Component c = tabPane.getTabComponentAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            height = c.getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                // html
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                height += (int) v.getPreferredSpan(View.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                // plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                height += fontHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            Icon icon = getIconForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                height = Math.max(height, icon.getIconHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        height += tabInsets.top + tabInsets.bottom + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1996
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1997
     * Calculates the maximum tab height.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1998
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  1999
     * @return the maximum tab height
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2000
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
    protected int calculateMaxTabHeight(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        FontMetrics metrics = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
        int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
        for(int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
            result = Math.max(calculateTabHeight(tabPlacement, i, fontHeight), result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2012
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2013
     * Calculates the tab width.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2014
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2015
     * @param tabIndex      the index of the tab with respect to other tabs
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2016
     * @param metrics       the font metrics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2017
     * @return the tab width
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2018
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
    protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        int width = tabInsets.left + tabInsets.right + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
        Component tabComponent = tabPane.getTabComponentAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        if (tabComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            width += tabComponent.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
            Icon icon = getIconForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                width += icon.getIconWidth() + textIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
            View v = getTextViewForTab(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                // html
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                width += (int) v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                // plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                String title = tabPane.getTitleAt(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
                width += SwingUtilities2.stringWidth(tabPane, metrics, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2043
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2044
     * Calculates the maximum tab width.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2045
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2046
     * @return the maximum tab width
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2047
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
    protected int calculateMaxTabWidth(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
        FontMetrics metrics = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
        for(int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2058
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2059
     * Calculates the tab area height.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2060
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2061
     * @param horizRunCount horizontal run count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2062
     * @param maxTabHeight maximum tab height
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2063
     * @return the tab area height
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2064
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
    protected int calculateTabAreaHeight(int tabPlacement, int horizRunCount, int maxTabHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
        Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
        int tabRunOverlay = getTabRunOverlay(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
        return (horizRunCount > 0?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                horizRunCount * (maxTabHeight-tabRunOverlay) + tabRunOverlay +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                tabAreaInsets.top + tabAreaInsets.bottom :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2074
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2075
     * Calculates the tab area width.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2076
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2077
     * @param vertRunCount vertical run count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2078
     * @param maxTabWidth maximum tab width
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2079
     * @return the tab area width
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2080
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
    protected int calculateTabAreaWidth(int tabPlacement, int vertRunCount, int maxTabWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
        int tabRunOverlay = getTabRunOverlay(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        return (vertRunCount > 0?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                vertRunCount * (maxTabWidth-tabRunOverlay) + tabRunOverlay +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                tabAreaInsets.left + tabAreaInsets.right :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2090
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2091
     * Returns the tab insets.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2092
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2093
     * @param tabIndex the tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2094
     * @return the tab insets
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2095
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
    protected Insets getTabInsets(int tabPlacement, int tabIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        return tabInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2100
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2101
     * Returns the selected tab pad insets.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2102
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2103
     * @return the selected tab pad insets
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2104
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
    protected Insets getSelectedTabPadInsets(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
        rotateInsets(selectedTabPadInsets, currentPadInsets, tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
        return currentPadInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2110
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2111
     * Returns the tab area insets.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2112
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2113
     * @return the pad area insets
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2114
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
    protected Insets getTabAreaInsets(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
        rotateInsets(tabAreaInsets, currentTabAreaInsets, tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        return currentTabAreaInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2120
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2121
     * Returns the content border insets.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2122
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2123
     * @return the content border insets
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2124
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
    protected Insets getContentBorderInsets(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        return contentBorderInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2129
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2130
     * Returns the font metrics.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2131
     * @return the font metrics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2132
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
    protected FontMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
        Font font = tabPane.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
        return tabPane.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
// Tab Navigation methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2141
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2142
     * Navigate the selected tab.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2143
     * @param direction the direction
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2144
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
    protected void navigateSelectedTab(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
        int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
        int current = DefaultLookup.getBoolean(tabPane, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                             "TabbedPane.selectionFollowsFocus", true) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                             tabPane.getSelectedIndex() : getFocusIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
        boolean leftToRight = BasicGraphicsUtils.isLeftToRight(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        // If we have no tabs then don't navigate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        if (tabCount <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
              switch(direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                 case NEXT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                     selectNextTab(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
                 case PREVIOUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
                     selectPreviousTab(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
                    selectPreviousTabInRun(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                    selectNextTabInRun(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                    offset = getTabRunOffset(tabPlacement, tabCount, current, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                    selectAdjacentRunTab(tabPlacement, current, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
                case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
                    offset = getTabRunOffset(tabPlacement, tabCount, current, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
                    selectAdjacentRunTab(tabPlacement, current, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
              switch(direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                case NEXT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
                    selectNextTab(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                case PREVIOUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
                    selectPreviousTab(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
                case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
                    offset = getTabRunOffset(tabPlacement, tabCount, current, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
                    selectAdjacentRunTab(tabPlacement, current, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
                    offset = getTabRunOffset(tabPlacement, tabCount, current, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                    selectAdjacentRunTab(tabPlacement, current, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
                case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                    if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                        selectNextTabInRun(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                        selectPreviousTabInRun(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                    if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                        selectPreviousTabInRun(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                        selectNextTabInRun(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2223
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2224
     * Select the next tab in the run.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2225
     * @param current the current tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2226
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    protected void selectNextTabInRun(int current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
        int tabIndex = getNextTabIndexInRun(tabCount, current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
        while(tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
            tabIndex = getNextTabIndexInRun(tabCount, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
        navigateTo(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2237
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2238
     * Select the previous tab in the run.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2239
     * @param current the current tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2240
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
    protected void selectPreviousTabInRun(int current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
        int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        int tabIndex = getPreviousTabIndexInRun(tabCount, current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        while(tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
            tabIndex = getPreviousTabIndexInRun(tabCount, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
        navigateTo(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2251
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2252
     * Select the next tab.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2253
     * @param current the current tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2254
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    protected void selectNextTab(int current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
        int tabIndex = getNextTabIndex(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
        while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            tabIndex = getNextTabIndex(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
        navigateTo(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2264
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2265
     * Select the previous tab.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2266
     * @param current the current tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2267
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
    protected void selectPreviousTab(int current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        int tabIndex = getPreviousTabIndex(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
            tabIndex = getPreviousTabIndex(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
        navigateTo(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2277
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2278
     * Selects an adjacent run of tabs.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2279
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2280
     * @param tabIndex      the index of the tab with respect to other tabs
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2281
     * @param offset        selection offset
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2282
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
    protected void selectAdjacentRunTab(int tabPlacement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                                        int tabIndex, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        if ( runCount < 2 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        int newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        Rectangle r = rects[tabIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
              newIndex = tabForCoordinate(tabPane, r.x + r.width/2 + offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                                       r.y + r.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
              newIndex = tabForCoordinate(tabPane, r.x + r.width/2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
                                       r.y + r.height/2 + offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        if (newIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            while (!tabPane.isEnabledAt(newIndex) && newIndex != tabIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                newIndex = getNextTabIndex(newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            navigateTo(newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    private void navigateTo(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
        if (DefaultLookup.getBoolean(tabPane, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
                             "TabbedPane.selectionFollowsFocus", true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
            tabPane.setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
            // Just move focus (not selection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            setFocusIndex(index, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
    void setFocusIndex(int index, boolean repaint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
        if (repaint && !isRunsDirty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
            repaintTab(focusIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
            focusIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
            repaintTab(focusIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
            focusIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
     * Repaints the specified tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    private void repaintTab(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        // If we're not valid that means we will shortly be validated and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
        // painted, which means we don't have to do anything here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
        if (!isRunsDirty && index >= 0 && index < tabPane.getTabCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
            tabPane.repaint(getTabBounds(tabPane, index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     * Makes sure the focusIndex is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    private void validateFocusIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        if (focusIndex >= tabPane.getTabCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
            setFocusIndex(tabPane.getSelectedIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     * Returns the index of the tab that has focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     * @return index of tab that has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
    protected int getFocusIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
        return focusIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2361
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2362
     * Returns the tab run offset.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2363
     * @param tabPlacement  the placement (left, right, bottom, top) of the tab
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2364
     * @param tabCount the tab count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2365
     * @param tabIndex      the index of the tab with respect to other tabs
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2366
     * @param forward forward or not
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2367
     * @return the tab run offset
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2368
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
    protected int getTabRunOffset(int tabPlacement, int tabCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
                                  int tabIndex, boolean forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        int run = getRunForTab(tabCount, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
        int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
          case LEFT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
              if (run == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                  offset = (forward?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                            -(calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth)-maxTabWidth) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
                            -maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
              } else if (run == runCount - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
                  offset = (forward?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
                            maxTabWidth :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
                            calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth)-maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
                  offset = (forward? maxTabWidth : -maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
          case RIGHT: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
              if (run == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
                  offset = (forward?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
                            maxTabWidth :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
                            calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth)-maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
              } else if (run == runCount - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
                  offset = (forward?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
                            -(calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth)-maxTabWidth) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
                            -maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
                  offset = (forward? maxTabWidth : -maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
          case BOTTOM: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
              if (run == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
                  offset = (forward?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                            maxTabHeight :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
                            calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight)-maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
              } else if (run == runCount - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
                  offset = (forward?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
                            -(calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight)-maxTabHeight) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
                            -maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
                  offset = (forward? maxTabHeight : -maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
          default: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
              if (run == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
                  offset = (forward?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                            -(calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight)-maxTabHeight) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                            -maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
              } else if (run == runCount - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
                  offset = (forward?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
                            maxTabHeight :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
                            calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight)-maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                  offset = (forward? maxTabHeight : -maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2435
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2436
     * Returns the previous tab index.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2437
     * @param base the base
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2438
     * @return the previous tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2439
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
    protected int getPreviousTabIndex(int base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
        int tabIndex = (base - 1 >= 0? base - 1 : tabPane.getTabCount() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        return (tabIndex >= 0? tabIndex : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2445
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2446
     * Returns the next tab index.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2447
     * @param base the base
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2448
     * @return the next tab index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2449
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
    protected int getNextTabIndex(int base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        return (base+1)%tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2454
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2455
     * Returns the next tab index in the run.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2456
     * @param tabCount the tab count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2457
     * @param base the base
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2458
     * @return the next tab index in the run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2459
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
    protected int getNextTabIndexInRun(int tabCount, int base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
        if (runCount < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
            return getNextTabIndex(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
        int currentRun = getRunForTab(tabCount, base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
        int next = getNextTabIndex(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        if (next == tabRuns[getNextTabRun(currentRun)]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
            return tabRuns[currentRun];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
        return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2472
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2473
     * Returns the previous tab index in the run.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2474
     * @param tabCount the tab count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2475
     * @param base the base
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2476
     * @return the previous tab index in the run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2477
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
    protected int getPreviousTabIndexInRun(int tabCount, int base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        if (runCount < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
            return getPreviousTabIndex(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
        int currentRun = getRunForTab(tabCount, base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        if (base == tabRuns[currentRun]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
            int previous = tabRuns[getNextTabRun(currentRun)]-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
            return (previous != -1? previous : tabCount-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        return getPreviousTabIndex(base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2490
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2491
     * Returns the previous tab run.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2492
     * @param baseRun the base run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2493
     * @return the previous tab run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2494
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
    protected int getPreviousTabRun(int baseRun) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        int runIndex = (baseRun - 1 >= 0? baseRun - 1 : runCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        return (runIndex >= 0? runIndex : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2500
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2501
     * Returns the next tab run.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2502
     * @param baseRun the base run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2503
     * @return the next tab run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2504
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
    protected int getNextTabRun(int baseRun) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
        return (baseRun+1)%runCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2509
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2510
     * Rotates the insets.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2511
     * @param topInsets the top insets
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2512
     * @param targetInsets the target insets
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2513
     * @param targetPlacement the target placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2514
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
    protected static void rotateInsets(Insets topInsets, Insets targetInsets, int targetPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
        switch(targetPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
              targetInsets.top = topInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
              targetInsets.left = topInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
              targetInsets.bottom = topInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
              targetInsets.right = topInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
          case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
              targetInsets.top = topInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
              targetInsets.left = topInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
              targetInsets.bottom = topInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
              targetInsets.right = topInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
              targetInsets.top = topInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
              targetInsets.left = topInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
              targetInsets.bottom = topInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
              targetInsets.right = topInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
          case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
              targetInsets.top = topInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
              targetInsets.left = topInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
              targetInsets.bottom = topInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
              targetInsets.right = topInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
    // REMIND(aim,7/29/98): This method should be made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
    // protected in the next release where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
    // API changes are allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
    boolean requestFocusForVisibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
        return SwingUtilities2.tabbedPaneChangeFocusTo(getVisibleComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
    private static class Actions extends UIAction {
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2553
        static final String NEXT = "navigateNext";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2554
        static final String PREVIOUS = "navigatePrevious";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2555
        static final String RIGHT = "navigateRight";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2556
        static final String LEFT = "navigateLeft";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2557
        static final String UP = "navigateUp";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2558
        static final String DOWN = "navigateDown";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2559
        static final String PAGE_UP = "navigatePageUp";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2560
        static final String PAGE_DOWN = "navigatePageDown";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2561
        static final String REQUEST_FOCUS = "requestFocus";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2562
        static final String REQUEST_FOCUS_FOR_VISIBLE =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
                                    "requestFocusForVisibleComponent";
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2564
        static final String SET_SELECTED = "setSelectedIndex";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2565
        static final String SELECT_FOCUSED = "selectTabWithFocus";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2566
        static final String SCROLL_FORWARD = "scrollTabsForwardAction";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30461
diff changeset
  2567
        static final String SCROLL_BACKWARD = "scrollTabsBackwardAction";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
        Actions(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
            JTabbedPane pane = (JTabbedPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
            BasicTabbedPaneUI ui = (BasicTabbedPaneUI)BasicLookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
                       getUIOfType(pane.getUI(), BasicTabbedPaneUI.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
            if (ui == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            if (key == NEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
                ui.navigateSelectedTab(SwingConstants.NEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
            else if (key == PREVIOUS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
                ui.navigateSelectedTab(SwingConstants.PREVIOUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
            else if (key == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
                ui.navigateSelectedTab(SwingConstants.EAST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
            else if (key == LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
                ui.navigateSelectedTab(SwingConstants.WEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            else if (key == UP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
                ui.navigateSelectedTab(SwingConstants.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
            else if (key == DOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
                ui.navigateSelectedTab(SwingConstants.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
            else if (key == PAGE_UP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
                int tabPlacement = pane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
                if (tabPlacement == TOP|| tabPlacement == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
                    ui.navigateSelectedTab(SwingConstants.WEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
                    ui.navigateSelectedTab(SwingConstants.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
            else if (key == PAGE_DOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
                int tabPlacement = pane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
                if (tabPlacement == TOP || tabPlacement == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
                    ui.navigateSelectedTab(SwingConstants.EAST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
                    ui.navigateSelectedTab(SwingConstants.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
            else if (key == REQUEST_FOCUS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
                pane.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
            else if (key == REQUEST_FOCUS_FOR_VISIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
                ui.requestFocusForVisibleComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
            else if (key == SET_SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
                String command = e.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
                if (command != null && command.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
                    int mnemonic = (int)e.getActionCommand().charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
                    if (mnemonic >= 'a' && mnemonic <='z') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
                        mnemonic  -= ('a' - 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
                    }
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  2630
                    Integer index = ui.mnemonicToIndexMap.get(Integer.valueOf(mnemonic));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
                    if (index != null && pane.isEnabledAt(index.intValue())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
                        pane.setSelectedIndex(index.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
            else if (key == SELECT_FOCUSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
                int focusIndex = ui.getFocusIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
                if (focusIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
                    pane.setSelectedIndex(focusIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
            else if (key == SCROLL_FORWARD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
                if (ui.scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
                    ui.tabScroller.scrollForward(pane.getTabPlacement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
            else if (key == SCROLL_BACKWARD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
                if (ui.scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
                    ui.tabScroller.scrollBackward(pane.getTabPlacement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
     * Instantiate it only within subclasses of BasicTabbedPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
    public class TabbedPaneLayout implements LayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
        public void addLayoutComponent(String name, Component comp) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
        public void removeLayoutComponent(Component comp) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
        public Dimension preferredLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
            return calculateSize(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
        public Dimension minimumLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
            return calculateSize(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2673
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2674
         * Returns the calculated size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2675
         * @param minimum use the minimum size or preferred size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2676
         * @return the calculated size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2677
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
        protected Dimension calculateSize(boolean minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
            int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
            Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
            Insets contentInsets = getContentBorderInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
            Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
            Dimension zeroSize = new Dimension(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
            int height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
            int width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
            int cWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
            int cHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
            // Determine minimum size required to display largest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
            // child in each dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
            for (int i = 0; i < tabPane.getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
                Component component = tabPane.getComponentAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
                if (component != null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  2696
                    Dimension size = minimum ? component.getMinimumSize() :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
                                component.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
                    if (size != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
                        cHeight = Math.max(size.height, cHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
                        cWidth = Math.max(size.width, cWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
            // Add content border insets to minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
            width += cWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
            height += cHeight;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  2708
            int tabExtent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            // Calculate how much space the tabs will need, based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
            // minimum size required to display largest child + content border
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
            switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
              case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
              case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
                  height = Math.max(height, calculateMaxTabHeight(tabPlacement));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
                  tabExtent = preferredTabAreaWidth(tabPlacement, height - tabAreaInsets.top - tabAreaInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
                  width += tabExtent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
              case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
              case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
                  width = Math.max(width, calculateMaxTabWidth(tabPlacement));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
                  tabExtent = preferredTabAreaHeight(tabPlacement, width - tabAreaInsets.left - tabAreaInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
                  height += tabExtent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
            return new Dimension(width + insets.left + insets.right + contentInsets.left + contentInsets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
                             height + insets.bottom + insets.top + contentInsets.top + contentInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2732
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2733
         * Returns the preferred tab area height.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2734
         * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2735
         * @param width the width
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2736
         * @return the preferred tab area height
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2737
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
        protected int preferredTabAreaHeight(int tabPlacement, int width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
            FontMetrics metrics = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
            int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
            int total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
            if (tabCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
                int rows = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
                int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
                int maxTabHeight = calculateMaxTabHeight(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
                for (int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
                    int tabWidth = calculateTabWidth(tabPlacement, i, metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
                    if (x != 0 && x + tabWidth > width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
                        rows++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
                        x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
                    x += tabWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
                total = calculateTabAreaHeight(tabPlacement, rows, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            return total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2762
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2763
         * Returns the preferred tab area width.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2764
         * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2765
         * @param height the height
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2766
         * @return the preferred tab area widty
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2767
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
        protected int preferredTabAreaWidth(int tabPlacement, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
            FontMetrics metrics = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
            int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            int total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
            if (tabCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
                int columns = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
                int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
                int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
                maxTabWidth = calculateMaxTabWidth(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
                for (int i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
                    int tabHeight = calculateTabHeight(tabPlacement, i, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
                    if (y != 0 && y + tabHeight > height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
                        columns++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
                        y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
                    y += tabHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
                total = calculateTabAreaWidth(tabPlacement, columns, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            return total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2793
        /** {@inheritDoc} */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 27266
diff changeset
  2794
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
        public void layoutContainer(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
            /* Some of the code in this method deals with changing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
            * visibility of components to hide and show the contents for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
            * selected tab. This is older code that has since been duplicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
            * in JTabbedPane.fireStateChanged(), so as to allow visibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
            * changes to happen sooner (see the note there). This code remains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
            * for backward compatibility as there are some cases, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
            * subclasses that don't fireStateChanged() where it may be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            * Any changes here need to be kept in synch with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            * JTabbedPane.fireStateChanged().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
            setRolloverTab(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
            Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
            Component visibleComponent = getVisibleComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            calculateLayoutInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
            Component selectedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
            if (selectedIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
                if (visibleComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
                    // The last tab was removed, so remove the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
                    setVisibleComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
                selectedComponent = tabPane.getComponentAt(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
            int cx, cy, cw, ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
            int totalTabWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
            int totalTabHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
            Insets contentInsets = getContentBorderInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
            boolean shouldChangeFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
            // In order to allow programs to use a single component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
            // as the display for multiple tabs, we will not change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
            // the visible compnent if the currently selected tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
            // has a null component.  This is a bit dicey, as we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
            // explicitly state we support this in the spec, but since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
            // programs are now depending on this, we're making it work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
            if(selectedComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
                if(selectedComponent != visibleComponent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
                        visibleComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
                    if(SwingUtilities.findFocusOwner(visibleComponent) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
                        shouldChangeFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
                setVisibleComponent(selectedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            Rectangle bounds = tabPane.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
            int numChildren = tabPane.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
            if(numChildren > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
                switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
                    case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
                        totalTabWidth = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
                        cx = insets.left + totalTabWidth + contentInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
                        cy = insets.top + contentInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
                    case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
                        totalTabWidth = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
                        cx = insets.left + contentInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
                        cy = insets.top + contentInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
                    case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
                        totalTabHeight = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
                        cx = insets.left + contentInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
                        cy = insets.top + contentInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
                    case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
                        totalTabHeight = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
                        cx = insets.left + contentInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
                        cy = insets.top + totalTabHeight + contentInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                cw = bounds.width - totalTabWidth -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                        insets.left - insets.right -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                        contentInsets.left - contentInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                ch = bounds.height - totalTabHeight -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
                        insets.top - insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
                        contentInsets.top - contentInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
                for(int i = 0; i < numChildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
                    Component child = tabPane.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
                    if(child == tabContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
                        int tabContainerWidth = totalTabWidth == 0 ? bounds.width :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
                                totalTabWidth + insets.left + insets.right +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
                                        contentInsets.left + contentInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
                        int tabContainerHeight = totalTabHeight == 0 ? bounds.height :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
                                totalTabHeight + insets.top + insets.bottom +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
                                        contentInsets.top + contentInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
                        int tabContainerX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
                        int tabContainerY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
                        if(tabPlacement == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
                            tabContainerY = bounds.height - tabContainerHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
                        } else if(tabPlacement == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
                            tabContainerX = bounds.width - tabContainerWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
                        child.setBounds(tabContainerX, tabContainerY, tabContainerWidth, tabContainerHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
                        child.setBounds(cx, cy, cw, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
            layoutTabComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
            if(shouldChangeFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
                if(!requestFocusForVisibleComponent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
                    tabPane.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2916
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2917
         * Calculates the layout info.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2918
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
        public void calculateLayoutInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
            int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
            assureRectsCreated(tabCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
            calculateTabRects(tabPane.getTabPlacement(), tabCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
            isRunsDirty = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
        private void layoutTabComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
            if (tabContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
            Rectangle rect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
            Point delta = new Point(-tabContainer.getX(), -tabContainer.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
            if (scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
                translatePointToTabPanel(0, 0, delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
            for (int i = 0; i < tabPane.getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
                Component c = tabPane.getTabComponentAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
                if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
                getTabBounds(i, rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
                Dimension preferredSize = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
                Insets insets = getTabInsets(tabPane.getTabPlacement(), i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
                int outerX = rect.x + insets.left + delta.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
                int outerY = rect.y + insets.top + delta.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
                int outerWidth = rect.width - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
                int outerHeight = rect.height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
                //centralize component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
                int x = outerX + (outerWidth - preferredSize.width) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
                int y = outerY + (outerHeight - preferredSize.height) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
                int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
                boolean isSeleceted = i == tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
                c.setBounds(x + getTabLabelShiftX(tabPlacement, i, isSeleceted),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
                            y + getTabLabelShiftY(tabPlacement, i, isSeleceted),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
                        preferredSize.width, preferredSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2958
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2959
         * Calculate the tab rectangles.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2960
         * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2961
         * @param tabCount the tab count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  2962
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
        protected void calculateTabRects(int tabPlacement, int tabCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
            FontMetrics metrics = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
            Dimension size = tabPane.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
            Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
            Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
            int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
            int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
            int tabRunOverlay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
            int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
            int x, y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
            int returnAt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
            boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
            boolean leftToRight = BasicGraphicsUtils.isLeftToRight(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            // Calculate bounds within which a tab run must fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
            switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
              case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
                  maxTabWidth = calculateMaxTabWidth(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
                  x = insets.left + tabAreaInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
                  y = insets.top + tabAreaInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                  returnAt = size.height - (insets.bottom + tabAreaInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
              case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                  maxTabWidth = calculateMaxTabWidth(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
                  x = size.width - insets.right - tabAreaInsets.right - maxTabWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
                  y = insets.top + tabAreaInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
                  returnAt = size.height - (insets.bottom + tabAreaInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
              case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
                  maxTabHeight = calculateMaxTabHeight(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
                  x = insets.left + tabAreaInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
                  y = size.height - insets.bottom - tabAreaInsets.bottom - maxTabHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
                  returnAt = size.width - (insets.right + tabAreaInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
              case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
                  maxTabHeight = calculateMaxTabHeight(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
                  x = insets.left + tabAreaInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
                  y = insets.top + tabAreaInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
                  returnAt = size.width - (insets.right + tabAreaInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
            tabRunOverlay = getTabRunOverlay(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
            runCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
            selectedRun = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
            if (tabCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
            // Run through tabs and partition them into runs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
            Rectangle rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
            for (i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
                rect = rects[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
                if (!verticalTabRuns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
                    // Tabs on TOP or BOTTOM....
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
                    if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
                        rect.x = rects[i-1].x + rects[i-1].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
                        tabRuns[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
                        runCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
                        maxTabWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
                        rect.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
                    rect.width = calculateTabWidth(tabPlacement, i, metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
                    maxTabWidth = Math.max(maxTabWidth, rect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
                    // Never move a TAB down a run if it is in the first column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
                    // Even if there isn't enough room, moving it to a fresh
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
                    // line won't help.
20151
6f98c259939c 7024235: Nimbus L&F: wrong "packing" of a frame containing tabbed pane
malenkov
parents: 20108
diff changeset
  3038
                    if (rect.x != x && rect.x + rect.width > returnAt) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
                        if (runCount > tabRuns.length - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
                            expandTabRunsArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
                        tabRuns[runCount] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
                        runCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
                        rect.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
                    // Initialize y position in case there's just one run
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
                    rect.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
                    rect.height = maxTabHeight/* - 2*/;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
                    // Tabs on LEFT or RIGHT...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
                    if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
                        rect.y = rects[i-1].y + rects[i-1].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
                        tabRuns[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
                        runCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
                        maxTabHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
                        rect.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
                    rect.height = calculateTabHeight(tabPlacement, i, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
                    maxTabHeight = Math.max(maxTabHeight, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
                    // Never move a TAB over a run if it is in the first run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
                    // Even if there isn't enough room, moving it to a fresh
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
                    // column won't help.
20151
6f98c259939c 7024235: Nimbus L&F: wrong "packing" of a frame containing tabbed pane
malenkov
parents: 20108
diff changeset
  3066
                    if (rect.y != y && rect.y + rect.height > returnAt) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
                        if (runCount > tabRuns.length - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
                            expandTabRunsArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
                        tabRuns[runCount] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
                        runCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
                        rect.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
                    // Initialize x position in case there's just one column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
                    rect.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
                    rect.width = maxTabWidth/* - 2*/;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
                if (i == selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
                    selectedRun = runCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
            if (runCount > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
                // Re-distribute tabs in case last run has leftover space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
                normalizeTabRuns(tabPlacement, tabCount, verticalTabRuns? y : x, returnAt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
                selectedRun = getRunForTab(tabCount, selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
                // Rotate run array so that selected run is first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
                if (shouldRotateTabRuns(tabPlacement)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
                    rotateTabRuns(tabPlacement, selectedRun);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
            // Step through runs from back to front to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
            // tab y locations and to pad runs appropriately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
            for (i = runCount - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
                int start = tabRuns[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
                int next = tabRuns[i == (runCount - 1)? 0 : i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
                int end = (next != 0? next - 1 : tabCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
                if (!verticalTabRuns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
                    for (j = start; j <= end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
                        rect = rects[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
                        rect.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
                        rect.x += getTabRunIndent(tabPlacement, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
                    if (shouldPadTabRun(tabPlacement, i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
                        padTabRun(tabPlacement, start, end, returnAt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
                    if (tabPlacement == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
                        y -= (maxTabHeight - tabRunOverlay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
                        y += (maxTabHeight - tabRunOverlay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
                    for (j = start; j <= end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
                        rect = rects[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
                        rect.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
                        rect.y += getTabRunIndent(tabPlacement, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
                    if (shouldPadTabRun(tabPlacement, i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
                        padTabRun(tabPlacement, start, end, returnAt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
                    if (tabPlacement == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
                        x -= (maxTabWidth - tabRunOverlay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
                        x += (maxTabWidth - tabRunOverlay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
            // Pad the selected tab so that it appears raised in front
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
            padSelectedTab(tabPlacement, selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
            // if right to left and tab placement on the top or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
            // the bottom, flip x positions and adjust by widths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
            if (!leftToRight && !verticalTabRuns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
                int rightMargin = size.width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
                                  - (insets.right + tabAreaInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
                for (i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
                    rects[i].x = rightMargin - rects[i].x - rects[i].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3148
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3149
         * Rotates the run-index array so that the selected run is run[0].
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3150
         * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3151
         * @param selectedRun the selected run
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3152
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
        protected void rotateTabRuns(int tabPlacement, int selectedRun) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
            for (int i = 0; i < selectedRun; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
                int save = tabRuns[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
                for (int j = 1; j < runCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
                    tabRuns[j - 1] = tabRuns[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
                tabRuns[runCount-1] = save;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3163
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3164
         * Normalizes the tab runs.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3165
         * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3166
         * @param tabCount the tab count
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3167
         * @param start the start
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3168
         * @param max the max
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3169
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
        protected void normalizeTabRuns(int tabPlacement, int tabCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
                                     int start, int max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
            boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
            int run = runCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
            boolean keepAdjusting = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
            double weight = 1.25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
            // At this point the tab runs are packed to fit as many
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
            // tabs as possible, which can leave the last run with a lot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
            // of extra space (resulting in very fat tabs on the last run).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
            // So we'll attempt to distribute this extra space more evenly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
            // across the runs in order to make the runs look more consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
            // Starting with the last run, determine whether the last tab in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
            // the previous run would fit (generously) in this run; if so,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
            // move tab to current run and shift tabs accordingly.  Cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
            // through remaining runs using the same algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
            while (keepAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
                int last = lastTabInRun(tabCount, run);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
                int prevLast = lastTabInRun(tabCount, run-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
                int end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
                int prevLastLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
                if (!verticalTabRuns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
                    end = rects[last].x + rects[last].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
                    prevLastLen = (int)(maxTabWidth*weight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
                    end = rects[last].y + rects[last].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
                    prevLastLen = (int)(maxTabHeight*weight*2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
                // Check if the run has enough extra space to fit the last tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
                // from the previous row...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
                if (max - end > prevLastLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
                    // Insert tab from previous row and shift rest over
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
                    tabRuns[run] = prevLast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
                    if (!verticalTabRuns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
                        rects[prevLast].x = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
                        rects[prevLast].y = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
                    for (int i = prevLast+1; i <= last; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
                        if (!verticalTabRuns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
                            rects[i].x = rects[i-1].x + rects[i-1].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
                            rects[i].y = rects[i-1].y + rects[i-1].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
                } else if (run == runCount - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
                    // no more room left in last run, so we're done!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
                    keepAdjusting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
                if (run - 1 > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
                    // check previous run next...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
                    run -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
                    // check last run again...but require a higher ratio
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
                    // of extraspace-to-tabsize because we don't want to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
                    // end up with too many tabs on the last run!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
                    run = runCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
                    weight += .25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3238
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3239
         * Pads the tab run.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3240
         * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3241
         * @param start the start
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3242
         * @param end the end
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3243
         * @param max the max
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3244
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
        protected void padTabRun(int tabPlacement, int start, int end, int max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
            Rectangle lastRect = rects[end];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
            if (tabPlacement == TOP || tabPlacement == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
                int runWidth = (lastRect.x + lastRect.width) - rects[start].x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
                int deltaWidth = max - (lastRect.x + lastRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
                float factor = (float)deltaWidth / (float)runWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
                for (int j = start; j <= end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
                    Rectangle pastRect = rects[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
                    if (j > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
                        pastRect.x = rects[j-1].x + rects[j-1].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
                    pastRect.width += Math.round((float)pastRect.width * factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
                lastRect.width = max - lastRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
                int runHeight = (lastRect.y + lastRect.height) - rects[start].y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
                int deltaHeight = max - (lastRect.y + lastRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
                float factor = (float)deltaHeight / (float)runHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
                for (int j = start; j <= end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
                    Rectangle pastRect = rects[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
                    if (j > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
                        pastRect.y = rects[j-1].y + rects[j-1].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                    pastRect.height += Math.round((float)pastRect.height * factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
                lastRect.height = max - lastRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3276
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3277
         * Pads selected tab.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3278
         * @param tabPlacement the tab placement
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3279
         * @param selectedIndex the selected index
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28231
diff changeset
  3280
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
        protected void padSelectedTab(int tabPlacement, int selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
            if (selectedIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
                Rectangle selRect = rects[selectedIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
                Insets padInsets = getSelectedTabPadInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
                selRect.x -= padInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
                selRect.width += (padInsets.left + padInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
                selRect.y -= padInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
                selRect.height += (padInsets.top + padInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
                if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
                    // do not expand selected tab more then necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
                    Dimension size = tabPane.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
                    Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
                    if ((tabPlacement == LEFT) || (tabPlacement == RIGHT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
                        int top = insets.top - selRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
                        if (top > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
                            selRect.y += top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
                            selRect.height -= top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
                        int bottom = (selRect.y + selRect.height) + insets.bottom - size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
                        if (bottom > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
                            selRect.height -= bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
                        int left = insets.left - selRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
                        if (left > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
                            selRect.x += left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
                            selRect.width -= left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
                        int right = (selRect.x + selRect.width) + insets.right - size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
                        if (right > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
                            selRect.width -= right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
    private class TabbedPaneScrollLayout extends TabbedPaneLayout {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
        protected int preferredTabAreaHeight(int tabPlacement, int width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
            return calculateMaxTabHeight(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
        protected int preferredTabAreaWidth(int tabPlacement, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
            return calculateMaxTabWidth(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 27266
diff changeset
  3332
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
        public void layoutContainer(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
            /* Some of the code in this method deals with changing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
             * visibility of components to hide and show the contents for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
             * selected tab. This is older code that has since been duplicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
             * in JTabbedPane.fireStateChanged(), so as to allow visibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
             * changes to happen sooner (see the note there). This code remains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
             * for backward compatibility as there are some cases, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
             * subclasses that don't fireStateChanged() where it may be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
             * Any changes here need to be kept in synch with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
             * JTabbedPane.fireStateChanged().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
            setRolloverTab(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
            int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
            int tabCount = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
            Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
            int selectedIndex = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
            Component visibleComponent = getVisibleComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
            calculateLayoutInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
            Component selectedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
            if (selectedIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
                if (visibleComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
                    // The last tab was removed, so remove the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
                    setVisibleComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
                selectedComponent = tabPane.getComponentAt(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
            if (tabPane.getTabCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
                tabScroller.croppedEdge.resetParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
                tabScroller.scrollForwardButton.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
                tabScroller.scrollBackwardButton.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
            boolean shouldChangeFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
            // In order to allow programs to use a single component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
            // as the display for multiple tabs, we will not change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
            // the visible compnent if the currently selected tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
            // has a null component.  This is a bit dicey, as we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
            // explicitly state we support this in the spec, but since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
            // programs are now depending on this, we're making it work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
            if(selectedComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
                if(selectedComponent != visibleComponent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
                        visibleComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                    if(SwingUtilities.findFocusOwner(visibleComponent) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
                        shouldChangeFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
                setVisibleComponent(selectedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
            int tx, ty, tw, th; // tab area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
            int cx, cy, cw, ch; // content area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
            Insets contentInsets = getContentBorderInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
            Rectangle bounds = tabPane.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
            int numChildren = tabPane.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
            if(numChildren > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
                switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
                    case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
                        // calculate tab area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
                        tw = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
                        th = bounds.height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
                        tx = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
                        ty = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
                        // calculate content area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                        cx = tx + tw + contentInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                        cy = ty + contentInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
                        cw = bounds.width - insets.left - insets.right - tw -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
                                contentInsets.left - contentInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
                        ch = bounds.height - insets.top - insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                                contentInsets.top - contentInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                    case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                        // calculate tab area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
                        tw = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
                        th = bounds.height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
                        tx = bounds.width - insets.right - tw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
                        ty = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
                        // calculate content area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
                        cx = insets.left + contentInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
                        cy = insets.top + contentInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
                        cw = bounds.width - insets.left - insets.right - tw -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
                                contentInsets.left - contentInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
                        ch = bounds.height - insets.top - insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
                                contentInsets.top - contentInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
                    case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
                        // calculate tab area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
                        tw = bounds.width - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
                        th = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
                        tx = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
                        ty = bounds.height - insets.bottom - th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
                        // calculate content area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
                        cx = insets.left + contentInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
                        cy = insets.top + contentInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
                        cw = bounds.width - insets.left - insets.right -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
                                contentInsets.left - contentInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
                        ch = bounds.height - insets.top - insets.bottom - th -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
                                contentInsets.top - contentInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
                    case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
                        // calculate tab area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
                        tw = bounds.width - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
                        th = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
                        tx = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
                        ty = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
                        // calculate content area bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
                        cx = tx + contentInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
                        cy = ty + th + contentInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
                        cw = bounds.width - insets.left - insets.right -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
                                contentInsets.left - contentInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
                        ch = bounds.height - insets.top - insets.bottom - th -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
                                contentInsets.top - contentInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
                for(int i = 0; i < numChildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
                    Component child = tabPane.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
                    if(tabScroller != null && child == tabScroller.viewport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
                        JViewport viewport = (JViewport) child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
                        Rectangle viewRect = viewport.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
                        int vw = tw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
                        int vh = th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
                        Dimension butSize = tabScroller.scrollForwardButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
                        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
                            case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
                            case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
                                int totalTabHeight = rects[tabCount - 1].y + rects[tabCount - 1].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
                                if(totalTabHeight > th) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
                                    // Allow space for scrollbuttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
                                    vh = (th > 2 * butSize.height) ? th - 2 * butSize.height : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
                                    if(totalTabHeight - viewRect.y <= vh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
                                        // Scrolled to the end, so ensure the viewport size is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
                                        // such that the scroll offset aligns with a tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
                                        vh = totalTabHeight - viewRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
                            case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
                            case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
                            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
                                int totalTabWidth = rects[tabCount - 1].x + rects[tabCount - 1].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
                                if(totalTabWidth > tw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
                                    // Need to allow space for scrollbuttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
                                    vw = (tw > 2 * butSize.width) ? tw - 2 * butSize.width : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
                                    if(totalTabWidth - viewRect.x <= vw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
                                        // Scrolled to the end, so ensure the viewport size is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
                                        // such that the scroll offset aligns with a tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
                                        vw = totalTabWidth - viewRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
                        child.setBounds(tx, ty, vw, vh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
                    } else if(tabScroller != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
                            (child == tabScroller.scrollForwardButton ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
                            child == tabScroller.scrollBackwardButton)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
                        Component scrollbutton = child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
                        Dimension bsize = scrollbutton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
                        int bx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
                        int by = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
                        int bw = bsize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
                        int bh = bsize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
                        boolean visible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
                        switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
                            case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
                            case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
                                int totalTabHeight = rects[tabCount - 1].y + rects[tabCount - 1].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
                                if(totalTabHeight > th) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
                                    visible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
                                    bx = (tabPlacement == LEFT ? tx + tw - bsize.width : tx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
                                    by = (child == tabScroller.scrollForwardButton) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
                                            bounds.height - insets.bottom - bsize.height :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
                                            bounds.height - insets.bottom - 2 * bsize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
                            case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
                            case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
                            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
                                int totalTabWidth = rects[tabCount - 1].x + rects[tabCount - 1].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
                                if(totalTabWidth > tw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
                                    visible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
                                    bx = (child == tabScroller.scrollForwardButton) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
                                            bounds.width - insets.left - bsize.width :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
                                            bounds.width - insets.left - 2 * bsize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
                                    by = (tabPlacement == TOP ? ty + th - bsize.height : ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
                        child.setVisible(visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
                        if(visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
                            child.setBounds(bx, by, bw, bh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
                        // All content children...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
                        child.setBounds(cx, cy, cw, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
                super.layoutTabComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
                layoutCroppedEdge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
                if(shouldChangeFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
                    if(!requestFocusForVisibleComponent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
                        tabPane.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
        private void layoutCroppedEdge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
            tabScroller.croppedEdge.resetParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
            Rectangle viewRect = tabScroller.viewport.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
            int cropline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
            for (int i = 0; i < rects.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
                Rectangle tabRect = rects[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
                switch (tabPane.getTabPlacement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
                    case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
                    case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
                        cropline = viewRect.y + viewRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
                        if ((tabRect.y < cropline) && (tabRect.y + tabRect.height > cropline)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
                            tabScroller.croppedEdge.setParams(i, cropline - tabRect.y - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
                                    -currentTabAreaInsets.left,  0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
                    case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
                    case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
                        cropline = viewRect.x + viewRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
                        if ((tabRect.x < cropline - 1) && (tabRect.x + tabRect.width > cropline)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
                            tabScroller.croppedEdge.setParams(i, cropline - tabRect.x - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
                                    0, -currentTabAreaInsets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
        protected void calculateTabRects(int tabPlacement, int tabCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
            FontMetrics metrics = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
            Dimension size = tabPane.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
            Insets insets = tabPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
            Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
            int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
            int selectedIndex = tabPane.getSelectedIndex();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  3590
            int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
            boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
            boolean leftToRight = BasicGraphicsUtils.isLeftToRight(tabPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
            int x = tabAreaInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
            int y = tabAreaInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
            int totalWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
            int totalHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
            // Calculate bounds within which a tab run must fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
            switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
              case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
              case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
                  maxTabWidth = calculateMaxTabWidth(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
              case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
              case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
                  maxTabHeight = calculateMaxTabHeight(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
            runCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
            selectedRun = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
            if (tabCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
            selectedRun = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
            runCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
            // Run through tabs and lay them out in a single run
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
            Rectangle rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
            for (i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
                rect = rects[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
                if (!verticalTabRuns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
                    // Tabs on TOP or BOTTOM....
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
                    if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
                        rect.x = rects[i-1].x + rects[i-1].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
                        tabRuns[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
                        maxTabWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
                        totalHeight += maxTabHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
                        rect.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
                    rect.width = calculateTabWidth(tabPlacement, i, metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
                    totalWidth = rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
                    maxTabWidth = Math.max(maxTabWidth, rect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
                    rect.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
                    rect.height = maxTabHeight/* - 2*/;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
                    // Tabs on LEFT or RIGHT...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
                    if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
                        rect.y = rects[i-1].y + rects[i-1].height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
                        tabRuns[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
                        maxTabHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
                        totalWidth = maxTabWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
                        rect.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
                    rect.height = calculateTabHeight(tabPlacement, i, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
                    totalHeight = rect.y + rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
                    maxTabHeight = Math.max(maxTabHeight, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
                    rect.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
                    rect.width = maxTabWidth/* - 2*/;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
            if (tabsOverlapBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
                // Pad the selected tab so that it appears raised in front
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
                padSelectedTab(tabPlacement, selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
            // if right to left and tab placement on the top or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
            // the bottom, flip x positions and adjust by widths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
            if (!leftToRight && !verticalTabRuns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
                int rightMargin = size.width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
                                  - (insets.right + tabAreaInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
                for (i = 0; i < tabCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
                    rects[i].x = rightMargin - rects[i].x - rects[i].width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
            tabScroller.tabPanel.setPreferredSize(new Dimension(totalWidth, totalHeight));
27266
677e0bfc64d7 7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents: 26037
diff changeset
  3679
            tabScroller.tabPanel.invalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
    private class ScrollableTabSupport implements ActionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
                            ChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
        public ScrollableTabViewport viewport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
        public ScrollableTabPanel tabPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
        public JButton scrollForwardButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
        public JButton scrollBackwardButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
        public CroppedEdge croppedEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
        public int leadingTabIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
        private Point tabViewPosition = new Point(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
        ScrollableTabSupport(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
            viewport = new ScrollableTabViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
            tabPanel = new ScrollableTabPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
            viewport.setView(tabPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
            viewport.addChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
            croppedEdge = new CroppedEdge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
            createButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
         * Recreates the scroll buttons and adds them to the TabbedPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
        void createButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
            if (scrollForwardButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
                tabPane.remove(scrollForwardButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
                scrollForwardButton.removeActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
                tabPane.remove(scrollBackwardButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
                scrollBackwardButton.removeActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
            int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
            if (tabPlacement == TOP || tabPlacement == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
                scrollForwardButton = createScrollButton(EAST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
                scrollBackwardButton = createScrollButton(WEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
            } else { // tabPlacement = LEFT || RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
                scrollForwardButton = createScrollButton(SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
                scrollBackwardButton = createScrollButton(NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
            scrollForwardButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
            scrollBackwardButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
            tabPane.add(scrollForwardButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
            tabPane.add(scrollBackwardButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
        public void scrollForward(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
            Dimension viewSize = viewport.getViewSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
            Rectangle viewRect = viewport.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
            if (tabPlacement == TOP || tabPlacement == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
                if (viewRect.width >= viewSize.width - viewRect.x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
                    return; // no room left to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
            } else { // tabPlacement == LEFT || tabPlacement == RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
                if (viewRect.height >= viewSize.height - viewRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
            setLeadingTabIndex(tabPlacement, leadingTabIndex+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
        public void scrollBackward(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
            if (leadingTabIndex == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
                return; // no room left to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
            setLeadingTabIndex(tabPlacement, leadingTabIndex-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
        public void setLeadingTabIndex(int tabPlacement, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
            leadingTabIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
            Dimension viewSize = viewport.getViewSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
            Rectangle viewRect = viewport.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
            switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
              case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
              case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
                tabViewPosition.x = leadingTabIndex == 0? 0 : rects[leadingTabIndex].x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
                if ((viewSize.width - tabViewPosition.x) < viewRect.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
                    // We've scrolled to the end, so adjust the viewport size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
                    // to ensure the view position remains aligned on a tab boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
                    Dimension extentSize = new Dimension(viewSize.width - tabViewPosition.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
                                                         viewRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
                    viewport.setExtentSize(extentSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
              case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
              case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
                tabViewPosition.y = leadingTabIndex == 0? 0 : rects[leadingTabIndex].y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
                if ((viewSize.height - tabViewPosition.y) < viewRect.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
                // We've scrolled to the end, so adjust the viewport size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
                // to ensure the view position remains aligned on a tab boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
                     Dimension extentSize = new Dimension(viewRect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
                                                          viewSize.height - tabViewPosition.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
                     viewport.setExtentSize(extentSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
            viewport.setViewPosition(tabViewPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
            updateView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
        private void updateView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
            int tabPlacement = tabPane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
            int tabCount = tabPane.getTabCount();
20108
e466f9fb7f00 6943780: JTabbedPane throws ArrayIndexOutOfBoundsException sometimes
malenkov
parents: 12279
diff changeset
  3791
            assureRectsCreated(tabCount);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
            Rectangle vpRect = viewport.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
            Dimension viewSize = viewport.getViewSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
            Rectangle viewRect = viewport.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
            leadingTabIndex = getClosestTab(viewRect.x, viewRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
            // If the tab isn't right aligned, adjust it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
            if (leadingTabIndex + 1 < tabCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
                switch (tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
                case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
                case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
                    if (rects[leadingTabIndex].x < viewRect.x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
                        leadingTabIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
                case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
                case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
                    if (rects[leadingTabIndex].y < viewRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
                        leadingTabIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
            Insets contentInsets = getContentBorderInsets(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
            switch(tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
              case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
                  tabPane.repaint(vpRect.x+vpRect.width, vpRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
                                  contentInsets.left, vpRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
                  scrollBackwardButton.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
                          viewRect.y > 0 && leadingTabIndex > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
                  scrollForwardButton.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
                          leadingTabIndex < tabCount-1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
                          viewSize.height-viewRect.y > viewRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
              case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                  tabPane.repaint(vpRect.x-contentInsets.right, vpRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
                                  contentInsets.right, vpRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
                  scrollBackwardButton.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                          viewRect.y > 0 && leadingTabIndex > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
                  scrollForwardButton.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
                          leadingTabIndex < tabCount-1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
                          viewSize.height-viewRect.y > viewRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
              case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
                  tabPane.repaint(vpRect.x, vpRect.y-contentInsets.bottom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
                                  vpRect.width, contentInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
                  scrollBackwardButton.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
                          viewRect.x > 0 && leadingTabIndex > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
                  scrollForwardButton.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
                          leadingTabIndex < tabCount-1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
                          viewSize.width-viewRect.x > viewRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
              case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
                  tabPane.repaint(vpRect.x, vpRect.y+vpRect.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
                                  vpRect.width, contentInsets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
                  scrollBackwardButton.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
                          viewRect.x > 0 && leadingTabIndex > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
                  scrollForwardButton.setEnabled(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
                          leadingTabIndex < tabCount-1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
                          viewSize.width-viewRect.x > viewRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
         * ActionListener for the scroll buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
            ActionMap map = tabPane.getActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
            if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
                String actionKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
                if (e.getSource() == scrollForwardButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
                    actionKey = "scrollTabsForwardAction";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
                    actionKey = "scrollTabsBackwardAction";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
                Action action = map.get(actionKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
                if (action != null && action.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
                    action.actionPerformed(new ActionEvent(tabPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
                        ActionEvent.ACTION_PERFORMED, null, e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
                        e.getModifiers()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
        public String toString() {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  3882
            return "viewport.viewSize=" + viewport.getViewSize() + "\n" +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
                              "viewport.viewRectangle="+viewport.getViewRect()+"\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
                              "leadingTabIndex="+leadingTabIndex+"\n"+
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  3885
                              "tabViewPosition=" + tabViewPosition;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  3890
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
    private class ScrollableTabViewport extends JViewport implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
        public ScrollableTabViewport() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
            setName("TabbedPane.scrollableViewport");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
            setScrollMode(SIMPLE_SCROLL_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
            setOpaque(tabPane.isOpaque());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
            Color bgColor = UIManager.getColor("TabbedPane.tabAreaBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
            if (bgColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
                bgColor = tabPane.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
            setBackground(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  3905
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
    private class ScrollableTabPanel extends JPanel implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
        public ScrollableTabPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
            super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
            setOpaque(tabPane.isOpaque());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
            Color bgColor = UIManager.getColor("TabbedPane.tabAreaBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
            if (bgColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
                bgColor = tabPane.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
            setBackground(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
            BasicTabbedPaneUI.this.paintTabArea(g, tabPane.getTabPlacement(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
                                                tabPane.getSelectedIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
            if (tabScroller.croppedEdge.isParamsSet() && tabContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
                Rectangle croppedRect = rects[tabScroller.croppedEdge.getTabIndex()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
                g.translate(croppedRect.x, croppedRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
                tabScroller.croppedEdge.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
                g.translate(-croppedRect.x, -croppedRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
        public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
            if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
                Component child = getComponent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
                child.setBounds(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  3936
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
    private class ScrollableTabButton extends BasicArrowButton implements UIResource,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
                                                                            SwingConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
        public ScrollableTabButton(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
            super(direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
                  UIManager.getColor("TabbedPane.selected"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
                  UIManager.getColor("TabbedPane.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
                  UIManager.getColor("TabbedPane.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
                  UIManager.getColor("TabbedPane.highlight"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
// Controller: event listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
    private class Handler implements ChangeListener, ContainerListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
                  FocusListener, MouseListener, MouseMotionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
                  PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
            JTabbedPane pane = (JTabbedPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
            boolean isScrollLayout = scrollableTabLayoutEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
            if (name == "mnemonicAt") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
                updateMnemonics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
                pane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
            else if (name == "displayedMnemonicIndexAt") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
                pane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
            else if (name =="indexForTitle") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
                calculatedBaseline = false;
5596
3d2dffc5a67d 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem)
alexp
parents: 2658
diff changeset
  3970
                Integer index = (Integer) e.getNewValue();
26033
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  3971
                updateHtmlViews(index, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
            } else if (name == "tabLayoutPolicy") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
                BasicTabbedPaneUI.this.uninstallUI(pane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
                BasicTabbedPaneUI.this.installUI(pane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
                calculatedBaseline = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
            } else if (name == "tabPlacement") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
                if (scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
                    tabScroller.createButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
                calculatedBaseline = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
            } else if (name == "opaque" && isScrollLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
                boolean newVal = ((Boolean)e.getNewValue()).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
                tabScroller.tabPanel.setOpaque(newVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
                tabScroller.viewport.setOpaque(newVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
            } else if (name == "background" && isScrollLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
                Color newVal = (Color)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
                tabScroller.tabPanel.setBackground(newVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
                tabScroller.viewport.setBackground(newVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
                Color newColor = selectedColor == null ? newVal : selectedColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                tabScroller.scrollForwardButton.setBackground(newColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                tabScroller.scrollBackwardButton.setBackground(newColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
            } else if (name == "indexForTabComponent") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
                if (tabContainer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
                    tabContainer.removeUnusedTabComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                Component c = tabPane.getTabComponentAt(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
                        (Integer)e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
                if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                    if (tabContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                        installTabContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
                        tabContainer.add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
                tabPane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
                tabPane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
                calculatedBaseline = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
            } else if (name == "indexForNullComponent") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
                isRunsDirty = true;
26033
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4010
                updateHtmlViews((Integer)e.getNewValue(), true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
            } else if (name == "font") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
                calculatedBaseline = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
26033
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4016
        private void updateHtmlViews(int index, boolean inserted) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
            String title = tabPane.getTitleAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
            boolean isHTML = BasicHTML.isHTMLString(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
            if (isHTML) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
                if (htmlViews==null) {    // Initialize vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
                    htmlViews = createHTMLVector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
                } else {                  // Vector already exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
                    View v = BasicHTML.createHTMLView(tabPane, title);
26033
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4024
                    setHtmlView(v, inserted, index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
            } else {                             // Not HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
                if (htmlViews!=null) {           // Add placeholder
26033
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4028
                    setHtmlView(null, inserted, index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
                }                                // else nada!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
            updateMnemonics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
26033
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4034
        private void setHtmlView(View v, boolean inserted, int index) {
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4035
            if (inserted || index >= htmlViews.size()) {
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4036
                htmlViews.insertElementAt(v, index);
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4037
            } else {
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4038
                htmlViews.setElementAt(v, index);
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4039
            }
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4040
        }
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4041
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
        // ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
            JTabbedPane tabPane = (JTabbedPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
            tabPane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
            tabPane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
            setFocusIndex(tabPane.getSelectedIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
            if (scrollableTabLayoutEnabled()) {
27266
677e0bfc64d7 7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents: 26037
diff changeset
  4053
                ensureCurrentLayout();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
                int index = tabPane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
                if (index < rects.length && index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
                    tabScroller.tabPanel.scrollRectToVisible(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
                            (Rectangle)rects[index].clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
        // MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
            setRolloverTab(e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
            setRolloverTab(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
            if (!tabPane.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
            int tabIndex = tabForCoordinate(tabPane, e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
            if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
                if (tabIndex != tabPane.getSelectedIndex()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
                    // Clicking on unselected tab, change selection, do NOT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
                    // request focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
                    // This will trigger the focusIndex to change by way
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
                    // of stateChanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
                    tabPane.setSelectedIndex(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
                else if (tabPane.isRequestFocusEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
                    // Clicking on selected tab, try and give the tabbedpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
                    // focus.  Repaint will occur in focusGained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
                    tabPane.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
        // MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
            setRolloverTab(e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
        // FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
           setFocusIndex(tabPane.getSelectedIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
           repaintTab(focusIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
        // ContainerListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
    /* GES 2/3/99:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
       The container listener code was added to support HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
       rendering of tab titles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
       Ideally, we would be able to listen for property changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
       when a tab is added or its text modified.  At the moment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
       there are no such events because the Beans spec doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
       allow 'indexed' property changes (i.e. tab 2's text changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
       from A to B).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
       In order to get around this, we listen for tabs to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
       or removed by listening for the container events.  we then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
       queue up a runnable (so the component has a chance to complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
       the add) which checks the tab title of the new component to see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
       if it requires HTML rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
       The Views (one per tab title requiring HTML rendering) are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
       stored in the htmlViews Vector, which is only allocated after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
       the first time we run into an HTML tab.  Note that this vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
       is kept in step with the number of pages, and nulls are added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
       for those pages whose tab title do not require HTML rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
       This makes it easy for the paint and layout code to tell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
       whether to invoke the HTML engine without having to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
       the string during time-sensitive operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
       When we have added a way to listen for tab additions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
       changes to tab text, this code should be removed and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
       replaced by something which uses that.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
        public void componentAdded(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
            JTabbedPane tp = (JTabbedPane)e.getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
            Component child = e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
            if (child instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
            isRunsDirty = true;
26033
3f7c9aad7cc0 8017284: Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
alexsch
parents: 26012
diff changeset
  4161
            updateHtmlViews(tp.indexOfComponent(child), true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
        public void componentRemoved(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
            JTabbedPane tp = (JTabbedPane)e.getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
            Component child = e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
            if (child instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
            // NOTE 4/15/2002 (joutwate):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
            // This fix is implemented using client properties since there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
            // currently no IndexPropertyChangeEvent.  Once
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
            // IndexPropertyChangeEvents have been added this code should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
            // modified to use it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
            Integer indexObj =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
                (Integer)tp.getClientProperty("__index_to_remove__");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
            if (indexObj != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
                int index = indexObj.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
                if (htmlViews != null && htmlViews.size() > index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
                    htmlViews.removeElementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
                tp.putClientProperty("__index_to_remove__", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
            isRunsDirty = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
            updateMnemonics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
            validateFocusIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
     * Instantiate it only within subclasses of BasicTabbedPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
    public class PropertyChangeHandler implements PropertyChangeListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  4196
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
            getHandler().propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
     * Instantiate it only within subclasses of BasicTabbedPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
    public class TabSelectionHandler implements ChangeListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  4210
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
     * Instantiate it only within subclasses of BasicTabbedPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
    public class MouseHandler extends MouseAdapter {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  4224
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
            getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
     * Instantiate it only within subclasses of BasicTabbedPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
    public class FocusHandler extends FocusAdapter {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  4238
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
            getHandler().focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
            getHandler().focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  4250
    private Vector<View> createHTMLVector() {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
  4251
        Vector<View> htmlViews = new Vector<View>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
        int count = tabPane.getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
        if (count>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
            for (int i=0 ; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
                String title = tabPane.getTitleAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
                if (BasicHTML.isHTMLString(title)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
                    htmlViews.addElement(BasicHTML.createHTMLView(tabPane, title));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
                    htmlViews.addElement(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
        return htmlViews;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  4266
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
    private class TabContainer extends JPanel implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
        private boolean notifyTabbedPane = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
        public TabContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
            super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
            setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
        public void remove(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
            int index = tabPane.indexOfTabComponent(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
            super.remove(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
            if (notifyTabbedPane && index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
                tabPane.setTabComponentAt(index, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
        private void removeUnusedTabComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
            for (Component c : getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
                if (!(c instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
                    int index = tabPane.indexOfTabComponent(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
                    if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
                        super.remove(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
        public boolean isOptimizedDrawingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
            return tabScroller != null && !tabScroller.croppedEdge.isParamsSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
        public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
            // We layout tabComponents in JTabbedPane's layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
            // and use this method as a hook for repainting tabs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
            // to update tabs area e.g. when the size of tabComponent was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
            if (scrollableTabLayoutEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
                tabScroller.tabPanel.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
                tabScroller.updateView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
                tabPane.repaint(getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  4311
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
    private class CroppedEdge extends JPanel implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
        private Shape shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
        private int tabIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
        private int cropline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
        private int cropx, cropy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
        public CroppedEdge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
            setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
        public void setParams(int tabIndex, int cropline, int cropx, int cropy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
            this.tabIndex = tabIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
            this.cropline = cropline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
            this.cropx = cropx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
            this.cropy = cropy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
            Rectangle tabRect = rects[tabIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
            setBounds(tabRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
            shape = createCroppedTabShape(tabPane.getTabPlacement(), tabRect, cropline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
            if (getParent() == null && tabContainer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
                tabContainer.add(this, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
        public void resetParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
            shape = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
            if (getParent() == tabContainer && tabContainer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
                tabContainer.remove(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
        public boolean isParamsSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
            return shape != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
        public int getTabIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
            return tabIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
        public int getCropline() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
            return cropline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
        public int getCroppedSideWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
            return 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
        private Color getBgColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
            Component parent = tabPane.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
                Color bg = parent.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
                if (bg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
                    return bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
            return UIManager.getColor("control");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
        protected void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
            if (isParamsSet() && g instanceof Graphics2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
                Graphics2D g2 = (Graphics2D) g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
                g2.clipRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
                g2.setColor(getBgColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
                g2.translate(cropx, cropy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
                g2.fill(shape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
                paintCroppedTabEdge(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
                g2.translate(-cropx, -cropy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
}