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