harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r453843 - in /incubator/harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/ main/java/common/org/apache/harmony/awt/ test/api/java/common/org/apache/harmony/awt/
Date Sat, 07 Oct 2006 04:09:29 GMT
Author: ndbeyer
Date: Fri Oct  6 21:09:28 2006
New Revision: 453843

URL: http://svn.apache.org/viewvc?view=rev&rev=453843
Log:
Generify ListenerList and AWTListenerList; cleanup improper use of ListenerList; cleanup tests

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/AWTListenerList.java
    incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ListenerList.java
    incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/ListenerListTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/AWTListenerList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/AWTListenerList.java?view=diff&rev=453843&r1=453842&r2=453843
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/AWTListenerList.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/AWTListenerList.java
Fri Oct  6 21:09:28 2006
@@ -14,32 +14,29 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Pavel Dolgov
- * @version $Revision$
- */
+
 package java.awt;
 
 import java.util.EventListener;
 
 import org.apache.harmony.awt.ListenerList;
 
-
-final class AWTListenerList extends ListenerList {
+final class AWTListenerList<T extends EventListener> extends ListenerList<T>
{
     private static final long serialVersionUID = -2622077171532840953L;
 
     private final Component owner;
 
     AWTListenerList(Component owner) {
+        super();
         this.owner = owner;
     }
 
-    public void addUserListener(EventListener listener) {
+    @Override
+    public void addUserListener(T listener) {
         super.addUserListener(listener);
 
         if (owner != null) {
             owner.deprecatedEventHandler = false;
         }
     }
-
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java?view=diff&rev=453843&r1=453842&r2=453843
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java
Fri Oct  6 21:09:28 2006
@@ -20,14 +20,12 @@
  */
 package java.awt;
 
-import java.awt.Toolkit;
 import java.awt.event.FocusEvent;
 import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.WindowEvent;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 
 public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
@@ -106,15 +104,12 @@
 
     private boolean preProcessKeyEvent(KeyEvent ke) {
         // first pass event to every key event dispatcher:
-        if (keyEventDispatchers != null) {
-            Iterator<?> it = keyEventDispatchers.getUserIterator();
-            while (it.hasNext()) {
-                KeyEventDispatcher ked = (KeyEventDispatcher)it.next();
-                if (ked.dispatchKeyEvent(ke)) {
-                    return true;
-                }
+        for (KeyEventDispatcher ked : getKeyEventDispatchers()) {
+            if (ked.dispatchKeyEvent(ke)) {
+                return true;
             }
         }
+
         return false;
     }
 
@@ -432,15 +427,12 @@
     @Override
     public boolean postProcessKeyEvent(KeyEvent ke) {
         // pass event to every key event postprocessor:
-        if (keyEventPostProcessors != null) {
-            Iterator<?> it = keyEventPostProcessors.getUserIterator();
-            while (it.hasNext()) {
-                KeyEventPostProcessor kep = (KeyEventPostProcessor) it.next();
-                if (kep.postProcessKeyEvent(ke)) {
-                    return true;
-                }
+        for (KeyEventPostProcessor kep : getKeyEventPostProcessors()) {
+            if (kep.postProcessKeyEvent(ke)) {
+                return true;
             }
         }
+        
         // postprocess the event if no KeyEventPostProcessor dispatched it
         if (!ke.isConsumed()) {
             handleShortcut(ke);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java?view=diff&rev=453843&r1=453842&r2=453843
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java
Fri Oct  6 21:09:28 2006
@@ -28,17 +28,16 @@
 import java.beans.PropertyVetoException;
 import java.beans.VetoableChangeListener;
 import java.beans.VetoableChangeSupport;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Vector;
 
-import org.apache.harmony.awt.ListenerList;
 
-
-public abstract class KeyboardFocusManager
-implements KeyEventDispatcher, KeyEventPostProcessor {
+public abstract class KeyboardFocusManager implements KeyEventDispatcher, KeyEventPostProcessor
{
 
     public static final int FORWARD_TRAVERSAL_KEYS = 0;
 
@@ -85,9 +84,9 @@
 
     private static Window prevFocusedWindow;
 
-    final ListenerList<KeyEventDispatcher> keyEventDispatchers = new ListenerList<KeyEventDispatcher>();
+    private final Vector<KeyEventDispatcher> keyEventDispatchers = new Vector<KeyEventDispatcher>();
 
-    final ListenerList<KeyEventPostProcessor> keyEventPostProcessors = new ListenerList<KeyEventPostProcessor>();
+    private final Vector<KeyEventPostProcessor> keyEventPostProcessors = new Vector<KeyEventPostProcessor>();
 
     private PropertyChangeSupport propertyChangeSupport;
 
@@ -104,11 +103,11 @@
     }
 
     public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) {
-        keyEventDispatchers.addUserListener(dispatcher);
+        keyEventDispatchers.add(dispatcher);
     }
 
     public void addKeyEventPostProcessor(KeyEventPostProcessor processor) {
-        keyEventPostProcessors.addUserListener(processor);
+        keyEventPostProcessors.add(processor);
     }
 
     public void addPropertyChangeListener(String propertyName,
@@ -274,11 +273,11 @@
     }
 
     protected List<KeyEventDispatcher> getKeyEventDispatchers() {
-        return keyEventDispatchers.getUserListeners();
+        return new ArrayList<KeyEventDispatcher>(keyEventDispatchers);
     }
 
     protected List<KeyEventPostProcessor> getKeyEventPostProcessors() {
-        return keyEventPostProcessors.getUserListeners();
+        return new ArrayList<KeyEventPostProcessor>(keyEventPostProcessors);
     }
 
     public Component getPermanentFocusOwner() {
@@ -313,11 +312,11 @@
     }
 
     public void removeKeyEventDispatcher(KeyEventDispatcher dispatcher) {
-       keyEventDispatchers.removeUserListener(dispatcher);
+       keyEventDispatchers.remove(dispatcher);
     }
 
     public void removeKeyEventPostProcessor(KeyEventPostProcessor processor) {
-        keyEventPostProcessors.removeUserListener(processor);
+        keyEventPostProcessors.remove(processor);
     }
 
     public void removePropertyChangeListener(String propertyName,

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ListenerList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ListenerList.java?view=diff&rev=453843&r1=453842&r2=453843
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ListenerList.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ListenerList.java
Fri Oct  6 21:09:28 2006
@@ -14,10 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Pavel Dolgov
- * @version $Revision$
- */
+
 package org.apache.harmony.awt;
 
 import java.io.IOException;
@@ -36,20 +33,24 @@
  * 2. To ensure call for all listeners as atomic operation
  * 3. To support system listeners that are needed for built-in AWT components
  */
-public class ListenerList<T> implements Serializable {
+public class ListenerList<T extends EventListener> implements Serializable {
     private static final long serialVersionUID = 9180703263299648154L;
 
-    private transient ArrayList<EventListener> systemList;
+    private transient ArrayList<T> systemList;
     private transient ArrayList<T> userList;
+    
+    public ListenerList() {
+        super();
+    }
 
     /**
      * Adds system listener to this list.
      *
      * @param listener - listener to be added.
      */
-    public void addSystemListener(EventListener listener) {
+    public void addSystemListener(T listener) {
         if (systemList == null) {
-            systemList = new ArrayList<EventListener>();
+            systemList = new ArrayList<T>();
         }
         systemList.add(listener);
     }
@@ -102,7 +103,7 @@
      * @param emptyArray - empty array, it's for deriving particular listeners class.
      * @return array of all user listeners.
      */
-    public EventListener[] getUserListeners(EventListener[] emptyArray){
+    public <AT> AT[] getUserListeners(AT[] emptyArray){
         synchronized (this) {
             return (userList != null ? userList.toArray(emptyArray) : emptyArray);
 
@@ -140,7 +141,7 @@
      *
      * @return iterator for system listeners.
      */
-    public Iterator<EventListener> getSystemIterator() {
+    public Iterator<T> getSystemIterator() {
         return systemList.iterator();
     }
 
@@ -174,7 +175,7 @@
 
         stream.defaultReadObject();
 
-        systemList = (ArrayList<EventListener>)stream.readObject();
+        systemList = (ArrayList<T>)stream.readObject();
         userList = (ArrayList<T>)stream.readObject();
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/ListenerListTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/ListenerListTest.java?view=diff&rev=453843&r1=453842&r2=453843
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/ListenerListTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/ListenerListTest.java
Fri Oct  6 21:09:28 2006
@@ -14,86 +14,61 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Pavel Dolgov
- * @version $Revision$
- */
+
 package org.apache.harmony.awt;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.util.EventListener;
 
 import junit.framework.TestCase;
 
-/**
- * ListenerListTest
- */
 public class ListenerListTest extends TestCase {
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(ListenerListTest.class);
-    }
-
-    public void testAddSystemListener() {
-    }
-
-    public void testAddUserListener() {
-    }
-
-    public void testRemoveUserListener() {
-    }
-
-    public void testGetUserListeners() {
-    }
-
-    public void testGetUserIterator() {
-    }
-
-    public void testGetSystemIterator() {
-    }
-
     static class SerializableListener implements EventListener, Serializable {
-    };
+        private static final long serialVersionUID = 1L;
+    }
 
     public void testSerialize() {
+        ListenerList<EventListener> list = new ListenerList<EventListener>();
 
-        ListenerList list = new ListenerList();
-
-        list.addUserListener(new EventListener() {});
+        list.addUserListener(new EventListener() {
+        });
         assertTrue(list.getUserIterator().hasNext());
 
         list.addSystemListener(new SerializableListener());
         assertTrue(list.getSystemIterator().hasNext());
 
-        ListenerList restored = writeAndRead(list);
+        ListenerList<EventListener> restored = writeAndRead(list);
         assertFalse(restored.getUserIterator().hasNext());
         assertTrue(restored.getSystemIterator().hasNext());
 
     }
 
-    ListenerList writeAndRead(ListenerList original) {
+    @SuppressWarnings("unchecked")
+    ListenerList<EventListener> writeAndRead(ListenerList<EventListener> original)
{
         try {
-            File tempFile = File.createTempFile("save", ".object");
-
-            FileOutputStream fos = new FileOutputStream(tempFile);
-
-            ObjectOutputStream oos = new ObjectOutputStream(fos);
+            ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512);
+            ObjectOutputStream oos = new ObjectOutputStream(byteStream);
             oos.writeObject(original);
+            oos.flush();
             oos.close();
 
+            ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(byteStream
+                    .toByteArray()));
 
-            FileInputStream fis = new FileInputStream(tempFile);
-            ObjectInputStream ois = new ObjectInputStream(fis);
-
-            ListenerList restored = (ListenerList)ois.readObject();
-            tempFile.delete();
+            ListenerList<EventListener> restored = (ListenerList<EventListener>)
ois
+                    .readObject();
             return restored;
 
         } catch (IOException e) {
-            throw new RuntimeException(e);
+            throw new AssertionError(e);
         } catch (ClassNotFoundException e) {
-            throw new RuntimeException(e);
+            throw new AssertionError(e);
         }
-
     }
 }



Mime
View raw message