2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / event / ContainerEvent.java
blobfe087d2e507ad7041409ecef478badddf3aabf0d
1 /* ContainerEvent.java -- components added/removed from a container
2 Copyright (C) 1999, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt.event;
41 import java.awt.Component;
42 import java.awt.Container;
44 /**
45 * This event is generated when a component is added or removed from a
46 * container. Applications do not ordinarily need to handle these events
47 * since the AWT system handles them internally.
49 * @author Aaron M. Renn <arenn@urbanophile.com>
50 * @see ContainerAdapter
51 * @see ContainerListener
52 * @since 1.1
53 * @status updated to 1.4
55 public class ContainerEvent extends ComponentEvent
57 /**
58 * Compatible with JDK 1.1+.
60 private static final long serialVersionUID = -4114942250539772041L;
62 /** This is the first id in the id range used by this class. */
63 public static final int CONTAINER_FIRST = 300;
65 /** This is the last id in the id range used by this class. */
66 public static final int CONTAINER_LAST = 301;
68 /** This id indicates a component was added to the container. */
69 public static final int COMPONENT_ADDED = 300;
71 /** This id indicates a component was removed from the container. */
72 public static final int COMPONENT_REMOVED = 301;
74 /**
75 * The non-null child component that was added or removed.
77 * @serial the child component that changed
79 private final Component child;
81 /**
82 * Initializes a new instance of <code>ContainerEvent</code> with the
83 * specified source and id. Additionally, the affected child component
84 * is also passed as a parameter. Note that an invalid id leads to
85 * unspecified results.
87 * @param source the source container of the event
88 * @param id the event id
89 * @param child the child component affected by this event
90 * @throws IllegalArgumentException if source is null
92 public ContainerEvent(Component source, int id, Component child)
94 super(source, id);
95 this.child = child;
98 /**
99 * Returns the source of this event as a <code>Container</code>.
101 * @return the source of the event
102 * @throws ClassCastException if the source is changed to a non-Container
104 public Container getContainer()
106 return (Container) source;
110 * This method returns the child object that was added or removed from
111 * the container.
113 * @return the child object added or removed
115 public Component getChild()
117 return child;
121 * This method returns a string identifying this event. It is formatted as:
122 * <code>(getID() == COMPONENT_ADDED ? "COMPONENT_ADDED"
123 * : "COMPONENT_REMOVED") + ",child=" + getChild().getName()</code>.
125 * @return a string identifying this event
127 public String paramString()
129 // Unlike Sun, we don't throw NullPointerException if child is illegally
130 // null.
131 return (id == COMPONENT_ADDED ? "COMPONENT_ADDED,child="
132 : id == COMPONENT_REMOVED ? "COMPONENT_REMOVED,child="
133 : "unknown type,child=") + (child == null ? "" : child.getName());
135 } // class ContainerEvent