001 /* FocusEvent.java -- generated for a focus change
002 Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath is distributed in the hope that it will be useful, but
012 WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package java.awt.event;
040
041 import java.awt.Component;
042
043 /**
044 * This class represents an event generated when a focus change occurs for a
045 * component. There are both temporary changes, such as when focus is stolen
046 * during a sroll then returned, and permanent changes, such as when the user
047 * TABs through focusable components.
048 *
049 * @author Aaron M. Renn (arenn@urbanophile.com)
050 * @see FocusAdapter
051 * @see FocusListener
052 * @since 1.1
053 * @status updated to 1.4
054 */
055 public class FocusEvent extends ComponentEvent
056 {
057 /**
058 * Compatible with JDK 1.1+.
059 */
060 private static final long serialVersionUID = 523753786457416396L;
061
062 /** This is the first id in the range of ids used by this class. */
063 public static final int FOCUS_FIRST = 1004;
064
065 /** This is the last id in the range of ids used by this class. */
066 public static final int FOCUS_LAST = 1005;
067
068 /** This is the event id for a focus gained event. */
069 public static final int FOCUS_GAINED = 1004;
070
071 /** This is the event id for a focus lost event. */
072 public static final int FOCUS_LOST = 1005;
073
074 /**
075 * Indicates whether or not the focus change is temporary.
076 *
077 * @see #isTemporary()
078 * @serial true if the focus change is temporary
079 */
080 private final boolean temporary;
081
082 /**
083 * The other component which is giving up or stealing focus from this
084 * component, if known.
085 *
086 * @see #getOppositeComponent()
087 * @serial the component with the opposite focus event, or null
088 * @since 1.4
089 */
090 private final Component opposite;
091
092 /**
093 * Initializes a new instance of <code>FocusEvent</code> with the
094 * specified source, id, temporary status, and opposite counterpart. Note
095 * that an invalid id leads to unspecified results.
096 *
097 * @param source the component that is gaining or losing focus
098 * @param id the event id
099 * @param temporary true if the focus change is temporary
100 * @param opposite the component receiving the opposite focus event, or null
101 * @throws IllegalArgumentException if source is null
102 */
103 public FocusEvent(Component source, int id, boolean temporary,
104 Component opposite)
105 {
106 super(source, id);
107 this.temporary = temporary;
108 this.opposite = opposite;
109 }
110
111 /**
112 * Initializes a new instance of <code>FocusEvent</code> with the
113 * specified source, id, and temporary status. Note that an invalid id
114 * leads to unspecified results.
115 *
116 * @param source the component that is gaining or losing focus
117 * @param id the event id
118 * @param temporary true if the focus change is temporary
119 * @throws IllegalArgumentException if source is null
120 */
121 public FocusEvent(Component source, int id, boolean temporary)
122 {
123 this(source, id, temporary, null);
124 }
125
126 /**
127 * Initializes a new instance of <code>FocusEvent</code> with the
128 * specified source and id. Note that an invalid id leads to unspecified
129 * results.
130 *
131 * @param source the component that is gaining or losing focus
132 * @param id the event id
133 * @throws IllegalArgumentException if source is null
134 */
135 public FocusEvent(Component source, int id)
136 {
137 this(source, id, false, null);
138 }
139
140 /**
141 * This method tests whether or not the focus change is temporary or
142 * permanent.
143 *
144 * @return true if the focus change is temporary
145 */
146 public boolean isTemporary()
147 {
148 return temporary;
149 }
150
151 /**
152 * Returns the component which received the opposite focus event. If this
153 * component gained focus, the opposite lost focus; likewise if this
154 * component is giving up focus, the opposite is gaining it. If this
155 * information is unknown, perhaps because the opposite is a native
156 * application, this returns null.
157 *
158 * @return the component with the focus opposite, or null
159 * @since 1.4
160 */
161 public Component getOppositeComponent()
162 {
163 return opposite;
164 }
165
166 /**
167 * Returns a string identifying this event. This is formatted as:
168 * <code>(getID() == FOCUS_GAINED ? "FOCUS_GAINED" : "FOCUS_LOST")
169 * + (isTemporary() ? ",temporary," : ",permanent,") + "opposite="
170 * + getOppositeComponent()</code>.
171 *
172 * @return a string identifying this event
173 */
174 public String paramString()
175 {
176 return (id == FOCUS_GAINED ? "FOCUS_GAINED"
177 : id == FOCUS_LOST ? "FOCUS_LOST" : "unknown type")
178 + (temporary ? ",temporary,opposite=" : ",permanent,opposite=")
179 + opposite;
180 }
181 } // class FocusEvent