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