rollback of #79406 fix, it is breaking qa tests for some reason dev_suite_removal2_root
authordsimonek@netbeans.org
Tue, 05 Dec 2006 17:43:27 +0000
changeset 243865a2b58704d
parent 242 3d04a4ffe74a
child 244 7a50f5d982bc
rollback of #79406 fix, it is breaking qa tests for some reason
openide.util/src/org/openide/util/AsyncInitSupport.java
openide.util/test/unit/src/org/openide/util/InitJobTest.java
     1.1 --- a/openide.util/src/org/openide/util/AsyncInitSupport.java	Tue Dec 05 10:56:46 2006 +0000
     1.2 +++ b/openide.util/src/org/openide/util/AsyncInitSupport.java	Tue Dec 05 17:43:27 2006 +0000
     1.3 @@ -19,11 +19,15 @@
     1.4  
     1.5  package org.openide.util;
     1.6  
     1.7 +import java.awt.AWTEvent;
     1.8  import java.awt.Component;
     1.9 +import java.awt.Toolkit;
    1.10 +import java.awt.event.AWTEventListener;
    1.11  import java.awt.event.ActionEvent;
    1.12  import java.awt.event.ActionListener;
    1.13  import java.awt.event.HierarchyEvent;
    1.14  import java.awt.event.HierarchyListener;
    1.15 +import javax.swing.RepaintManager;
    1.16  import javax.swing.SwingUtilities;
    1.17  import javax.swing.Timer;
    1.18  
    1.19 @@ -37,7 +41,7 @@
    1.20   *
    1.21   * @author Dafe Simonek
    1.22   */
    1.23 -final class AsyncInitSupport implements HierarchyListener, Runnable, ActionListener {
    1.24 +final class AsyncInitSupport implements AWTEventListener, HierarchyListener, Runnable, ActionListener {
    1.25      /** lock for access to wasCancelled flag */
    1.26      private static final Object CANCELLED_LOCK = new Object();
    1.27  
    1.28 @@ -62,11 +66,20 @@
    1.29      public AsyncInitSupport(Component comp4Init, AsyncGUIJob initJob) {
    1.30          this.comp4Init = comp4Init;
    1.31          this.initJob = initJob;
    1.32 +
    1.33          if (comp4Init.isShowing()) {
    1.34              throw new IllegalStateException("Component already shown, can't be inited: " + comp4Init);
    1.35          }
    1.36  
    1.37 +        Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.PAINT_EVENT_MASK);
    1.38          comp4Init.addHierarchyListener(this);
    1.39 +
    1.40 +        if (!RepaintManager.currentManager(comp4Init).isDoubleBufferingEnabled()) {
    1.41 +            //We're running with hardware double buffering - cannot rely on an
    1.42 +            //AWT PaintEvent to start the job running - on mac, it will never come
    1.43 +            timer = new Timer(20, this);
    1.44 +            timer.start();
    1.45 +        }
    1.46      }
    1.47  
    1.48      public void actionPerformed(ActionEvent ae) {
    1.49 @@ -83,6 +96,18 @@
    1.50          }
    1.51      }
    1.52  
    1.53 +    /** Invokes execution of init code in non-ED thread.
    1.54 +     * @param evt ignored
    1.55 +     */
    1.56 +    public void eventDispatched(AWTEvent event) {
    1.57 +        if (
    1.58 +            event.getSource() instanceof Component &&
    1.59 +                SwingUtilities.isDescendingFrom(comp4Init, (Component) (event.getSource()))
    1.60 +        ) {
    1.61 +            start();
    1.62 +        }
    1.63 +    }
    1.64 +
    1.65      private void start() {
    1.66          detach();
    1.67  
    1.68 @@ -95,22 +120,18 @@
    1.69          if (timer != null) {
    1.70              timer.stop();
    1.71          }
    1.72 +
    1.73 +        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    1.74      }
    1.75  
    1.76 -    /** Starts init job with delay when component shown,
    1.77 -     * stops listening to asociated component it isn't showing anymore,
    1.78 +    /** Stops listening to asociated component it isn't showing anymore,
    1.79       * calls cancel if desirable.
    1.80       * @param evt hierarchy event
    1.81       */
    1.82      public void hierarchyChanged(HierarchyEvent evt) {
    1.83 -        if (((evt.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0)) {
    1.84 -            if (comp4Init.isShowing()) {
    1.85 -                timer = new Timer(20, this);
    1.86 -                timer.start();
    1.87 -            } else {
    1.88 -                comp4Init.removeHierarchyListener(this);
    1.89 -                cancel();
    1.90 -            }
    1.91 +        if (((evt.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) && !comp4Init.isShowing()) {
    1.92 +            comp4Init.removeHierarchyListener(this);
    1.93 +            cancel();
    1.94          }
    1.95      }
    1.96  
    1.97 @@ -151,5 +172,4 @@
    1.98              ((Cancellable) initJob).cancel();
    1.99          }
   1.100      }
   1.101 -    
   1.102  }
     2.1 --- a/openide.util/test/unit/src/org/openide/util/InitJobTest.java	Tue Dec 05 10:56:46 2006 +0000
     2.2 +++ b/openide.util/test/unit/src/org/openide/util/InitJobTest.java	Tue Dec 05 17:43:27 2006 +0000
     2.3 @@ -47,8 +47,6 @@
     2.4      Thread edThread;
     2.5      /** test component */
     2.6      SimpleInitComp comp;
     2.7 -    /** parent, main frame */
     2.8 -    private Frame frame;
     2.9      
    2.10      /** Creates a new instance of UtilProgressCursorTest */
    2.11      public InitJobTest(String testName) {
    2.12 @@ -64,30 +62,24 @@
    2.13       * impl conforms to the API behaviour described in javadoc *
    2.14       */
    2.15      public void testInitJob() throws Exception {
    2.16 -        System.out.println("Testing simple init job run");
    2.17          initializeSimple();
    2.18          comp = new SimpleInitComp();
    2.19          Utilities.attachInitJob(comp, comp);
    2.20 -        frame = new Frame();
    2.21 -        frame.setSize(100, 100);
    2.22 -        frame.setVisible(true);
    2.23 -        dlg = new Dialog(frame, true);
    2.24 -        dlg.setSize(50, 50);
    2.25 +        Frame f = new Frame();
    2.26 +        f.setVisible(true);
    2.27 +        dlg = new Dialog(f, true);
    2.28          dlg.add(comp);
    2.29          dlg.setVisible(true);
    2.30      }
    2.31      
    2.32      public void testCancelAbility() throws Exception {
    2.33 -        System.out.println("Testing cancel ability of async init job");
    2.34          initializeSimple();
    2.35          initCancelResults();
    2.36          CancelInitComp comp = new CancelInitComp();
    2.37          Utilities.attachInitJob(comp, comp);
    2.38 -        frame = new Frame();
    2.39 -        frame.setSize(100, 100);
    2.40 -        frame.setVisible(true);
    2.41 -        dlg = new Dialog(frame, true);
    2.42 -        dlg.setSize(50, 50);
    2.43 +        Frame f = new Frame();
    2.44 +        f.setVisible(true);
    2.45 +        dlg = new Dialog(f, true);
    2.46          dlg.add(comp);
    2.47          dlg.setVisible(true);
    2.48      }
    2.49 @@ -185,7 +177,6 @@
    2.50          }
    2.51      }
    2.52      
    2.53 -    /** Disposer of windows */
    2.54      private final class TimerListener implements ActionListener {
    2.55          /** true for cancel test, false otherwise */
    2.56          private boolean cancel;
    2.57 @@ -194,7 +185,6 @@
    2.58          }
    2.59          public void actionPerformed(ActionEvent e) {
    2.60              dlg.dispose();
    2.61 -            frame.dispose();
    2.62              if (cancel) {
    2.63                  checkCancelResults();
    2.64              } else {