jdk/src/share/classes/javax/swing/LayoutFocusTraversalPolicy.java
author dmarkov
Wed, 16 Apr 2014 12:51:25 +0400
changeset 24184 4da2f6ec4dab
parent 23697 e556a715949f
child 25568 b906a74c6882
permissions -rw-r--r--
8032874: ArrayIndexOutOfBoundsException in JTable while clearing data in JTable Reviewed-by: alexp, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3084
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: 3084
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: 3084
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3084
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3084
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.ComponentOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Comparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
    32
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A SortingFocusTraversalPolicy which sorts Components based on their size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * position, and orientation. Based on their size and position, Components are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * roughly categorized into rows and columns. For a Container with horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * orientation, columns run left-to-right or right-to-left, and rows run top-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * to-bottom. For a Container with vertical orientation, columns run top-to-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * bottom and rows run left-to-right or right-to-left. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>ComponentOrientation</code> for more information. All columns in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * row are fully traversed before proceeding to the next row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author David Mendenhall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see java.awt.ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 5506
diff changeset
    50
@SuppressWarnings("serial") // Parts of superclass are not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class LayoutFocusTraversalPolicy extends SortingFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    implements Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // Delegate most of our fitness test to Default so that we only have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // code the algorithm once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final SwingDefaultFocusTraversalPolicy fitnessTestPolicy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        new SwingDefaultFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Constructs a LayoutFocusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public LayoutFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super(new LayoutComparator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Constructs a LayoutFocusTraversalPolicy with the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * <code>Comparator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
    70
    LayoutFocusTraversalPolicy(Comparator<? super Component> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        super(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Returns the Component that should receive the focus after aComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * aContainer must be a focus cycle root of aComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * By default, LayoutFocusTraversalPolicy implicitly transfers focus down-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * cycle. That is, during normal focus traversal, the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * traversed after a focus cycle root will be the focus-cycle-root's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * default Component to focus. This behavior can be disabled using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * <code>setImplicitDownCycleTraversal</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * traversal policy provider</a>, the focus is always transferred down-cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param aComponent a (possibly indirect) child of aContainer, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *        aContainer itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @return the Component that should receive the focus after aComponent, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *         null if no suitable Component can be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @throws IllegalArgumentException if aContainer is not a focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *         root of aComponent or a focus traversal policy provider, or if either aContainer or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *         aComponent is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public Component getComponentAfter(Container aContainer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                       Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (aContainer == null || aComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            throw new IllegalArgumentException("aContainer and aComponent cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        Comparator comparator = getComparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (comparator instanceof LayoutComparator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            ((LayoutComparator)comparator).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                setComponentOrientation(aContainer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                        getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return super.getComponentAfter(aContainer, aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Returns the Component that should receive the focus before aComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * aContainer must be a focus cycle root of aComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * By default, LayoutFocusTraversalPolicy implicitly transfers focus down-
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * cycle. That is, during normal focus traversal, the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * traversed after a focus cycle root will be the focus-cycle-root's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * default Component to focus. This behavior can be disabled using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <code>setImplicitDownCycleTraversal</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * traversal policy provider</a>, the focus is always transferred down-cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param aComponent a (possibly indirect) child of aContainer, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *        aContainer itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return the Component that should receive the focus before aComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *         or null if no suitable Component can be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @throws IllegalArgumentException if aContainer is not a focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *         root of aComponent or a focus traversal policy provider, or if either aContainer or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *         aComponent is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public Component getComponentBefore(Container aContainer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                        Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (aContainer == null || aComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            throw new IllegalArgumentException("aContainer and aComponent cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Comparator comparator = getComparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (comparator instanceof LayoutComparator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            ((LayoutComparator)comparator).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                setComponentOrientation(aContainer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                        getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return super.getComponentBefore(aContainer, aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Returns the first Component in the traversal cycle. This method is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * to determine the next Component to focus when traversal wraps in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * forward direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *        first Component is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return the first Component in the traversal cycle of aContainer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *         or null if no suitable Component can be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @throws IllegalArgumentException if aContainer is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public Component getFirstComponent(Container aContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (aContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throw new IllegalArgumentException("aContainer cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Comparator comparator = getComparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (comparator instanceof LayoutComparator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            ((LayoutComparator)comparator).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                setComponentOrientation(aContainer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                        getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return super.getFirstComponent(aContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Returns the last Component in the traversal cycle. This method is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * to determine the next Component to focus when traversal wraps in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * reverse direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *        last Component is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @return the last Component in the traversal cycle of aContainer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *         or null if no suitable Component can be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @throws IllegalArgumentException if aContainer is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public Component getLastComponent(Container aContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (aContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw new IllegalArgumentException("aContainer cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Comparator comparator = getComparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (comparator instanceof LayoutComparator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            ((LayoutComparator)comparator).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                setComponentOrientation(aContainer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                        getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return super.getLastComponent(aContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Determines whether the specified <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * is an acceptable choice as the new focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * This method performs the following sequence of operations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <li>Checks whether <code>aComponent</code> is visible, displayable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *     enabled, and focusable.  If any of these properties is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *     <code>false</code>, this method returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <li>If <code>aComponent</code> is an instance of <code>JTable</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *     returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <li>If <code>aComponent</code> is an instance of <code>JComboBox</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *     then returns the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *     <code>aComponent.getUI().isFocusTraversable(aComponent)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <li>If <code>aComponent</code> is a <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *     with a <code>JComponent.WHEN_FOCUSED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *     <code>InputMap</code> that is neither <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *     nor empty, returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <li>Returns the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *     <code>DefaultFocusTraversalPolicy.accept(aComponent)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param aComponent the <code>Component</code> whose fitness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *                   as a focus owner is to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @see java.awt.Component#isVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see java.awt.Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see java.awt.Component#isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see java.awt.Component#isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see javax.swing.plaf.ComboBoxUI#isFocusTraversable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see javax.swing.JComponent#getInputMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see java.awt.DefaultFocusTraversalPolicy#accept
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @return <code>true</code> if <code>aComponent</code> is a valid choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *         for a focus owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *         otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     protected boolean accept(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (!super.accept(aComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return false;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   231
        } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JTable")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            // JTable only has ancestor focus bindings, we thus force it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            // to be focusable by returning true here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return true;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   235
        } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JComboBox")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            JComboBox box = (JComboBox)aComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return box.getUI().isFocusTraversable(box);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } else if (aComponent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            JComponent jComponent = (JComponent)aComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            InputMap inputMap = jComponent.getInputMap(JComponent.WHEN_FOCUSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                                       false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            while (inputMap != null && inputMap.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                inputMap = inputMap.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (inputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            // Delegate to the fitnessTestPolicy, this will test for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            // case where the developer has overriden isFocusTraversable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            // return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return fitnessTestPolicy.accept(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    private void writeObject(ObjectOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        out.writeObject(getComparator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        out.writeBoolean(getImplicitDownCycleTraversal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        setComparator((Comparator)in.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        setImplicitDownCycleTraversal(in.readBoolean());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
// Create our own subclass and change accept to public so that we can call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
// accept.
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 5506
diff changeset
   269
@SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
class SwingDefaultFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    extends java.awt.DefaultFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public boolean accept(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return super.accept(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}