1. /*
  2. * %W% %E%
  3. *
  4. * Copyright 2002 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 appropriate
  18. * for short term storage or RMI between applications running the same
  19. * version of Swing. A future release of Swing will provide support for
  20. * long term persistence.
  21. *
  22. * @version %I% %G%
  23. * @author Dave Moore
  24. */
  25. public class AncestorEvent extends AWTEvent {
  26. /**
  27. * An ancestor-component was added to the hierarchy of
  28. * visible objects (made visible), and is currently being displayed.
  29. */
  30. public static final int ANCESTOR_ADDED = 1;
  31. /**
  32. * An ancestor-component was removed from the hierarchy
  33. * of visible objects (hidden) and is no longer being displayed.
  34. */
  35. public static final int ANCESTOR_REMOVED = 2;
  36. /** An ancestor-component changed its position on the screen. */
  37. public static final int ANCESTOR_MOVED = 3;
  38. Container ancestor;
  39. Container ancestorParent;
  40. /**
  41. * Constructs an AncestorEvent object to identify a change
  42. * in an ancestor-component's display-status.
  43. *
  44. * @param source the JComponent that originated the event
  45. * (typically <code>this</code>)
  46. * @param id an int specifying {@link ANCESTOR_ADDED},
  47. * {@link ANCESTOR_REMOVED} or {@link ANCESTOR_MOVED}
  48. * @param ancestor a Container object specifying the ancestor-component
  49. * whose display-status changed
  50. * @param ancestorParent a Container object specifying the ancestor's parent
  51. */
  52. public AncestorEvent(JComponent source, int id, Container ancestor, Container ancestorParent) {
  53. super(source, id);
  54. this.ancestor = ancestor;
  55. this.ancestorParent = ancestorParent;
  56. }
  57. /**
  58. * Returns the ancestor that the event actually occured on.
  59. */
  60. public Container getAncestor() {
  61. return ancestor;
  62. }
  63. /**
  64. * Returns the parent of the ancestor the event actually occured on.
  65. * This is most interesting in an ANCESTOR_REMOVED event, as
  66. * the ancestor may no longer be in the component hierarchy.
  67. */
  68. public Container getAncestorParent() {
  69. return ancestorParent;
  70. }
  71. /**
  72. * Returns the component that the listener was added to.
  73. */
  74. public JComponent getComponent() {
  75. return (JComponent)getSource();
  76. }
  77. }