XEventQueue.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright (C) 2000 Free Software Foundation
  2. This file is part of libgcj.
  3. This software is copyrighted work licensed under the terms of the
  4. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  5. details. */
  6. package gnu.awt.xlib;
  7. import gnu.gcj.xlib.Display;
  8. import java.awt.AWTEvent;
  9. import java.awt.Component;
  10. import java.awt.Container;
  11. import java.awt.EventQueue;
  12. import java.awt.event.ComponentEvent;
  13. import java.awt.event.ContainerEvent;
  14. /**
  15. * The main difference here from a standard EventQueue is that the X
  16. * display connection is flushed before waiting for more events.
  17. */
  18. public class XEventQueue extends EventQueue
  19. {
  20. Display display;
  21. public XEventQueue(Display display)
  22. {
  23. this.display = display;
  24. }
  25. public AWTEvent getNextEvent() throws InterruptedException
  26. {
  27. if ((peekEvent() == null) && (display != null))
  28. display.flush();
  29. AWTEvent event = super.getNextEvent();
  30. if (event != null)
  31. {
  32. switch (event.getID ())
  33. {
  34. case ContainerEvent.COMPONENT_ADDED:
  35. {
  36. /* If a component has been added to a container, it needs to be
  37. * invalidated, to ensure that it ultimately gets an addNotify.
  38. * If it's not invalidated, the component will never display in
  39. * an already-showing container (probably applies only to CardLayout).
  40. * Perhaps this code should be in java.awt, but the problem only seems
  41. * to happen with xlib peers (not with gtk peers) so it's here instead.
  42. */
  43. ContainerEvent ce = (ContainerEvent)event;
  44. ce.getChild ().invalidate ();
  45. ce.getContainer ().validate ();
  46. }
  47. break;
  48. case ComponentEvent.COMPONENT_RESIZED:
  49. {
  50. ComponentEvent ce = (ComponentEvent)event;
  51. // FIXME: there may be opportunities to coalesce resize events
  52. ce.getComponent ().validate ();
  53. }
  54. break;
  55. case ComponentEvent.COMPONENT_SHOWN:
  56. {
  57. ComponentEvent ce = (ComponentEvent)event;
  58. Component comp = ce.getComponent ();
  59. if (!comp.isValid ())
  60. {
  61. /* Try to validate, going up the tree to the highest-level invalid
  62. * Container. The idea is to ensure that addNotify gets called for
  63. * any non-top-level component being shown, to make it create a peer.
  64. */
  65. Container parent = comp.getParent ();
  66. while (parent != null)
  67. {
  68. Container next = parent.getParent ();
  69. if (next == null || next.isValid ())
  70. {
  71. parent.validate ();
  72. break;
  73. }
  74. else
  75. parent = next;
  76. }
  77. if (comp instanceof Container)
  78. comp.validate ();
  79. }
  80. comp.repaint ();
  81. }
  82. break;
  83. default:
  84. break;
  85. }
  86. }
  87. return event;
  88. }
  89. }