1 |
771 |
jeremybenn |
/* ContainerEvent.java -- components added/removed from a container
|
2 |
|
|
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
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.
|
10 |
|
|
|
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.
|
15 |
|
|
|
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., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
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.
|
25 |
|
|
|
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. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package java.awt.event;
|
40 |
|
|
|
41 |
|
|
import java.awt.Component;
|
42 |
|
|
import java.awt.Container;
|
43 |
|
|
|
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.
|
48 |
|
|
*
|
49 |
|
|
* @author Aaron M. Renn (arenn@urbanophile.com)
|
50 |
|
|
* @see ContainerAdapter
|
51 |
|
|
* @see ContainerListener
|
52 |
|
|
* @since 1.1
|
53 |
|
|
* @status updated to 1.4
|
54 |
|
|
*/
|
55 |
|
|
public class ContainerEvent extends ComponentEvent
|
56 |
|
|
{
|
57 |
|
|
/**
|
58 |
|
|
* Compatible with JDK 1.1+.
|
59 |
|
|
*/
|
60 |
|
|
private static final long serialVersionUID = -4114942250539772041L;
|
61 |
|
|
|
62 |
|
|
/** This is the first id in the id range used by this class. */
|
63 |
|
|
public static final int CONTAINER_FIRST = 300;
|
64 |
|
|
|
65 |
|
|
/** This is the last id in the id range used by this class. */
|
66 |
|
|
public static final int CONTAINER_LAST = 301;
|
67 |
|
|
|
68 |
|
|
/** This id indicates a component was added to the container. */
|
69 |
|
|
public static final int COMPONENT_ADDED = 300;
|
70 |
|
|
|
71 |
|
|
/** This id indicates a component was removed from the container. */
|
72 |
|
|
public static final int COMPONENT_REMOVED = 301;
|
73 |
|
|
|
74 |
|
|
/**
|
75 |
|
|
* The non-null child component that was added or removed.
|
76 |
|
|
*
|
77 |
|
|
* @serial the child component that changed
|
78 |
|
|
*/
|
79 |
|
|
private final Component child;
|
80 |
|
|
|
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.
|
86 |
|
|
*
|
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
|
91 |
|
|
*/
|
92 |
|
|
public ContainerEvent(Component source, int id, Component child)
|
93 |
|
|
{
|
94 |
|
|
super(source, id);
|
95 |
|
|
this.child = child;
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
/**
|
99 |
|
|
* Returns the source of this event as a <code>Container</code>.
|
100 |
|
|
*
|
101 |
|
|
* @return the source of the event
|
102 |
|
|
* @throws ClassCastException if the source is changed to a non-Container
|
103 |
|
|
*/
|
104 |
|
|
public Container getContainer()
|
105 |
|
|
{
|
106 |
|
|
return (Container) source;
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
/**
|
110 |
|
|
* This method returns the child object that was added or removed from
|
111 |
|
|
* the container.
|
112 |
|
|
*
|
113 |
|
|
* @return the child object added or removed
|
114 |
|
|
*/
|
115 |
|
|
public Component getChild()
|
116 |
|
|
{
|
117 |
|
|
return child;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
/**
|
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>.
|
124 |
|
|
*
|
125 |
|
|
* @return a string identifying this event
|
126 |
|
|
*/
|
127 |
|
|
public String paramString()
|
128 |
|
|
{
|
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());
|
134 |
|
|
}
|
135 |
|
|
} // class ContainerEvent
|