[kaffe] CVS kaffe (guilhem): kaffe xlib-awt fixlets

Kaffe CVS cvs-commits at kaffe.org
Sun Nov 19 13:33:04 PST 2006


PatchSet 7450 
Date: 2006/11/19 21:32:12
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
kaffe xlib-awt fixlets

	*
	libraries/javalib/awt-implementations/kaffe/java/awt/Component.java
	(dispatchEventImpl): Imported GNU Classpath's logic. Use event
	dispatcher to process the event.

	*
	libraries/javalib/awt-implementations/kaffe/java/awt/EventDispatchThread.java:
	Large code importation from GNU Classpath. First try to dispatch
	to FocusManager and then dispatch explicitly to the destination.

	*
	libraries/javalib/awt-implementations/kaffe/java/awt/KeyEvt.java
	(dispatch) Dispatch the synthetic event first through the FocusManager and
	then directly to the destination.

	*
	libraries/javalib/awt-implementations/kaffe/java/awt/MenuComponent.java:
	(dispatchEventImpl): New internal method. It calls directly
	AWTEvent.dispatch()
	(dispatchEvent): Delegate to dispatchEventImpl.

Members: 
	ChangeLog:1.4950->1.4951 
	libraries/javalib/awt-implementations/kaffe/java/awt/Component.java:1.19->1.20 
	libraries/javalib/awt-implementations/kaffe/java/awt/EventDispatchThread.java:1.1->1.2 
	libraries/javalib/awt-implementations/kaffe/java/awt/KeyEvt.java:1.1->1.2 
	libraries/javalib/awt-implementations/kaffe/java/awt/MenuComponent.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4950 kaffe/ChangeLog:1.4951
--- kaffe/ChangeLog:1.4950	Sun Nov 19 18:31:38 2006
+++ kaffe/ChangeLog	Sun Nov 19 21:32:12 2006
@@ -1,3 +1,27 @@
+2006-11-19  Guilhem Lavaux  <guilhem at kaffe.org>,
+	Riccardo Mottola <riccardo at kaffe.org>
+
+	*
+	libraries/javalib/awt-implementations/kaffe/java/awt/Component.java
+	(dispatchEventImpl): Imported GNU Classpath's logic. Use event
+	dispatcher to process the event.
+
+	*
+	libraries/javalib/awt-implementations/kaffe/java/awt/EventDispatchThread.java:
+	Large code importation from GNU Classpath. First try to dispatch 
+	to FocusManager and then dispatch explicitly to the destination.
+	
+	*
+	libraries/javalib/awt-implementations/kaffe/java/awt/KeyEvt.java
+	(dispatch) Dispatch the synthetic event first through the FocusManager and
+	then directly to the destination.
+	
+	*
+	libraries/javalib/awt-implementations/kaffe/java/awt/MenuComponent.java:
+	(dispatchEventImpl): New internal method. It calls directly
+	AWTEvent.dispatch()
+	(dispatchEvent): Delegate to dispatchEventImpl.
+
 2006-11-19  Dalibor Topic  <robilad at kaffe.org>
 
 	* kaffe/kaffevm/boehm-gc/gc-refs.c (KaffeGC_rmRef),
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java:1.19 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java:1.20
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java:1.19	Fri Nov 10 17:20:05 2006
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java	Sun Nov 19 21:32:12 2006
@@ -1221,45 +1221,26 @@
 {
     // This boolean tells us not to process focus events when the focus
     // opposite component is the same as the focus component.
-    boolean ignoreFocus =
-    (e instanceof FocusEvent &&
-     ((FocusEvent)e).getComponent() == ((FocusEvent)e).getOppositeComponent());
-
-    if (eventTypeEnabled (e.id))
-    {
-        if (e.id != PaintEvent.PAINT && e.id != PaintEvent.UPDATE
-            && !ignoreFocus)
-            processEvent(e);
-
-        // the trick we use to communicate between dispatch and redispatch
-        // is to have KeyboardFocusManager.redispatch synchronize on the
-        // object itself. we then do not redispatch to KeyboardFocusManager
-        // if we are already holding the lock.
-        if (! Thread.holdsLock(e))
-        {
-            switch (e.id)
-            {
-                case WindowEvent.WINDOW_GAINED_FOCUS:
-                case WindowEvent.WINDOW_LOST_FOCUS:
-                case KeyEvent.KEY_PRESSED:
-                case KeyEvent.KEY_RELEASED:
-                case KeyEvent.KEY_TYPED:
-                case FocusEvent.FOCUS_GAINED:
-                case FocusEvent.FOCUS_LOST:
-                    if (KeyboardFocusManager
-                        .getCurrentKeyboardFocusManager()
-                        .dispatchEvent(e))
-                        return;
-                case MouseEvent.MOUSE_PRESSED:
-                    if (isLightweight() && !e.isConsumed())
-                        requestFocus();
-                    break;
-            }
-        }
-    }
-
-    // here we differ from classpath since we have no peers
-    e.dispatch();
+    // Retarget focus events before dispatching it to the KeyboardFocusManager
+    // in order to handle lightweight components properly.
+    boolean dispatched = false;
+    if (! e.isFocusManagerEvent)
+      {
+ 	e = KeyboardFocusManager.retargetFocusEvent(e);
+	dispatched = KeyboardFocusManager.getCurrentKeyboardFocusManager()
+	    .dispatchEvent(e);
+      }
+	
+    if (! dispatched)
+      {
+	if (eventTypeEnabled (e.id))
+	    {
+		if (e.id != PaintEvent.PAINT && e.id != PaintEvent.UPDATE)
+		processEvent(e);
+	    }
+	// here we differ from classpath since we have no peers
+	e.dispatch();
+      }
 }
 
 
@@ -2950,7 +2931,7 @@
             Window toplevel = (Window) parent;
 // we can't check for that or  choice windows won't get focus
 //            if (toplevel.isFocusableWindow ())
-//            {
+            {
                 //if (peer != null && !isLightweight()) { // we don't have a peer
                 if (!isLightweight()) {
                     // This call will cause a FOCUS_GAINED event to be
@@ -2985,9 +2966,9 @@
                             eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false));
                     }
                 }
-            //}
-            //else
-            //    pendingFocusRequest = new FocusEvent(this, FocusEvent.FOCUS_GAINED);
+	    }
+	    //	    else
+	    //		pendingFocusRequest = new FocusEvent(this, FocusEvent.FOCUS_GAINED);
     }
     }
 }
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/EventDispatchThread.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/EventDispatchThread.java:1.1 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/EventDispatchThread.java:1.2
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/EventDispatchThread.java:1.1	Thu Jul 22 19:19:31 2004
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/EventDispatchThread.java	Sun Nov 19 21:32:12 2006
@@ -8,20 +8,45 @@
  * See the file "license.terms" for information on usage and redistribution
  * of this file.
  * @author P.C.Mehlitz
+ * @author Bryce McKinlay
+ * @author Riccardo Mottola
  */
 class EventDispatchThread
   extends Thread
 {
-	boolean stop;
-	EventQueue queue;
-
-EventDispatchThread ( EventQueue queue ) {
-	super( "AWT-EventQueue-0" ); // some apps depend on this JDK thread name
-
-	this.queue = queue;
-
-	setPriority( Thread.NORM_PRIORITY + 1);
-}
+  /**
+   * The default priority when no property has been set.
+   */
+  private static final int DEFAULT_PRIORITY = NORM_PRIORITY + 1;
+
+  private static int dispatchThreadNum;
+
+  private EventQueue queue;
+  
+  boolean stop;
+
+  EventDispatchThread(EventQueue queue)
+  {
+    super();
+    setName("AWT-EventQueue-" + ++dispatchThreadNum);
+    this.queue = queue;
+
+    int priority = DEFAULT_PRIORITY;
+    try
+      {
+        String priorityString =
+          System.getProperty("gnu.awt.dispatchthread.priority");
+        if (priorityString != null)
+          {
+            priority = Integer.parseInt(priorityString); 
+          }      
+      }
+    catch (NumberFormatException ex)
+      {
+        // Ignore and use default.
+      }
+    setPriority(priority);
+  }
 
 public void run () {
 	AWTEvent e;
@@ -29,26 +54,37 @@
 	while ( !stop ) {
 		// the inner loop protects us from being disrupted by
 		// an exception (we should continue to dispatch as long as possible)
-		try {
-			while ( !stop ) {			
-				if ( (e = queue.getNextEvent()) != null ){
-					e.dispatch();
-				}
-			}
-		}
-		catch ( SecurityException sx ) {
-			if ( "system_exit".equals( sx.getMessage()) ) {
-				// this is from our KaffeServer SecurityManager, ignore
-			}
-			else {
-				Toolkit.tlkBeep();
-				sx.printStackTrace( System.err);
-			}
-		}
-		catch ( Throwable x ) {
-			Toolkit.tlkBeep();
-			x.printStackTrace( System.err);
-		}
+        try
+	{
+	  AWTEvent evt = queue.getNextEvent();
+
+          KeyboardFocusManager manager;
+          manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
+
+          // Try to dispatch this event to the current keyboard focus
+          // manager.  It will dispatch all FocusEvents, all
+          // WindowEvents related to focus, and all KeyEvents,
+          // returning true.  Otherwise, it returns false and we
+          // dispatch the event normally.
+          if (!manager.dispatchEvent (evt))
+	    queue.dispatchEvent(evt);
+	}
+        catch (ThreadDeath death)
+        {
+          // If someone wants to kill us, let them.
+          return;
+        }
+	catch (InterruptedException ie)
+	{
+	  // We are interrupted when we should finish executing
+	  return;
+	}
+	catch (Throwable x)
+	{
+	  System.err.println("Exception during event dispatch:");
+	  x.printStackTrace(System.err);
+	}
+
 	}
 }
 
@@ -70,31 +106,39 @@
 		while ( !stop ) {
 			// the inner loop protects us from being disrupted by
 			// an exception (we should continue to dispatch as long as possible)
-			try {
-				while ( !stop ) {			
-					if ( (e = queue.getNextEvent()) != null ){
-						e.dispatch();
-						// this is better than to rely on a WINDOW_CLOSED, since we can
-						// save postEvents AND make dispatching faster
-						if ( (modalWindow.flags & Component.IS_ADD_NOTIFIED) == 0 ){
-							return;
-						}
-					}
-				}
-			}
-			catch ( SecurityException sx ) {
-				if ( "system_exit".equals( sx.getMessage()) ) {
-					// this is from our KaffeServer SecurityManager, ignore
-				}
-				else {
-					sx.printStackTrace( System.err);
-				}
-			}
-			catch ( Throwable x ) {
-				x.printStackTrace( System.err);
-			}
-		}
+			        try
+	{
+	  AWTEvent evt = queue.getNextEvent();
+
+          KeyboardFocusManager manager;
+          manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
+
+          // Try to dispatch this event to the current keyboard focus
+          // manager.  It will dispatch all FocusEvents, all
+          // WindowEvents related to focus, and all KeyEvents,
+          // returning true.  Otherwise, it returns false and we
+          // dispatch the event normally.
+          if (!manager.dispatchEvent (evt))
+	    queue.dispatchEvent(evt);
 	}
+        catch (ThreadDeath death)
+        {
+          // If someone wants to kill us, let them.
+          return;
+        }
+	catch (InterruptedException ie)
+	{
+	  // We are interrupted when we should finish executing
+	  return;
+	}
+	catch (Throwable x)
+	{
+	  System.err.println("Exception during event dispatch:");
+	  x.printStackTrace(System.err);
+	}
+
+}
+}
 }
 
 public void stopDispatching () {
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/KeyEvt.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/KeyEvt.java:1.1 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/KeyEvt.java:1.2
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/KeyEvt.java:1.1	Thu Jul 22 19:19:32 2004
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/KeyEvt.java	Sun Nov 19 21:32:12 2006
@@ -39,7 +39,9 @@
 				if ( keyChar != 0 ) {         // printable key
 					if ( AWTEvent.keyTgt != null ) {     // maybe a fast finger pulled the keyTgt under our feet
 						KeyEvt typedEvt = getEvent((Component)source, KEY_TYPED, 0, keyChar, modifiers);
-						AWTEvent.keyTgt.process(typedEvt);
+						
+						if (!KeyboardFocusManager.getCurrentKeyboardFocusManager ().dispatchEvent(typedEvt))
+						  AWTEvent.keyTgt.process(typedEvt);
 					}
 				}
 			}
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/MenuComponent.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/MenuComponent.java:1.2 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/MenuComponent.java:1.3
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/MenuComponent.java:1.2	Fri Nov 10 15:31:26 2006
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/MenuComponent.java	Sun Nov 19 21:32:12 2006
@@ -29,6 +29,11 @@
 }
 
 final public void dispatchEvent( AWTEvent e) {
+	dispatchEventImpl(e);
+}
+
+void dispatchEventImpl (AWTEvent e) {
+	e.dispatch();
 }
 
 ClassProperties getClassProperties () {




More information about the kaffe mailing list