jdk/src/share/classes/javax/swing/DelegatingDefaultFocusManager.java
author dmarkov
Wed, 16 Apr 2014 12:51:25 +0400
changeset 24184 4da2f6ec4dab
parent 5506 202f599c92aa
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
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2004, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Provides a javax.swing.DefaultFocusManager view onto an arbitrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * java.awt.KeyboardFocusManager. We subclass DefaultFocusManager instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * FocusManager because it seems more backward-compatible. It is likely that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * some pre-1.4 code assumes that the object returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * FocusManager.getCurrentManager is an instance of DefaultFocusManager unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * set explicitly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
final class DelegatingDefaultFocusManager extends DefaultFocusManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private final KeyboardFocusManager delegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    DelegatingDefaultFocusManager(KeyboardFocusManager delegate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        this.delegate = delegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        setDefaultFocusTraversalPolicy(gluePolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    KeyboardFocusManager getDelegate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        return delegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // Legacy methods which first appeared in javax.swing.FocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // Client code is most likely to invoke these methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public void processKeyEvent(Component focusedComponent, KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        delegate.processKeyEvent(focusedComponent, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public void focusNextComponent(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        delegate.focusNextComponent(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public void focusPreviousComponent(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        delegate.focusPreviousComponent(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // Make sure that we delegate all new methods in KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // as well as the legacy methods from Swing. It is theoretically possible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // although unlikely, that a client app will treat this instance as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // new-style KeyboardFocusManager. We might as well be safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // The JLS won't let us override the protected methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // KeyboardFocusManager such that they invoke the corresponding methods on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // the delegate. However, since client code would never be able to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // those methods anyways, we don't have to worry about that problem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public Component getFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return delegate.getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public void clearGlobalFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        delegate.clearGlobalFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public Component getPermanentFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return delegate.getPermanentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public Window getFocusedWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return delegate.getFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public Window getActiveWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return delegate.getActiveWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public FocusTraversalPolicy getDefaultFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return delegate.getDefaultFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                               defaultPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (delegate != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            // Will be null when invoked from supers constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            delegate.setDefaultFocusTraversalPolicy(defaultPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        setDefaultFocusTraversalKeys(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                     Set<? extends AWTKeyStroke> keystrokes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        delegate.setDefaultFocusTraversalKeys(id, keystrokes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public Set<AWTKeyStroke> getDefaultFocusTraversalKeys(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return delegate.getDefaultFocusTraversalKeys(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public Container getCurrentFocusCycleRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return delegate.getCurrentFocusCycleRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        delegate.setGlobalCurrentFocusCycleRoot(newFocusCycleRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        delegate.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        delegate.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void addPropertyChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                          PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        delegate.addPropertyChangeListener(propertyName, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void removePropertyChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                             PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        delegate.removePropertyChangeListener(propertyName, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public void addVetoableChangeListener(VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        delegate.addVetoableChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void removeVetoableChangeListener(VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        delegate.removeVetoableChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public void addVetoableChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                          VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        delegate.addVetoableChangeListener(propertyName, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void removeVetoableChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                             VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        delegate.removeVetoableChangeListener(propertyName, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        delegate.addKeyEventDispatcher(dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public void removeKeyEventDispatcher(KeyEventDispatcher dispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        delegate.removeKeyEventDispatcher(dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public boolean dispatchEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return delegate.dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public boolean dispatchKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return delegate.dispatchKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void upFocusCycle(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        delegate.upFocusCycle(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public void downFocusCycle(Container aContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        delegate.downFocusCycle(aContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}