2003-03-02 Michael Koch <konqueror@gmx.de>
authorMichael Koch <konqueror@gmx.de>
Sun, 2 Mar 2003 14:01:40 +0000 (14:01 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Sun, 2 Mar 2003 14:01:40 +0000 (14:01 +0000)
* java/awt/Component.java
(eventTypeEnabled): New method.
(dispatchEventImpl): Moved checks for event to eventTypeEnabled.
* java/awt/Container.java
(changeSupport): New member variable.
(addPropertyChangeListener): New methods.
* java/awt/ContainerOrderFocusTraversalPolicy.java
(ContainerOrderFocusTraversalPolicy): Added comment.
(getComponentAfter): Throw exception, documentation added.
(getComponentBefore): Throw exception, documentation added.
(getFirstComponent): Throw exception, documentation added.
(getLastComponent): Throw exception, documentation added.
(getDefaultComponent): Throw exception, documentation added.
* java/awt/EventQueue.java: Reindented.
* java/awt/FocusTraversalPolicy.java:
(FocusTraversalPolicy): Added comment.
(getComponentAfter): Documentation added.
(getComponentBefore): Documentation added.
(getFirstComponent): Documentation added.
(getLastComponent): Documentation added.
(getDefaultComponent): Documentation added.
(getInitialComponent): Documentation added.
* java/awt/ScrollPane.java
(wheelScrollingEnabled): New member variable.
(ScrollPane): Initialize wheelScollingEnabled.
(eventTypeEnabled): New method.
(isWheelScrollingEnabled): New method.
(setWheelScrollingEnabled): New method.

From-SVN: r63663

libjava/ChangeLog
libjava/java/awt/Component.java
libjava/java/awt/Container.java
libjava/java/awt/ContainerOrderFocusTraversalPolicy.java
libjava/java/awt/EventQueue.java
libjava/java/awt/ScrollPane.java

index 6d91983d0ad8c08477673b70038c3d2ceaf14578..6ac880bc938ede2f075a139bbbaf0c0418c67016 100644 (file)
@@ -1,3 +1,34 @@
+2003-03-02  Michael Koch  <konqueror@gmx.de>
+
+       * java/awt/Component.java
+       (eventTypeEnabled): New method.
+       (dispatchEventImpl): Moved checks for event to eventTypeEnabled.
+       * java/awt/Container.java
+       (changeSupport): New member variable.
+       (addPropertyChangeListener): New methods.
+       * java/awt/ContainerOrderFocusTraversalPolicy.java
+       (ContainerOrderFocusTraversalPolicy): Added comment.
+       (getComponentAfter): Throw exception, documentation added.
+       (getComponentBefore): Throw exception, documentation added.
+       (getFirstComponent): Throw exception, documentation added.
+       (getLastComponent): Throw exception, documentation added.
+       (getDefaultComponent): Throw exception, documentation added.
+       * java/awt/EventQueue.java: Reindented.
+       * java/awt/FocusTraversalPolicy.java:
+       (FocusTraversalPolicy): Added comment.
+       (getComponentAfter): Documentation added.
+       (getComponentBefore): Documentation added.
+       (getFirstComponent): Documentation added.
+       (getLastComponent): Documentation added.
+       (getDefaultComponent): Documentation added.
+       (getInitialComponent): Documentation added.
+       * java/awt/ScrollPane.java
+       (wheelScrollingEnabled): New member variable.
+       (ScrollPane): Initialize wheelScollingEnabled.
+       (eventTypeEnabled): New method.
+       (isWheelScrollingEnabled): New method.
+       (setWheelScrollingEnabled): New method.
+
 2003-03-02  Michael Koch  <konqueror@gmx.de>
 
        * java/net/DatagramSocket.java
index 88f91810dc0b0fc8e8748a4972d78a6331d09492..c9afaa14bf35d4aee8a5c7029cf45588582077b4 100644 (file)
@@ -4075,45 +4075,61 @@ p   * <li>the set of backward traversal keys
    */
   void dispatchEventImpl(AWTEvent e)
   {
-    // Make use of event id's in order to avoid multiple instanceof tests.
-    if (e.id <= ComponentEvent.COMPONENT_LAST
-        && e.id >= ComponentEvent.COMPONENT_FIRST
-        && (componentListener != null
-            || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0))
-      processEvent(e);
-    else if (e.id <= KeyEvent.KEY_LAST
-             && e.id >= KeyEvent.KEY_FIRST
-             && (keyListener != null
-                 || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0))
-      processEvent(e);
-    else if (e.id <= MouseEvent.MOUSE_LAST
-             && e.id >= MouseEvent.MOUSE_FIRST
-             && (mouseListener != null
-                 || mouseMotionListener != null
-                 || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0))
-      processEvent(e);
-    else if (e.id <= FocusEvent.FOCUS_LAST
-             && e.id >= FocusEvent.FOCUS_FIRST
-             && (focusListener != null
-                 || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0))
-      processEvent(e);
-    else if (e.id <= InputMethodEvent.INPUT_METHOD_LAST
-             && e.id >= InputMethodEvent.INPUT_METHOD_FIRST
-             && (inputMethodListener != null
-                 || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0))
-      processEvent(e);
-    else if (e.id <= HierarchyEvent.HIERARCHY_LAST
-             && e.id >= HierarchyEvent.HIERARCHY_FIRST
-             && (hierarchyListener != null
-                 || hierarchyBoundsListener != null
-                 || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0))
-      processEvent(e);
-    else if (e.id <= PaintEvent.PAINT_LAST
-             && e.id >= PaintEvent.PAINT_FIRST
-             && (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0)
+    if (eventTypeEnabled (e.id))
       processEvent(e);
   }
 
+  /**
+   * Tells wether or not an event type is enabled.
+   */
+  boolean eventTypeEnabled (int type)
+  {
+    if (type > AWTEvent.RESERVED_ID_MAX)
+      return true;
+
+    switch (type)
+      {
+      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
+                || mouseMotionListener != null
+                || (eventMask & AWTEvent.MOUSE_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;
+      }
+  }
+
   /**
    * Coalesce paint events. Current heuristic is: Merge if the union of
    * areas is less than twice that of the sum of the areas. The X server
index 91804d7f8c95d2f205c7bb2cbd8d40135f8877ab..caffc50ab0e4aee15cd56204ca2e823e2f0073fc 100644 (file)
@@ -45,6 +45,7 @@ import java.awt.peer.ComponentPeer;
 import java.awt.peer.ContainerPeer;
 import java.awt.peer.LightweightPeer;
 import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.Serializable;
@@ -89,6 +90,7 @@ public class Container extends Component
 
   /* Anything else is non-serializable, and should be declared "transient". */
   transient ContainerListener containerListener;
+  transient PropertyChangeSupport changeSupport; 
 
   /**
    * Default constructor for subclasses.
@@ -1125,12 +1127,27 @@ public class Container extends Component
       throw new NullPointerException ();
   }
   
-  public void addPropertyChangeListener(PropertyChangeListener l)
+  public void addPropertyChangeListener (PropertyChangeListener listener)
   {
+    if (listener == null)
+      return;
+
+    if (changeSupport == null)
+      changeSupport = new PropertyChangeSupport (this);
+
+    changeSupport.addPropertyChangeListener (listener);
   }
   
-  public void addPropertyChangeListener(String name, PropertyChangeListener l)
+  public void addPropertyChangeListener (String name,
+                                         PropertyChangeListener listener)
   {
+    if (listener == null)
+      return;
+    
+    if (changeSupport == null)
+      changeSupport = new PropertyChangeSupport (this);
+
+    changeSupport.addPropertyChangeListener (name, listener);
   }
 
   // Hidden helper methods.
index 71267a579f0645b126ef8f138f69eca25e720999..1042939c076fc1c4209db642fbd7dd9c87ea6223 100644 (file)
@@ -41,11 +41,15 @@ package java.awt;
 import java.io.Serializable;
 
 /**
- * STUB CLASS ONLY
+ * @author Michael Koch
+ * @since 1.4
  */
 public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
   implements Serializable
 {
+  /**
+   * Compatible to JDK 1.4+
+   */
   static final long serialVersionUID = 486933713763926351L;
 
   private boolean implicitDownCycleTraversal = true;
@@ -55,31 +59,77 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
    */
   public ContainerOrderFocusTraversalPolicy()
   {
-    throw new Error("not implemented");
+    // Nothing to do here
   }
 
+  /**
+   * Returns the Component that should receive the focus after current.
+   * root must be a focus cycle root of current.
+   *
+   * @exception IllegalArgumentException If root is not a focus cycle
+   * root of current, or if either root or current is null.
+   */
   public Component getComponentAfter(Container root, Component current)
   {
+    if (root == null
+        || current == null)
+      throw new IllegalArgumentException ();
+    
     return null;
   }
 
+  /**
+   * Returns the Component that should receive the focus before current.
+   * root must be a focus cycle root of current.
+   *
+   * @exception IllegalArgumentException If root is not a focus cycle
+   * root of current, or if either root or current is null.
+   */
   public Component getComponentBefore(Container root, Component current)
   {
+    if (root == null
+        || current == null)
+      throw new IllegalArgumentException ();
+
     return null;
   }
 
+  /**
+   * Returns the first Component of root that should receive the focus.
+   *
+   * @exception IllegalArgumentException If root is null.
+   */
   public Component getFirstComponent(Container root)
   {
+    if (root == null)
+      throw new IllegalArgumentException ();
+
     return null;
   }
 
+  /**
+   * Returns the last Component of root that should receive the focus.
+   *
+   * @exception IllegalArgumentException If root is null.
+   */
   public Component getLastComponent(Container root)
   {
+    if (root == null)
+      throw new IllegalArgumentException ();
+
     return null;
   }
 
+  /**
+   * Returns the default Component of root that should receive the focus.
+   *
+   * @exception IllegalArgumentException If root is null.
+   */
   public Component getDefaultComponent(Container root)
   {
+    if (root == null)
+      throw new IllegalArgumentException ();
+
     return null;
   }
 
index 6b64fb7ee3b950c56d1ee14828d55e52f5ff6107..90ba6eafcf1c12b737e110fd6e09da524f2a59ee 100644 (file)
@@ -116,7 +116,8 @@ public class EventQueue
 
     if (next_in != next_out)
       return queue[next_out];
-    else return null;
+    else
+      return null;
   }
 
   /**
@@ -142,7 +143,7 @@ public class EventQueue
       {
         AWTEvent qevt = queue[i];
         if (qevt.id == id)
-         return qevt;
+          return qevt;
       }
     return null;
   }
@@ -159,7 +160,7 @@ public class EventQueue
     if (next != null)
       {
         next.postEvent(evt);
-       return;
+        return;
       }
     // FIXME: Security checks?
 
@@ -169,25 +170,25 @@ public class EventQueue
     while (i != next_in)
       {
         AWTEvent qevt = queue[i];
-       Object src;
-       if (qevt.id == evt.id
-           && (src = qevt.getSource()) == evt.getSource()
-           && src instanceof Component)
-         {
-           /* If there are, call coalesceEvents on the source component 
-              to see if they can be combined. */
-           Component srccmp = (Component) src;
-           AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt);
-           if (coalesced_evt != null)
-             {
-               /* Yes. Replace the existing event with the combined event. */
-               queue[i] = coalesced_evt;
-               return;
-             }
+        Object src;
+        if (qevt.id == evt.id
+            && (src = qevt.getSource()) == evt.getSource()
+            && src instanceof Component)
+          {
+            /* If there are, call coalesceEvents on the source component 
+               to see if they can be combined. */
+            Component srccmp = (Component) src;
+            AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt);
+            if (coalesced_evt != null)
+              {
+                /* Yes. Replace the existing event with the combined event. */
+                queue[i] = coalesced_evt;
+                return;
+              }
             break;
-         }
-       if (++i == queue.length)
-         i = 0;
+          }
+        if (++i == queue.length)
+          i = 0;
       }
 
     queue[next_in] = evt;    
@@ -198,15 +199,15 @@ public class EventQueue
       {
         /* Queue is full. Extend it. */
         AWTEvent[] oldQueue = queue;
-       queue = new AWTEvent[queue.length * 2];
+        queue = new AWTEvent[queue.length * 2];
 
-       int len = oldQueue.length - next_out;
-       System.arraycopy(oldQueue, next_out, queue, 0, len);
-       if (next_out != 0)
-         System.arraycopy(oldQueue, 0, queue, len, next_out);
+        int len = oldQueue.length - next_out;
+        System.arraycopy(oldQueue, next_out, queue, 0, len);
+        if (next_out != 0)
+          System.arraycopy(oldQueue, 0, queue, len, next_out);
 
-       next_out = 0;
-       next_in = oldQueue.length;
+        next_out = 0;
+        next_in = oldQueue.length;
       }
     notify();
   }
@@ -237,8 +238,8 @@ public class EventQueue
 
     synchronized (current)
       {
-       eq.postEvent(ie);
-       current.wait();
+        eq.postEvent(ie);
+        current.wait();
       }
 
     Exception exception;
@@ -247,7 +248,9 @@ public class EventQueue
       throw new InvocationTargetException(exception);
   }
 
-  /** @since JDK1.2 */
+  /**
+   * @since 1.2
+   */
   public static void invokeLater(Runnable runnable)
   {
     EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 
@@ -264,22 +267,26 @@ public class EventQueue
     return (Thread.currentThread() == eq.dispatchThread);
   }
 
-  /** Allows a custom EventQueue implementation to replace this one. 
-    * All pending events are transferred to the new queue. Calls to postEvent,
-    * getNextEvent, and peekEvent are forwarded to the pushed queue until it
-    * is removed with a pop().
-    *
-    * @exception NullPointerException if newEventQueue is null.
-    */
+  /**
+   * Allows a custom EventQueue implementation to replace this one. 
+   * All pending events are transferred to the new queue. Calls to postEvent,
+   * getNextEvent, and peekEvent are forwarded to the pushed queue until it
+   * is removed with a pop().
+   *
+   * @exception NullPointerException if newEventQueue is null.
+   */
   public synchronized void push(EventQueue newEventQueue)
   {
+    if (newEventQueue == null)
+      throw new NullPointerException ();
+
     int i = next_out;
     while (i != next_in)
       {
         newEventQueue.postEvent(queue[i]);
-       next_out = i;
-       if (++i == queue.length)
-         i = 0;
+        next_out = i;
+        if (++i == queue.length)
+          i = 0;
       }
 
     next = newEventQueue;
@@ -301,19 +308,19 @@ public class EventQueue
     // occur.
     synchronized (prev)
       {
-       prev.next = null;
+        prev.next = null;
       }
 
     synchronized (this)
       {
-       int i = next_out;
-       while (i != next_in)
-         {
+        int i = next_out;
+        while (i != next_in)
+          {
             prev.postEvent(queue[i]);
-           next_out = i;
-           if (++i == queue.length)
-             i = 0;
-         }
+            next_out = i;
+            if (++i == queue.length)
+              i = 0;
+          }
       }
   }
 
@@ -328,22 +335,22 @@ public class EventQueue
     if (evt instanceof ActiveEvent)
       {
         ActiveEvent active_evt = (ActiveEvent) evt;
-       active_evt.dispatch();
+        active_evt.dispatch();
       }
     else
       {
-       Object source = evt.getSource();
+        Object source = evt.getSource();
 
-       if (source instanceof Component)
-         {
+        if (source instanceof Component)
+          {
             Component srccmp = (Component) source;
-           srccmp.dispatchEvent(evt);
-         }
-       else if (source instanceof MenuComponent)
-         {
-           MenuComponent srccmp = (MenuComponent) source;
-           srccmp.dispatchEvent(evt);
-         }
+            srccmp.dispatchEvent(evt);
+          }
+        else if (source instanceof MenuComponent)
+          {
+            MenuComponent srccmp = (MenuComponent) source;
+            srccmp.dispatchEvent(evt);
+          }
       }
   }
 
index 9b8b82a9a952cc525469f7cd0a85cb4ae583b5ad..b5192f32faac64aff657a78675109332f82a313e 100644 (file)
@@ -38,6 +38,7 @@ exception statement from your version. */
 
 package java.awt;
 
+import java.awt.event.MouseEvent;
 import java.awt.peer.ScrollPanePeer;
 import java.awt.peer.ContainerPeer;
 import java.awt.peer.ComponentPeer;
@@ -105,6 +106,8 @@ private int scrollbarDisplayPolicy;
 // Current scroll position
 private Point scrollPosition = new Point(0, 0);
 
+private boolean wheelScrollingEnabled;
+
 /*************************************************************************/
 
 /*
@@ -153,6 +156,8 @@ ScrollPane(int scrollbarDisplayPolicy)
       hAdjustable = new ScrollPaneAdjustable(Scrollbar.HORIZONTAL);
       vAdjustable = new ScrollPaneAdjustable(Scrollbar.VERTICAL);
     }
+
+  wheelScrollingEnabled = true;
 }
 
 /*************************************************************************/
@@ -470,5 +475,37 @@ paramString()
   return(getClass().getName());
 }
 
+  /**
+   * Tells wether or not an event is enabled.
+   *
+   * @since 1.4
+   */
+  public boolean eventTypeEnabled (int type)
+  {
+    if (type == MouseEvent.MOUSE_WHEEL)
+      return wheelScrollingEnabled;
+
+    return super.eventTypeEnabled (type);
+  }
+
+  /**
+   * Tells wether or not wheel scrolling is enabled.
+   *
+   * @since 1.4
+   */
+  public boolean isWheelScrollingEnabled ()
+  {
+    return wheelScrollingEnabled;
+  }
+
+  /**
+   * Enables/disables wheel scrolling.
+   *
+   * @since 1.4
+   */
+  public void setWheelScrollingEnabled (boolean enable)
+  {
+    wheelScrollingEnabled = enable;
+  }
 } // class ScrollPane