2
|
1 |
/*
|
|
2 |
* Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package javax.swing.event;
|
|
26 |
|
|
27 |
import java.awt.event.*;
|
|
28 |
import java.awt.*;
|
|
29 |
import javax.swing.*;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* An event reported to a child component that originated from an
|
|
33 |
* ancestor in the component hierarchy.
|
|
34 |
* <p>
|
|
35 |
* <strong>Warning:</strong>
|
|
36 |
* Serialized objects of this class will not be compatible with
|
|
37 |
* future Swing releases. The current serialization support is
|
|
38 |
* appropriate for short term storage or RMI between applications running
|
|
39 |
* the same version of Swing. As of 1.4, support for long term storage
|
|
40 |
* of all JavaBeans<sup><font size="-2">TM</font></sup>
|
|
41 |
* has been added to the <code>java.beans</code> package.
|
|
42 |
* Please see {@link java.beans.XMLEncoder}.
|
|
43 |
*
|
|
44 |
* @author Dave Moore
|
|
45 |
*/
|
|
46 |
public class AncestorEvent extends AWTEvent {
|
|
47 |
/**
|
|
48 |
* An ancestor-component was added to the hierarchy of
|
|
49 |
* visible objects (made visible), and is currently being displayed.
|
|
50 |
*/
|
|
51 |
public static final int ANCESTOR_ADDED = 1;
|
|
52 |
/**
|
|
53 |
* An ancestor-component was removed from the hierarchy
|
|
54 |
* of visible objects (hidden) and is no longer being displayed.
|
|
55 |
*/
|
|
56 |
public static final int ANCESTOR_REMOVED = 2;
|
|
57 |
/** An ancestor-component changed its position on the screen. */
|
|
58 |
public static final int ANCESTOR_MOVED = 3;
|
|
59 |
|
|
60 |
Container ancestor;
|
|
61 |
Container ancestorParent;
|
|
62 |
|
|
63 |
/**
|
|
64 |
* Constructs an AncestorEvent object to identify a change
|
|
65 |
* in an ancestor-component's display-status.
|
|
66 |
*
|
|
67 |
* @param source the JComponent that originated the event
|
|
68 |
* (typically <code>this</code>)
|
|
69 |
* @param id an int specifying {@link #ANCESTOR_ADDED},
|
|
70 |
* {@link #ANCESTOR_REMOVED} or {@link #ANCESTOR_MOVED}
|
|
71 |
* @param ancestor a Container object specifying the ancestor-component
|
|
72 |
* whose display-status changed
|
|
73 |
* @param ancestorParent a Container object specifying the ancestor's parent
|
|
74 |
*/
|
|
75 |
public AncestorEvent(JComponent source, int id, Container ancestor, Container ancestorParent) {
|
|
76 |
super(source, id);
|
|
77 |
this.ancestor = ancestor;
|
|
78 |
this.ancestorParent = ancestorParent;
|
|
79 |
}
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Returns the ancestor that the event actually occurred on.
|
|
83 |
*/
|
|
84 |
public Container getAncestor() {
|
|
85 |
return ancestor;
|
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Returns the parent of the ancestor the event actually occurred on.
|
|
90 |
* This is most interesting in an ANCESTOR_REMOVED event, as
|
|
91 |
* the ancestor may no longer be in the component hierarchy.
|
|
92 |
*/
|
|
93 |
public Container getAncestorParent() {
|
|
94 |
return ancestorParent;
|
|
95 |
}
|
|
96 |
|
|
97 |
/**
|
|
98 |
* Returns the component that the listener was added to.
|
|
99 |
*/
|
|
100 |
public JComponent getComponent() {
|
|
101 |
return (JComponent)getSource();
|
|
102 |
}
|
|
103 |
}
|