KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > event > AncestorEvent


1 /*
2  * @(#)AncestorEvent.java 1.19 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.event;
8
9 import java.awt.event.*;
10 import java.awt.*;
11 import javax.swing.*;
12
13 /**
14  * An event reported to a child component that originated from an
15  * ancestor in the component hierarchy.
16  * <p>
17  * <strong>Warning:</strong>
18  * Serialized objects of this class will not be compatible with
19  * future Swing releases. The current serialization support is
20  * appropriate for short term storage or RMI between applications running
21  * the same version of Swing. As of 1.4, support for long term storage
22  * of all JavaBeans<sup><font size="-2">TM</font></sup>
23  * has been added to the <code>java.beans</code> package.
24  * Please see {@link java.beans.XMLEncoder}.
25  *
26  * @version 1.19 12/19/03
27  * @author Dave Moore
28  */

29 public class AncestorEvent extends AWTEvent {
30     /**
31      * An ancestor-component was added to the hierarchy of
32      * visible objects (made visible), and is currently being displayed.
33      */

34     public static final int ANCESTOR_ADDED = 1;
35     /**
36      * An ancestor-component was removed from the hierarchy
37      * of visible objects (hidden) and is no longer being displayed.
38      */

39     public static final int ANCESTOR_REMOVED = 2;
40     /** An ancestor-component changed its position on the screen. */
41     public static final int ANCESTOR_MOVED = 3;
42
43     Container ancestor;
44     Container ancestorParent;
45
46     /**
47      * Constructs an AncestorEvent object to identify a change
48      * in an ancestor-component's display-status.
49      *
50      * @param source the JComponent that originated the event
51      * (typically <code>this</code>)
52      * @param id an int specifying {@link #ANCESTOR_ADDED},
53      * {@link #ANCESTOR_REMOVED} or {@link #ANCESTOR_MOVED}
54      * @param ancestor a Container object specifying the ancestor-component
55      * whose display-status changed
56      * @param ancestorParent a Container object specifying the ancestor's parent
57      */

58     public AncestorEvent(JComponent source, int id, Container ancestor, Container ancestorParent) {
59         super(source, id);
60         this.ancestor = ancestor;
61         this.ancestorParent = ancestorParent;
62     }
63
64     /**
65      * Returns the ancestor that the event actually occurred on.
66      */

67     public Container getAncestor() {
68         return ancestor;
69     }
70
71     /**
72      * Returns the parent of the ancestor the event actually occurred on.
73      * This is most interesting in an ANCESTOR_REMOVED event, as
74      * the ancestor may no longer be in the component hierarchy.
75      */

76     public Container getAncestorParent() {
77         return ancestorParent;
78     }
79
80     /**
81      * Returns the component that the listener was added to.
82      */

83     public JComponent getComponent() {
84         return (JComponent)getSource();
85     }
86 }
87
Popular Tags