home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / FocusEvent.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  123 lines

  1. /*
  2.  * @(#)FocusEvent.java    1.14 97/01/27
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.awt.event;
  24.  
  25. import java.awt.Component;
  26. import java.awt.Event;
  27.  
  28. /**
  29.  * The component-level focus event.
  30.  * There are two levels of focus change events: permanent and temporary.
  31.  * Permanent focus change events occur when focus is directly moved
  32.  * from one component to another, such as through calls to requestFocus()
  33.  * or as the user uses the Tab key to traverse components.
  34.  * Temporary focus change events occur when focus is temporarily
  35.  * gained or lost for a component as the indirect result of another
  36.  * operation, such as window deactivation or a scrollbar drag.  In this
  37.  * case, the original focus state will automatically be restored once
  38.  * that operation is finished, or, for the case of window deactivation,
  39.  * when the window is reactivated.  Both permanent and temporary focus
  40.  * events are delivered using the FOCUS_GAINED and FOCUS_LOST event ids;
  41.  * the levels may be distinguished in the event using the isTemporary()
  42.  * method.
  43.  *  
  44.  * @version 1.14 01/27/97
  45.  * @author Carl Quinn
  46.  * @author Amy Fowler
  47.  */
  48. public class FocusEvent extends ComponentEvent {
  49.  
  50.     /**
  51.      * Marks the first integer id for the range of focus event ids.
  52.      */    
  53.     public static final int FOCUS_FIRST        = 1004;
  54.  
  55.     /**
  56.      * Marks the last integer id for the range of focus event ids.
  57.      */
  58.     public static final int FOCUS_LAST        = 1005;
  59.  
  60.     /**
  61.      * The focus gained event type.  
  62.      */
  63.     public static final int FOCUS_GAINED = FOCUS_FIRST; //Event.GOT_FOCUS
  64.  
  65.     /**
  66.      * The focus lost event type.  
  67.      */
  68.     public static final int FOCUS_LOST = 1 + FOCUS_FIRST; //Event.LOST_FOCUS
  69.  
  70.     boolean temporary = false;
  71.  
  72.     /*
  73.      * JDK 1.1 serialVersionUID 
  74.      */
  75.      private static final long serialVersionUID = 523753786457416396L;
  76.  
  77.     /**
  78.      * Constructs a FocusEvent object with the specified source component,
  79.      * type, and whether or not the focus event is a temporary level event.
  80.      * @param source the object where the event originated
  81.      * @id the event type
  82.      * @temporary whether or not this focus change is temporary
  83.      */
  84.     public FocusEvent(Component source, int id, boolean temporary) {
  85.         super(source, id);
  86.         this.temporary = temporary;
  87.     }
  88.  
  89.     /**
  90.      * Constructs a permanent-level FocusEvent object with the 
  91.      * specified source component and type.
  92.      * @param source the object where the event originated
  93.      * @id the event type
  94.      */
  95.     public FocusEvent(Component source, int id) {
  96.         this(source, id, false);
  97.     }
  98.  
  99.     /**
  100.      * Returns whether or not this focus change event is a temporary
  101.      * change.
  102.      */
  103.     public boolean isTemporary() {
  104.         return temporary;
  105.     }
  106.  
  107.     public String paramString() {
  108.         String typeStr;
  109.         switch(id) {
  110.           case FOCUS_GAINED:
  111.               typeStr = "FOCUS_GAINED";
  112.               break;
  113.           case FOCUS_LOST:
  114.               typeStr = "FOCUS_LOST";
  115.               break;
  116.           default:
  117.               typeStr = "unknown type";
  118.         }
  119.         return typeStr + (temporary? ",temporary" : ",permanent");
  120.     }
  121.  
  122. }
  123.