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