You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/10/08 01:10:24 UTC

svn commit: r454042 [6/6] - in /incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common: java/awt/ org/apache/harmony/awt/

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java?view=diff&rev=454042&r1=454041&r2=454042
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java Sat Oct  7 16:10:23 2006
@@ -71,7 +71,6 @@
 import java.util.MissingResourceException;
 import java.util.Properties;
 import java.util.ResourceBundle;
-
 import org.apache.harmony.awt.ChoiceStyle;
 import org.apache.harmony.awt.ComponentInternals;
 import org.apache.harmony.awt.ContextStorage;
@@ -95,35 +94,44 @@
 import org.apache.harmony.awt.wtk.WTK;
 import org.apache.harmony.awt.wtk.WindowFactory;
 
-
 public abstract class Toolkit {
-
     private static final String RECOURCE_PATH = "org.apache.harmony.awt.resources.AWTProperties";
 
     private static final ResourceBundle properties = loadResources(RECOURCE_PATH);
 
     final Dispatcher dispatcher;
+
     private EventQueueCore systemEventQueueCore;
+
     final EventDispatchThread dispatchThread;
+
     NativeEventThread nativeThread;
+
     private final AWTEventsManager awtEventsManager;
+
     /* key = nativeWindow, value = Component, should be Map<NativeWindow, Component> */
     private final Map<NativeWindow, Object> windowComponentMap = new HashMap<NativeWindow, Object>();
-    /* key = nativeWindow, value = MenuComponent */
 
+    /* key = nativeWindow, value = MenuComponent */
     private final Map<NativeWindow, Object> windowPopupMap = new HashMap<NativeWindow, Object>();
 
     private final Map<NativeWindow, Window> windowFocusProxyMap = new HashMap<NativeWindow, Window>();
 
-    private class AWTTreeLock {}
+    private class AWTTreeLock {
+    }
+
     final Object awtTreeLock = new AWTTreeLock();
+
     private final Synchronizer synchronizer = ContextStorage.getSynchronizer();
+
     final ShutdownWatchdog shutdownWatchdog = new ShutdownWatchdog();
 
     final Theme theme = createTheme();
 
     final AutoNumber autoNumber = new AutoNumber();
+
     final AWTEvent.EventTypeLookup eventTypeLookup = new AWTEvent.EventTypeLookup();
+
     final Frame.AllFrames allFrames = new Frame.AllFrames();
 
     KeyboardFocusManager currentKeyboardFocusManager;
@@ -131,6 +139,7 @@
     MouseEventPreprocessor mouseEventPreprocessor;
 
     NativeClipboard systemClipboard = null;
+
     private NativeClipboard systemSelection = null;
 
     private boolean bDynamicLayoutSet = true;
@@ -155,11 +164,11 @@
 
     final WindowList windows = new WindowList();
 
-    private WTK wtk = null;
+    private WTK wtk;
+
     final DTK dtk;
 
     private final class ComponentInternalsImpl extends ComponentInternals {
-
         @Override
         public NativeWindow getNativeWindow(Component component) {
             lockAWT();
@@ -230,8 +239,8 @@
         }
 
         @Override
-        public void unsafeInvokeAndWait(Runnable runnable)
-                throws InterruptedException, InvocationTargetException {
+        public void unsafeInvokeAndWait(Runnable runnable) throws InterruptedException,
+                InvocationTargetException {
             Toolkit.this.unsafeInvokeAndWait(runnable);
         }
 
@@ -256,7 +265,7 @@
         }
 
         @Override
-        public TextFieldKit getTextFieldKit(Component comp)  {
+        public TextFieldKit getTextFieldKit(Component comp) {
             lockAWT();
             try {
                 return comp.getTextFieldKit();
@@ -281,8 +290,7 @@
         }
 
         @Override
-        public void setMouseEventPreprocessor(
-                MouseEventPreprocessor preprocessor) {
+        public void setMouseEventPreprocessor(MouseEventPreprocessor preprocessor) {
             lockAWT();
             try {
                 mouseEventPreprocessor = preprocessor;
@@ -342,7 +350,7 @@
 
         @Override
         public void setDesktopProperty(String name, Object value) {
-            Toolkit.this.setDesktopProperty(name, value);            
+            Toolkit.this.setDesktopProperty(name, value);
         }
 
         @Override
@@ -352,12 +360,12 @@
 
         @Override
         public void endModalLoop(Dialog dlg) {
-            dlg.endModalLoop();            
+            dlg.endModalLoop();
         }
 
         @Override
         public void setVisibleFlag(Component comp, boolean visible) {
-            comp.visible = visible;            
+            comp.visible = visible;
         }
     }
 
@@ -401,9 +409,8 @@
      *                                      can be called from layoutContainer()
      *                                      for layout managers
      */
-    final void unsafeInvokeAndWait(Runnable runnable)
-            throws InterruptedException, InvocationTargetException
-    {
+    final void unsafeInvokeAndWait(Runnable runnable) throws InterruptedException,
+            InvocationTargetException {
         synchronizer.storeStateAndFree();
         try {
             EventQueue.invokeAndWait(runnable);
@@ -430,8 +437,8 @@
             if (properties != null) {
                 try {
                     retVal = properties.getString(propName);
-                } catch(MissingResourceException e) {
-                } catch(ClassCastException e) {
+                } catch (MissingResourceException e) {
+                } catch (ClassCastException e) {
                 }
             }
             return (retVal == null) ? defVal : retVal;
@@ -441,7 +448,7 @@
     }
 
     public static Toolkit getDefaultToolkit() {
-        synchronized(ContextStorage.getContextLock()) {
+        synchronized (ContextStorage.getContextLock()) {
             if (ContextStorage.shutdownPending()) {
                 return null;
             }
@@ -457,11 +464,9 @@
             } finally {
                 staticUnlockAWT();
             }
-            
-            
-        //TODO: read system property named awt.toolkit
-        //and create an instance of the specified class,
-        //by default use ToolkitImpl
+            //TODO: read system property named awt.toolkit
+            //and create an instance of the specified class,
+            //by default use ToolkitImpl
         }
     }
 
@@ -472,7 +477,7 @@
     private static ResourceBundle loadResources(String path) {
         try {
             return ResourceBundle.getBundle(path);
-        } catch(MissingResourceException e) {
+        } catch (MissingResourceException e) {
             return null;
         }
     }
@@ -490,21 +495,21 @@
     }
 
     Component getComponentById(long id) {
-        if(id == 0) {
+        if (id == 0) {
             return null;
         }
         return (Component) windowComponentMap.get(getWindowFactory().getWindowById(id));
     }
 
     PopupBox getPopupBoxById(long id) {
-        if(id == 0) {
+        if (id == 0) {
             return null;
         }
         return (PopupBox) windowPopupMap.get(getWindowFactory().getWindowById(id));
     }
 
     Window getFocusProxyOwnerById(long id) {
-        if(id == 0) {
+        if (id == 0) {
             return null;
         }
         return windowFocusProxyMap.get(getWindowFactory().getWindowById(id));
@@ -525,16 +530,12 @@
             new EventQueue(this); // create the system EventQueue
             dispatcher = new Dispatcher(this);
             final String className = getWTKClassName();
-
             desktopProperties = new HashMap<String, Object>();
             desktopPropsSupport = new PropertyChangeSupport(this);
-
             awtEventsManager = new AWTEventsManager();
             dispatchThread = new EventDispatchThread(this, dispatcher);
             nativeThread = new NativeEventThread();
-            
             dtk = DTK.getDTK();
-
             NativeEventThread.Init init = new NativeEventThread.Init() {
                 public WTK init() {
                     wtk = createWTK(className);
@@ -546,7 +547,6 @@
                 }
             };
             nativeThread.start(init);
-            
             dispatchThread.start();
             wtk.getNativeEventQueue().awake();
         } finally {
@@ -586,13 +586,15 @@
 
     protected abstract CheckboxPeer createCheckbox(Checkbox a0) throws HeadlessException;
 
-    protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem a0) throws HeadlessException;
+    protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem a0)
+            throws HeadlessException;
 
     protected abstract ChoicePeer createChoice(Choice a0) throws HeadlessException;
 
     protected abstract DialogPeer createDialog(Dialog a0) throws HeadlessException;
 
-    public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent a0) throws InvalidDnDOperationException;
+    public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent a0)
+            throws InvalidDnDOperationException;
 
     protected abstract FileDialogPeer createFileDialog(FileDialog a0) throws HeadlessException;
 
@@ -646,14 +648,15 @@
 
     protected abstract EventQueue getSystemEventQueueImpl();
 
-    public abstract Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight) throws HeadlessException;
+    public abstract Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
+            InputMethodHighlight highlight) throws HeadlessException;
 
-    Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlightImpl(InputMethodHighlight highlight)
-            throws HeadlessException {
+    Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlightImpl(
+            InputMethodHighlight highlight) throws HeadlessException {
         checkHeadless();
         HashMap<java.awt.font.TextAttribute, ?> map = new HashMap<java.awt.font.TextAttribute, Object>();
         wtk.getSystemProperties().mapInputMethodHighlight(highlight, map);
-        return Collections.<java.awt.font.TextAttribute, Object>unmodifiableMap(map);
+        return Collections.<java.awt.font.TextAttribute, Object> unmodifiableMap(map);
     }
 
     public void addPropertyChangeListener(String propName, PropertyChangeListener l) {
@@ -671,7 +674,8 @@
     }
 
     protected java.awt.peer.MouseInfoPeer getMouseInfoPeer() {
-        return new MouseInfoPeer() {};
+        return new MouseInfoPeer() {
+        };
     }
 
     protected LightweightPeer createComponent(Component a0) {
@@ -712,7 +716,8 @@
         desktopPropsSupport.removePropertyChangeListener(propName, l);
     }
 
-    public Cursor createCustomCursor(Image img, Point hotSpot, String name) throws IndexOutOfBoundsException, HeadlessException {
+    public Cursor createCustomCursor(Image img, Point hotSpot, String name)
+            throws IndexOutOfBoundsException, HeadlessException {
         lockAWT();
         try {
             checkHeadless();
@@ -756,19 +761,16 @@
             if (desktopProperties.isEmpty()) {
                 initializeDesktopProperties();
             }
-
             if (propName.equals("awt.dynamicLayoutSupported")) {
                 // dynamicLayoutSupported is special case
                 return Boolean.valueOf(isDynamicLayoutActive());
             }
-
             Object val = desktopProperties.get(propName);
             if (val == null) {
                 // try to lazily load prop value
                 // just for compatibility, our lazilyLoad is empty
                 val = lazilyLoadDesktopProperty(propName);
             }
-
             return val;
         } finally {
             unlockAWT();
@@ -781,7 +783,6 @@
         } finally {
             unlockAWT();
         }
-
         if (true) {
             throw new RuntimeException("Method is not implemented"); //TODO: implement
         }
@@ -814,7 +815,6 @@
         } finally {
             unlockAWT();
         }
-
         if (true) {
             throw new RuntimeException("Method is not implemented"); //TODO: implement
         }
@@ -844,26 +844,22 @@
     EventQueueCore getSystemEventQueueCore() {
         return systemEventQueueCore;
     }
-    
+
     void setSystemEventQueueCore(EventQueueCore core) {
         systemEventQueueCore = core;
     }
-    
+
     public Clipboard getSystemSelection() throws HeadlessException {
         lockAWT();
         try {
             checkHeadless();
-
             SecurityManager security = System.getSecurityManager();
-
             if (security != null) {
                 security.checkSystemClipboardAccess();
             }
-
             if (systemSelection == null) {
                 systemSelection = dtk.getNativeSelection();
             }
-
             return systemSelection;
         } finally {
             unlockAWT();
@@ -883,7 +879,6 @@
         lockAWT();
         try {
             checkHeadless();
-
             // always return true
             return true;
         } finally {
@@ -895,7 +890,6 @@
         lockAWT();
         try {
             checkHeadless();
-
             return bDynamicLayoutSet;
         } finally {
             unlockAWT();
@@ -906,7 +900,6 @@
         lockAWT();
         try {
             checkHeadless();
-
             return wtk.getWindowFactory().isWindowStateSupported(state);
         } finally {
             unlockAWT();
@@ -930,10 +923,8 @@
         lockAWT();
         try {
             oldVal = getDesktopProperty(propName);
-
             userPropSet.add(propName);
             desktopProperties.put(propName, value);
-
         } finally {
             unlockAWT();
         }
@@ -944,7 +935,6 @@
         lockAWT();
         try {
             checkHeadless();
-
             bDynamicLayoutSet = dynamic;
         } finally {
             unlockAWT();
@@ -957,7 +947,6 @@
         } finally {
             unlockAWT();
         }
-
         if (true) {
             throw new RuntimeException("Method is not implemented"); //TODO: implement
         }
@@ -982,9 +971,8 @@
 
     private WTK createWTK(String clsName) {
         WTK newWTK = null;
-
         try {
-            newWTK = (WTK)Class.forName(clsName).newInstance();
+            newWTK = (WTK) Class.forName(clsName).newInstance();
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
@@ -1009,15 +997,12 @@
         if (recentNativeWindowComponent == null) {
             return;
         }
-
         if (recentNativeWindowComponent instanceof Component) {
             windowComponentMap.put(win, recentNativeWindowComponent);
-            ((Component)recentNativeWindowComponent).nativeWindowCreated(win);
-
-        } else if(recentNativeWindowComponent instanceof PopupBox) {
+            ((Component) recentNativeWindowComponent).nativeWindowCreated(win);
+        } else if (recentNativeWindowComponent instanceof PopupBox) {
             windowPopupMap.put(win, recentNativeWindowComponent);
         }
-
         recentNativeWindowComponent = null;
     }
 
@@ -1027,82 +1012,63 @@
      */
     boolean onWindowCreated(long winId) {
         nativeWindowCreated(getWindowFactory().getWindowById(winId));
-
         return false;
     }
 
     NativeWindow createEmbeddedNativeWindow(EmbeddedWindow ew) {
         windows.add(ew);
-
         CreationParams cp = new CreationParams();
-
         cp.child = true;
         cp.disabled = false;
         cp.name = "EmbeddedWindow";
-
         cp.parentId = ew.nativeWindowId;
         cp.x = 0;
         cp.y = 0;
-
         Dimension size = getWindowFactory().getWindowSizeById(ew.nativeWindowId);
-
         cp.w = size.width;
         cp.h = size.height;
-
         recentNativeWindowComponent = ew;
         NativeWindow win = getWindowFactory().createWindow(cp);
         nativeWindowCreated(win);
-
         shutdownWatchdog.setWindowListEmpty(false);
-
         return win;
     }
 
-
     NativeWindow createNativeWindow(Component c) {
         if (c instanceof Window) {
             windows.add(c);
         }
-
         Component parent = null;
         Point location = c.getLocation();
-
         CreationParams cp = new CreationParams();
-
         cp.child = !(c instanceof Window);
         cp.disabled = !c.isEnabled();
-
         if (c instanceof Window) {
-            Window w = (Window)c;
+            Window w = (Window) c;
             cp.resizable = w.isResizable();
             cp.undecorated = w.isUndecorated();
             parent = w.getOwner();
             cp.locationByPlatform = w.locationByPlatform;
-
             if (c instanceof Frame) {
-                Frame frame = (Frame)c;
+                Frame frame = (Frame) c;
                 int state = frame.getExtendedState();
                 cp.name = frame.getTitle();
                 cp.iconified = (state & Frame.ICONIFIED) != 0;
-
                 cp.maximizedState = 0;
-                if ( (state & Frame.MAXIMIZED_BOTH) != 0) {
+                if ((state & Frame.MAXIMIZED_BOTH) != 0) {
                     cp.maximizedState |= cp.MAXIMIZED;
                 }
-                if ( (state & Frame.MAXIMIZED_HORIZ) != 0) {
+                if ((state & Frame.MAXIMIZED_HORIZ) != 0) {
                     cp.maximizedState |= cp.MAXIMIZED_HORIZ;
                 }
-                if ( (state & Frame.MAXIMIZED_VERT) != 0) {
+                if ((state & Frame.MAXIMIZED_VERT) != 0) {
                     cp.maximizedState |= cp.MAXIMIZED_VERT;
                 }
-
                 cp.decorType = CreationParams.DECOR_TYPE_FRAME;
-
             } else if (c instanceof Dialog) {
-                Dialog dlg = (Dialog)c;
+                Dialog dlg = (Dialog) c;
                 cp.name = dlg.getTitle();
                 cp.decorType = CreationParams.DECOR_TYPE_DIALOG;
-
             } else if (w.isPopup()) {
                 cp.decorType = CreationParams.DECOR_TYPE_POPUP;
             } else {
@@ -1111,11 +1077,9 @@
         } else {
             parent = c.getHWAncestor();
             cp.name = c.getName();
-
             //set location relative to the nearest heavy weight ancestor
             location = MouseDispatcher.convertPoint(c, 0, 0, parent);
         }
-
         if (parent != null) {
             NativeWindow nativeParent = parent.getNativeWindow();
             if (nativeParent == null) {
@@ -1127,26 +1091,21 @@
             }
             cp.parentId = nativeParent.getId();
         }
-
         cp.x = location.x;
         cp.y = location.y;
         cp.w = c.getWidth();
         cp.h = c.getHeight();
-
         recentNativeWindowComponent = c;
         NativeWindow win = getWindowFactory().createWindow(cp);
         nativeWindowCreated(win);
-
         if (c instanceof Window) {
             shutdownWatchdog.setWindowListEmpty(false);
         }
-
         return win;
     }
 
     void removeNativeWindow(NativeWindow w) {
         Component comp = (Component) windowComponentMap.get(w);
-
         if ((comp != null) && (comp instanceof Window)) {
             windows.remove(comp);
         }
@@ -1154,9 +1113,7 @@
     }
 
     NativeWindow createPopupNativeWindow(PopupBox popup) {
-
         CreationParams cp = new CreationParams();
-
         cp.child = popup.isMenuBar();
         cp.disabled = false;
         cp.resizable = false;
@@ -1166,26 +1123,20 @@
         cp.maximizedState = 0;
         cp.decorType = CreationParams.DECOR_TYPE_POPUP;
         NativeWindow nativeParent;
-
         if (popup.getParent() != null) {
             nativeParent = popup.getParent().getNativeWindow();
         } else {
             nativeParent = popup.getOwner().getNativeWindow();
         }
-
         assert nativeParent != null;
-
         cp.parentId = nativeParent.getId();
-
         cp.x = popup.getLocation().x;
         cp.y = popup.getLocation().y;
         cp.w = popup.getSize().width;
         cp.h = popup.getSize().height;
-
         recentNativeWindowComponent = popup;
         NativeWindow win = getWindowFactory().createWindow(cp);
         nativeWindowCreated(win);
-
         return win;
     }
 
@@ -1194,9 +1145,7 @@
     }
 
     NativeWindow createFocusProxyNativeWindow(Window owner) {
-
         CreationParams cp = new CreationParams();
-
         cp.child = true;
         cp.disabled = false;
         cp.resizable = false;
@@ -1206,15 +1155,12 @@
         cp.maximizedState = 0;
         cp.decorType = CreationParams.DECOR_TYPE_NONE;
         cp.parentId = owner.getNativeWindow().getId();
-
         cp.x = -10;
         cp.y = -10;
         cp.w = 1;
         cp.h = 1;
-
         NativeWindow win = getWindowFactory().createWindow(cp);
         windowFocusProxyMap.put(win, owner);
-
         return win;
     }
 
@@ -1222,7 +1168,7 @@
         windowFocusProxyMap.remove(w);
     }
 
-    NativeEventQueue getNativeEventQueue(){
+    NativeEventQueue getNativeEventQueue() {
         return wtk.getNativeEventQueue();
     }
 
@@ -1235,6 +1181,7 @@
     NativeCursor createNativeCursor(int type) {
         return wtk.getCursorFactory().getCursor(type);
     }
+
     /**
      * Returns a shared instance of implementation of org.apache.harmony.awt.wtk.NativeCursor
      * for current platform for custom cursor
@@ -1258,11 +1205,9 @@
         lockAWT();
         try {
             SecurityManager security = System.getSecurityManager();
-
             if (security != null) {
                 security.checkPermission(awtEventsManager.permission);
             }
-
             awtEventsManager.addAWTEventListener(listener, eventMask);
         } finally {
             unlockAWT();
@@ -1273,11 +1218,9 @@
         lockAWT();
         try {
             SecurityManager security = System.getSecurityManager();
-
             if (security != null) {
                 security.checkPermission(awtEventsManager.permission);
             }
-
             awtEventsManager.removeAWTEventListener(listener);
         } finally {
             unlockAWT();
@@ -1288,11 +1231,9 @@
         lockAWT();
         try {
             SecurityManager security = System.getSecurityManager();
-
             if (security != null) {
                 security.checkPermission(awtEventsManager.permission);
             }
-
             return awtEventsManager.getAWTEventListeners();
         } finally {
             unlockAWT();
@@ -1303,11 +1244,9 @@
         lockAWT();
         try {
             SecurityManager security = System.getSecurityManager();
-
             if (security != null) {
                 security.checkPermission(awtEventsManager.permission);
             }
-
             return awtEventsManager.getAWTEventListeners(eventMask);
         } finally {
             unlockAWT();
@@ -1321,14 +1260,12 @@
     private static Theme createTheme() {
         String osName = System.getProperty("os.name").toLowerCase();
         String packageBase = "org.apache.harmony.awt.theme", win = "windows", lin = "linux";
-
         PrivilegedAction<String> action = new PrivilegedAction<String>() {
             public String run() {
                 return System.getProperty("awt.theme");
-            }};
-
+            }
+        };
         String className = AccessController.doPrivileged(action);
-
         if (className == null) {
             if (osName.startsWith(lin)) {
                 className = packageBase + "." + lin + ".LinuxTheme";
@@ -1336,22 +1273,19 @@
                 className = packageBase + "." + win + ".WinTheme";
             }
         }
-
         if (className != null) {
             try {
-                return (Theme)Class.forName(className).newInstance();
+                return (Theme) Class.forName(className).newInstance();
             } catch (Exception e) {
             }
         }
-
         return new Theme();
     }
-    
-    final class AWTEventsManager {
 
+    final class AWTEventsManager {
         AWTPermission permission = new AWTPermission("listenToAllAWTEvents");
 
-        private final AWTListenerList listeners = new AWTListenerList(null);
+        private final AWTListenerList<AWTEventListenerProxy> listeners = new AWTListenerList<AWTEventListenerProxy>();
 
         void addAWTEventListener(AWTEventListener listener, long eventMask) {
             if (listener != null) {
@@ -1361,12 +1295,9 @@
 
         void removeAWTEventListener(AWTEventListener listener) {
             if (listener != null) {
-                for (Iterator<?> i = listeners.getUserIterator(); i.hasNext();) {
-                    AWTEventListenerProxy proxy = (AWTEventListenerProxy) i.next();
-
+                for (AWTEventListenerProxy proxy : listeners.getUserListeners()) {
                     if (listener == proxy.getListener()) {
                         listeners.removeUserListener(proxy);
-
                         return;
                     }
                 }
@@ -1375,63 +1306,68 @@
 
         AWTEventListener[] getAWTEventListeners() {
             HashSet<EventListener> listenersSet = new HashSet<EventListener>();
-
-            for (Iterator<?> i = listeners.getUserIterator(); i.hasNext();) {
-                listenersSet.add(((AWTEventListenerProxy) i.next()).getListener());
+            for (AWTEventListenerProxy proxy : listeners.getUserListeners()) {
+                listenersSet.add(proxy.getListener());
             }
-
-            return listenersSet.toArray(new AWTEventListener[0]);
+            return listenersSet.toArray(new AWTEventListener[listenersSet.size()]);
         }
 
         AWTEventListener[] getAWTEventListeners(long eventMask) {
             HashSet<EventListener> listenersSet = new HashSet<EventListener>();
-
-            for (Iterator<?> i = listeners.getUserIterator(); i.hasNext();) {
-                AWTEventListenerProxy listenerProxy = (AWTEventListenerProxy) i.next();
-
-                if ((listenerProxy.getEventMask() & eventMask) == eventMask) {
-                    listenersSet.add(listenerProxy.getListener());
+            for (AWTEventListenerProxy proxy : listeners.getUserListeners()) {
+                if ((proxy.getEventMask() & eventMask) == eventMask) {
+                    listenersSet.add(proxy.getListener());
                 }
             }
-
-            return listenersSet.toArray(new AWTEventListener[0]);
+            return listenersSet.toArray(new AWTEventListener[listenersSet.size()]);
         }
 
         void dispatchAWTEvent(AWTEvent event) {
             AWTEvent.EventDescriptor descriptor = eventTypeLookup.getEventDescriptor(event);
-
             if (descriptor == null) {
                 return;
             }
-
-            for (Iterator<?> i = listeners.getUserIterator(); i.hasNext();) {
-                AWTEventListenerProxy listenerProxy = (AWTEventListenerProxy) i.next();
-
-                if ((listenerProxy.getEventMask() & descriptor.eventMask) != 0) {
-                    listenerProxy.eventDispatched(event);
+            for (AWTEventListenerProxy proxy : listeners.getUserListeners()) {
+                if ((proxy.getEventMask() & descriptor.eventMask) != 0) {
+                    proxy.eventDispatched(event);
                 }
             }
         }
-
     }
 
     static final class AutoNumber {
         int nextComponent = 0;
+
         int nextCanvas = 0;
+
         int nextPanel = 0;
+
         int nextWindow = 0;
+
         int nextFrame = 0;
+
         int nextDialog = 0;
+
         int nextButton = 0;
+
         int nextMenuComponent = 0;
+
         int nextLabel = 0;
+
         int nextCheckBox = 0;
+
         int nextScrollbar = 0;
+
         int nextScrollPane = 0;
+
         int nextList = 0;
+
         int nextChoice = 0;
+
         int nextFileDialog = 0;
+
         int nextTextArea = 0;
+
         int nextTextField = 0;
     }
 
@@ -1439,14 +1375,16 @@
      * Thread-safe collection of Window objects
      */
     static final class WindowList {
-
         /**
          * If a non-dispatch thread adds/removes a window,
          * this set it is replaced to avoid the possible conflict
          * with concurrently running lock-free iterator loop
          */
         private LinkedHashSet<Component> windows = new LinkedHashSet<Component>();
-        private class Lock {}
+
+        private class Lock {
+        }
+
         private final Object lock = new Lock();
 
         @SuppressWarnings("unchecked")
@@ -1455,7 +1393,7 @@
                 if (isDispatchThread()) {
                     windows.add(w);
                 } else {
-                    windows = (LinkedHashSet<Component>)windows.clone();
+                    windows = (LinkedHashSet<Component>) windows.clone();
                     windows.add(w);
                 }
             }
@@ -1467,15 +1405,15 @@
                 if (isDispatchThread()) {
                     windows.remove(w);
                 } else {
-                    windows = (LinkedHashSet<Component>)windows.clone();
+                    windows = (LinkedHashSet<Component>) windows.clone();
                     windows.remove(w);
                 }
             }
         }
 
-        Iterator<?> iterator() {
+        Iterator<Component> iterator() {
             synchronized (lock) {
-                return new ReadOnlyIterator(windows.iterator());
+                return new ReadOnlyIterator<Component>(windows.iterator());
             }
         }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/ToolkitImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/ToolkitImpl.java?view=diff&rev=454042&r1=454041&r2=454042
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/ToolkitImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/ToolkitImpl.java Sat Oct  7 16:10:23 2006
@@ -14,10 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Pavel Dolgov, Michael Danilov
- * @version $Revision$
- */
+
 package java.awt;
 
 import java.awt.datatransfer.Clipboard;
@@ -34,14 +31,11 @@
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;
-
 import org.apache.harmony.awt.datatransfer.DTK;
 import org.apache.harmony.awt.gl.*;
 import org.apache.harmony.awt.gl.image.*;
 
-
 class ToolkitImpl extends Toolkit {
-
     static final Hashtable<Serializable, Image> imageCache = new Hashtable<Serializable, Image>();
 
     @Override
@@ -68,13 +62,13 @@
     public int checkImage(Image image, int width, int height, ImageObserver observer) {
         lockAWT();
         try {
-            if(width == 0 || height == 0){
+            if (width == 0 || height == 0) {
                 return ImageObserver.ALLBITS;
             }
-            if(!(image instanceof OffscreenImage)){
+            if (!(image instanceof OffscreenImage)) {
                 return ImageObserver.ALLBITS;
             }
-            OffscreenImage oi = (OffscreenImage)image;
+            OffscreenImage oi = (OffscreenImage) image;
             return oi.checkImage(observer);
         } finally {
             unlockAWT();
@@ -95,8 +89,8 @@
     public Image createImage(byte[] imagedata, int imageoffset, int imagelength) {
         lockAWT();
         try {
-            return new OffscreenImage(new ByteArrayDecodingImageSource(imagedata,
-                    imageoffset, imagelength));
+            return new OffscreenImage(new ByteArrayDecodingImageSource(imagedata, imageoffset,
+                    imagelength));
         } finally {
             unlockAWT();
         }
@@ -126,15 +120,16 @@
     public ColorModel getColorModel() throws HeadlessException {
         lockAWT();
         try {
-            return GraphicsEnvironment.getLocalGraphicsEnvironment().
-                    getDefaultScreenDevice().getDefaultConfiguration().
-                    getColorModel();
+            return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
+                    .getDefaultConfiguration().getColorModel();
         } finally {
             unlockAWT();
         }
     }
 
+    @SuppressWarnings("deprecation")
     @Override
+    @Deprecated
     public FontMetrics getFontMetrics(Font font) {
         lockAWT();
         try {
@@ -148,13 +143,13 @@
     public boolean prepareImage(Image image, int width, int height, ImageObserver observer) {
         lockAWT();
         try {
-            if(width == 0 || height == 0){
+            if (width == 0 || height == 0) {
                 return true;
             }
-            if(!(image instanceof OffscreenImage)){
+            if (!(image instanceof OffscreenImage)) {
                 return true;
             }
-            OffscreenImage oi = (OffscreenImage)image;
+            OffscreenImage oi = (OffscreenImage) image;
             return oi.prepareImage(observer);
         } finally {
             unlockAWT();
@@ -204,8 +199,7 @@
 
     @Override
     protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem a0)
-            throws HeadlessException
-    {
+            throws HeadlessException {
         lockAWT();
         try {
             checkHeadless();
@@ -238,15 +232,13 @@
     }
 
     @Override
-    public DragSourceContextPeer createDragSourceContextPeer(
-            DragGestureEvent dge) throws InvalidDnDOperationException {
+    public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
+            throws InvalidDnDOperationException {
         return dtk.createDragSourceContextPeer(dge);
     }
 
     @Override
-    protected FileDialogPeer createFileDialog(FileDialog a0)
-            throws HeadlessException
-    {
+    protected FileDialogPeer createFileDialog(FileDialog a0) throws HeadlessException {
         lockAWT();
         try {
             checkHeadless();
@@ -333,9 +325,7 @@
     }
 
     @Override
-    protected PopupMenuPeer createPopupMenu(PopupMenu a0)
-            throws HeadlessException
-    {
+    protected PopupMenuPeer createPopupMenu(PopupMenu a0) throws HeadlessException {
         lockAWT();
         try {
             checkHeadless();
@@ -346,9 +336,7 @@
     }
 
     @Override
-    protected ScrollPanePeer createScrollPane(ScrollPane a0)
-            throws HeadlessException
-    {
+    protected ScrollPanePeer createScrollPane(ScrollPane a0) throws HeadlessException {
         lockAWT();
         try {
             checkHeadless();
@@ -359,9 +347,7 @@
     }
 
     @Override
-    protected ScrollbarPeer createScrollbar(Scrollbar a0)
-            throws HeadlessException
-    {
+    protected ScrollbarPeer createScrollbar(Scrollbar a0) throws HeadlessException {
         lockAWT();
         try {
             checkHeadless();
@@ -372,9 +358,7 @@
     }
 
     @Override
-    protected TextFieldPeer createTextField(TextField a0)
-            throws HeadlessException
-    {
+    protected TextFieldPeer createTextField(TextField a0) throws HeadlessException {
         lockAWT();
         try {
             checkHeadless();
@@ -395,7 +379,9 @@
         }
     }
 
+    @SuppressWarnings("deprecation")
     @Override
+    @Deprecated
     public String[] getFontList() {
         lockAWT();
         try {
@@ -405,7 +391,9 @@
         return null;
     }
 
+    @SuppressWarnings("deprecation")
     @Override
+    @Deprecated
     protected FontPeer getFontPeer(String a0, int a1) {
         lockAWT();
         try {
@@ -420,15 +408,14 @@
         return getImage(filename, this);
     }
 
-    static Image getImage(String filename, Toolkit toolkit){
-        synchronized(imageCache) {
+    static Image getImage(String filename, Toolkit toolkit) {
+        synchronized (imageCache) {
             Image im = imageCache.get(filename);
-            if(im == null){
-                try{
+            if (im == null) {
+                try {
                     im = toolkit.createImage(filename);
                     imageCache.put(filename, im);
-                }catch(Exception e){
-
+                } catch (Exception e) {
                 }
             }
             return im;
@@ -441,14 +428,13 @@
     }
 
     static Image getImage(URL url, Toolkit toolkit) {
-        synchronized(imageCache) {
+        synchronized (imageCache) {
             Image im = imageCache.get(url);
-            if(im == null){
-                try{
+            if (im == null) {
+                try {
                     im = toolkit.createImage(url);
                     imageCache.put(url, im);
-                }catch(Exception e){
-
+                } catch (Exception e) {
                 }
             }
             return im;
@@ -469,8 +455,8 @@
     public int getScreenResolution() throws HeadlessException {
         lockAWT();
         try {
-            return ((GLGraphicsDevice)GraphicsEnvironment.getLocalGraphicsEnvironment().
-                    getDefaultScreenDevice()).getResolution().width;
+            return ((GLGraphicsDevice) GraphicsEnvironment.getLocalGraphicsEnvironment()
+                    .getDefaultScreenDevice()).getResolution().width;
         } finally {
             unlockAWT();
         }
@@ -480,8 +466,8 @@
     public Dimension getScreenSize() throws HeadlessException {
         lockAWT();
         try {
-            DisplayMode dm =  GraphicsEnvironment.getLocalGraphicsEnvironment().
-                    getDefaultScreenDevice().getDisplayMode();
+            DisplayMode dm = GraphicsEnvironment.getLocalGraphicsEnvironment()
+                    .getDefaultScreenDevice().getDisplayMode();
             return new Dimension(dm.getWidth(), dm.getHeight());
         } finally {
             unlockAWT();
@@ -493,17 +479,13 @@
         lockAWT();
         try {
             checkHeadless();
-
             SecurityManager security = System.getSecurityManager();
-
             if (security != null) {
                 security.checkSystemClipboardAccess();
             }
-
             if (systemClipboard == null) {
                 systemClipboard = DTK.getDTK().getNativeClipboard();
             }
-
             return systemClipboard;
         } finally {
             unlockAWT();
@@ -511,8 +493,8 @@
     }
 
     @Override
-    public Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight)
-            throws HeadlessException {
+    public Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
+            InputMethodHighlight highlight) throws HeadlessException {
         lockAWT();
         try {
             return mapInputMethodHighlightImpl(highlight);
@@ -525,5 +507,4 @@
     protected EventQueue getSystemEventQueueImpl() {
         return getSystemEventQueueCore().getActiveEventQueue();
     }
-
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Window.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Window.java?view=diff&rev=454042&r1=454041&r2=454042
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Window.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Window.java Sat Oct  7 16:10:23 2006
@@ -14,10 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Dmitry A. Durnev
- * @version $Revision$
- */
+
 package java.awt;
 
 import java.awt.event.WindowEvent;
@@ -37,29 +34,36 @@
 import java.util.Locale;
 import java.util.ResourceBundle;
 import java.util.Set;
-
 import javax.accessibility.Accessible;
 import javax.accessibility.AccessibleContext;
 import javax.accessibility.AccessibleRole;
 import javax.accessibility.AccessibleState;
 import javax.accessibility.AccessibleStateSet;
-
 import org.apache.harmony.awt.AWTPermissionCollection;
 import org.apache.harmony.awt.FieldsAccessor;
 import org.apache.harmony.awt.gl.MultiRectArea;
 import org.apache.harmony.awt.im.InputMethodContext;
 import org.apache.harmony.awt.wtk.NativeWindow;
 
-
 public class Window extends Container implements Accessible {
-
     private static final long serialVersionUID = 4497834738069338734L;
-    private final AWTListenerList windowFocusListeners = new AWTListenerList(this);
-    private final AWTListenerList windowListeners = new AWTListenerList(this);
-    private final AWTListenerList windowStateListeners = new AWTListenerList(this);
+
+    private final AWTListenerList<WindowFocusListener> windowFocusListeners = new AWTListenerList<WindowFocusListener>(
+            this);
+
+    private final AWTListenerList<WindowListener> windowListeners = new AWTListenerList<WindowListener>(
+            this);
+
+    private final AWTListenerList<WindowStateListener> windowStateListeners = new AWTListenerList<WindowStateListener>(
+            this);
+
     private final ArrayList<Window> ownedWindows = new ArrayList<Window>();
+
     private transient Component focusOwner;
-    private boolean focusableWindowState = true;//By default, all Windows have a focusable Window state of true
+
+    private boolean focusableWindowState = true;// By default, all Windows have
+                                                // a focusable Window state of
+                                                // true
 
     private Insets nativeInsets = new Insets(0, 0, 0, 0);
 
@@ -68,21 +72,24 @@
 
     // Properties of Frame and Dialog
     private String title;
+
     private boolean resizable;
+
     private boolean undecorated;
+
     private boolean alwaysOnTop;
+
     boolean locationByPlatform;
 
     /** The window is popup menu or tooltip (for internal use) */
     private boolean popup;
-    
+
     /**
-     * Focus proxy native window actually has native focus
-     * when this Window(Frame) is active, but some other
-     * (owned) Window is focused
+     * Focus proxy native window actually has native focus when this
+     * Window(Frame) is active, but some other (owned) Window is focused
      */
     private transient NativeWindow focusProxy;
-    
+
     /**
      * Component which has requested focus last
      */
@@ -90,15 +97,15 @@
 
     private final transient GraphicsConfiguration graphicsConfiguration;
 
-    private boolean opened = false;
-    private boolean disposed = false;
+    private boolean opened;
+
+    private boolean disposed;
 
     boolean painted;
-    
-    private transient InputContext inputContext;
 
-    protected  class AccessibleAWTWindow extends AccessibleAWTContainer {
+    private transient InputContext inputContext;
 
+    protected class AccessibleAWTWindow extends AccessibleAWTContainer {
         private static final long serialVersionUID = 4215068635060671780L;
 
         @Override
@@ -127,7 +134,6 @@
                 toolkit.unlockAWT();
             }
         }
-
     }
 
     public Window(Window owner) {
@@ -142,41 +148,36 @@
     private void addWindow(Window window) {
         ownedWindows.add(window);
     }
-    
+
     public Window(Window owner, GraphicsConfiguration gc) {
         toolkit.lockAWT();
         try {
-            if (! (this instanceof Frame) && ! (this instanceof EmbeddedWindow)) {
+            if (!(this instanceof Frame) && !(this instanceof EmbeddedWindow)) {
                 if (owner == null) {
                     throw new IllegalArgumentException("null owner window");
                 }
                 owner.addWindow(this);
             }
-
             parent = owner; // window's parent is the same as owner(by spec)
             graphicsConfiguration = getGraphicsConfiguration(gc);
             warningString = getWarningStringImpl();
-
             super.setLayout(new BorderLayout());
-
             if (owner == null) {
                 setBackground(getDefaultBackground());
                 setForeground(getDefaultForeground());
             }
-
             visible = false;
-            focusCycleRoot = true; //FIXME
+            focusCycleRoot = true; // FIXME
             // Top-levels initialize their focus traversal policies
             // using the context default policy.
             // The context default policy is established by
             // using KeyboardFocusManager.setDefaultFocusTraversalPolicy().
-            setFocusTraversalPolicy(KeyboardFocusManager.getCurrentKeyboardFocusManager().
-                    getDefaultFocusTraversalPolicy());
-
+            setFocusTraversalPolicy(KeyboardFocusManager.getCurrentKeyboardFocusManager()
+                    .getDefaultFocusTraversalPolicy());
             redrawManager = new RedrawManager(this);
-
-            setFont(new Font("dialog", Font.PLAIN, 12));        //TODO: fix it
-            cursor = Cursor.getDefaultCursor(); //for Window cursor is always set(non-null)
+            setFont(new Font("dialog", Font.PLAIN, 12)); // TODO: fix it
+            cursor = Cursor.getDefaultCursor(); // for Window cursor is always
+                                                // set(non-null)
         } finally {
             toolkit.unlockAWT();
         }
@@ -185,9 +186,9 @@
     NativeWindow getFocusProxy() {
         return focusProxy;
     }
-    
+
     public Window(Frame owner) {
-        this( (Window) owner);
+        this((Window) owner);
         toolkit.lockAWT();
         try {
         } finally {
@@ -205,7 +206,6 @@
         toolkit.lockAWT();
         try {
             super.addNotify();
-
             focusProxy = toolkit.createFocusProxyNativeWindow(this);
         } finally {
             toolkit.unlockAWT();
@@ -217,7 +217,6 @@
         toolkit.lockAWT();
         try {
             disposeFocusProxy();
-
             super.removeNotify();
         } finally {
             toolkit.unlockAWT();
@@ -243,9 +242,8 @@
     public void setCursor(Cursor cursor) {
         toolkit.lockAWT();
         try {
-            //for Window cursor is always set(non-null)
-            super.setCursor(
-                    cursor != null ? cursor : Cursor.getDefaultCursor());
+            // for Window cursor is always set(non-null)
+            super.setCursor(cursor != null ? cursor : Cursor.getDefaultCursor());
         } finally {
             toolkit.unlockAWT();
         }
@@ -290,7 +288,8 @@
             toolkit.unlockAWT();
         }
         if (true) {
-            throw new RuntimeException("Method is not implemented"); //TODO: implement
+            throw new RuntimeException("Method is not implemented"); // TODO:
+                                                                        // implement
         }
         return;
     }
@@ -300,14 +299,12 @@
         try {
             if (!disposed) {
                 prepare4HierarchyChange();
-
                 hide();
                 disposeOwnedWindows();
                 mapToDisplay(false);
                 disposed = true;
                 opened = false;
                 disposeInputContext();
-
                 finishHierarchyChange(this, parent, 0);
                 postEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSED));
             }
@@ -326,8 +323,7 @@
     }
 
     /**
-     * Remove focus proxy native window
-     * from map which is stored in Toolkit
+     * Remove focus proxy native window from map which is stored in Toolkit
      */
     private void disposeFocusProxy() {
         if (focusProxy != null) {
@@ -337,17 +333,15 @@
     }
 
     /**
-     * dispose all owned windows explicitly
-     * to remove them from Toolkit's map
+     * dispose all owned windows explicitly to remove them from Toolkit's map
      */
     private void disposeOwnedWindows() {
-        for (int i=0; i < ownedWindows.size(); i++) {
+        for (int i = 0; i < ownedWindows.size(); i++) {
             Window win = ownedWindows.get(i);
             if (win != null) {
                 win.dispose();
             }
         }
-
     }
 
     public BufferStrategy getBufferStrategy() {
@@ -357,7 +351,8 @@
             toolkit.unlockAWT();
         }
         if (true) {
-            throw new RuntimeException("Method is not implemented"); //TODO: implement
+            throw new RuntimeException("Method is not implemented"); // TODO:
+                                                                        // implement
         }
         return null;
     }
@@ -366,7 +361,7 @@
     public final Container getFocusCycleRootAncestor() {
         toolkit.lockAWT();
         try {
-            //Always returns null because Windows have no ancestors
+            // Always returns null because Windows have no ancestors
             return null;
         } finally {
             toolkit.unlockAWT();
@@ -384,7 +379,7 @@
 
     @Override
     public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
-        //why override?
+        // why override?
         toolkit.lockAWT();
         try {
             return super.getFocusTraversalKeys(id);
@@ -399,12 +394,11 @@
         try {
             if (graphicsConfiguration != null) {
                 return graphicsConfiguration;
-            } else
-            if (parent != null) {
+            } else if (parent != null) {
                 return parent.getGraphicsConfiguration();
             } else {
-                return GraphicsEnvironment.getLocalGraphicsEnvironment().
-                    getDefaultScreenDevice().getDefaultConfiguration();
+                return GraphicsEnvironment.getLocalGraphicsEnvironment()
+                        .getDefaultScreenDevice().getDefaultConfiguration();
             }
         } finally {
             toolkit.unlockAWT();
@@ -462,7 +456,7 @@
     public final boolean isFocusCycleRoot() {
         toolkit.lockAWT();
         try {
-            //Every Window is, by default, a "focus cycle root".
+            // Every Window is, by default, a "focus cycle root".
             return true;
         } finally {
             toolkit.unlockAWT();
@@ -472,17 +466,17 @@
     public final boolean isFocusableWindow() {
         toolkit.lockAWT();
         try {
-            return getFocusableWindowState() && ( isActivateable() ||
-                    getFrameDialogOwner().isShowing() && focusTraversalCycleNotEmpty());
+            return getFocusableWindowState()
+                    && (isActivateable() || getFrameDialogOwner().isShowing()
+                            && focusTraversalCycleNotEmpty());
         } finally {
             toolkit.unlockAWT();
         }
     }
 
     final boolean isActivateable() {
-        return (this instanceof Frame) ||
-                (this instanceof Dialog) ||
-                (this instanceof EmbeddedWindow);
+        return (this instanceof Frame) || (this instanceof Dialog)
+                || (this instanceof EmbeddedWindow);
     }
 
     private boolean focusTraversalCycleNotEmpty() {
@@ -490,11 +484,11 @@
     }
 
     /**
-     * Gets the nearest ancestor "activateable" window
-     * which is typically Frame or Dialog
+     * Gets the nearest ancestor "activateable" window which is typically Frame
+     * or Dialog
      */
     Window getFrameDialogOwner() {
-        for (Window o = this; ; o = (Window) o.parent) {
+        for (Window o = this;; o = (Window) o.parent) {
             if ((o == null) || o.isActivateable()) {
                 return o;
             }
@@ -520,7 +514,7 @@
     public boolean postEvent(Event evt) {
         toolkit.lockAWT();
         try {
-            //do not propagate event to parent(owner) window:
+            // do not propagate event to parent(owner) window:
             return handleEvent(evt);
         } finally {
             toolkit.unlockAWT();
@@ -560,8 +554,9 @@
         try {
             // if the Window has never been focused, focus should be set to the
             // Window's initial Component to focus
-            return (focusOwner != null) && (focusOwner != this) ? focusOwner :
-                (isFocusableWindow() ? getFocusTraversalPolicy().getInitialComponent(this) : null);
+            return (focusOwner != null) && (focusOwner != this) ? focusOwner
+                    : (isFocusableWindow() ? getFocusTraversalPolicy()
+                            .getInitialComponent(this) : null);
         } finally {
             toolkit.unlockAWT();
         }
@@ -575,8 +570,9 @@
     public final void setFocusCycleRoot(boolean value) {
         toolkit.lockAWT();
         try {
-            //Does nothing because Windows must always be roots of a focus traversal cycle.
-            //The passed-in value is ignored.
+            // Does nothing because Windows must always be roots of a focus
+            // traversal cycle.
+            // The passed-in value is ignored.
         } finally {
             toolkit.unlockAWT();
         }
@@ -652,7 +648,6 @@
         return warningString;
     }
 
-
     private final String getWarningStringImpl() {
         SecurityManager sm = System.getSecurityManager();
         if (sm == null) {
@@ -661,12 +656,11 @@
         if (sm.checkTopLevelWindow(this)) {
             return null;
         }
-
         PrivilegedAction<String> action = new PrivilegedAction<String>() {
             public String run() {
                 return System.getProperty("awt.appletWarning", "Warning: Java window");
-            }};
-
+            }
+        };
         return AccessController.doPrivileged(action);
     }
 
@@ -697,7 +691,6 @@
             if (!isDisplayable()) {
                 mapToDisplay(true);
             }
-
             setSize(getPreferredSize());
             validate();
             getNativeWindow().setPacked(true);
@@ -715,15 +708,13 @@
         }
     }
 
-    public final void setAlwaysOnTop(boolean alwaysOnTop)
-            throws SecurityException {
+    public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException {
         boolean wasAlwaysOnTop;
         toolkit.lockAWT();
         try {
             if (this.alwaysOnTop == alwaysOnTop) {
                 return;
             }
-
             SecurityManager sm = System.getSecurityManager();
             if (sm != null) {
                 sm.checkPermission(AWTPermissionCollection.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
@@ -734,7 +725,6 @@
             if (win != null) {
                 win.setAlwaysOnTop(alwaysOnTop);
             }
-
         } finally {
             toolkit.unlockAWT();
         }
@@ -742,8 +732,8 @@
     }
 
     /**
-     * Called by AWT in response to
-     * native event "insets changed" on this Window
+     * Called by AWT in response to native event "insets changed" on this Window
+     * 
      * @param insets new native insets
      */
     void setNativeInsets(Insets insets) {
@@ -751,7 +741,6 @@
             return;
         }
         nativeInsets = (Insets) insets.clone();
-
         validateMenuBar();
         invalidate();
         validate();
@@ -763,14 +752,13 @@
 
     @Override
     Insets getNativeInsets() {
-        return (Insets)nativeInsets.clone();
+        return (Insets) nativeInsets.clone();
     }
 
     @Override
     void setBounds(int x, int y, int w, int h, int bMask, boolean updateBehavior) {
         boolean resized = ((w != this.w) || (h != this.h));
         super.setBounds(x, y, w, h, bMask, updateBehavior);
-
         if (visible && resized && !updateBehavior) {
             validate();
         }
@@ -812,7 +800,7 @@
         try {
             oldState = focusableWindowState;
             focusableWindowState = state;
-            //call cb here to make window natively non-focusable
+            // call cb here to make window natively non-focusable
             NativeWindow win = getNativeWindow();
             if (win != null) {
                 win.setFocusable(state);
@@ -823,21 +811,19 @@
         } finally {
             toolkit.unlockAWT();
         }
-        firePropertyChange("focusableWindowState",
-                oldState, focusableWindowState);
+        firePropertyChange("focusableWindowState", oldState, focusableWindowState);
     }
 
     /**
-     * If this is a focused window then
-     * attempt to focus the most recently focused Component 
-     * of this Window's owner
-     * or clear global focus owner if attempt fails
+     * If this is a focused window then attempt to focus the most recently
+     * focused Component of this Window's owner or clear global focus owner if
+     * attempt fails
      */
     private void moveFocusToOwner() {
-
         if (isFocused()) {
             Component compToFocus = null;
-            for (Window wnd = getOwner(); wnd != null && compToFocus == null; wnd = wnd.getOwner()) {
+            for (Window wnd = getOwner(); wnd != null && compToFocus == null; wnd = wnd
+                    .getOwner()) {
                 compToFocus = wnd.getMostRecentFocusOwner();
                 if (compToFocus != null && !compToFocus.requestFocusImpl(false, true, false)) {
                     compToFocus = null;
@@ -846,7 +832,6 @@
             if (compToFocus == null) {
                 KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
             }
-
         }
     }
 
@@ -862,27 +847,25 @@
             int centerY = (minY + maxY) / 2;
             int x = centerX;
             int y = centerY;
-
-            //if comp is null or not showing, then set location
-            //relative to "component" of 1-pixel size located
-            //at the center of the screen
+            // if comp is null or not showing, then set location
+            // relative to "component" of 1-pixel size located
+            // at the center of the screen
             Point loc = new Point(centerX, centerY);
             int compX = loc.x;
             Dimension compSize = new Dimension();
-
             if ((c != null) && c.isShowing()) {
                 loc = c.getLocationOnScreen();
                 compX = loc.x;
                 compSize = c.getSize();
             }
-            //first get center coords:
+            // first get center coords:
             loc.translate(compSize.width / 2, compSize.height / 2);
-            //now get upper-left corner coords:
+            // now get upper-left corner coords:
             int w = getWidth(), h = getHeight();
             loc.translate(-w / 2, -h / 2);
-            //check if screenRect contains new window
-            //bounds rectangle and if not - change location
-            //of window to fit into screenRect
+            // check if screenRect contains new window
+            // bounds rectangle and if not - change location
+            // of window to fit into screenRect
             x = Math.max(loc.x, minX);
             y = Math.max(loc.y, minY);
             int right = x + w, bottom = y + h;
@@ -891,10 +874,9 @@
             }
             if (bottom > maxY) {
                 y -= bottom - maxY;
-
-                //If the bottom of the component is offscreen,
-                //the window is placed to the side of the Component
-                //that is closest to the center of the screen.
+                // If the bottom of the component is offscreen,
+                // the window is placed to the side of the Component
+                // that is closest to the center of the screen.
                 int compRight = compX + compSize.width;
                 int distRight = Math.abs(compRight - centerX);
                 int distLeft = Math.abs(centerX - compX);
@@ -906,7 +888,6 @@
                 }
             }
             setLocation(x, y);
-
         } finally {
             toolkit.unlockAWT();
         }
@@ -919,7 +900,8 @@
             if (win != null) {
                 win.toBack();
             }
-            //TODO?: reset the focused Window(this or any of owners) to the top-most Window in the VM
+            // TODO?: reset the focused Window(this or any of owners) to the
+            // top-most Window in the VM
         } finally {
             toolkit.unlockAWT();
         }
@@ -948,10 +930,10 @@
         if (this.undecorated == undecorated) {
             return;
         }
-        if(isDisplayable()) {
-            throw new IllegalComponentStateException("Cannot change the decorations while the window is visible");
+        if (isDisplayable()) {
+            throw new IllegalComponentStateException(
+                    "Cannot change the decorations while the window is visible");
         }
-
         this.undecorated = undecorated;
     }
 
@@ -960,8 +942,9 @@
     }
 
     void setPopup(boolean popup) {
-        if(isDisplayable()) {
-            throw new IllegalComponentStateException("Cannot change the decorations while the window is visible");
+        if (isDisplayable()) {
+            throw new IllegalComponentStateException(
+                    "Cannot change the decorations while the window is visible");
         }
         this.popup = popup;
     }
@@ -972,8 +955,9 @@
 
     /**
      * Set title for Frame or Dialog<br>
-     * It does lockAWT() properly so there's no need
-     * to synchronize the calls of this method
+     * It does lockAWT() properly so there's no need to synchronize the calls of
+     * this method
+     * 
      * @param title - value to set
      */
     void setTitle(String title) {
@@ -1004,7 +988,6 @@
 
     void setRequestedFocus(Component component) {
         requestedFocus = component;
-
     }
 
     Component getRequestedFocus() {
@@ -1017,14 +1000,15 @@
     }
 
     /**
-     * Gets the default Cursor if Window is disabled
-     * even if Cursor is explicitly set
+     * Gets the default Cursor if Window is disabled even if Cursor is
+     * explicitly set
+     * 
      * @return actual Cursor to be displayed
      * @see Component.getRealCursor()
      */
     @Override
     Cursor getRealCursor() {
-       return isEnabled() ? getCursor() : Cursor.getDefaultCursor();
+        return isEnabled() ? getCursor() : Cursor.getDefaultCursor();
     }
 
     @Override
@@ -1046,17 +1030,15 @@
     }
 
     public WindowFocusListener[] getWindowFocusListeners() {
-        return (WindowFocusListener[])
-                windowFocusListeners.getUserListeners(new WindowFocusListener[0]);
+        return windowFocusListeners.getUserListeners(new WindowFocusListener[0]);
     }
 
     public WindowListener[] getWindowListeners() {
-        return (WindowListener[]) windowListeners.getUserListeners(new WindowListener[0]);
+        return windowListeners.getUserListeners(new WindowListener[0]);
     }
 
     public WindowStateListener[] getWindowStateListeners() {
-        return (WindowStateListener[])
-                windowStateListeners.getUserListeners(new WindowStateListener[0]);
+        return windowStateListeners.getUserListeners(new WindowStateListener[0]);
     }
 
     public void removeWindowFocusListener(WindowFocusListener l) {
@@ -1071,6 +1053,7 @@
         windowStateListeners.removeUserListener(l);
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
         if (WindowFocusListener.class.isAssignableFrom(listenerType)) {
@@ -1087,7 +1070,6 @@
     @Override
     protected void processEvent(AWTEvent e) {
         long eventMask = toolkit.eventTypeLookup.getEventMask(e);
-
         if (eventMask == AWTEvent.WINDOW_EVENT_MASK) {
             processWindowEvent((WindowEvent) e);
         } else if (eventMask == AWTEvent.WINDOW_STATE_EVENT_MASK) {
@@ -1102,29 +1084,28 @@
     protected void processWindowEvent(WindowEvent e) {
         for (Iterator<?> i = windowListeners.getUserIterator(); i.hasNext();) {
             WindowListener listener = (WindowListener) i.next();
-
             switch (e.getID()) {
-            case WindowEvent.WINDOW_ACTIVATED:
-                listener.windowActivated(e);
-                break;
-            case WindowEvent.WINDOW_CLOSED:
-                listener.windowClosed(e);
-                break;
-            case WindowEvent.WINDOW_CLOSING:
-                listener.windowClosing(e);
-                break;
-            case WindowEvent.WINDOW_DEACTIVATED:
-                listener.windowDeactivated(e);
-                break;
-            case WindowEvent.WINDOW_DEICONIFIED:
-                listener.windowDeiconified(e);
-                break;
-            case WindowEvent.WINDOW_ICONIFIED:
-                listener.windowIconified(e);
-                break;
-            case WindowEvent.WINDOW_OPENED:
-                listener.windowOpened(e);
-                break;
+                case WindowEvent.WINDOW_ACTIVATED:
+                    listener.windowActivated(e);
+                    break;
+                case WindowEvent.WINDOW_CLOSED:
+                    listener.windowClosed(e);
+                    break;
+                case WindowEvent.WINDOW_CLOSING:
+                    listener.windowClosing(e);
+                    break;
+                case WindowEvent.WINDOW_DEACTIVATED:
+                    listener.windowDeactivated(e);
+                    break;
+                case WindowEvent.WINDOW_DEICONIFIED:
+                    listener.windowDeiconified(e);
+                    break;
+                case WindowEvent.WINDOW_ICONIFIED:
+                    listener.windowIconified(e);
+                    break;
+                case WindowEvent.WINDOW_OPENED:
+                    listener.windowOpened(e);
+                    break;
             }
         }
     }
@@ -1132,14 +1113,13 @@
     protected void processWindowFocusEvent(WindowEvent e) {
         for (Iterator<?> i = windowFocusListeners.getUserIterator(); i.hasNext();) {
             WindowFocusListener listener = (WindowFocusListener) i.next();
-
             switch (e.getID()) {
-            case WindowEvent.WINDOW_GAINED_FOCUS:
-                listener.windowGainedFocus(e);
-                break;
-            case WindowEvent.WINDOW_LOST_FOCUS:
-                listener.windowLostFocus(e);
-                break;
+                case WindowEvent.WINDOW_GAINED_FOCUS:
+                    listener.windowGainedFocus(e);
+                    break;
+                case WindowEvent.WINDOW_LOST_FOCUS:
+                    listener.windowLostFocus(e);
+                    break;
             }
         }
     }
@@ -1147,11 +1127,10 @@
     protected void processWindowStateEvent(WindowEvent e) {
         for (Iterator<?> i = windowStateListeners.getUserIterator(); i.hasNext();) {
             WindowStateListener listener = (WindowStateListener) i.next();
-
             switch (e.getID()) {
-            case WindowEvent.WINDOW_STATE_CHANGED:
-                listener.windowStateChanged(e);
-                break;
+                case WindowEvent.WINDOW_STATE_CHANGED:
+                    listener.windowStateChanged(e);
+                    break;
             }
         }
     }
@@ -1172,20 +1151,16 @@
     }
 
     private GraphicsConfiguration getGraphicsConfiguration(GraphicsConfiguration gc) {
-
         if (gc == null) {
             Toolkit.checkHeadless();
-            GraphicsEnvironment ge  = GraphicsEnvironment.getLocalGraphicsEnvironment();
+            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
             gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
-        }
-        else if (GraphicsEnvironment.isHeadless()) {
+        } else if (GraphicsEnvironment.isHeadless()) {
             throw new IllegalArgumentException("Graphics environment is headless");
         }
-
         if (gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN) {
             throw new IllegalArgumentException("Not a screen device");
         }
-
         return gc;
     }
 
@@ -1216,10 +1191,9 @@
     }
 
     /**
-     * Called immediately after native window
-     * has been created. Updates native window state
-     * & properties to make them correspond to Java
-     * Window state/properties
+     * Called immediately after native window has been created. Updates native
+     * window state & properties to make them correspond to Java Window
+     * state/properties
      */
     @Override
     void nativeWindowCreated(NativeWindow win) {
@@ -1230,15 +1204,15 @@
     }
 
     /**
-     * Returns icon image of the owner frame. 
-     * This method is overridden as public in the class Frame
+     * Returns icon image of the owner frame. This method is overridden as
+     * public in the class Frame
      */
     Image getIconImage() {
         toolkit.lockAWT();
         try {
             for (Container c = parent; c != null; c = c.parent) {
                 if (c instanceof Frame) {
-                    return ((Frame)c).getIconImage();
+                    return ((Frame) c).getIconImage();
                 }
             }
             return null;
@@ -1253,8 +1227,8 @@
             return null;
         }
         Insets ins = getNativeInsets();
-        Rectangle r = new Rectangle(ins.left, ins.top,
-                w - ins.left - ins.right, h - ins.top - ins.bottom);
+        Rectangle r = new Rectangle(ins.left, ins.top, w - ins.left - ins.right, h - ins.top
+                - ins.bottom);
         if (part != null) {
             r = r.intersection(part);
         }
@@ -1264,24 +1238,20 @@
         return behaviour.getNativeWindow().getObscuredRegion(r);
     }
 
-    private void readObject(ObjectInputStream stream)
-            throws IOException, ClassNotFoundException {
-
+    private void readObject(ObjectInputStream stream) throws IOException,
+            ClassNotFoundException {
         stream.defaultReadObject();
-
         FieldsAccessor accessor = new FieldsAccessor(Window.class, this);
         accessor.set("graphicsConfiguration", getGraphicsConfiguration(null));
-
         visible = false;
         redrawManager = new RedrawManager(this);
     }
-    
+
     @Override
     void notifyInputMethod(Rectangle bounds) {
         InputContext ic = getInputContext();
         if (ic instanceof InputMethodContext) {
-            ((InputMethodContext)ic).notifyClientWindowChange(bounds);
+            ((InputMethodContext) ic).notifyClientWindowChange(bounds);
         }
     }
-    
 }

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=454042&r1=454041&r2=454042
==============================================================================
--- 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 Sat Oct  7 16:10:23 2006
@@ -117,7 +117,19 @@
      */
     public List<T> getUserListeners() {
         synchronized (this) {
+            if (userList == null || userList.isEmpty()) {
+                return Collections.emptyList();
+            }
             return new ArrayList<T>(userList);
+        }
+    }
+    
+    public List<T> getSystemListeners() {
+        synchronized (this) {
+            if (systemList == null || systemList.isEmpty()) {
+                return Collections.emptyList();
+            }
+            return new ArrayList<T>(systemList);
         }
     }