1. /*
  2. * %W% %E%
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.event;
  11. import java.awt.event.*;
  12. import java.awt.*;
  13. import javax.swing.*;
  14. /**
  15. * An event reported to a child component that originated from an
  16. * ancestor in the component hierarchy.
  17. * <p>
  18. * <strong>Warning:</strong>
  19. * Serialized objects of this class will not be compatible with
  20. * future Swing releases. The current serialization support is appropriate
  21. * for short term storage or RMI between applications running the same
  22. * version of Swing. A future release of Swing will provide support for
  23. * long term persistence.
  24. *
  25. * @version %I% %G%
  26. * @author Dave Moore
  27. */
  28. public class AncestorEvent extends AWTEvent {
  29. /**
  30. * An ancestor-component was added to the hierarchy of
  31. * visible objects (made visible), and is currently being displayed.
  32. */
  33. public static final int ANCESTOR_ADDED = 1;
  34. /**
  35. * An ancestor-component was removed from the hierarchy
  36. * of visible objects (hidden) and is no longer being displayed.
  37. */
  38. public static final int ANCESTOR_REMOVED = 2;
  39. /** An ancestor-component changed its position on the screen. */
  40. public static final int ANCESTOR_MOVED = 3;
  41. Container ancestor;
  42. Container ancestorParent;
  43. /**
  44. * Constructs an AncestorEvent object to identify a change
  45. * in an ancestor-component's display-status.
  46. *
  47. * @param source the JComponent that originated the event
  48. * (typically <code>this</code>)
  49. * @param id an int specifying {@link #ANCESTOR_ADDED},
  50. * {@link #ANCESTOR_REMOVED} or {@link #ANCESTOR_MOVED}
  51. * @param ancestor a Container object specifying the ancestor-component
  52. * whose display-status changed
  53. * @param ancestorParent a Container object specifying the ancestor's parent
  54. */
  55. public AncestorEvent(JComponent source, int id, Container ancestor, Container ancestorParent) {
  56. super(source, id);
  57. this.ancestor = ancestor;
  58. this.ancestorParent = ancestorParent;
  59. }
  60. /**
  61. * Returns the ancestor that the event actually occured on.
  62. */
  63. public Container getAncestor() {
  64. return ancestor;
  65. }
  66. /**
  67. * Returns the parent of the ancestor the event actually occured on.
  68. * This is most interesting in an ANCESTOR_REMOVED event, as
  69. * the ancestor may no longer be in the component hierarchy.
  70. */
  71. public Container getAncestorParent() {
  72. return ancestorParent;
  73. }
  74. /**
  75. * Returns the component that the listener was added to.
  76. */
  77. public JComponent getComponent() {
  78. return (JComponent)getSource();
  79. }
  80. }