Source for java.awt.event.FocusEvent

   1: /* FocusEvent.java -- generated for a focus change
   2:    Copyright (C) 1999, 2002, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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.
  10: 
  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.
  15: 
  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., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  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.
  25: 
  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. */
  37: 
  38: 
  39: package java.awt.event;
  40: 
  41: import java.awt.Component;
  42: 
  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.
  48:  *
  49:  * @author Aaron M. Renn (arenn@urbanophile.com)
  50:  * @see FocusAdapter
  51:  * @see FocusListener
  52:  * @since 1.1
  53:  * @status updated to 1.4
  54:  */
  55: public class FocusEvent extends ComponentEvent
  56: {
  57:   /**
  58:    * Compatible with JDK 1.1+.
  59:    */
  60:   private static final long serialVersionUID = 523753786457416396L;
  61: 
  62:   /** This is the first id in the range of ids used by this class. */
  63:   public static final int FOCUS_FIRST = 1004;
  64: 
  65:   /** This is the last id in the range of ids used by this class. */
  66:   public static final int FOCUS_LAST = 1005;
  67: 
  68:   /** This is the event id for a focus gained event. */
  69:   public static final int FOCUS_GAINED = 1004;
  70: 
  71:   /** This is the event id for a focus lost event. */
  72:   public static final int FOCUS_LOST = 1005;
  73: 
  74:   /**
  75:    * Indicates whether or not the focus change is temporary.
  76:    *
  77:    * @see #isTemporary()
  78:    * @serial true if the focus change is temporary
  79:    */
  80:   private final boolean temporary;
  81: 
  82:   /**
  83:    * The other component which is giving up or stealing focus from this
  84:    * component, if known.
  85:    *
  86:    * @see #getOppositeComponent()
  87:    * @serial the component with the opposite focus event, or null
  88:    * @since 1.4
  89:    */
  90:   private final Component opposite;
  91: 
  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.
  96:    *
  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
 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