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