jdk/src/share/classes/javax/swing/JTabbedPane.java
author malenkov
Wed, 30 Apr 2014 19:28:05 +0400
changeset 24544 c0133e7c7162
parent 22574 7f8ce0c8c20a
child 25201 4adc75e0c4e5
permissions -rw-r--r--
8041917: unexcepted behavior of LineBorder while using Boolean variable true Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1997, 2014, 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: 2473
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: 2473
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: 2473
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2473
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2473
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    30
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A component that lets the user switch between a group of components by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * clicking on a tab with a given title and/or icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * For examples and information on using tabbed panes see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20451
diff changeset
    46
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html">How to Use Tabbed Panes</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Tabs/components are added to a <code>TabbedPane</code> object by using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>addTab</code> and <code>insertTab</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * A tab is represented by an index corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * to the position it was added in, where the first tab has an index equal to 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * and the last tab has an index equal to the tab count minus 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The <code>TabbedPane</code> uses a <code>SingleSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * to represent the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * of tab indices and the currently selected index.  If the tab count
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * is greater than 0, then there will always be a selected index, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * by default will be initialized to the first tab.  If the tab count is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * 0, then the selected index will be -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * The tab title can be rendered by a <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * For example, the following produce similar results:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * // In this case the look and feel renders the title for the tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * tabbedPane.addTab("Tab", myComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * // In this case the custom component is responsible for rendering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * // title of the tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * tabbedPane.addTab(null, myComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * tabbedPane.setTabComponentAt(0, new JLabel("Tab"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * The latter is typically used when you want a more complex user interaction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * that requires custom components on the tab.  For example, you could
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * provide a custom component that animates or one that has widgets for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * closing the tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * If you specify a component for a tab, the <code>JTabbedPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * will not render any text or icon you have specified for the tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <strong>Note:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Do not use <code>setVisible</code> directly on a tab component to make it visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * use <code>setSelectedComponent</code> or <code>setSelectedIndex</code> methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    94
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *      attribute: isContainer true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *    description: A component which provides a tab folder metaphor for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *                 displaying one component from a set of components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @author Dave Moore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * @see SingleSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
   109
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
public class JTabbedPane extends JComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
       implements Serializable, Accessible, SwingConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    * The tab layout policy for wrapping tabs in multiple runs when all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    * tabs will not fit within a single run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public static final int WRAP_TAB_LAYOUT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    * Tab layout policy for providing a subset of available tabs when all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    * the tabs will not fit within a single run.  If all the tabs do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    * not fit within a single run the look and feel will provide a way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    * to navigate to hidden tabs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static final int SCROLL_TAB_LAYOUT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private static final String uiClassID = "TabbedPaneUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Where the tabs are placed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #setTabPlacement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected int tabPlacement = TOP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private int tabLayoutPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /** The default selection model */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    protected SingleSelectionModel model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private boolean haveRegistered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * The <code>changeListener</code> is the listener we add to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected ChangeListener changeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private final java.util.List<Page> pages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /* The component that is currently visible */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private Component visComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Only one <code>ChangeEvent</code> is needed per <code>TabPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * instance since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * event's only (read-only) state is the source property.  The source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * of events generated here is always "this".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    protected transient ChangeEvent changeEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Creates an empty <code>TabbedPane</code> with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * tab placement of <code>JTabbedPane.TOP</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see #addTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public JTabbedPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        this(TOP, WRAP_TAB_LAYOUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Creates an empty <code>TabbedPane</code> with the specified tab placement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * of either: <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param tabPlacement the placement for the tabs relative to the content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @see #addTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public JTabbedPane(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        this(tabPlacement, WRAP_TAB_LAYOUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Creates an empty <code>TabbedPane</code> with the specified tab placement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * and tab layout policy.  Tab placement may be either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Tab layout policy may be either: <code>JTabbedPane.WRAP_TAB_LAYOUT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * or <code>JTabbedPane.SCROLL_TAB_LAYOUT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param tabPlacement the placement for the tabs relative to the content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param tabLayoutPolicy the policy for laying out tabs when all tabs will not fit on one run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @exception IllegalArgumentException if tab placement or tab layout policy are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *            one of the above supported values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see #addTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public JTabbedPane(int tabPlacement, int tabLayoutPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        setTabPlacement(tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        setTabLayoutPolicy(tabLayoutPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        pages = new ArrayList<Page>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        setModel(new DefaultSingleSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
   211
     * Returns the UI object which implements the L&amp;F for this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @return a <code>TabbedPaneUI</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @see #setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public TabbedPaneUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return (TabbedPaneUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
   221
     * Sets the UI object which implements the L&amp;F for this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param ui the new UI object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *  description: The UI object that implements the tabbedpane's LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public void setUI(TabbedPaneUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        // disabled icons are generated by LF so they should be unset here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        for (int i = 0; i < getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            Icon icon = pages.get(i).disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (icon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                setDisabledIconAt(i, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        setUI((TabbedPaneUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Returns the name of the UI class that implements the
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
   254
     * L&amp;F for this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the string "TabbedPaneUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * We pass <code>ModelChanged</code> events along to the listeners with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * the tabbedpane (instead of the model itself) as the event source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    protected class ModelListener implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Subclasses that want to handle <code>ChangeEvents</code> differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * can override this to return a subclass of <code>ModelListener</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * another <code>ChangeListener</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    protected ChangeListener createChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return new ModelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Adds a <code>ChangeListener</code> to this tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param l the <code>ChangeListener</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @see #removeChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public void addChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        listenerList.add(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Removes a <code>ChangeListener</code> from this tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param l the <code>ChangeListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public void removeChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        listenerList.remove(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Returns an array of all the <code>ChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * to this <code>JTabbedPane</code> with <code>addChangeListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @return all of the <code>ChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public ChangeListener[] getChangeListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 467
diff changeset
   317
        return listenerList.getListeners(ChangeListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Sends a {@code ChangeEvent}, with this {@code JTabbedPane} as the source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * to each registered listener. This method is called each time there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * a change to either the selected index or the selected tab in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * {@code JTabbedPane}. Usually, the selected index and selected tab change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * together. However, there are some cases, such as tab addition, where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * selected index changes and the same tab remains selected. There are other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * cases, such as deleting the selected tab, where the index remains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * same, but a new tab moves to that index. Events are fired for all of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * these cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    protected void fireStateChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        /* --- Begin code to deal with visibility --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        /* This code deals with changing the visibility of components to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * hide and show the contents for the selected tab. It duplicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * logic already present in BasicTabbedPaneUI, logic that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * processed during the layout pass. This code exists to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * developers to do things that are quite difficult to accomplish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * with the previous model of waiting for the layout pass to process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * visibility changes; such as requesting focus on the new visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * For the average code, using the typical JTabbedPane methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * all visibility changes will now be processed here. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * the code in BasicTabbedPaneUI still exists, for the purposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * of backward compatibility. Therefore, when making changes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * this code, ensure that the BasicTabbedPaneUI code is kept in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * synch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        int selIndex = getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        /* if the selection is now nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (selIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            /* if there was a previous visible component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (visComp != null && visComp.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                /* make it invisible */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                visComp.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            /* now there's no visible component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            visComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        /* else - the selection is now something */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            /* Fetch the component for the new selection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            Component newComp = getComponentAt(selIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            /* if the new component is non-null and different */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            if (newComp != null && newComp != visComp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                boolean shouldChangeFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                /* Note: the following (clearing of the old visible component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                 * is inside this if-statement for good reason: Tabbed pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                 * should continue to show the previously visible component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                 * if there is no component for the chosen tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                /* if there was a previous visible component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                if (visComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    shouldChangeFocus =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                        (SwingUtilities.findFocusOwner(visComp) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    /* if it's still visible */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    if (visComp.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                        /* make it invisible */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        visComp.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                if (!newComp.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    newComp.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                if (shouldChangeFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    SwingUtilities2.tabbedPaneChangeFocusTo(newComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                visComp = newComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            } /* else - the visible component shouldn't changed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        /* --- End code to deal with visibility --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            if (listeners[i]==ChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                if (changeEvent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Returns the model associated with this tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public SingleSelectionModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Sets the model to be used with this tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @param model the model to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * description: The tabbedpane's SingleSelectionModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public void setModel(SingleSelectionModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        SingleSelectionModel oldModel = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            oldModel.removeChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            changeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        this.model = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            changeListener = createChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            model.addChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        firePropertyChange("model", oldModel, model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * Returns the placement of the tabs for this tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @see #setTabPlacement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public int getTabPlacement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return tabPlacement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Sets the tab placement for this tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * Possible values are:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * <li><code>JTabbedPane.TOP</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * <li><code>JTabbedPane.BOTTOM</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * <li><code>JTabbedPane.LEFT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * <li><code>JTabbedPane.RIGHT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * The default value, if not set, is <code>SwingConstants.TOP</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @param tabPlacement the placement for the tabs relative to the content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @exception IllegalArgumentException if tab placement value isn't one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *                          of the above valid values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *         enum: TOP JTabbedPane.TOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *               LEFT JTabbedPane.LEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *               BOTTOM JTabbedPane.BOTTOM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *               RIGHT JTabbedPane.RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *  description: The tabbedpane's tab placement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public void setTabPlacement(int tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (tabPlacement != TOP && tabPlacement != LEFT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            tabPlacement != BOTTOM && tabPlacement != RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            throw new IllegalArgumentException("illegal tab placement: must be TOP, BOTTOM, LEFT, or RIGHT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (this.tabPlacement != tabPlacement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            int oldValue = this.tabPlacement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            this.tabPlacement = tabPlacement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            firePropertyChange("tabPlacement", oldValue, tabPlacement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Returns the policy used by the tabbedpane to layout the tabs when all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * tabs will not fit within a single run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @see #setTabLayoutPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    public int getTabLayoutPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        return tabLayoutPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Sets the policy which the tabbedpane will use in laying out the tabs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * when all the tabs will not fit within a single run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Possible values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * <li><code>JTabbedPane.WRAP_TAB_LAYOUT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <li><code>JTabbedPane.SCROLL_TAB_LAYOUT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * The default value, if not set by the UI, is <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Some look and feels might only support a subset of the possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * layout policies, in which case the value of this property may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @param tabLayoutPolicy the policy used to layout the tabs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @exception IllegalArgumentException if layoutPolicy value isn't one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *                          of the above valid values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @see #getTabLayoutPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *         enum: WRAP_TAB_LAYOUT JTabbedPane.WRAP_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *               SCROLL_TAB_LAYOUT JTabbedPane.SCROLL_TAB_LAYOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *  description: The tabbedpane's policy for laying out the tabs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public void setTabLayoutPolicy(int tabLayoutPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (tabLayoutPolicy != WRAP_TAB_LAYOUT && tabLayoutPolicy != SCROLL_TAB_LAYOUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            throw new IllegalArgumentException("illegal tab layout policy: must be WRAP_TAB_LAYOUT or SCROLL_TAB_LAYOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (this.tabLayoutPolicy != tabLayoutPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            int oldValue = this.tabLayoutPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            this.tabLayoutPolicy = tabLayoutPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            firePropertyChange("tabLayoutPolicy", oldValue, tabLayoutPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * Returns the currently selected index for this tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Returns -1 if there is no currently selected tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @return the index of the selected tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @see #setSelectedIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   566
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public int getSelectedIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return model.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Sets the selected index for this tabbedpane. The index must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * a valid tab index or -1, which indicates that no tab should be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * (can also be used when there are no tabs in the tabbedpane).  If a -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * value is specified when the tabbedpane contains one or more tabs, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * the results will be implementation defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @param index  the index to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
   580
     *            {@code (index < -1 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @see #getSelectedIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @see SingleSelectionModel#setSelectedIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * description: The tabbedpane's selected tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public void setSelectedIndex(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            checkIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        setSelectedIndexImpl(index, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    private void setSelectedIndexImpl(int index, boolean doAccessibleChanges) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        int oldIndex = model.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        Page oldPage = null, newPage = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        String oldName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        doAccessibleChanges = doAccessibleChanges && (oldIndex != index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (doAccessibleChanges) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                oldName = accessibleContext.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            if (oldIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                oldPage = pages.get(oldIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                newPage = pages.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        model.setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if (doAccessibleChanges) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            changeAccessibleSelection(oldPage, oldName, newPage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    private void changeAccessibleSelection(Page oldPage, String oldName, Page newPage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        if (oldPage != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            oldPage.firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                       AccessibleState.SELECTED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if (newPage != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            newPage.firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                                       null, AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            oldName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            accessibleContext.getAccessibleName());
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 the currently selected component for this tabbedpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * Returns <code>null</code> if there is no currently selected tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @return the component corresponding to the selected tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @see #setSelectedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   652
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    public Component getSelectedComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        int index = getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return getComponentAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Sets the selected component for this tabbedpane.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * will automatically set the <code>selectedIndex</code> to the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * corresponding to the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @exception IllegalArgumentException if component not found in tabbed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *          pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @see #getSelectedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * description: The tabbedpane's selected component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    public void setSelectedComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        int index = indexOfComponent(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            throw new IllegalArgumentException("component not found in tabbed pane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * Inserts a new tab for the given component, at the given index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * represented by the given title and/or icon, either of which may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * be {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @param title the title to be displayed on the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @param icon the icon to be displayed on the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @param component the component to be displayed when this tab is clicked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * @param tip the tooltip to be displayed for this tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * @param index the position to insert this new tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *       ({@code > 0 and <= getTabCount()})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * @throws IndexOutOfBoundsException if the index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *         ({@code < 0 or > getTabCount()})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @see #addTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    public void insertTab(String title, Icon icon, Component component, String tip, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        int newIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        // If component already exists, remove corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        // tab so that new tab gets added correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        // Note: we are allowing component=null because of compatibility,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        // but we really should throw an exception because much of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        // rest of the JTabbedPane implementation isn't designed to deal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        // with null components for tabs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        int removeIndex = indexOfComponent(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        if (component != null && removeIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            removeTabAt(removeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            if (newIndex > removeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                newIndex--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        int selectedIndex = getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        pages.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            newIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            new Page(this, title != null? title : "", icon, null, component, tip));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            addImpl(component, null, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            component.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            firePropertyChange("indexForNullComponent", -1, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if (pages.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            setSelectedIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        if (selectedIndex >= newIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            setSelectedIndexImpl(selectedIndex + 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if (!haveRegistered && tip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            haveRegistered = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                    AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    null, component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * Adds a <code>component</code> and <code>tip</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * represented by a <code>title</code> and/or <code>icon</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * either of which can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Cover method for <code>insertTab</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @param title the title to be displayed in this tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @param icon the icon to be displayed in this tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @param component the component to be displayed when this tab is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @param tip the tooltip to be displayed for this tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    public void addTab(String title, Icon icon, Component component, String tip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        insertTab(title, icon, component, tip, pages.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * Adds a <code>component</code> represented by a <code>title</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * and/or <code>icon</code>, either of which can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * Cover method for <code>insertTab</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @param title the title to be displayed in this tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * @param icon the icon to be displayed in this tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @param component the component to be displayed when this tab is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public void addTab(String title, Icon icon, Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        insertTab(title, icon, component, null, pages.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * Adds a <code>component</code> represented by a <code>title</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * and no icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Cover method for <code>insertTab</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @param title the title to be displayed in this tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @param component the component to be displayed when this tab is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    public void addTab(String title, Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        insertTab(title, null, component, null, pages.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * Adds a <code>component</code> with a tab title defaulting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * the name of the component which is the result of calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * <code>component.getName</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * Cover method for <code>insertTab</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @param component the component to be displayed when this tab is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    public Component add(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        if (!(component instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            addTab(component.getName(), component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            super.add(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        return component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * Adds a <code>component</code> with the specified tab title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * Cover method for <code>insertTab</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * @param title the title to be displayed in this tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * @param component the component to be displayed when this tab is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    public Component add(String title, Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        if (!(component instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            addTab(title, component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            super.add(title, component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        return component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Adds a <code>component</code> at the specified tab index with a tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * title defaulting to the name of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * Cover method for <code>insertTab</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @param component the component to be displayed when this tab is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @param index the position to insert this new tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    public Component add(Component component, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        if (!(component instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            // Container.add() interprets -1 as "append", so convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            // the index appropriately to be handled by the vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            insertTab(component.getName(), null, component, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                      index == -1? getTabCount() : index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            super.add(component, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        return component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * Adds a <code>component</code> to the tabbed pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * If <code>constraints</code> is a <code>String</code> or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * <code>Icon</code>, it will be used for the tab title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * otherwise the component's name will be used as the tab title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * Cover method for <code>insertTab</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @param component the component to be displayed when this tab is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @param constraints the object to be displayed in the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    public void add(Component component, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        if (!(component instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            if (constraints instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                addTab((String)constraints, component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            } else if (constraints instanceof Icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                addTab(null, (Icon)constraints, component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                add(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            super.add(component, constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * Adds a <code>component</code> at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * If <code>constraints</code> is a <code>String</code> or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * <code>Icon</code>, it will be used for the tab title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * otherwise the component's name will be used as the tab title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * Cover method for <code>insertTab</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @param component the component to be displayed when this tab is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * @param constraints the object to be displayed in the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * @param index the position to insert this new tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public void add(Component component, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        if (!(component instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            Icon icon = constraints instanceof Icon? (Icon)constraints : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            String title = constraints instanceof String? (String)constraints : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            // Container.add() interprets -1 as "append", so convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            // the index appropriately to be handled by the vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            insertTab(title, icon, component, null, index == -1? getTabCount() : index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            super.add(component, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * Removes the tab at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * After the component associated with <code>index</code> is removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * its visibility is reset to true to ensure it will be visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * if added to other containers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @param index the index of the tab to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
   928
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @see #addTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * @see #insertTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    public void removeTabAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        checkIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        Component component = getComponentAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        boolean shouldChangeFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        int selected = getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        String oldName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        /* if we're about to remove the visible component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if (component == visComp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            shouldChangeFocus = (SwingUtilities.findFocusOwner(visComp) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            visComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            /* if we're removing the selected page */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            if (index == selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                /* fire an accessible notification that it's unselected */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                pages.get(index).firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                    AccessibleState.SELECTED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                oldName = accessibleContext.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    component, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        // Force the tabComponent to be cleaned up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        setTabComponentAt(index, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        pages.remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        // NOTE 4/15/2002 (joutwate):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        // This fix is implemented using client properties since there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        // currently no IndexPropertyChangeEvent.  Once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        // IndexPropertyChangeEvents have been added this code should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        // modified to use it.
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   972
        putClientProperty("__index_to_remove__", Integer.valueOf(index));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        /* if the selected tab is after the removal */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        if (selected > index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            setSelectedIndexImpl(selected - 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        /* if the selected tab is the last tab */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        } else if (selected >= getTabCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            setSelectedIndexImpl(selected - 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            Page newSelected = (selected != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                ? pages.get(selected - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            changeAccessibleSelection(null, oldName, newSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        /* selected index hasn't changed, but the associated tab has */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        } else if (index == selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            changeAccessibleSelection(null, oldName, pages.get(index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        // We can't assume the tab indices correspond to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        // container's children array indices, so make sure we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        // remove the correct child!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            Component components[] = getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            for (int i = components.length; --i >= 0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                if (components[i] == component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                    super.remove(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                    component.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        if (shouldChangeFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            SwingUtilities2.tabbedPaneChangeFocusTo(getSelectedComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * Removes the specified <code>Component</code> from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * <code>JTabbedPane</code>. The method does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * if the <code>component</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @param component the component to remove from the tabbedpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @see #addTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    public void remove(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        int index = indexOfComponent(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            removeTabAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            // Container#remove(comp) invokes Container#remove(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            // so make sure JTabbedPane#remove(int) isn't called here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            Component children[] = getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            for (int i=0; i < children.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                if (component == children[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    super.remove(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * Removes the tab and component which corresponds to the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * @param index the index of the component to remove from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     *          <code>tabbedpane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1047
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * @see #addTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    public void remove(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        removeTabAt(index);
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
     * Removes all the tabs and their corresponding components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * from the <code>tabbedpane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * @see #addTab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @see #removeTabAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        setSelectedIndexImpl(-1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        int tabCount = getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        // We invoke removeTabAt for each tab, otherwise we may end up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        // removing Components added by the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        while (tabCount-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            removeTabAt(tabCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * Returns the number of tabs in this <code>tabbedpane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @return an integer specifying the number of tabbed pages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    public int getTabCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        return pages.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * Returns the number of tab runs currently used to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * the tabs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * @return an integer giving the number of rows if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     *          <code>tabPlacement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     *          is <code>TOP</code> or <code>BOTTOM</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     *          and the number of columns if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *          <code>tabPlacement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     *          is <code>LEFT</code> or <code>RIGHT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     *          or 0 if there is no UI set on this <code>tabbedpane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    public int getTabRunCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            return ((TabbedPaneUI)ui).getTabRunCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
// Getters for the Pages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * Returns the tab title at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * @return the title at <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1109
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * @see #setTitleAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    public String getTitleAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        return pages.get(index).title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * Returns the tab icon at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @return the icon at <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1122
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * @see #setIconAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    public Icon getIconAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        return pages.get(index).icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * Returns the tab disabled icon at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * If the tab disabled icon doesn't exist at <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * this will forward the call to the look and feel to construct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * an appropriate disabled Icon from the corresponding enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * Icon. Some look and feels might not render the disabled Icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * in which case it won't be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * @return the icon at <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1141
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * @see #setDisabledIconAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    public Icon getDisabledIconAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        Page page = pages.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        if (page.disabledIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            page.disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, page.icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        return page.disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * Returns the tab tooltip text at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * @return a string containing the tool tip text at <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1159
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * @see #setToolTipTextAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    public String getToolTipTextAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        return pages.get(index).tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * Returns the tab background color at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @return the <code>Color</code> of the tab background at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *          <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1175
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * @see #setBackgroundAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    public Color getBackgroundAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        return pages.get(index).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * Returns the tab foreground color at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @return the <code>Color</code> of the tab foreground at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *          <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1190
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * @see #setForegroundAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    public Color getForegroundAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        return pages.get(index).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * Returns whether or not the tab at <code>index</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * currently enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * @return true if the tab at <code>index</code> is enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     *          false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1206
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @see #setEnabledAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    public boolean isEnabledAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        return pages.get(index).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * Returns the component at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * @return the <code>Component</code> at <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1220
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * @see #setComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    public Component getComponentAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        return pages.get(index).component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * Returns the keyboard mnemonic for accessing the specified tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * The mnemonic is the key which when combined with the look and feel's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * mouseless modifier (usually Alt) will activate the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * @param tabIndex the index of the tab that the mnemonic refers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * @return the key code which represents the mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     *         -1 if a mnemonic is not specified for the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * @exception IndexOutOfBoundsException if index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     *            (<code>tabIndex</code> &lt; 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *              <code>tabIndex</code> &gt;= tab count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @see #setDisplayedMnemonicIndexAt(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @see #setMnemonicAt(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    public int getMnemonicAt(int tabIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        checkIndex(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        Page page = pages.get(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        return page.getMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * Returns the character, as an index, that the look and feel should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * provide decoration for as representing the mnemonic character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * @param tabIndex the index of the tab that the mnemonic refers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * @return index representing mnemonic character if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     *    otherwise returns -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * @exception IndexOutOfBoundsException if index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     *            (<code>tabIndex</code> &lt; 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     *              <code>tabIndex</code> &gt;= tab count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * @see #setDisplayedMnemonicIndexAt(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * @see #setMnemonicAt(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    public int getDisplayedMnemonicIndexAt(int tabIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        checkIndex(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        Page page = pages.get(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        return page.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * Returns the tab bounds at <code>index</code>.  If the tab at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * this index is not currently visible in the UI, then returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * If there is no UI set on this <code>tabbedpane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * then returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * @param index the index to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * @return a <code>Rectangle</code> containing the tab bounds at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     *          <code>index</code>, or <code>null</code> if tab at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     *          <code>index</code> is not currently visible in the UI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     *          or if there is no UI set on this <code>tabbedpane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1285
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    public Rectangle getBoundsAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        checkIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            return ((TabbedPaneUI)ui).getTabBounds(this, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
// Setters for the Pages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * Sets the title at <code>index</code> to <code>title</code> which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * The title is not shown if a tab component for this tab was specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * An internal exception is raised if there is no tab at that index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * @param index the tab index where the title should be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * @param title the title to be displayed in the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1307
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * @see #getTitleAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * @see #setTabComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     *  description: The title at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    public void setTitleAt(int index, String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        Page page = pages.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        String oldTitle =page.title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        page.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        if (oldTitle != title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            firePropertyChange("indexForTitle", -1, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        page.updateDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        if ((oldTitle != title) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                    AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                    oldTitle, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        if (title == null || oldTitle == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            !title.equals(oldTitle)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     * Sets the icon at <code>index</code> to <code>icon</code> which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * <code>null</code>. This does not set disabled icon at <code>icon</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * If the new Icon is different than the current Icon and disabled icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     * is not explicitly set, the LookAndFeel will be asked to generate a disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * Icon. To explicitly set disabled icon, use <code>setDisableIconAt()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * The icon is not shown if a tab component for this tab was specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * An internal exception is raised if there is no tab at that index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * @param index the tab index where the icon should be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * @param icon the icon to be displayed in the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1349
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * @see #setDisabledIconAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * @see #getIconAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * @see #getDisabledIconAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * @see #setTabComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     *  description: The icon at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    public void setIconAt(int index, Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        Page page = pages.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        Icon oldIcon = page.icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        if (icon != oldIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            page.icon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            /* If the default icon has really changed and we had
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
             * generated the disabled icon for this page, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
             * clear the disabledIcon field of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            if (page.disabledIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                page.disabledIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            // Fire the accessibility Visible data change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                        oldIcon, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * Sets the disabled icon at <code>index</code> to <code>icon</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * which can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * An internal exception is raised if there is no tab at that index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * @param index the tab index where the disabled icon should be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * @param disabledIcon the icon to be displayed in the tab when disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1393
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * @see #getDisabledIconAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     *  description: The disabled icon at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    public void setDisabledIconAt(int index, Icon disabledIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        Icon oldIcon = pages.get(index).disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        pages.get(index).disabledIcon = disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        if (disabledIcon != oldIcon && !isEnabledAt(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            repaint();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * Sets the tooltip text at <code>index</code> to <code>toolTipText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * which can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * An internal exception is raised if there is no tab at that index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * @param index the tab index where the tooltip text should be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * @param toolTipText the tooltip text to be displayed for the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1418
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * @see #getToolTipTextAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     *  description: The tooltip text at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    public void setToolTipTextAt(int index, String toolTipText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        String oldToolTipText = pages.get(index).tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        pages.get(index).tip = toolTipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        if ((oldToolTipText != toolTipText) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                    AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                    oldToolTipText, toolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        if (!haveRegistered && toolTipText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            haveRegistered = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * Sets the background color at <code>index</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * <code>background</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * which can be <code>null</code>, in which case the tab's background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * will default to the background color of the <code>tabbedpane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * An internal exception is raised if there is no tab at that index.
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1447
     * <p>
7260
d16b38ca60f1 6939001: Nimbus: JTabbedPane setBackgroundAt and setForegroundAt have no effect
alexp
parents: 5506
diff changeset
  1448
     * It is up to the look and feel to honor this property, some may
d16b38ca60f1 6939001: Nimbus: JTabbedPane setBackgroundAt and setForegroundAt have no effect
alexp
parents: 5506
diff changeset
  1449
     * choose to ignore it.
d16b38ca60f1 6939001: Nimbus: JTabbedPane setBackgroundAt and setForegroundAt have no effect
alexp
parents: 5506
diff changeset
  1450
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * @param index the tab index where the background should be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * @param background the color to be displayed in the tab's background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1454
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * @see #getBackgroundAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     *  description: The background color at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    public void setBackgroundAt(int index, Color background) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        Color oldBg = pages.get(index).background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        pages.get(index).setBackground(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        if (background == null || oldBg == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            !background.equals(oldBg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            Rectangle tabBounds = getBoundsAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            if (tabBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                repaint(tabBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * Sets the foreground color at <code>index</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * <code>foreground</code> which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * <code>null</code>, in which case the tab's foreground color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * will default to the foreground color of this <code>tabbedpane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     * An internal exception is raised if there is no tab at that index.
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1480
     * <p>
7260
d16b38ca60f1 6939001: Nimbus: JTabbedPane setBackgroundAt and setForegroundAt have no effect
alexp
parents: 5506
diff changeset
  1481
     * It is up to the look and feel to honor this property, some may
d16b38ca60f1 6939001: Nimbus: JTabbedPane setBackgroundAt and setForegroundAt have no effect
alexp
parents: 5506
diff changeset
  1482
     * choose to ignore it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * @param index the tab index where the foreground should be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * @param foreground the color to be displayed as the tab's foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1487
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     * @see #getForegroundAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     *  description: The foreground color at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    public void setForegroundAt(int index, Color foreground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        Color oldFg = pages.get(index).foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        pages.get(index).setForeground(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        if (foreground == null || oldFg == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            !foreground.equals(oldFg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            Rectangle tabBounds = getBoundsAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            if (tabBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                repaint(tabBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * Sets whether or not the tab at <code>index</code> is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * An internal exception is raised if there is no tab at that index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * @param index the tab index which should be enabled/disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * @param enabled whether or not the tab should be enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1514
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * @see #isEnabledAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    public void setEnabledAt(int index, boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        boolean oldEnabled = pages.get(index).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        pages.get(index).setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        if (enabled != oldEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     * Sets the component at <code>index</code> to <code>component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * An internal exception is raised if there is no tab at that index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * @param index the tab index where this component is being placed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * @param component the component for the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1534
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * @see #getComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     *  description: The component at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    public void setComponentAt(int index, Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        Page page = pages.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        if (component != page.component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            boolean shouldChangeFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            if (page.component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                shouldChangeFocus =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                    (SwingUtilities.findFocusOwner(page.component) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                // REMIND(aim): this is really silly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                // why not if (page.component.getParent() == this) remove(component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                    int count = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                    Component children[] = getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                    for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                        if (children[i] == page.component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                            super.remove(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            page.component = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            boolean selectedPage = (getSelectedIndex() == index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            if (selectedPage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                this.visComp = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                component.setVisible(selectedPage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                addImpl(component, null, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                if (shouldChangeFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                    SwingUtilities2.tabbedPaneChangeFocusTo(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * Provides a hint to the look and feel as to which character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * text should be decorated to represent the mnemonic. Not all look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * feels may support this. A value of -1 indicates either there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * no mnemonic for this tab, or you do not wish the mnemonic to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * displayed for this tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * The value of this is updated as the properties relating to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     * mnemonic change (such as the mnemonic itself, the text...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     * You should only ever have to call this if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
     * you do not wish the default character to be underlined. For example, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
     * the text at tab index 3 was 'Apple Price', with a mnemonic of 'p',
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
     * and you wanted the 'P'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * to be decorated, as 'Apple <u>P</u>rice', you would have to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * <code>setDisplayedMnemonicIndex(3, 6)</code> after invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * <code>setMnemonicAt(3, KeyEvent.VK_P)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * <p>Note that it is the programmer's responsibility to ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * that each tab has a unique mnemonic or unpredictable results may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     * occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * @param tabIndex the index of the tab that the mnemonic refers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * @param mnemonicIndex index into the <code>String</code> to underline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * @exception IndexOutOfBoundsException if <code>tabIndex</code> is
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1609
     *            out of range ({@code tabIndex < 0 || tabIndex >= tab
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1610
     *            count})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * @exception IllegalArgumentException will be thrown if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     *            <code>mnemonicIndex</code> is &gt;= length of the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     *            title , or &lt; -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * @see #setMnemonicAt(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     * @see #getDisplayedMnemonicIndexAt(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     *  description: the index into the String to draw the keyboard character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     *               mnemonic at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    public void setDisplayedMnemonicIndexAt(int tabIndex, int mnemonicIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        checkIndex(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        Page page = pages.get(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        page.setDisplayedMnemonicIndex(mnemonicIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * Sets the keyboard mnemonic for accessing the specified tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * The mnemonic is the key which when combined with the look and feel's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     * mouseless modifier (usually Alt) will activate the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     * A mnemonic must correspond to a single key on the keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     * and should be specified using one of the <code>VK_XXX</code>
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  1639
     * keycodes defined in <code>java.awt.event.KeyEvent</code>
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  1640
     * or one of the extended keycodes obtained through
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  1641
     * <code>java.awt.event.KeyEvent.getExtendedKeyCodeForChar</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
     * Mnemonics are case-insensitive, therefore a key event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
     * with the corresponding keycode would cause the button to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
     * activated whether or not the Shift modifier was pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
     * This will update the displayed mnemonic property for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
     * tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * @param tabIndex the index of the tab that the mnemonic refers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * @param mnemonic the key code which represents the mnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     * @exception IndexOutOfBoundsException if <code>tabIndex</code> is out
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  1653
     *            of range ({@code tabIndex < 0 || tabIndex >= tab count})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * @see #getMnemonicAt(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * @see #setDisplayedMnemonicIndexAt(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     *  description: The keyboard mnenmonic, as a KeyEvent VK constant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     *               for the specified tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    public void setMnemonicAt(int tabIndex, int mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        checkIndex(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        Page page = pages.get(tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        page.setMnemonic(mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        firePropertyChange("mnemonicAt", null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
// end of Page setters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * Returns the first tab index with a given <code>title</code>,  or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     * -1 if no tab has this title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     * @param title the title for the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     * @return the first tab index which matches <code>title</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     *          -1 if no tab has this title
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
    public int indexOfTab(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        for(int i = 0; i < getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            if (getTitleAt(i).equals(title == null? "" : title)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * Returns the first tab index with a given <code>icon</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * or -1 if no tab has this icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * @param icon the icon for the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * @return the first tab index which matches <code>icon</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     *          or -1 if no tab has this icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    public int indexOfTab(Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        for(int i = 0; i < getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
            Icon tabIcon = getIconAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            if ((tabIcon != null && tabIcon.equals(icon)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                (tabIcon == null && tabIcon == icon)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * Returns the index of the tab for the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * Returns -1 if there is no tab for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * @param component the component for the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * @return the first tab which matches this component, or -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     *          if there is no tab for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    public int indexOfComponent(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        for(int i = 0; i < getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
            Component c = getComponentAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            if ((c != null && c.equals(component)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                (c == null && c == component)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * Returns the tab index corresponding to the tab whose bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * intersect the specified location.  Returns -1 if no tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     * intersects the location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * @param x the x location relative to this tabbedpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * @param y the y location relative to this tabbedpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * @return the tab index which intersects the location, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     *         -1 if no tab intersects the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    public int indexAtLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            return ((TabbedPaneUI)ui).tabForCoordinate(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * Returns the tooltip text for the component determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * mouse event location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * @param event  the <code>MouseEvent</code> that tells where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     *          cursor is lingering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * @return the <code>String</code> containing the tooltip text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    public String getToolTipText(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            int index = ((TabbedPaneUI)ui).tabForCoordinate(this, event.getX(), event.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                return pages.get(index).tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        return super.getToolTipText(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
    private void checkIndex(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
        if (index < 0 || index >= pages.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            throw new IndexOutOfBoundsException("Index: "+index+", Tab count: "+pages.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
    /* Called from the <code>JComponent</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * <code>EnableSerializationFocusListener</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     * do any Swing-specific pre-serialization configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
    void compWriteObjectNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        super.compWriteObjectNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
        // If ToolTipText != null, then the tooltip has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        // unregistered by JComponent.compWriteObjectNotify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        if (getToolTipText() == null && haveRegistered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            ToolTipManager.sharedInstance().unregisterComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        if ((ui != null) && (getUIClassID().equals(uiClassID))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        // If ToolTipText != null, then the tooltip has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        // registered by JComponent.readObject()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        if (getToolTipText() == null && haveRegistered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * Returns a string representation of this <code>JTabbedPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * @return  a string representation of this JTabbedPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
        String tabPlacementString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        if (tabPlacement == TOP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            tabPlacementString = "TOP";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        } else if (tabPlacement == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
            tabPlacementString = "BOTTOM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
        } else if (tabPlacement == LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
            tabPlacementString = "LEFT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        } else if (tabPlacement == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            tabPlacementString = "RIGHT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        } else tabPlacementString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        String haveRegisteredString = (haveRegistered ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                                       "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        ",haveRegistered=" + haveRegisteredString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
        ",tabPlacement=" + tabPlacementString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * Gets the AccessibleContext associated with this JTabbedPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * For tabbed panes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * AccessibleJTabbedPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     * A new AccessibleJTabbedPane instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * @return an AccessibleJTabbedPane that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     *         AccessibleContext of this JTabbedPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
            accessibleContext = new AccessibleJTabbedPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            // initialize AccessibleContext for the existing pages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            int count = getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                pages.get(i).initAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     * <code>JTabbedPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     * Java Accessibility API appropriate to tabbed pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
  1889
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
  1893
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    protected class AccessibleJTabbedPane extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        implements AccessibleSelection, ChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
         * Returns the accessible name of this object, or {@code null} if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
         * there is no accessible name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
         * @return the accessible name of this object, nor {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            if (accessibleName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            String cp = (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                return cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            int index = getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                return pages.get(index).getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            return super.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
         *  Constructs an AccessibleJTabbedPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        public AccessibleJTabbedPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            JTabbedPane.this.model.addChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
            Object o = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                               null, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
         * @return an instance of AccessibleRole describing the role of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
         *          the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
            return AccessibleRole.PAGE_TAB_LIST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
         * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
         * @return the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            return getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
         * Return the specified Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
         * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
         * @exception IllegalArgumentException if index is out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
            if (i < 0 || i >= getTabCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
            return pages.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
         * Gets the <code>AccessibleSelection</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
         * this object.  In the implementation of the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
         * Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
         * returns this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
         * <code>AccessibleSelection</code> interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
           return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
         * Returns the <code>Accessible</code> child contained at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
         * the local coordinate <code>Point</code>, if one exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
         * Otherwise returns the currently selected tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
         * @return the <code>Accessible</code> at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
         *    location, if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
            int tab = ((TabbedPaneUI) ui).tabForCoordinate(JTabbedPane.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                                                           p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            if (tab == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                tab = getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
            return getAccessibleChild(tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
        public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            int index = getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
            if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            return pages.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            return (i == getSelectedIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
           setSelectedIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
           // can't do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
           // can't do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
           // can't do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    private class Page extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        implements Serializable, Accessible, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
        String title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
        Color background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
        Color foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
        Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
        Icon disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
        JTabbedPane parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
        Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        String tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
        boolean enabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
        boolean needsUIUpdate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
        int mnemonic = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        int mnemonicIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        Component tabComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        Page(JTabbedPane parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
             String title, Icon icon, Icon disabledIcon, Component component, String tip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            this.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            this.icon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
            this.disabledIcon = disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
            this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
            this.setAccessibleParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            this.component = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
            this.tip = tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            initAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
         * initializes the AccessibleContext for the page
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
        void initAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
            if (JTabbedPane.this.accessibleContext != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                component instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                 * Do initialization if the AccessibleJTabbedPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                 * has been instantiated. We do not want to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                 * Accessibility classes unnecessarily.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                AccessibleContext ac;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 467
diff changeset
  2075
                ac = component.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                    ac.setAccessibleParent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        void setMnemonic(int mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            this.mnemonic = mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
            updateDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
        int getMnemonic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            return mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
         * Sets the page displayed mnemonic index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
        void setDisplayedMnemonicIndex(int mnemonicIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            if (this.mnemonicIndex != mnemonicIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                if (mnemonicIndex != -1 && (title == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                        mnemonicIndex < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                        mnemonicIndex >= title.length())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                                "Invalid mnemonic index: " + mnemonicIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                this.mnemonicIndex = mnemonicIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                JTabbedPane.this.firePropertyChange("displayedMnemonicIndexAt",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                                                    null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
         * Returns the page displayed mnemonic index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
        int getDisplayedMnemonicIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
            return this.mnemonicIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
        void updateDisplayedMnemonicIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
            setDisplayedMnemonicIndex(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                SwingUtilities.findDisplayedMnemonicIndex(title, mnemonic));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        /////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
        // Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        ////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
            if (accessibleName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
            } else if (title != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                return title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            if (accessibleDescription != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
                return accessibleDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
            } else if (tip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
            return AccessibleRole.PAGE_TAB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            AccessibleStateSet states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            states = parent.getAccessibleContext().getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            states.add(AccessibleState.SELECTABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
            int i = parent.indexOfTab(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            if (i == parent.getSelectedIndex()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
                states.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            return parent.indexOfTab(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            if (component instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            if (component instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                return (Accessible) component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            return parent.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
        public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
            return background != null? background : parent.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
            background = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            return foreground != null? foreground : parent.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
            foreground = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
        public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
            return parent.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
        public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
            parent.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
        public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            return parent.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
            parent.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
            return parent.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
            return enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
            enabled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
        public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
            return parent.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            parent.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
            return parent.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
        public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
            Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
            return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
        public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
             Point parentLocation = parent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
             Point componentLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
             componentLocation.translate(parentLocation.x, parentLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
             return componentLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
             Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
             return new Point(r.x, r.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
        public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
            // do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
            return parent.getUI().getTabBounds(parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                                               parent.indexOfTab(title));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
        public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
            // do nothing
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 getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
            Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
            return new Dimension(r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
        public void setSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
            // do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
            if (component instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
                return (Accessible) component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
        public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            // do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
            // do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
        public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
            // do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
        // TIGER - 4732339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
         * Returns an AccessibleIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
         * @return the enabled icon if one exists and the page
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
         * is enabled. Otherwise, returns the disabled icon if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
         * one exists and the page is disabled.  Otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
         * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
        public AccessibleIcon [] getAccessibleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
            AccessibleIcon accessibleIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
            if (enabled && icon instanceof ImageIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
                AccessibleContext ac =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
                    ((ImageIcon)icon).getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                accessibleIcon = (AccessibleIcon)ac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
            } else if (!enabled && disabledIcon instanceof ImageIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                AccessibleContext ac =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                    ((ImageIcon)disabledIcon).getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
                accessibleIcon = (AccessibleIcon)ac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            if (accessibleIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
                AccessibleIcon [] returnIcons = new AccessibleIcon[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
                returnIcons[0] = accessibleIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
                return returnIcons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    * Sets the component that is responsible for rendering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
    * title for the specified tab.  A null value means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
    * <code>JTabbedPane</code> will render the title and/or icon for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
    * the specified tab.  A non-null value means the component will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
    * render the title and <code>JTabbedPane</code> will not render
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
    * the title and/or icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
    * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
    * Note: The component must not be one that the developer has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    *       already added to the tabbed pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
    * @param index the tab index where the component should be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
    * @param component the component to render the title for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
    *                  specified tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
    * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  2359
    *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
    * @exception IllegalArgumentException if component has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
    *            added to this <code>JTabbedPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
    * @see #getTabComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
    * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
    *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
    *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
    *  description: The tab component at the specified tab index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
    * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
    public void setTabComponentAt(int index, Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        if (component != null && indexOfComponent(component) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            throw new IllegalArgumentException("Component is already added to this JTabbedPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
        Component oldValue = getTabComponentAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
        if (component != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
            int tabComponentIndex = indexOfTabComponent(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
            if (tabComponentIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
                setTabComponentAt(tabComponentIndex, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            pages.get(index).tabComponent = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
            firePropertyChange("indexForTabComponent", -1, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     * Returns the tab component at <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
     * @param index  the index of the item being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
     * @return the tab component at <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
     * @exception IndexOutOfBoundsException if index is out of range
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 7668
diff changeset
  2391
     *            {@code (index < 0 || index >= tab count)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
     * @see #setTabComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
    public Component getTabComponentAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
        return pages.get(index).tabComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     * Returns the index of the tab for the specified tab component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
     * Returns -1 if there is no tab for this tab component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
     * @param tabComponent the tab component for the tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
     * @return the first tab which matches this tab component, or -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
     *          if there is no tab for this tab component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
     * @see #setTabComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
     * @see #getTabComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
     public int indexOfTabComponent(Component tabComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
        for(int i = 0; i < getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
            Component c = getTabComponentAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
            if (c == tabComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
}