[kaffe] CVS kaffe (riccardo): improved focus event and refactored some fields to match classpath

Kaffe CVS cvs-commits at kaffe.org
Wed May 10 08:56:09 PDT 2006


PatchSet 7285 
Date: 2006/05/10 15:43:03
Author: riccardo
Branch: HEAD
Tag: (none) 
Log:
improved focus event and refactored some fields to match classpath

Members: 
	ChangeLog:1.4789->1.4790 
	libraries/javalib/awt-implementations/kaffe/java/awt/Component.java:1.9->1.10 
	libraries/javalib/awt-implementations/kaffe/java/awt/FocusEvt.java:1.1->1.2 
	libraries/javalib/awt-implementations/kaffe/java/awt/List.java:1.1->1.2 
	libraries/javalib/awt-implementations/kaffe/java/awt/RowCanvas.java:1.2->1.3 
	libraries/javalib/awt-implementations/kaffe/java/awt/TextArea.java:1.1->1.2 
	libraries/javalib/awt-implementations/kaffe/java/awt/event/FocusEvent.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4789 kaffe/ChangeLog:1.4790
--- kaffe/ChangeLog:1.4789	Fri May  5 23:35:03 2006
+++ kaffe/ChangeLog	Wed May 10 15:43:03 2006
@@ -1,3 +1,13 @@
+2006-05-10  Riccardo Mottola <riccardo at kaffe.org>
+
+	* libraries/javalib/awt-implementations/kaffe/java/awt/Component.java,
+	libraries/javalib/awt-implementations/kaffe/java/awt/FocusEvt.java,
+	libraries/javalib/awt-implementations/kaffe/java/awt/List.java,
+	libraries/javalib/awt-implementations/kaffe/java/awt/RowCanvas.java,
+	libraries/javalib/awt-implementations/kaffe/java/awt/TextArea.java,
+	libraries/javalib/awt-implementations/kaffe/java/awt/event/FocusEvent.java:
+	improved focus event and refactored some fields to match classpath
+
 2006-05-06  Riccardo Mottola <riccardo at kaffe.org>
 
 	* libraries/javalib/awt-implementations/kaffe/java/awt/FileDialog.java:
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java:1.9 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java:1.10
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java:1.9	Tue May  2 14:32:32 2006
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/Component.java	Wed May 10 15:43:09 2006
@@ -24,6 +24,11 @@
 import java.awt.event.ContainerEvent;
 import java.awt.event.FocusEvent;
 import java.awt.event.FocusListener;
+import java.awt.event.HierarchyBoundsListener;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.InputMethodListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
@@ -68,11 +73,6 @@
 	Color bgClr;
 	Font font;
 	Cursor cursor;
-	ComponentListener cmpListener;
-	KeyListener keyListener;
-	FocusListener focusListener;
-	MouseListener mouseListener;
-	MouseMotionListener motionListener;
 	String name;
 	int eventMask;
 	Locale locale;
@@ -113,6 +113,52 @@
 	final static int IS_MOUSE_AWARE = 0x10000;
 	final static int IS_TEMP_HIDDEN = 0x20000;
 	final static int IS_SHOWING = IS_ADD_NOTIFIED | IS_PARENT_SHOWING | IS_VISIBLE;
+
+        // Guess what - listeners are special cased in serialization. See
+        // readObject and writeObject.
+
+        /** Component listener chain. */
+        transient ComponentListener componentListener;
+
+        /** Focus listener chain. */
+        transient FocusListener focusListener;
+
+        /** Key listener chain. */
+        transient KeyListener keyListener;
+
+        /** Mouse listener chain. */
+        transient MouseListener mouseListener;
+
+        /** Mouse motion listener chain. */
+        transient MouseMotionListener mouseMotionListener;
+
+        /**
+            * Mouse wheel listener chain.
+         *
+         * @since 1.4
+         */
+        transient MouseWheelListener mouseWheelListener;
+
+        /**
+            * Input method listener chain.
+         *
+         * @since 1.2
+         */
+        transient InputMethodListener inputMethodListener;
+
+        /**
+            * Hierarcy listener chain.
+         *
+         * @since 1.3
+         */
+        transient HierarchyListener hierarchyListener;
+
+        /**
+            * Hierarcy bounds listener chain.
+         *
+         * @since 1.3
+         */
+        transient HierarchyBoundsListener hierarchyBoundsListener;
 	
   /** The associated native peer. */
   transient ComponentPeer peer;
@@ -244,7 +290,7 @@
 }
 
 public void addComponentListener ( ComponentListener newListener ) {
-	cmpListener = AWTEventMulticaster.add( cmpListener, newListener);
+	componentListener = AWTEventMulticaster.add( componentListener, newListener);
 }
 
 public void addFocusListener ( FocusListener newListener ) {
@@ -262,7 +308,7 @@
 }
 
 public void addMouseMotionListener ( MouseMotionListener newListener ) {
-	motionListener = AWTEventMulticaster.add( motionListener, newListener);
+	mouseMotionListener = AWTEventMulticaster.add( mouseMotionListener, newListener);
 	
 	flags |= IS_MOUSE_AWARE;
 }
@@ -315,7 +361,7 @@
 void checkMouseAware () {
 	if ( ((eventMask & AWTEvent.DISABLED_MASK) == 0) &&
 	     ((mouseListener != null) ||
-	      (motionListener != null) ||
+	      (mouseMotionListener != null) ||
 	      (eventMask & (AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK)) != 0 ||
 	      (flags & IS_OLD_EVENT) != 0 )) {
 		flags |= IS_MOUSE_AWARE;
@@ -382,15 +428,130 @@
 	dispatchEventImpl( evt);
 }
 
-void dispatchEventImpl ( AWTEvent event ) {
-	// A hidden method that seems to be called automatically by the JDKs
-	// 'final' dispatchEvent() method. We just provide it to get some more
-	// compatibility (in case dispatchEvent is called explicitly), but
-	// we don't route all events through it (since this is a private,
-	// undocumented method)
-	event.dispatch();
+/**
+* Implementation of dispatchEvent. Allows trusted package classes
+ * to dispatch additional events first.  This implementation first
+ * translates <code>e</code> to an AWT 1.0 event and sends the
+ * result to {@link #postEvent}.  If the AWT 1.0 event is not
+ * handled, and events of type <code>e</code> are enabled for this
+ * component, e is passed on to {@link #processEvent}.
+ *
+ * @param e the event to dispatch
+ */
+
+void dispatchEventImpl(AWTEvent e)
+{
+    // 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();
+}
+
+
+/**
+* Tells whether or not an event type is enabled.
+ */
+boolean eventTypeEnabled (int type)
+{
+    if (type > AWTEvent.RESERVED_ID_MAX)
+        return true;
+
+    switch (type)
+    {
+        case HierarchyEvent.HIERARCHY_CHANGED:
+            return (hierarchyListener != null
+                    || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0);
+
+        case HierarchyEvent.ANCESTOR_MOVED:
+        case HierarchyEvent.ANCESTOR_RESIZED:
+            return (hierarchyBoundsListener != null
+                    || (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0);
+
+        case ComponentEvent.COMPONENT_HIDDEN:
+        case ComponentEvent.COMPONENT_MOVED:
+        case ComponentEvent.COMPONENT_RESIZED:
+        case ComponentEvent.COMPONENT_SHOWN:
+            return (componentListener != null
+                    || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0);
+
+        case KeyEvent.KEY_PRESSED:
+        case KeyEvent.KEY_RELEASED:
+        case KeyEvent.KEY_TYPED:
+            return (keyListener != null
+                    || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0);
+
+        case MouseEvent.MOUSE_CLICKED:
+        case MouseEvent.MOUSE_ENTERED:
+        case MouseEvent.MOUSE_EXITED:
+        case MouseEvent.MOUSE_PRESSED:
+        case MouseEvent.MOUSE_RELEASED:
+            return (mouseListener != null
+                    || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0);
+        case MouseEvent.MOUSE_MOVED:
+        case MouseEvent.MOUSE_DRAGGED:
+            return (mouseMotionListener != null
+                    || (eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0);
+        case MouseEvent.MOUSE_WHEEL:
+            return (mouseWheelListener != null
+                    || (eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0);
+
+        case FocusEvent.FOCUS_GAINED:
+        case FocusEvent.FOCUS_LOST:
+            return (focusListener != null
+                    || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0);
+
+        case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
+        case InputMethodEvent.CARET_POSITION_CHANGED:
+            return (inputMethodListener != null
+                    || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0);
+
+        case PaintEvent.PAINT:
+        case PaintEvent.UPDATE:
+            return (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0;
+
+        default:
+            return false;
+    }
 }
 
+
 public void doLayout () {
 	layout();
 }
@@ -717,7 +878,7 @@
 				parent.invalidate();
 		}
 		
-		if ( (cmpListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ){
+		if ( (componentListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ){
 			Toolkit.eventQueue.postEvent( ComponentEvt.getEvent( this,
 			                                  ComponentEvent.COMPONENT_HIDDEN));
 		}
@@ -1136,7 +1297,7 @@
 }
 
 void process ( ComponentEvent e ) {
-	if ( (cmpListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)
+	if ( (componentListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)
 		processEvent( e);
 }
 
@@ -1190,19 +1351,19 @@
 
 protected void processComponentEvent ( ComponentEvent event ) {
 
-	if ( cmpListener != null ){
+	if ( componentListener != null ){
 		switch ( event.getID() ) {
 		case ComponentEvent.COMPONENT_RESIZED:
-			cmpListener.componentResized( event);
+			componentListener.componentResized( event);
 			break;
 		case ComponentEvent.COMPONENT_MOVED:
-			cmpListener.componentMoved( event);
+			componentListener.componentMoved( event);
 			break;
 		case ComponentEvent.COMPONENT_SHOWN:
-			cmpListener.componentShown( event);
+			componentListener.componentShown( event);
 			break;
 		case ComponentEvent.COMPONENT_HIDDEN:
-			cmpListener.componentHidden( event);
+			componentListener.componentHidden( event);
 			break;
 		}
 	}
@@ -1334,7 +1495,7 @@
 			return;
 	}
 
-	if ( (motionListener != null) || (eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)
+	if ( (mouseMotionListener != null) || (eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)
 		processEvent( e);
 
 	if ( (flags & IS_OLD_EVENT) != 0 ){
@@ -1379,13 +1540,13 @@
 }
 
 protected void processMouseMotionEvent ( MouseEvent event ) {
-	if ( motionListener != null ) {
+	if ( mouseMotionListener != null ) {
 		switch ( event.id ) {
 		case MouseEvent.MOUSE_MOVED:
-			motionListener.mouseMoved( event);
+			mouseMotionListener.mouseMoved( event);
 			return;
 		case MouseEvent.MOUSE_DRAGGED:
-			motionListener.mouseDragged( event);
+			mouseMotionListener.mouseDragged( event);
 			return;
 		}
 	}
@@ -1466,7 +1627,7 @@
 }
 
 public void removeComponentListener ( ComponentListener client ) {
-	cmpListener = AWTEventMulticaster.remove( cmpListener, client);
+	componentListener = AWTEventMulticaster.remove( componentListener, client);
 }
 
 public void removeFocusListener ( FocusListener listener ) {
@@ -1484,7 +1645,7 @@
 }
 
 public void removeMouseMotionListener ( MouseMotionListener listener ) {
-	motionListener = AWTEventMulticaster.remove( motionListener, listener);
+	mouseMotionListener = AWTEventMulticaster.remove( mouseMotionListener, listener);
 	
 	checkMouseAware();
 }
@@ -1612,7 +1773,7 @@
 				x = xNew; y = yNew; width = wNew; height = hNew;
 				invalidate();
 				
-				if ( (cmpListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ){
+				if ( (componentListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ){
 					Toolkit.eventQueue.postEvent( ComponentEvt.getEvent( this, id));
 				}
 				propagateReshape();
@@ -1627,7 +1788,7 @@
 		x = xNew; y = yNew; width = wNew; height = hNew;
 		invalidate();
 
-		if ( (cmpListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ){
+		if ( (componentListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ){
 			Toolkit.eventQueue.postEvent( ComponentEvt.getEvent( this, id));
 		}
 		propagateReshape();
@@ -1811,7 +1972,7 @@
 				parent.invalidate();
 		}
 
-		if ( (cmpListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ){
+		if ( (componentListener != null) || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ){
 			Toolkit.eventQueue.postEvent( ComponentEvt.getEvent( this,
 				                                    ComponentEvent.COMPONENT_SHOWN));
 		}
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/FocusEvt.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/FocusEvt.java:1.1 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/FocusEvt.java:1.2
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/FocusEvt.java:1.1	Thu Jul 22 19:19:31 2004
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/FocusEvt.java	Wed May 10 15:43:09 2006
@@ -99,7 +99,7 @@
 		
 		e.id = id;
 		e.source = source;
-		e.isTemporary = isTemporary;
+		e.temporary = isTemporary;
 
 		return e;
 	}
@@ -121,7 +121,7 @@
 		
 		e.id = id;
 		e.source = source;
-		e.isTemporary = isTemporary;
+		e.temporary = isTemporary;
 	}
 
 	if ( (Toolkit.flags & Toolkit.NATIVE_DISPATCHER_LOOP) != 0 ) {
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/List.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/List.java:1.1 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/List.java:1.2
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/List.java:1.1	Thu Jul 22 19:19:32 2004
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/List.java	Wed May 10 15:43:09 2006
@@ -169,7 +169,7 @@
 }
 
 public void mouseDragged( MouseEvent e) {
-	if ( this.parent.motionListener != null ){
+	if ( this.parent.mouseMotionListener != null ){
 		// unlikely, check listener first
 		redirectMotionEvent( e);
 	}
@@ -192,7 +192,7 @@
 		updateFlyOver( row );
 	}
 
-	if ( this.parent.motionListener != null ){
+	if ( this.parent.mouseMotionListener != null ){
 		// unlikely, check listener first
 		redirectMotionEvent( e);
 	}
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/RowCanvas.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/RowCanvas.java:1.2 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/RowCanvas.java:1.3
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/RowCanvas.java:1.2	Tue Apr 25 22:14:05 2006
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/RowCanvas.java	Wed May 10 15:43:09 2006
@@ -237,7 +237,7 @@
 }
 
 void redirectMotionEvent( MouseEvent e) {
-	if ( parent.motionListener != null ){
+	if ( parent.mouseMotionListener != null ){
 		e.retarget( parent, x, y);
 		parent.process( e);
 
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/TextArea.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/TextArea.java:1.1 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/TextArea.java:1.2
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/TextArea.java:1.1	Thu Jul 22 19:19:33 2004
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/TextArea.java	Wed May 10 15:43:10 2006
@@ -588,7 +588,7 @@
 	int x = getCol( y, e.getX() );
 	updateSel( x, y, true);
 
-	if ( this.parent.motionListener != null ){
+	if ( this.parent.mouseMotionListener != null ){
 		// unlikely, check motionListener first
 		redirectMotionEvent( e);
 	}
@@ -603,7 +603,7 @@
 }
 
 public void mouseMoved( MouseEvent e) {
-	if ( this.parent.motionListener != null ){
+	if ( this.parent.mouseMotionListener != null ){
 		// unlikely, check listener first
 		redirectMotionEvent( e);
 	}
Index: kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/FocusEvent.java
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/FocusEvent.java:1.1 kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/FocusEvent.java:1.2
--- kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/FocusEvent.java:1.1	Thu Jul 22 19:19:42 2004
+++ kaffe/libraries/javalib/awt-implementations/kaffe/java/awt/event/FocusEvent.java	Wed May 10 15:43:10 2006
@@ -1,59 +1,181 @@
+/* FocusEvent.java -- generated for a focus change
+   Copyright (C) 1999, 2002, 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
 package java.awt.event;
 
 import java.awt.Component;
-import java.awt.Event;
 
 /**
+ * This class represents an event generated when a focus change occurs for a
+ * component. There are both temporary changes, such as when focus is stolen
+ * during a sroll then returned, and permanent changes, such as when the user
+ * TABs through focusable components.
  *
- * Copyright (c) 1998
- *   Transvirtual Technologies Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- * @author P.C.Mehlitz
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see FocusAdapter
+ * @see FocusListener
+ * @since 1.1
+ * @status updated to 1.4
  */
-public class FocusEvent
-  extends ComponentEvent
+public class FocusEvent extends ComponentEvent
 {
-	protected boolean isTemporary;
-	final public static int FOCUS_FIRST = 1004;
-	final public static int FOCUS_LAST = 1005;
-	final public static int FOCUS_GAINED = FOCUS_FIRST;
-	final public static int FOCUS_LOST = FOCUS_FIRST + 1;
-	private static final long serialVersionUID = 523753786457416396L;
-
-public FocusEvent ( Component src, int evtId ) {
-	super( src, evtId);
-}
-
-public FocusEvent ( Component src, int evtId, boolean isTemporary ) {
-	super( src, evtId);
-	this.isTemporary = isTemporary;
-}
-
-protected Event initOldEvent ( Event e ) {
-	e.target = source;
-	e.id = id;
-	
-	return e;
-}
-
-public boolean isTemporary() {
-	return isTemporary;
-}
-
-public String paramString() {
-	String s;
-
-	switch ( id ) {
-		case FOCUS_GAINED:  s = "FOCUS_GAINED"; break;
-		case FOCUS_LOST:    s = "FOCUS_LOST"; break;
-		default:            s = "unknown type"; break;
-	}
-	
-	if ( isTemporary )
-		s += ", temporary";
-	
-	return s;
-}
-}
+  /**
+   * Compatible with JDK 1.1+.
+   */
+  private static final long serialVersionUID = 523753786457416396L;
+
+  /** This is the first id in the range of ids used by this class. */
+  public static final int FOCUS_FIRST = 1004;
+
+  /** This is the last id in the range of ids used by this class. */
+  public static final int FOCUS_LAST = 1005;
+
+  /** This is the event id for a focus gained event. */
+  public static final int FOCUS_GAINED = 1004;
+
+  /** This is the event id for a focus lost event. */
+  public static final int FOCUS_LOST = 1005;
+
+  /**
+   * Indicates whether or not the focus change is temporary.
+   *
+   * @see #isTemporary()
+   * @serial true if the focus change is temporary
+   */
+  protected boolean temporary;
+
+  /**
+   * The other component which is giving up or stealing focus from this
+   * component, if known.
+   *
+   * @see #getOppositeComponent()
+   * @serial the component with the opposite focus event, or null
+   * @since 1.4
+   */
+  private final Component opposite;
+
+  /**
+   * Initializes a new instance of <code>FocusEvent</code> with the
+   * specified source, id, temporary status, and opposite counterpart. Note
+   * that an invalid id leads to unspecified results.
+   *
+   * @param source the component that is gaining or losing focus
+   * @param id the event id
+   * @param temporary true if the focus change is temporary
+   * @param opposite the component receiving the opposite focus event, or null
+   * @throws IllegalArgumentException if source is null
+   */
+  public FocusEvent(Component source, int id, boolean temporary,
+                    Component opposite)
+  {
+    super(source, id);
+    this.temporary = temporary;
+    this.opposite = opposite;
+  }
+
+  /**
+   * Initializes a new instance of <code>FocusEvent</code> with the
+   * specified source, id, and temporary status. Note that an invalid id
+   * leads to unspecified results.
+   *
+   * @param source the component that is gaining or losing focus
+   * @param id the event id
+   * @param temporary true if the focus change is temporary
+   * @throws IllegalArgumentException if source is null
+   */
+  public FocusEvent(Component source, int id, boolean temporary)
+  {
+    this(source, id, temporary, null);
+  }
+
+  /**
+   * Initializes a new instance of <code>FocusEvent</code> with the
+   * specified source and id. Note that an invalid id leads to unspecified
+   * results.
+   *
+   * @param source the component that is gaining or losing focus
+   * @param id the event id
+   * @throws IllegalArgumentException if source is null
+   */
+  public FocusEvent(Component source, int id)
+  {
+    this(source, id, false, null);
+  }
+
+  /**
+   * This method tests whether or not the focus change is temporary or
+   * permanent.
+   *
+   * @return true if the focus change is temporary
+   */
+  public boolean isTemporary()
+  {
+    return temporary;
+  }
+
+  /**
+   * Returns the component which received the opposite focus event. If this
+   * component gained focus, the opposite lost focus; likewise if this
+   * component is giving up focus, the opposite is gaining it. If this
+   * information is unknown, perhaps because the opposite is a native
+   * application, this returns null.
+   *
+   * @return the component with the focus opposite, or null
+   * @since 1.4
+   */
+  public Component getOppositeComponent()
+  {
+    return opposite;
+  }
+
+  /**
+   * Returns a string identifying this event. This is formatted as:
+   * <code>(getID() == FOCUS_GAINED ? "FOCUS_GAINED" : "FOCUS_LOST")
+   * + (isTemporary() ? ",temporary," : ",permanent,") + "opposite="
+   * + getOppositeComponent()</code>.
+   *
+   * @return a string identifying this event
+   */
+  public String paramString()
+  {
+    return (id == FOCUS_GAINED ? "FOCUS_GAINED"
+            : id == FOCUS_LOST ? "FOCUS_LOST" : "unknown type")
+      + (temporary ? ",temporary,opposite=" : ",permanent,opposite=")
+      + opposite;
+  }
+} // class FocusEvent




More information about the kaffe mailing list