1 /* 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * 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™ 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 @SuppressWarnings("serial") 47 public class AncestorEvent extends AWTEvent { 48 /** 49 * An ancestor-component was added to the hierarchy of 50 * visible objects (made visible), and is currently being displayed. 51 */ 52 public static final int ANCESTOR_ADDED = 1; 53 /** 54 * An ancestor-component was removed from the hierarchy 55 * of visible objects (hidden) and is no longer being displayed. 56 */ 57 public static final int ANCESTOR_REMOVED = 2; 58 /** An ancestor-component changed its position on the screen. */ 59 public static final int ANCESTOR_MOVED = 3; 60 61 Container ancestor; 62 Container ancestorParent; 63 64 /** 65 * Constructs an AncestorEvent object to identify a change 66 * in an ancestor-component's display-status. 67 * 68 * @param source the JComponent that originated the event 69 * (typically <code>this</code>) 70 * @param id an int specifying {@link #ANCESTOR_ADDED}, 71 * {@link #ANCESTOR_REMOVED} or {@link #ANCESTOR_MOVED} 72 * @param ancestor a Container object specifying the ancestor-component 73 * whose display-status changed 74 * @param ancestorParent a Container object specifying the ancestor's parent 75 */ 76 public AncestorEvent(JComponent source, int id, Container ancestor, Container ancestorParent) { 77 super(source, id); 78 this.ancestor = ancestor; 79 this.ancestorParent = ancestorParent; 80 } 81 82 /** 83 * Returns the ancestor that the event actually occurred on. 84 * 85 * @return the {@code Container} object specifying the ancestor component 86 */ 87 public Container getAncestor() { 88 return ancestor; 89 } 90 91 /** 92 * Returns the parent of the ancestor the event actually occurred on. 93 * This is most interesting in an ANCESTOR_REMOVED event, as 94 * the ancestor may no longer be in the component hierarchy. 95 * 96 * @return the {@code Container} object specifying the ancestor's parent 97 */ 98 public Container getAncestorParent() { 99 return ancestorParent; 100 } 101 102 /** 103 * Returns the component that the listener was added to. 104 * 105 * @return the {@code JComponent} on which the event occurred 106 */ 107 public JComponent getComponent() { 108 return (JComponent)getSource(); 109 } 110 }