0N/A/*
2362N/A * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt.event;
0N/A
0N/Aimport java.awt.AWTEvent;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.Container;
0N/A
0N/A/**
0N/A * An event which indicates a change to the <code>Component</code>
217N/A * hierarchy to which <code>Component</code> belongs.
0N/A * <ul>
0N/A * <li>Hierarchy Change Events (HierarchyListener)
0N/A * <ul>
0N/A * <li> addition of an ancestor
0N/A * <li> removal of an ancestor
0N/A * <li> hierarchy made displayable
0N/A * <li> hierarchy made undisplayable
0N/A * <li> hierarchy shown on the screen (both visible and displayable)
0N/A * <li> hierarchy hidden on the screen (either invisible or undisplayable)
0N/A * </ul>
0N/A * <li>Ancestor Reshape Events (HierarchyBoundsListener)
0N/A * <ul>
0N/A * <li> an ancestor was resized
0N/A * <li> an ancestor was moved
0N/A * </ul>
0N/A * </ul>
0N/A * <p>
0N/A * Hierarchy events are provided for notification purposes ONLY.
0N/A * The AWT will automatically handle changes to the hierarchy internally so
0N/A * that GUI layout and displayability works properly regardless of whether a
0N/A * program is receiving these events or not.
0N/A * <p>
0N/A * This event is generated by a Container object (such as a Panel) when the
0N/A * Container is added, removed, moved, or resized, and passed down the
0N/A * hierarchy. It is also generated by a Component object when that object's
0N/A * <code>addNotify</code>, <code>removeNotify</code>, <code>show</code>, or
217N/A * <code>hide</code> method is called. The {@code ANCESTOR_MOVED} and
217N/A * {@code ANCESTOR_RESIZED}
0N/A * events are dispatched to every <code>HierarchyBoundsListener</code> or
0N/A * <code>HierarchyBoundsAdapter</code> object which registered to receive
0N/A * such events using the Component's <code>addHierarchyBoundsListener</code>
0N/A * method. (<code>HierarchyBoundsAdapter</code> objects implement the <code>
217N/A * HierarchyBoundsListener</code> interface.) The {@code HIERARCHY_CHANGED} events are
0N/A * dispatched to every <code>HierarchyListener</code> object which registered
0N/A * to receive such events using the Component's <code>addHierarchyListener
0N/A * </code> method. Each such listener object gets this <code>HierarchyEvent
0N/A * </code> when the event occurs.
217N/A * <p>
217N/A * An unspecified behavior will be caused if the {@code id} parameter
217N/A * of any particular {@code HierarchyEvent} instance is not
217N/A * in the range from {@code HIERARCHY_FIRST} to {@code HIERARCHY_LAST}.
217N/A * <br>
217N/A * The {@code changeFlags} parameter of any {@code HierarchyEvent} instance takes one of the following
217N/A * values:
217N/A * <ul>
217N/A * <li> {@code HierarchyEvent.PARENT_CHANGED}
217N/A * <li> {@code HierarchyEvent.DISPLAYABILITY_CHANGED}
217N/A * <li> {@code HierarchyEvent.SHOWING_CHANGED}
217N/A * </ul>
217N/A * Assigning the value different from listed above will cause unspecified behavior.
0N/A *
0N/A * @author David Mendenhall
0N/A * @see HierarchyListener
0N/A * @see HierarchyBoundsAdapter
0N/A * @see HierarchyBoundsListener
0N/A * @since 1.3
0N/A */
0N/Apublic class HierarchyEvent extends AWTEvent {
0N/A /*
0N/A * serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = -5337576970038043990L;
0N/A
0N/A /**
0N/A * Marks the first integer id for the range of hierarchy event ids.
0N/A */
0N/A public static final int HIERARCHY_FIRST = 1400; // 1300 used by sun.awt.windows.ModalityEvent
0N/A
0N/A /**
0N/A * The event id indicating that modification was made to the
0N/A * entire hierarchy tree.
0N/A */
0N/A public static final int HIERARCHY_CHANGED = HIERARCHY_FIRST;
0N/A
0N/A /**
0N/A * The event id indicating an ancestor-Container was moved.
0N/A */
0N/A public static final int ANCESTOR_MOVED = 1 + HIERARCHY_FIRST;
0N/A
0N/A /**
0N/A * The event id indicating an ancestor-Container was resized.
0N/A */
0N/A public static final int ANCESTOR_RESIZED = 2 + HIERARCHY_FIRST;
0N/A
0N/A /**
0N/A * Marks the last integer id for the range of ancestor event ids.
0N/A */
0N/A public static final int HIERARCHY_LAST = ANCESTOR_RESIZED;
0N/A
0N/A /**
217N/A * A change flag indicates that the <code>HIERARCHY_CHANGED</code> event
0N/A * was generated by a reparenting operation.
0N/A */
0N/A public static final int PARENT_CHANGED = 0x1;
0N/A
0N/A /**
217N/A * A change flag indicates that the <code>HIERARCHY_CHANGED</code> event
217N/A * was generated due to the changing of the hierarchy displayability.
217N/A * To discern the
217N/A * current displayability of the hierarchy, call the
217N/A * <code>Component.isDisplayable</code> method. Displayability changes occur
217N/A * in response to explicit or implicit calls of the
0N/A * <code>Component.addNotify</code> and
217N/A * <code>Component.removeNotify</code> methods.
0N/A *
0N/A * @see java.awt.Component#isDisplayable()
0N/A * @see java.awt.Component#addNotify()
0N/A * @see java.awt.Component#removeNotify()
0N/A */
0N/A public static final int DISPLAYABILITY_CHANGED = 0x2;
0N/A
0N/A /**
217N/A * A change flag indicates that the <code>HIERARCHY_CHANGED</code> event
217N/A * was generated due to the changing of the hierarchy showing state.
217N/A * To discern the
217N/A * current showing state of the hierarchy, call the
217N/A * <code>Component.isShowing</code> method. Showing state changes occur
0N/A * when either the displayability or visibility of the
0N/A * hierarchy occurs. Visibility changes occur in response to explicit
217N/A * or implicit calls of the <code>Component.show</code> and
217N/A * <code>Component.hide</code> methods.
0N/A *
0N/A * @see java.awt.Component#isShowing()
0N/A * @see java.awt.Component#addNotify()
0N/A * @see java.awt.Component#removeNotify()
0N/A * @see java.awt.Component#show()
0N/A * @see java.awt.Component#hide()
0N/A */
0N/A public static final int SHOWING_CHANGED = 0x4;
0N/A
0N/A Component changed;
0N/A Container changedParent;
0N/A long changeFlags;
0N/A
0N/A /**
0N/A * Constructs an <code>HierarchyEvent</code> object to identify a
0N/A * change in the <code>Component</code> hierarchy.
217N/A * <p>This method throws an
0N/A * <code>IllegalArgumentException</code> if <code>source</code>
0N/A * is <code>null</code>.
0N/A *
217N/A * @param source The <code>Component</code> object that
0N/A * originated the event
217N/A * @param id An integer indicating the type of event.
217N/A * For information on allowable values, see
217N/A * the class description for {@link HierarchyEvent}
217N/A * @param changed The <code>Component</code> at the top of
0N/A * the hierarchy which was changed
217N/A * @param changedParent The parent of the <code>changed</code> component.
217N/A * This
0N/A * may be the parent before or after the
0N/A * change, depending on the type of change
217N/A * @throws IllegalArgumentException if <code>source</code> is {@code null}
217N/A * @see #getSource()
217N/A * @see #getID()
217N/A * @see #getChanged()
217N/A * @see #getChangedParent()
0N/A */
0N/A public HierarchyEvent(Component source, int id, Component changed,
0N/A Container changedParent) {
0N/A super(source, id);
0N/A this.changed = changed;
0N/A this.changedParent = changedParent;
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <code>HierarchyEvent</code> object to identify
0N/A * a change in the <code>Component</code> hierarchy.
217N/A * <p> This method throws an
0N/A * <code>IllegalArgumentException</code> if <code>source</code>
0N/A * is <code>null</code>.
0N/A *
217N/A * @param source The <code>Component</code> object that
0N/A * originated the event
217N/A * @param id An integer indicating the type of event.
217N/A * For information on allowable values, see
217N/A * the class description for {@link HierarchyEvent}
217N/A * @param changed The <code>Component</code> at the top
0N/A * of the hierarchy which was changed
217N/A * @param changedParent The parent of the <code>changed</code> component.
217N/A * This
0N/A * may be the parent before or after the
0N/A * change, depending on the type of change
217N/A * @param changeFlags A bitmask which indicates the type(s) of
217N/A * the <code>HIERARCHY_CHANGED</code> events
217N/A * represented in this event object.
217N/A * For information on allowable values, see
217N/A * the class description for {@link HierarchyEvent}
0N/A * @throws IllegalArgumentException if <code>source</code> is null
217N/A * @see #getSource()
217N/A * @see #getID()
217N/A * @see #getChanged()
217N/A * @see #getChangedParent()
217N/A * @see #getChangeFlags()
0N/A */
0N/A public HierarchyEvent(Component source, int id, Component changed,
0N/A Container changedParent, long changeFlags) {
0N/A super(source, id);
0N/A this.changed = changed;
0N/A this.changedParent = changedParent;
0N/A this.changeFlags = changeFlags;
0N/A }
0N/A
0N/A /**
0N/A * Returns the originator of the event.
0N/A *
0N/A * @return the <code>Component</code> object that originated
0N/A * the event, or <code>null</code> if the object is not a
0N/A * <code>Component</code>.
0N/A */
0N/A public Component getComponent() {
0N/A return (source instanceof Component) ? (Component)source : null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the Component at the top of the hierarchy which was
0N/A * changed.
0N/A *
0N/A * @return the changed Component
0N/A */
0N/A public Component getChanged() {
0N/A return changed;
0N/A }
0N/A
0N/A /**
0N/A * Returns the parent of the Component returned by <code>
0N/A * getChanged()</code>. For a HIERARCHY_CHANGED event where the
0N/A * change was of type PARENT_CHANGED via a call to <code>
0N/A * Container.add</code>, the parent returned is the parent
0N/A * after the add operation. For a HIERARCHY_CHANGED event where
0N/A * the change was of type PARENT_CHANGED via a call to <code>
0N/A * Container.remove</code>, the parent returned is the parent
0N/A * before the remove operation. For all other events and types,
0N/A * the parent returned is the parent during the operation.
0N/A *
0N/A * @return the parent of the changed Component
0N/A */
0N/A public Container getChangedParent() {
0N/A return changedParent;
0N/A }
0N/A
0N/A /**
0N/A * Returns a bitmask which indicates the type(s) of
0N/A * HIERARCHY_CHANGED events represented in this event object.
0N/A * The bits have been bitwise-ored together.
0N/A *
0N/A * @return the bitmask, or 0 if this is not an HIERARCHY_CHANGED
0N/A * event
0N/A */
0N/A public long getChangeFlags() {
0N/A return changeFlags;
0N/A }
0N/A
0N/A /**
0N/A * Returns a parameter string identifying this event.
0N/A * This method is useful for event-logging and for debugging.
0N/A *
0N/A * @return a string identifying the event and its attributes
0N/A */
0N/A public String paramString() {
0N/A String typeStr;
0N/A switch(id) {
0N/A case ANCESTOR_MOVED:
0N/A typeStr = "ANCESTOR_MOVED ("+changed+","+changedParent+")";
0N/A break;
0N/A case ANCESTOR_RESIZED:
0N/A typeStr = "ANCESTOR_RESIZED ("+changed+","+changedParent+")";
0N/A break;
0N/A case HIERARCHY_CHANGED: {
0N/A typeStr = "HIERARCHY_CHANGED (";
0N/A boolean first = true;
0N/A if ((changeFlags & PARENT_CHANGED) != 0) {
0N/A first = false;
0N/A typeStr += "PARENT_CHANGED";
0N/A }
0N/A if ((changeFlags & DISPLAYABILITY_CHANGED) != 0) {
0N/A if (first) {
0N/A first = false;
0N/A } else {
0N/A typeStr += ",";
0N/A }
0N/A typeStr += "DISPLAYABILITY_CHANGED";
0N/A }
0N/A if ((changeFlags & SHOWING_CHANGED) != 0) {
0N/A if (first) {
0N/A first = false;
0N/A } else {
0N/A typeStr += ",";
0N/A }
0N/A typeStr += "SHOWING_CHANGED";
0N/A }
0N/A if (!first) {
0N/A typeStr += ",";
0N/A }
0N/A typeStr += changed + "," + changedParent + ")";
0N/A break;
0N/A }
0N/A default:
0N/A typeStr = "unknown type";
0N/A }
0N/A return typeStr;
0N/A }
0N/A}