1. /*
  2. * @(#)SentEvent.java 1.6 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 java.awt;
  8. import java.awt.AWTEvent;
  9. import java.awt.ActiveEvent;
  10. import sun.awt.AppContext;
  11. import sun.awt.SunToolkit;
  12. /**
  13. * A wrapping tag for a nested AWTEvent which indicates that the event was
  14. * sent from another AppContext. The destination AppContext should handle the
  15. * event even if it is currently blocked waiting for a SequencedEvent or
  16. * another SentEvent to be handled.
  17. *
  18. * @version 1.6, 12/19/03
  19. * @author David Mendenhall
  20. */
  21. class SentEvent extends AWTEvent implements ActiveEvent {
  22. static final int ID =
  23. java.awt.event.FocusEvent.FOCUS_LAST + 2;
  24. boolean dispatched;
  25. private AWTEvent nested;
  26. private AppContext toNotify;
  27. SentEvent() {
  28. this(null);
  29. }
  30. SentEvent(AWTEvent nested) {
  31. this(nested, null);
  32. }
  33. SentEvent(AWTEvent nested, AppContext toNotify) {
  34. super((nested != null)
  35. ? nested.getSource()
  36. : Toolkit.getDefaultToolkit(),
  37. ID);
  38. this.nested = nested;
  39. this.toNotify = toNotify;
  40. }
  41. public void dispatch() {
  42. try {
  43. if (nested != null) {
  44. Toolkit.getEventQueue().dispatchEvent(nested);
  45. }
  46. } finally {
  47. dispatched = true;
  48. if (toNotify != null) {
  49. SunToolkit.postEvent(toNotify, new SentEvent());
  50. }
  51. synchronized (this) {
  52. notifyAll();
  53. }
  54. }
  55. }
  56. final void dispose() {
  57. dispatched = true;
  58. if (toNotify != null) {
  59. SunToolkit.postEvent(toNotify, new SentEvent());
  60. }
  61. synchronized (this) {
  62. notifyAll();
  63. }
  64. }
  65. }