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

  1. /*
  2.  * @(#)ContainerEvent.java    1.3 97/01/27 Amy Fowler
  3.  * 
  4.  * Copyright (c) 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.Container;
  27. import java.awt.Component;
  28.  
  29. /**
  30.  * The class for container-level events.
  31.  * These events are provided for notification purposes ONLY;
  32.  * The AWT will automatically handle container add and remove
  33.  * operations internally.
  34.  *
  35.  * @see ContainerListener
  36.  *
  37.  * @version 1.3 01/27/97
  38.  * @author Tim Prinzing
  39.  * @author Amy Fowler
  40.  */
  41. public class ContainerEvent extends ComponentEvent {
  42.  
  43.     /**
  44.      * Marks the first integer id for the range of container event ids.
  45.      */
  46.     public static final int CONTAINER_FIRST        = 300;
  47.  
  48.     /**
  49.      * Marks the last integer id for the range of container event ids.
  50.      */
  51.     public static final int CONTAINER_LAST        = 301;
  52.  
  53.    /**
  54.      * The component moved event type.
  55.      */
  56.     public static final int COMPONENT_ADDED    = CONTAINER_FIRST;
  57.  
  58.     /**
  59.      * The component resized event type.
  60.      */
  61.     public static final int COMPONENT_REMOVED = 1 + CONTAINER_FIRST;
  62.  
  63.     Component child;
  64.  
  65.     /*
  66.      * JDK 1.1 serialVersionUID 
  67.      */
  68.     private static final long serialVersionUID = -4114942250539772041L;
  69.  
  70.     /**
  71.      * Constructs a ContainerEvent object with the specified source
  72.      * container, type, and child which is being added or removed. 
  73.      * @param source the container where the event originated
  74.      * @id the event type
  75.      * @child the child component
  76.      */
  77.     public ContainerEvent(Component source, int id, Component child) {
  78.         super(source, id);
  79.         this.child = child;
  80.     }
  81.  
  82.     /**
  83.      * Returns the container where this event originated.
  84.      */
  85.     public Container getContainer() {
  86.         return (Container)source; // cast should always be OK, type was checked in constructor
  87.     }
  88.  
  89.     /**
  90.      * Returns the child component that was added or removed in
  91.      * this event.
  92.      */
  93.     public Component getChild() {
  94.         return child;
  95.     }
  96.  
  97.     public String paramString() {
  98.         String typeStr;
  99.         switch(id) {
  100.           case COMPONENT_ADDED:
  101.               typeStr = "COMPONENT_ADDED";
  102.               break;
  103.           case COMPONENT_REMOVED:
  104.               typeStr = "COMPONENT_REMOVED";
  105.               break;
  106.           default:
  107.               typeStr = "unknown type";
  108.         }
  109.         return typeStr + ",child="+child.getName();
  110.     }
  111. }
  112.