#79406: async init fixed on JDK 1.6, it doesn't rely on paint event anymore. tests upgraded.
1.1 --- a/openide.util/src/org/openide/util/AsyncInitSupport.java Wed Nov 29 17:53:19 2006 +0000
1.2 +++ b/openide.util/src/org/openide/util/AsyncInitSupport.java Tue Dec 05 10:56:46 2006 +0000
1.3 @@ -19,15 +19,11 @@
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 @@ -41,7 +37,7 @@
1.20 *
1.21 * @author Dafe Simonek
1.22 */
1.23 -final class AsyncInitSupport implements AWTEventListener, HierarchyListener, Runnable, ActionListener {
1.24 +final class AsyncInitSupport implements 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 @@ -66,20 +62,11 @@
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 @@ -96,18 +83,6 @@
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 @@ -120,18 +95,22 @@
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 - /** Stops listening to asociated component it isn't showing anymore,
1.77 + /** Starts init job with delay when component shown,
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) && !comp4Init.isShowing()) {
1.84 - comp4Init.removeHierarchyListener(this);
1.85 - cancel();
1.86 + if (((evt.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0)) {
1.87 + if (comp4Init.isShowing()) {
1.88 + timer = new Timer(20, this);
1.89 + timer.start();
1.90 + } else {
1.91 + comp4Init.removeHierarchyListener(this);
1.92 + cancel();
1.93 + }
1.94 }
1.95 }
1.96
1.97 @@ -172,4 +151,5 @@
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 Wed Nov 29 17:53:19 2006 +0000
2.2 +++ b/openide.util/test/unit/src/org/openide/util/InitJobTest.java Tue Dec 05 10:56:46 2006 +0000
2.3 @@ -47,6 +47,8 @@
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 @@ -62,24 +64,30 @@
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 f = new Frame();
2.21 - f.setVisible(true);
2.22 - dlg = new Dialog(f, true);
2.23 + frame = new Frame();
2.24 + frame.setSize(100, 100);
2.25 + frame.setVisible(true);
2.26 + dlg = new Dialog(frame, true);
2.27 + dlg.setSize(50, 50);
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 f = new Frame();
2.39 - f.setVisible(true);
2.40 - dlg = new Dialog(f, true);
2.41 + frame = new Frame();
2.42 + frame.setSize(100, 100);
2.43 + frame.setVisible(true);
2.44 + dlg = new Dialog(frame, true);
2.45 + dlg.setSize(50, 50);
2.46 dlg.add(comp);
2.47 dlg.setVisible(true);
2.48 }
2.49 @@ -177,6 +185,7 @@
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 @@ -185,6 +194,7 @@
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 {