home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / event / FocusEvent.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  4.7 KB  |  138 lines

  1. /*
  2.  * @(#)FocusEvent.java    1.17 98/03/18
  3.  *
  4.  * Copyright 1996, 1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.event;
  16.  
  17. import java.awt.Component;
  18. import java.awt.Event;
  19.  
  20. /**
  21.  * A low-level event which indicates that a component has gained
  22.  * or lost the keyboard focus.
  23.  * This low-level event is generated by a component (such as a text field).
  24.  * The event is passed to every <code>FocusListener</code>
  25.  * or <code>FocusAdapter</code> object which registered to receive such
  26.  * events using the component's <code>addFocusListener</code> method.
  27.  * (<code>FocusAdapter</code> objects implement the 
  28.  * <code>FocusListener</code> interface.) Each such listener object 
  29.  * gets this <code>FocusEvent</code> when the event occurs.
  30.  * <P>
  31.  * There are two levels of focus change events: permanent and temporary.
  32.  * Permanent focus change events occur when focus is directly moved
  33.  * from one component to another, such as through calls to requestFocus()
  34.  * or as the user uses the Tab key to traverse components.
  35.  * Temporary focus change events occur when focus is temporarily
  36.  * gained or lost for a component as the indirect result of another
  37.  * operation, such as window deactivation or a scrollbar drag.  In this
  38.  * case, the original focus state will automatically be restored once
  39.  * that operation is finished, or, for the case of window deactivation,
  40.  * when the window is reactivated.  Both permanent and temporary focus
  41.  * events are delivered using the FOCUS_GAINED and FOCUS_LOST event ids;
  42.  * the levels may be distinguished in the event using the isTemporary()
  43.  * method.
  44.  *  
  45.  * @see FocusAdapter
  46.  * @see FocusListener
  47.  * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/focuslistener.html">Tutorial: Writing a Focus Listener</a>
  48.  * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
  49.  *
  50.  * @version 1.17 03/18/98
  51.  * @author Carl Quinn
  52.  * @author Amy Fowler
  53.  */
  54. public class FocusEvent extends ComponentEvent {
  55.  
  56.     /**
  57.      * The first number in the range of ids used for focus events.
  58.      */    
  59.     public static final int FOCUS_FIRST        = 1004;
  60.  
  61.     /**
  62.      * The last number in the range of ids used for focus events.
  63.      */
  64.     public static final int FOCUS_LAST        = 1005;
  65.  
  66.     /**
  67.      * This event indicates that the component gained the keyboard focus.  
  68.      */
  69.     public static final int FOCUS_GAINED = FOCUS_FIRST; //Event.GOT_FOCUS
  70.  
  71.     /**
  72.      * This event indicates that the component lost the keyboard focus.  
  73.      */
  74.     public static final int FOCUS_LOST = 1 + FOCUS_FIRST; //Event.LOST_FOCUS
  75.  
  76.     boolean temporary = false;
  77.  
  78.     /*
  79.      * JDK 1.1 serialVersionUID 
  80.      */
  81.      private static final long serialVersionUID = 523753786457416396L;
  82.  
  83.     /**
  84.      * Constructs a FocusEvent object and identifies whether or not the
  85.      * change is temporary.
  86.      *
  87.      * @param source    the Component that originated the event
  88.      * @param id        an integer indicating the type of event
  89.      * @param temporary a boolean, true if the focus change is temporary
  90.      */
  91.     public FocusEvent(Component source, int id, boolean temporary) {
  92.         super(source, id);
  93.         this.temporary = temporary;
  94.     }
  95.  
  96.     /**
  97.      * Constructs a FocusEvent object and identifies it as a permanent 
  98.      * change in focus.
  99.      *
  100.      * @param source    the Component that originated the event
  101.      * @param id        an integer indicating the type of event
  102.      */
  103.     public FocusEvent(Component source, int id) {
  104.         this(source, id, false);
  105.     }
  106.  
  107.     /**
  108.      * Identifies the focus change event as temporary or permanent.
  109.      *
  110.      * @return a boolean value, true if the focus change is temporary
  111.      */
  112.     public boolean isTemporary() {
  113.         return temporary;
  114.     }
  115.  
  116.     /**
  117.      * Returns a parameter string identifying this event.
  118.      * This method is useful for event-logging and for debugging.
  119.      *
  120.      * @return a string identifying the event and its attributes
  121.      */
  122.     public String paramString() {
  123.         String typeStr;
  124.         switch(id) {
  125.           case FOCUS_GAINED:
  126.               typeStr = "FOCUS_GAINED";
  127.               break;
  128.           case FOCUS_LOST:
  129.               typeStr = "FOCUS_LOST";
  130.               break;
  131.           default:
  132.               typeStr = "unknown type";
  133.         }
  134.         return typeStr + (temporary? ",temporary" : ",permanent");
  135.     }
  136.  
  137. }
  138.