Merge from the pain train
[official-gcc.git] / libjava / java / awt / event / FocusEvent.java
blob3bca6a7d49e6a543b2bfb392365b3d8f68d49a70
1 /* FocusEvent.java -- generated for a focus change
2 Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt.event;
41 import java.awt.Component;
43 /**
44 * This class represents an event generated when a focus change occurs for a
45 * component. There are both temporary changes, such as when focus is stolen
46 * during a sroll then returned, and permanent changes, such as when the user
47 * TABs through focusable components.
49 * @author Aaron M. Renn (arenn@urbanophile.com)
50 * @see FocusAdapter
51 * @see FocusListener
52 * @since 1.1
53 * @status updated to 1.4
55 public class FocusEvent extends ComponentEvent
57 /**
58 * Compatible with JDK 1.1+.
60 private static final long serialVersionUID = 523753786457416396L;
62 /** This is the first id in the range of ids used by this class. */
63 public static final int FOCUS_FIRST = 1004;
65 /** This is the last id in the range of ids used by this class. */
66 public static final int FOCUS_LAST = 1005;
68 /** This is the event id for a focus gained event. */
69 public static final int FOCUS_GAINED = 1004;
71 /** This is the event id for a focus lost event. */
72 public static final int FOCUS_LOST = 1005;
74 /**
75 * Indicates whether or not the focus change is temporary.
77 * @see #isTemporary()
78 * @serial true if the focus change is temporary
80 private final boolean temporary;
82 /**
83 * The other component which is giving up or stealing focus from this
84 * component, if known.
86 * @see #getOppositeComponent()
87 * @serial the component with the opposite focus event, or null
88 * @since 1.4
90 private final Component opposite;
92 /**
93 * Initializes a new instance of <code>FocusEvent</code> with the
94 * specified source, id, temporary status, and opposite counterpart. Note
95 * that an invalid id leads to unspecified results.
97 * @param source the component that is gaining or losing focus
98 * @param id the event id
99 * @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
103 public FocusEvent(Component source, int id, boolean temporary,
104 Component opposite)
106 super(source, id);
107 this.temporary = temporary;
108 this.opposite = opposite;
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.
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
121 public FocusEvent(Component source, int id, boolean temporary)
123 this(source, id, temporary, null);
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.
131 * @param source the component that is gaining or losing focus
132 * @param id the event id
133 * @throws IllegalArgumentException if source is null
135 public FocusEvent(Component source, int id)
137 this(source, id, false, null);
141 * This method tests whether or not the focus change is temporary or
142 * permanent.
144 * @return true if the focus change is temporary
146 public boolean isTemporary()
148 return temporary;
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.
158 * @return the component with the focus opposite, or null
159 * @since 1.4
161 public Component getOppositeComponent()
163 return opposite;
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>.
172 * @return a string identifying this event
174 public String paramString()
176 return (id == FOCUS_GAINED ? "FOCUS_GAINED"
177 : id == FOCUS_LOST ? "FOCUS_LOST" : "unknown type")
178 + (temporary ? ",temporary,opposite=" : ",permanent,opposite=")
179 + opposite;
181 } // class FocusEvent