[kaffe] CVS kaffe (riccardo): awt update

Kaffe CVS cvs-commits at kaffe.org
Thu Mar 30 14:50:03 PST 2006


PatchSet 7203 
Date: 2006/03/30 22:17:42
Author: riccardo
Branch: HEAD
Tag: (none) 
Log:
awt update

Members: 
	ChangeLog:1.4710->1.4711 
	libraries/javalib/awt-implementations/kaffe/java/awt/AWTEvent.java:1.4->1.5 
	libraries/javalib/awt-implementations/kaffe/java/awt/Toolkit.java:1.4->1.5 
	libraries/javalib/awt-implementations/kaffe/java/awt/event/WindowEvent.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4710 kaffe/ChangeLog:1.4711
--- kaffe/ChangeLog:1.4710	Thu Mar 30 17:39:12 2006
+++ kaffe/ChangeLog	Thu Mar 30 22:17:42 2006
@@ -1,3 +1,10 @@
+2006-03-31  Riccardo Mottola  <riccardo at kaffe.org>
+
+	* libraries/javalib/awt-implementations/kaffe/java/awt/AWTEvent.java,
+	libraries/javalib/awt-implementations/kaffe/java/awt/Toolkit.java,
+	libraries/javalib/awt-implementations/kaffe/java/awt/event/WindowEvent.java:
+	Updated AWT implementation by importing 1.3/1.4 stuff from classpath
+
 2006-03-28  Guilhem Lavaux  <guilhem at kaffe.org>
 
 	* kaffe/kaffeh/main.c
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/AWTEvent.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/AWTEvent.java:1.4 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/AWTEvent.java:1.5
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/AWTEvent.java:1.4	Wed Oct 19 20:10:48 2005
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/AWTEvent.java	Thu Mar 30 22:14:11 2006
@@ -1,6 +1,18 @@
 package java.awt;
 
+import java.awt.event.ActionEvent;
 import java.awt.event.MouseEvent;
+import java.awt.event.ComponentEvent;
+import java.awt.event.PaintEvent;
+import java.awt.event.WindowEvent;
+import java.awt.event.TextEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.ContainerEvent;
+import java.awt.event.InvocationEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.KeyEvent;
 import java.util.EventObject;
 
 import org.kaffe.awt.FocusHook;
@@ -26,19 +38,49 @@
 	protected boolean consumed;
 	protected AWTEvent next;
 	final private static long serialVersionUID = -1825314779160409405L;
-	final public static long COMPONENT_EVENT_MASK = 0x01;
-	final public static long CONTAINER_EVENT_MASK = 0x02;
-	final public static long FOCUS_EVENT_MASK = 0x04;
-	final public static long KEY_EVENT_MASK = 0x08;
-	final public static long MOUSE_EVENT_MASK = 0x10;
-	final public static long MOUSE_MOTION_EVENT_MASK = 0x20;
-	final public static long WINDOW_EVENT_MASK = 0x40;
-	final public static long ACTION_EVENT_MASK = 0x80;
-	final public static long ADJUSTMENT_EVENT_MASK = 0x100;
-	final public static long ITEM_EVENT_MASK = 0x200;
-	final public static long TEXT_EVENT_MASK = 0x400;
+	public static final long COMPONENT_EVENT_MASK = 0x01;
+	public static final long CONTAINER_EVENT_MASK = 0x02;
+	public static final long FOCUS_EVENT_MASK = 0x04;
+	public static final long KEY_EVENT_MASK = 0x08;
+	public static final long MOUSE_EVENT_MASK = 0x10;
+	public static final long MOUSE_MOTION_EVENT_MASK = 0x20;
+	public static final long WINDOW_EVENT_MASK = 0x40;
+	public static final long ACTION_EVENT_MASK = 0x80;
+	public static final long ADJUSTMENT_EVENT_MASK = 0x100;
+	public static final long ITEM_EVENT_MASK = 0x200;
+	public static final long TEXT_EVENT_MASK = 0x400;
         public static final long INPUT_METHOD_EVENT_MASK = 0x800;
-	final public static int RESERVED_ID_MAX = 1999;
+	public static final int RESERVED_ID_MAX = 1999;
+	  /**
+   * Mask for paint events.
+   * @since 1.3
+   */
+  public static final long PAINT_EVENT_MASK = 0x02000;
+
+  /**
+   * Mask for invocation events.
+   * @since 1.3
+   */
+  public static final long INVOCATION_EVENT_MASK = 0x04000;
+  
+    /**
+   * Mask for mouse wheel events.
+   * @since 1.4
+   */
+  public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000;
+
+  /**
+   * Mask for window state events.
+   * @since 1.4
+   */
+  public static final long WINDOW_STATE_EVENT_MASK = 0x40000;
+  
+    /**
+   * Mask for window focus events.
+   * @since 1.4
+   */
+  public static final long WINDOW_FOCUS_EVENT_MASK = 0x80000;
+  
 	final static long DISABLED_MASK = 0x80000000;
 	final static long TEMP_DISABLED_MASK = 0x40000000;
 	static Component keyTgt;
@@ -186,4 +228,95 @@
 		}
 	}
 }
+
+  /**
+   * Converts an event id to the appropriate event mask.
+   *
+   * @param id the event id
+   *
+   * @return the event mask for the specified id
+   */
+  static long eventIdToMask(int id)
+  {
+    long mask = 0;
+    switch (id)
+    {
+      case ActionEvent.ACTION_PERFORMED:
+        mask = ACTION_EVENT_MASK;
+        break;
+      case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
+        mask = ADJUSTMENT_EVENT_MASK;
+        break;
+      case ComponentEvent.COMPONENT_MOVED:
+      case ComponentEvent.COMPONENT_RESIZED:
+      case ComponentEvent.COMPONENT_SHOWN:
+      case ComponentEvent.COMPONENT_HIDDEN:
+        mask = COMPONENT_EVENT_MASK;
+        break;
+      case ContainerEvent.COMPONENT_ADDED:
+      case ContainerEvent.COMPONENT_REMOVED:
+        mask = CONTAINER_EVENT_MASK;
+        break;
+      case FocusEvent.FOCUS_GAINED:
+      case FocusEvent.FOCUS_LOST:
+        mask = FOCUS_EVENT_MASK;
+        break;
+      case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
+      case InputMethodEvent.CARET_POSITION_CHANGED:
+        mask = INPUT_METHOD_EVENT_MASK;
+        break;
+      case InvocationEvent.INVOCATION_DEFAULT:
+        mask = INVOCATION_EVENT_MASK;
+        break;
+      case ItemEvent.ITEM_STATE_CHANGED:
+        mask = ITEM_EVENT_MASK;
+        break;
+      case KeyEvent.KEY_TYPED:
+      case KeyEvent.KEY_PRESSED:
+      case KeyEvent.KEY_RELEASED:
+        mask = KEY_EVENT_MASK;
+        break;
+      case MouseEvent.MOUSE_CLICKED:
+      case MouseEvent.MOUSE_PRESSED:
+      case MouseEvent.MOUSE_RELEASED:
+        mask = MOUSE_EVENT_MASK;
+        break;
+      case MouseEvent.MOUSE_MOVED:
+      case MouseEvent.MOUSE_ENTERED:
+      case MouseEvent.MOUSE_EXITED:
+      case MouseEvent.MOUSE_DRAGGED:
+        mask = MOUSE_MOTION_EVENT_MASK;
+        break;
+      case MouseEvent.MOUSE_WHEEL:
+        mask = MOUSE_WHEEL_EVENT_MASK;
+        break;
+      case PaintEvent.PAINT:
+      case PaintEvent.UPDATE:
+        mask = PAINT_EVENT_MASK;
+        break;
+      case TextEvent.TEXT_VALUE_CHANGED:
+        mask = TEXT_EVENT_MASK;
+        break;
+      case WindowEvent.WINDOW_OPENED:
+      case WindowEvent.WINDOW_CLOSING:
+      case WindowEvent.WINDOW_CLOSED:
+      case WindowEvent.WINDOW_ICONIFIED:
+      case WindowEvent.WINDOW_DEICONIFIED:
+      case WindowEvent.WINDOW_ACTIVATED:
+      case WindowEvent.WINDOW_DEACTIVATED:
+        mask = WINDOW_EVENT_MASK;
+        break;
+      case WindowEvent.WINDOW_GAINED_FOCUS:
+      case WindowEvent.WINDOW_LOST_FOCUS:
+        mask = WINDOW_FOCUS_EVENT_MASK;
+        break;
+      case WindowEvent.WINDOW_STATE_CHANGED:
+        mask = WINDOW_STATE_EVENT_MASK;
+        break;
+      default:
+        mask = 0;
+    }
+    return mask;
+  }
+
 }
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Toolkit.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Toolkit.java:1.4 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Toolkit.java:1.5
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Toolkit.java:1.4	Wed Oct 19 20:10:50 2005
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Toolkit.java	Thu Mar 30 22:14:11 2006
@@ -7,6 +7,8 @@
 import java.awt.dnd.DragGestureRecognizer;
 import java.awt.dnd.DragSource;
 import java.awt.event.InputEvent;
+import java.awt.event.AWTEventListener;
+import java.awt.event.AWTEventListenerProxy;
 import java.awt.image.ColorModel;
 import java.awt.image.ImageObserver;
 import java.awt.image.ImageProducer;
@@ -17,6 +19,7 @@
 import java.io.PrintStream;
 import java.net.URL;
 import java.util.Properties;
+import java.util.ArrayList;
 
 import org.kaffe.awt.DoNothingPeer;
 import org.kaffe.util.log.LogClient;
@@ -106,6 +109,12 @@
 	final static int NEEDS_FLUSH = 4;
 	final static int NATIVE_DISPATCHER_LOOP = 8;
 	final static int EXTERNAL_DECO = 16;
+	
+	/**
+   	* All registered AWTEventListener objects. This is package private, so the
+   	* event queue can efficiently access this list.
+   	*/
+  	AWTEventListenerProxy[] awtEventListeners;
 
 static {
 	final String AWT_NATIVE_LIBRARY = System.getProperty("kaffe.awt.nativelib");
@@ -138,6 +147,7 @@
 }
 
 public Toolkit () {
+	awtEventListeners = new AWTEventListenerProxy[0];
 }
 
 public void beep () {
@@ -613,6 +623,233 @@
   {
     return null;
   }
+  
+   /**
+   * Adds an AWTEventListener to this toolkit. This listener is informed about
+   * all events that pass the eventqueue that match the specified
+   * <code>evenMask</code>. The <code>eventMask</code> is an ORed combination
+   * of event masks as defined in {@link AWTEvent}.
+   *
+   * If a security manager is installed, it is asked first if an
+   * <code>AWTPermission(&quot;listenToAllAWTEvents&quot;)</code> is allowed.
+   * This may result in a <code>SecurityException</code> beeing thrown.
+   *
+   * It is not recommended to use this kind of notification for normal
+   * applications. It is intended solely for the purpose of debugging and to
+   * support special facilities.
+   *
+   * @param listener the listener to add
+   * @param eventMask the event mask of event types which the listener is
+   *        interested in
+   *
+   * @since 1.2
+   *
+   * @throws SecurityException if there is a <code>SecurityManager</code> that
+   *         doesn't grant
+   *         <code>AWTPermission(&quot;listenToAllAWTEvents&quot;)</code>
+   *
+   * @see #getAWTEventListeners()
+   * @see #getAWTEventListeners(long)
+   * @see #removeAWTEventListener(AWTEventListener)
+   */
+  public void addAWTEventListener(AWTEventListener listener, long eventMask)
+  {
+    // First we must check the security permissions.
+    SecurityManager s = System.getSecurityManager();
+    if (s != null)
+      s.checkPermission(new AWTPermission("listenToAllAWTEvents"));
+
+    // Go through the list and check if the requested listener is already
+    // registered.
+    boolean found = false;
+    for (int i = 0; i < awtEventListeners.length; ++i)
+      {
+        AWTEventListenerProxy proxy = awtEventListeners[i];
+        if (proxy.getListener() == listener)
+          {
+            found = true;
+            // Modify the proxies event mask to include the new event mask.
+            AWTEventListenerProxy newProxy =
+              new AWTEventListenerProxy(proxy.getEventMask() | eventMask,
+                                        listener);
+            awtEventListeners[i] = newProxy;
+            break;
+          }
+      }
+
+    // If that listener was not found, then add it.
+    if (! found)
+      {
+        AWTEventListenerProxy proxy =
+          new AWTEventListenerProxy(eventMask, listener);
+        AWTEventListenerProxy[] newArray =
+          new AWTEventListenerProxy[awtEventListeners.length + 1];
+        System.arraycopy(awtEventListeners, 0, newArray, 0,
+                         awtEventListeners.length);
+        newArray[newArray.length - 1] = proxy;
+        awtEventListeners = newArray;
+      }
+  }
+
+  /**
+   * Removes an AWT event listener from this toolkit. This listener is no
+   * longer informed of any event types it was registered in.
+   *
+   * If a security manager is installed, it is asked first if an
+   * <code>AWTPermission(&quot;listenToAllAWTEvents&quot;)</code> is allowed.
+   * This may result in a <code>SecurityException</code> beeing thrown.
+   *
+   * It is not recommended to use this kind of notification for normal
+   * applications. It is intended solely for the purpose of debugging and to
+   * support special facilities.
+   *
+   * @param listener the listener to remove
+   *
+   * @throws SecurityException if there is a <code>SecurityManager</code> that
+   *         doesn't grant
+   *         <code>AWTPermission(&quot;listenToAllAWTEvents&quot;)</code>
+   *
+   * @since 1.2
+   *
+   * @see #addAWTEventListener(AWTEventListener, long)
+   * @see #getAWTEventListeners()
+   * @see #getAWTEventListeners(long)
+   */
+  public void removeAWTEventListener(AWTEventListener listener)
+  {
+    // First we must check the security permissions.
+    SecurityManager s = System.getSecurityManager();
+    if (s != null)
+      s.checkPermission(new AWTPermission("listenToAllAWTEvents"));
+
+
+    // Find the index of the listener.
+    int index = -1;
+    for (int i = 0; i < awtEventListeners.length; ++i)
+      {
+        AWTEventListenerProxy proxy = awtEventListeners[i];
+        if (proxy.getListener() == listener)
+          {
+            index = i;
+            break;
+          }
+      }
+
+    // Copy over the arrays and leave out the removed element.
+    if (index != -1)
+      {
+        AWTEventListenerProxy[] newArray =
+          new AWTEventListenerProxy[awtEventListeners.length - 1];
+        if (index > 0)
+          System.arraycopy(awtEventListeners, 0, newArray, 0, index);
+        if (index < awtEventListeners.length - 1)
+          System.arraycopy(awtEventListeners, index + 1, newArray, index,
+                           awtEventListeners.length - index - 1);
+        awtEventListeners = newArray;
+      }
+  }
+
+  /**
+   * Returns all registered AWT event listeners. This method returns a copy of
+   * the listener array, so that application cannot trash the listener list.
+   *
+   * If a security manager is installed, it is asked first if an
+   * <code>AWTPermission(&quot;listenToAllAWTEvents&quot;)</code> is allowed.
+   * This may result in a <code>SecurityException</code> beeing thrown.
+   *
+   * It is not recommended to use this kind of notification for normal
+   * applications. It is intended solely for the purpose of debugging and to
+   * support special facilities.
+   *
+   * @return all registered AWT event listeners
+   *
+   * @throws SecurityException if there is a <code>SecurityManager</code> that
+   *         doesn't grant
+   *         <code>AWTPermission(&quot;listenToAllAWTEvents&quot;)</code>
+   *
+   * @since 1.4
+   *
+   * @see #addAWTEventListener(AWTEventListener, long)
+   * @see #removeAWTEventListener(AWTEventListener)
+   * @see #getAWTEventListeners(long)
+   */
+  public AWTEventListener[] getAWTEventListeners()
+  {
+    // First we must check the security permissions.
+    SecurityManager s = System.getSecurityManager();
+    if (s != null)
+      s.checkPermission(new AWTPermission("listenToAllAWTEvents"));
+
+    // Create a copy of the array.
+    AWTEventListener[] copy = new AWTEventListener[awtEventListeners.length];
+    System.arraycopy(awtEventListeners, 0, copy, 0, awtEventListeners.length);
+    return copy;
+  }
+
+  /**
+   * Returns all registered AWT event listeners that listen for events with
+   * the specified <code>eventMask</code>. This method returns a copy of
+   * the listener array, so that application cannot trash the listener list.
+   *
+   * If a security manager is installed, it is asked first if an
+   * <code>AWTPermission(&quot;listenToAllAWTEvents&quot;)</code> is allowed.
+   * This may result in a <code>SecurityException</code> beeing thrown.
+   *
+   * It is not recommended to use this kind of notification for normal
+   * applications. It is intended solely for the purpose of debugging and to
+   * support special facilities.
+   *
+   * @param mask the event mask
+   *
+   * @throws SecurityException if there is a <code>SecurityManager</code> that
+   *         doesn't grant
+   *         <code>AWTPermission(&quot;listenToAllAWTEvents&quot;)</code>
+   *
+   *
+   * @since 1.4
+   *
+   * @see #addAWTEventListener(AWTEventListener, long)
+   * @see #removeAWTEventListener(AWTEventListener)
+   * @see #getAWTEventListeners()
+   */
+  public AWTEventListener[] getAWTEventListeners(long mask)
+  {
+    // First we must check the security permissions.
+    SecurityManager s = System.getSecurityManager();
+    if (s != null)
+      s.checkPermission(new AWTPermission("listenToAllAWTEvents"));
+
+    // Create a copy of the array with only the requested listeners in it.
+    ArrayList l = new ArrayList(awtEventListeners.length);
+    for (int i = 0; i < awtEventListeners.length; ++i)
+      {
+        if ((awtEventListeners[i].getEventMask() & mask) != 0)
+          l.add(awtEventListeners[i]);
+      }
+
+    return (AWTEventListener[] ) l.toArray(new AWTEventListener[l.size()]);
+  }
+
+
+  /**
+   * Dispatches events to listeners registered to this Toolkit. This is called
+   * by {@link Component#dispatchEventImpl(AWTEvent)} in order to dispatch
+   * events globally.
+   *
+   * @param ev the event to dispatch
+   */
+  void globalDispatchEvent(AWTEvent ev)
+  {
+    // We do not use the accessor methods here because they create new
+    // arrays each time. We must be very efficient, so we access this directly.
+    for (int i = 0; i < awtEventListeners.length; ++i)
+      {
+        AWTEventListenerProxy proxy = awtEventListeners[i];
+        if ((proxy.getEventMask() & AWTEvent.eventIdToMask(ev.getID())) != 0)
+          proxy.eventDispatched(ev);
+      }
+  }
+
 
 native static synchronized void tlkBeep ();
 
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/WindowEvent.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/WindowEvent.java:1.1 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/WindowEvent.java:1.2
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/WindowEvent.java:1.1	Thu Jul 22 19:19:43 2004
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/WindowEvent.java	Thu Mar 30 22:14:11 2006
@@ -23,6 +23,28 @@
 	final public static int WINDOW_ACTIVATED = 205;
 	final public static int WINDOW_DEACTIVATED = 206;
 	final public static int WINDOW_LAST = 206;
+	
+	  /**
+   * This is the id for a window becoming the focused window.
+   *
+   * @since 1.4
+   */
+  public static final int WINDOW_GAINED_FOCUS = 207;
+
+  /**
+   * This is the id for a window losing all focus.
+   *
+   * @since 1.4
+   */
+  public static final int WINDOW_LOST_FOCUS = 208;
+
+  /**
+   * This is the id for a window state change, such as maximization.
+   *
+   * @since 1.4
+   */
+  public static final int WINDOW_STATE_CHANGED = 209;
+  
 	private static final long serialVersionUID = -1567959133147912127L;
 
 public WindowEvent ( Window  src, int evtId ) {




More information about the kaffe mailing list