foxtrot.utils
Class FlushJob

java.lang.Object
  extended by foxtrot.Task
      extended by foxtrot.Job
          extended by foxtrot.utils.FlushJob

public class FlushJob
extends Job

This job flushes all pending AWT events that are waiting in the EventQueue.
For example, imagine a complex GUI that displays different components on the same container (a single document user interface). The GUI has mechanisms to close one component and then open another one (for example clicking on a menu item of a menubar or a popup menu, or clicking on a toolbar button). If opening a component is a lenghty operation that must run in the EventDispatchThread, then the GUI freezes: the menu remains open (or the toolbar button pressed) and repaints do not happen until the lengthy operation of opening the new component is finished.
FlushJob can be used to avoid this freezing:

 public void actionPerformed(ActionEvent e)
 {
     // First step: close the current component (quick operation);
     // this removes it from its container, so that the GUI is now empty.
     closeCurrentComponent();
 

// Second step: flush events. At this point in the EventQueue there // may be repaint events for the menu (or the button), and repaint events // for the container (which should repaint an empty GUI, since the component // has been removed in the previous step) Worker.post(new FlushJob());

// After flushing the events, the user sees that the previous component // has been removed (sees that the GUI is empty). // Menus have been closed (or buttons repainted in non-pressed state), // time to open the new component (lengthy operation). loadComponent(); }

Version:
$Revision: 255 $

Constructor Summary
FlushJob()
           
 
Method Summary
 Object run()
          The method to implement with time-consuming code.
 
Methods inherited from class foxtrot.Task
getResultOrThrow, isCompleted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FlushJob

public FlushJob()
Method Detail

run

public Object run()
Description copied from class: Job
The method to implement with time-consuming code. It should NOT be synchronized or synchronize on this Job instance, otherwise the AWT Event Dispatch Thread cannot efficiently test when this Job is completed. Overridden to remove the throws clause, so that users does not have to catch unthrown exceptions.

Specified by:
run in class Job


Copyright © 2011 KnowledgePlaza. All Rights Reserved.