2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / event / HierarchyEvent.java
blobaadcc71703db7a03bda2ed981bed7b089022660b
1 /* HierarchyEvent.java -- generated for a change in hierarchy
2 Copyright (C) 2000, 2002 Free Software Foundation
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.AWTEvent;
42 import java.awt.Component;
43 import java.awt.Container;
45 /**
46 * This class represents an event generated for an ancestor component which
47 * may affect this component. These events normally do not need to be handled
48 * by the application, since the AWT system automatically takes care of them.
50 * <p>There are two types of hierarchy events. The first type is handled by
51 * HierarchyListener, and includes addition or removal of an ancestor, or
52 * an ancestor changing its on-screen status (visible and/or displayble). The
53 * second type is handled by HierarchyBoundsListener, and includes resizing
54 * or moving of an ancestor.
56 * @author Bryce McKinlay
57 * @see HierarchyListener
58 * @see HierarchyBoundsAdapter
59 * @see HierarchyBoundsListener
60 * @since 1.3
61 * @status updated to 1.4
63 public class HierarchyEvent extends AWTEvent
65 /**
66 * Compatible with JDK 1.3+.
68 private static final long serialVersionUID = -5337576970038043990L;
70 /** This is the first id in the range of ids used by this class. */
71 public static final int HIERARCHY_FIRST = 1400;
73 /** This id indicates that the hierarchy tree changed. */
74 public static final int HIERARCHY_CHANGED = 1400;
76 /** This id indicates that an ancestor was moved. */
77 public static final int ANCESTOR_MOVED = 1401;
79 /** This id indicates that an ancestor was resized. */
80 public static final int ANCESTOR_RESIZED = 1402;
82 /** This is the last id in the range of ids used by this class. */
83 public static final int HIERARCHY_LAST = 1402;
85 /** This indicates that the HIERARCHY_CHANGED is a changed parent. */
86 public static final int PARENT_CHANGED = 1;
88 /**
89 * This indicates that the HIERARCHY_CHANGED is caused by a change in
90 * displayability.
92 * @see Component#isDisplayable()
93 * @see Component#addNotify()
94 * @see Component#removeNotify()
96 public static final int DISPLAYABILITY_CHANGED = 2;
98 /**
99 * This indicates that the HIERARCHY_CHANGED is a changed visibility.
101 * @see Component#isShowing()
102 * @see Component#addNotify()
103 * @see Component#removeNotify()
104 * @see Component#show()
105 * @see Component#hide()
107 public static final int SHOWING_CHANGED = 4;
110 * The component at the top of the changed hierarchy.
112 * @serial the top component changed
114 private final Component changed;
117 * The parent of this component, either before or after the change depending
118 * on the type of change.
120 * @serial the parent component changed
122 private final Container changedParent;
125 * The bitmask of HIERARCHY_CHANGED event types.
127 * @serial the change flags
129 private final long changeFlags;
132 * Initializes a new instance of <code>HierarchyEvent</code> with the
133 * specified parameters. Note that an invalid id leads to unspecified
134 * results.
136 * @param source the component whose hierarchy changed
137 * @param id the event id
138 * @param changed the top component in the tree of changed hierarchy
139 * @param changedParent the updated parent of this object
140 * @throws IllegalArgumentException if source is null
142 public HierarchyEvent(Component source, int id, Component changed,
143 Container changedParent)
145 this(source, id, changed, changedParent, 0);
149 * Initializes a new instance of <code>HierarchyEvent</code> with the
150 * specified parameters. Note that an invalid id leads to unspecified
151 * results.
153 * @param source the component whose hierarchy changed
154 * @param id the event id
155 * @param changed the top component in the tree of changed hierarchy
156 * @param changedParent the updated parent of this object
157 * @param changeFlags the bitmask of specific HIERARCHY_CHANGED events
158 * @throws IllegalArgumentException if source is null
160 public HierarchyEvent(Component source, int id, Component changed,
161 Container changedParent, long changeFlags)
163 super(source, id);
164 this.changed = changed;
165 this.changedParent = changedParent;
166 this.changeFlags = changeFlags;
170 * This method returns the event source as a <code>Component</code>. If the
171 * source has subsequently been modified to a non-Component, this returns
172 * null.
174 * @return the event source as a <code>Component</code>, or null
176 public Component getComponent()
178 return source instanceof Component ? (Component) source : null;
182 * Returns the component at the top of the hierarchy which changed.
184 * @return the top changed component
186 public Component getChanged()
188 return changed;
192 * Returns the parent of the component listed in <code>getChanged()</code>.
193 * If the cause of this event was <code>Container.add</code>, this is the
194 * new parent; if the cause was <code>Container.remove</code>, this is the
195 * old parent; otherwise it is the unchanged parent.
197 * @return the parent container of the changed component
199 public Container getChangedParent()
201 return changedParent;
205 * If this is a HIERARCHY_CHANGED event, this returns a bitmask of the
206 * types of changes that took place.
208 * @return the bitwise or of hierarchy change types, or 0
209 * @see #PARENT_CHANGED
210 * @see #DISPLAYABILITY_CHANGED
211 * @see #SHOWING_CHANGED
213 public long getChangeFlags()
215 return changeFlags;
219 * This method returns a string identifying this event. This is the field
220 * name of the id type, followed by a parenthesized listing of the changed
221 * component and its parent container. In addition, if the type is
222 * HIERARCHY_CHANGED, the flags preceed the changed component, in the
223 * order PARENT_CHANGED, DISPLAYABILITY_CHANGED, and SHOWING_CHANGED.
225 * @return a string identifying this event
227 public String paramString()
229 StringBuffer r = new StringBuffer();
230 switch (id)
232 case HIERARCHY_CHANGED:
233 r.append("HIERARCHY_CHANGED (");
234 if ((changeFlags & PARENT_CHANGED) != 0)
235 r.append("PARENT_CHANGED,");
236 if ((changeFlags & DISPLAYABILITY_CHANGED) != 0)
237 r.append("DISPLAYABILITY_CHANGED,");
238 if ((changeFlags & SHOWING_CHANGED) != 0)
239 r.append("SHOWING_CHANGED,");
240 break;
241 case ANCESTOR_MOVED:
242 r.append("ANCESTOR_MOVED (");
243 break;
244 case ANCESTOR_RESIZED:
245 r.append("ANCESTOR_RESIZED (");
246 break;
247 default:
248 return "unknown type";
250 r.append(changed).append(',').append(changedParent).append(')');
251 return r.toString();
253 } // class HierarchyEvent