jdk/src/share/classes/java/awt/event/FocusEvent.java
author dxu
Thu, 04 Apr 2013 15:39:17 -0700
changeset 16734 da1901d79073
parent 12317 9670c1610c53
child 20455 f6f9a0c2796b
permissions -rw-r--r--
8000406: change files using @GenerateNativeHeader to use @Native Summary: Use @Native annotation to mark constants interested by native codes Reviewed-by: alanb, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12317
diff changeset
     2
 * Copyright (c) 1996, 2013, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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 java.awt.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A low-level event which indicates that a Component has gained or lost the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * input focus. This low-level event is generated by a Component (such as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * TextField). The event is passed to every <code>FocusListener</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>FocusAdapter</code> object which registered to receive such events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * using the Component's <code>addFocusListener</code> method. (<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * FocusAdapter</code> objects implement the <code>FocusListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * interface.) Each such listener object gets this <code>FocusEvent</code> when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * the event occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * There are two levels of focus events: permanent and temporary. Permanent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * focus change events occur when focus is directly moved from one Component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * another, such as through a call to requestFocus() or as the user uses the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * TAB key to traverse Components. Temporary focus change events occur when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * focus is temporarily lost for a Component as the indirect result of another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * operation, such as Window deactivation or a Scrollbar drag. In this case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the original focus state will automatically be restored once that operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * is finished, or, for the case of Window deactivation, when the Window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * reactivated. Both permanent and temporary focus events are delivered using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the FOCUS_GAINED and FOCUS_LOST event ids; the level may be distinguished in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the event using the isTemporary() method.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    53
 * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    54
 * An unspecified behavior will be caused if the {@code id} parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    55
 * of any particular {@code FocusEvent} instance is not
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    56
 * in the range from {@code FOCUS_FIRST} to {@code FOCUS_LAST}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see FocusAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/focuslistener.html">Tutorial: Writing a Focus Listener</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @author Carl Quinn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @since 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
public class FocusEvent extends ComponentEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The first number in the range of ids used for focus events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final int FOCUS_FIRST         = 1004;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * The last number in the range of ids used for focus events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static final int FOCUS_LAST          = 1005;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * This event indicates that the Component is now the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final int FOCUS_GAINED = FOCUS_FIRST; //Event.GOT_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * This event indicates that the Component is no longer the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final int FOCUS_LOST = 1 + FOCUS_FIRST; //Event.LOST_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * A focus event can have two different levels, permanent and temporary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * It will be set to true if some operation takes away the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * temporarily and intends on getting it back once the event is completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Otherwise it will be set to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see #isTemporary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    boolean temporary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * The other Component involved in this focus change. For a FOCUS_GAINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * event, this is the Component that lost focus. For a FOCUS_LOST event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * this is the Component that gained focus. If this focus change occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * with a native application, a Java application in a different VM, or with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * no other Component, then the opposite Component is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #getOppositeComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    transient Component opposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static final long serialVersionUID = 523753786457416396L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Constructs a <code>FocusEvent</code> object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * specified temporary state and opposite <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * The opposite <code>Component</code> is the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <code>Component</code> involved in this focus change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * For a <code>FOCUS_GAINED</code> event, this is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <code>Component</code> that lost focus. For a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <code>FOCUS_LOST</code> event, this is the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * that gained focus. If this focus change occurs with a native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * application, with a Java application in a different VM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * or with no other <code>Component</code>, then the opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <code>Component</code> is <code>null</code>.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   128
     * <p> This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   132
     * @param source     The <code>Component</code> that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   133
     * @param id         An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   134
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   135
     *                     the class description for {@link FocusEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   136
     * @param temporary  Equals <code>true</code> if the focus change is temporary;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *                   <code>false</code> otherwise
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   138
     * @param opposite   The other Component involved in the focus change,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *                   or <code>null</code>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   140
     * @throws IllegalArgumentException if <code>source</code> equals {@code null}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   141
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   142
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   143
     * @see #isTemporary()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   144
     * @see #getOppositeComponent()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public FocusEvent(Component source, int id, boolean temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                      Component opposite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this.temporary = temporary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.opposite = opposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Constructs a <code>FocusEvent</code> object and identifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * whether or not the change is temporary.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   157
     * <p> This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   161
     * @param source    The <code>Component</code> that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   162
     * @param id        An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   163
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   164
     *                     the class description for {@link FocusEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   165
     * @param temporary Equals <code>true</code> if the focus change is temporary;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *                  <code>false</code> otherwise
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   167
     * @throws IllegalArgumentException if <code>source</code> equals {@code null}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   168
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   169
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   170
     * @see #isTemporary()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public FocusEvent(Component source, int id, boolean temporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        this(source, id, temporary, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Constructs a <code>FocusEvent</code> object and identifies it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * as a permanent change in focus.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   179
     * <p> This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   183
     * @param source    The <code>Component</code> that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   184
     * @param id        An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   185
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   186
     *                     the class description for {@link FocusEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   187
     * @throws IllegalArgumentException if <code>source</code> equals {@code null}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   188
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   189
     * @see #getID()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public FocusEvent(Component source, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        this(source, id, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Identifies the focus change event as temporary or permanent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return <code>true</code> if the focus change is temporary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *         <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public boolean isTemporary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return temporary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Returns the other Component involved in this focus change. For a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * FOCUS_GAINED event, this is the Component that lost focus. For a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * FOCUS_LOST event, this is the Component that gained focus. If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * focus change occurs with a native application, with a Java application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * in a different VM or context, or with no other Component, then null is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @return the other Component involved in the focus change, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public Component getOppositeComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (opposite == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return (SunToolkit.targetToAppContext(opposite) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                AppContext.getAppContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            ? opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @return a string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        String typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
          case FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
              typeStr = "FOCUS_GAINED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
          case FOCUS_LOST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
              typeStr = "FOCUS_LOST";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
              typeStr = "unknown type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return typeStr + (temporary ? ",temporary" : ",permanent") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            ",opposite=" + getOppositeComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}