You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by no...@apache.org on 2011/08/04 14:37:00 UTC

svn commit: r1153866 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk: Component.java Container.java WTKListenerList.java

Author: noelgrandin
Date: Thu Aug  4 12:37:00 2011
New Revision: 1153866

URL: http://svn.apache.org/viewvc?rev=1153866&view=rev
Log:
PIVOT-780 Can't use BXMLSerializer from non-AWT threads makes background resource loading impossible
make the EDT checker tolerant of constructing WTK hierarchies from outside the event thread

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/WTKListenerList.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java?rev=1153866&r1=1153865&r2=1153866&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java Thu Aug  4 12:37:00 2011
@@ -1922,7 +1922,7 @@ public abstract class Component implemen
      * preferred size.
      */
     public void invalidate() {
-        Container.assertEventDispatchThread();
+        Container.assertEventDispatchThread(this);
         valid = false;
 
         // Clear the preferred size and baseline
@@ -2014,7 +2014,7 @@ public abstract class Component implemen
      * @param immediate
      */
     public void repaint(int x, int y, int width, int height, boolean immediate) {
-        Container.assertEventDispatchThread();
+        Container.assertEventDispatchThread(this);
         if (parent != null) {
             // Constrain the repaint area to this component's bounds
             int top = y;

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java?rev=1153866&r1=1153865&r2=1153866&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java Thu Aug  4 12:37:00 2011
@@ -844,8 +844,16 @@ public abstract class Container extends 
         return containerMouseListeners;
     }
 
-    private static Runnable EDT_CHECKER = new Runnable() {
-        public void run() {
+    public interface EDT_Checker {
+        public void check(Component component);
+    }
+
+    protected final void assertEventDispatchThread() {
+        assertEventDispatchThread(this);
+    }
+
+    private static EDT_Checker EDT_CHECKER = new EDT_Checker() {
+        public void check(Component component) {
             String threadName = Thread.currentThread().getName();
             /* Currently, application startup happens on the main thread, so we need to allow
              * that thread to modify WTK state.
@@ -853,6 +861,10 @@ public abstract class Container extends 
             if (threadName.equals("main") || threadName.equals("javawsApplicationMain")) {
                 return;
             }
+            // Allow components to be constructed from outside the event thread
+            if (component.getDisplay() == null) {
+                return;
+            }
             /*
              * See Sun/Oracle bug 6424157. There is a race condition where we can be running on the event thread
              * but isDispatchThread() will return false.
@@ -866,13 +878,13 @@ public abstract class Container extends 
         }
     };
 
-    public static final void assertEventDispatchThread() {
+    public static final void assertEventDispatchThread(Component component) {
         if (EDT_CHECKER != null) {
-            EDT_CHECKER.run();
+            EDT_CHECKER.check(component);
         }
     }
 
-    public static final void setEventDispatchThreadChecker(Runnable runnable) {
+    public static final void setEventDispatchThreadChecker(EDT_Checker runnable) {
         EDT_CHECKER = runnable;
     }
 }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/WTKListenerList.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/WTKListenerList.java?rev=1153866&r1=1153865&r2=1153866&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/WTKListenerList.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/WTKListenerList.java Thu Aug  4 12:37:00 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.pivot.wtk;
 
-import java.util.Iterator;
-
 import org.apache.pivot.util.ListenerList;
 
 /**
@@ -25,58 +23,4 @@ import org.apache.pivot.util.ListenerLis
  * for the WTK components.
  */
 public class WTKListenerList<T> extends ListenerList<T> {
-
-    /**
-     * Adds a listener to the list, if it has not previously been added.
-     *
-     * @param listener
-     */
-    @Override
-    public void add(T listener) {
-        Container.assertEventDispatchThread();
-        super.add(listener);
-    }
-
-    /**
-     * Removes a listener from the list, if it has previously been added.
-     *
-     * @param listener
-     */
-    @Override
-    public void remove(T listener) {
-        Container.assertEventDispatchThread();
-        super.remove(listener);
-    }
-
-    /**
-     * Tests the existence of a listener in the list.
-     *
-     * @param listener
-     *
-     * @return <tt>true</tt> if the listener exists in the list; <tt>false</tt>,
-     *         otherwise.
-     */
-    @Override
-    public boolean contains(T listener) {
-        Container.assertEventDispatchThread();
-        return super.contains(listener);
-    }
-
-    /**
-     * Tests the emptiness of the list.
-     *
-     * @return <tt>true</tt> if the list contains no listeners; <tt>false</tt>,
-     *         otherwise.
-     */
-    @Override
-    public boolean isEmpty() {
-        Container.assertEventDispatchThread();
-        return super.isEmpty();
-    }
-
-    @Override
-    public Iterator<T> iterator() {
-        Container.assertEventDispatchThread();
-        return super.iterator();
-    }
 }