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

  1. /*
  2.  * @(#)ComponentEvent.java    1.14 97/01/27 Carl Quinn
  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.AWTEvent;
  26. import java.awt.Event;
  27. import java.awt.Component;
  28. import java.awt.Rectangle;
  29.  
  30. /**
  31.  * The root event class for all component-level events.
  32.  * These events are provided for notification purposes ONLY;
  33.  * The AWT will automatically handle component moves and resizes
  34.  * internally so that GUI layout works properly regardless of
  35.  * whether a program is receiving these events or not.
  36.  *
  37.  * @see ComponentListener
  38.  *
  39.  * @version 1.14 01/27/97
  40.  * @author Carl Quinn
  41.  */
  42. public class ComponentEvent extends AWTEvent {
  43.  
  44.     /**
  45.      * Marks the first integer id for the range of component event ids.
  46.      */
  47.     public static final int COMPONENT_FIRST        = 100;
  48.  
  49.     /**
  50.      * Marks the last integer id for the range of component event ids.
  51.      */
  52.     public static final int COMPONENT_LAST        = 103;
  53.  
  54.    /**
  55.      * The component moved event type.
  56.      */
  57.     public static final int COMPONENT_MOVED    = COMPONENT_FIRST;
  58.  
  59.     /**
  60.      * The component resized event type.
  61.      */
  62.     public static final int COMPONENT_RESIZED    = 1 + COMPONENT_FIRST;
  63.  
  64.     /**
  65.      * The component shown event type.
  66.      */
  67.     public static final int COMPONENT_SHOWN    = 2 + COMPONENT_FIRST;
  68.  
  69.     /**
  70.      * The component hidden event type.
  71.      */
  72.     public static final int COMPONENT_HIDDEN    = 3 + COMPONENT_FIRST;
  73.  
  74.     /*
  75.      * JDK 1.1 serialVersionUID 
  76.      */
  77.     private static final long serialVersionUID = 8101406823902992965L;
  78.  
  79.     /**
  80.      * Constructs a ComponentEvent object with the specified source component 
  81.      * and type.
  82.      * @param source the component where the event originated
  83.      * @id the event type
  84.      */
  85.     public ComponentEvent(Component source, int id) {
  86.         super(source, id);
  87.     }
  88.  
  89.     /**
  90.      * Returns the component where this event originated.
  91.      */
  92.     public Component getComponent() {
  93. //        return (source instanceof Component) ? (Component)source : null;
  94.         return (Component)source; // cast should always be OK, type was checked in constructor
  95.     }
  96.  
  97.     public String paramString() {
  98.         String typeStr;
  99.         Rectangle b = (source !=null
  100.                ? ((Component)source).getBounds()
  101.                : null);
  102.  
  103.         switch(id) {
  104.           case COMPONENT_SHOWN:
  105.               typeStr = "COMPONENT_SHOWN";
  106.               break;
  107.           case COMPONENT_HIDDEN:
  108.               typeStr = "COMPONENT_HIDDEN";
  109.               break;
  110.           case COMPONENT_MOVED:
  111.               typeStr = "COMPONENT_MOVED ("+ 
  112.                          b.x+","+b.y+" "+b.width+"x"+b.height+")";
  113.               break;
  114.           case COMPONENT_RESIZED:
  115.               typeStr = "COMPONENT_RESIZED ("+ 
  116.                          b.x+","+b.y+" "+b.width+"x"+b.height+")";
  117.               break;
  118.           default:
  119.               typeStr = "unknown type";
  120.         }
  121.         return typeStr;
  122.     }
  123. }
  124.