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