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. import java.awt.event.*;
  9. import java.awt.*;
  10. import javax.swing.*;
  11. /**
  12. * An event reported to a child component that originated from an
  13. * ancestor in the component hierarchy.
  14. * <p>
  15. * <strong>Warning:</strong>
  16. * Serialized objects of this class will not be compatible with
  17. * future Swing releases. The current serialization support is
  18. * appropriate for short term storage or RMI between applications running
  19. * the same version of Swing. As of 1.4, support for long term storage
  20. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  21. * has been added to the <code>java.beans</code> package.
  22. * Please see {@link java.beans.XMLEncoder}.
  23. *
  24. * @version 1.19 12/19/03
  25. * @author Dave Moore
  26. */
  27. public class AncestorEvent extends AWTEvent {
  28. /**
  29. * An ancestor-component was added to the hierarchy of
  30. * visible objects (made visible), and is currently being displayed.
  31. */
  32. public static final int ANCESTOR_ADDED = 1;
  33. /**
  34. * An ancestor-component was removed from the hierarchy
  35. * of visible objects (hidden) and is no longer being displayed.
  36. */
  37. public static final int ANCESTOR_REMOVED = 2;
  38. /** An ancestor-component changed its position on the screen. */
  39. public static final int ANCESTOR_MOVED = 3;
  40. Container ancestor;
  41. Container ancestorParent;
  42. /**
  43. * Constructs an AncestorEvent object to identify a change
  44. * in an ancestor-component's display-status.
  45. *
  46. * @param source the JComponent that originated the event
  47. * (typically <code>this</code>)
  48. * @param id an int specifying {@link #ANCESTOR_ADDED},
  49. * {@link #ANCESTOR_REMOVED} or {@link #ANCESTOR_MOVED}
  50. * @param ancestor a Container object specifying the ancestor-component
  51. * whose display-status changed
  52. * @param ancestorParent a Container object specifying the ancestor's parent
  53. */
  54. public AncestorEvent(JComponent source, int id, Container ancestor, Container ancestorParent) {
  55. super(source, id);
  56. this.ancestor = ancestor;
  57. this.ancestorParent = ancestorParent;
  58. }
  59. /**
  60. * Returns the ancestor that the event actually occurred on.
  61. */
  62. public Container getAncestor() {
  63. return ancestor;
  64. }
  65. /**
  66. * Returns the parent of the ancestor the event actually occurred on.
  67. * This is most interesting in an ANCESTOR_REMOVED event, as
  68. * the ancestor may no longer be in the component hierarchy.
  69. */
  70. public Container getAncestorParent() {
  71. return ancestorParent;
  72. }
  73. /**
  74. * Returns the component that the listener was added to.
  75. */
  76. public JComponent getComponent() {
  77. return (JComponent)getSource();
  78. }
  79. }