001: /*
002: * @(#)ContainerEvent.java 1.12 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.awt.event;
029:
030: import java.awt.AWTEvent;
031: import java.awt.Container;
032: import java.awt.Component;
033:
034: /**
035: * The class for container-level events.
036: * These events are provided for notification purposes ONLY;
037: * The AWT will automatically handle container add and remove
038: * operations internally.
039: *
040: * @see ContainerListener
041: *
042: * @version 1.8 08/19/02
043: * @author Tim Prinzing
044: * @author Amy Fowler
045: */
046: public class ContainerEvent extends ComponentEvent {
047: /**
048: * Marks the first integer id for the range of container event ids.
049: */
050: public static final int CONTAINER_FIRST = 300;
051: /**
052: * Marks the last integer id for the range of container event ids.
053: */
054: public static final int CONTAINER_LAST = 301;
055: /**
056: * The component moved event type.
057: */
058: public static final int COMPONENT_ADDED = CONTAINER_FIRST;
059: /**
060: * The component resized event type.
061: */
062: public static final int COMPONENT_REMOVED = 1 + CONTAINER_FIRST;
063: Component child;
064: /*
065: * JDK 1.1 serialVersionUID
066: */
067: private static final long serialVersionUID = -4114942250539772041L;
068:
069: /**
070: * Constructs a ContainerEvent object with the specified source
071: * container, type, and child which is being added or removed.
072: * @param source the container where the event originated
073: * @id the event type
074: * @child the child component
075: */
076: public ContainerEvent(Component source, int id, Component child) {
077: super (source, id);
078: this .child = child;
079: }
080:
081: /**
082: * Returns the container where this event originated.
083: */
084: public Container getContainer() {
085: return (Container) source; // cast should always be OK, type was checked in constructor
086: }
087:
088: /**
089: * Returns the child component that was added or removed in
090: * this event.
091: */
092: public Component getChild() {
093: return child;
094: }
095:
096: public String paramString() {
097: String typeStr;
098: switch (id) {
099: case COMPONENT_ADDED:
100: typeStr = "COMPONENT_ADDED";
101: break;
102:
103: case COMPONENT_REMOVED:
104: typeStr = "COMPONENT_REMOVED";
105: break;
106:
107: default:
108: typeStr = "unknown type";
109: }
110: return typeStr + ",child=" + child.getName();
111: }
112: }
|