harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440748 [2/25] - in /incubator/harmony/enhanced/classlib/trunk/modules: accessibility/src/main/java/javax/accessibility/ awt/ awt/make/ awt/src/main/java/common/java/awt/ awt/src/main/java/common/java/awt/datatransfer/ awt/src/main/java/com...
Date Wed, 06 Sep 2006 16:06:30 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueue.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueue.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueue.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueue.java Wed Sep  6 09:06:15 2006
@@ -19,23 +19,26 @@
  */
 package java.awt;
 
-import java.awt.event.*;
-
-import java.util.EmptyStackException;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.awt.event.InvocationEvent;
 import java.lang.reflect.InvocationTargetException;
+import java.util.EmptyStackException;
 
 public class EventQueue {
+    
+    private final EventQueueCoreAtomicReference coreRef = 
+            new EventQueueCoreAtomicReference();
+    
+    private static final class EventQueueCoreAtomicReference {
+        private EventQueueCore core;
 
-    private final Toolkit toolkit;
-
-    private final boolean systemEventQueue;
-
-    private LinkedList events;
+        /*synchronized*/ EventQueueCore get() { 
+            return core;
+        }
 
-    private LinkedList queues;
-    private EventQueue curQueue;
+        /*synchronized*/ void set(EventQueueCore newCore) { 
+            core = newCore;
+        }
+    }
 
     public static boolean isDispatchThread() {
         return Thread.currentThread() instanceof EventDispatchThread;
@@ -43,22 +46,24 @@
 
     public static void invokeLater(Runnable runnable) {
         Toolkit toolkit = Toolkit.getDefaultToolkit();
-        toolkit.systemEventQueue.postEvent(new InvocationEvent(toolkit, runnable));
+        InvocationEvent event = new InvocationEvent(toolkit, runnable);
+        toolkit.getSystemEventQueueImpl().postEvent(event);
     }
 
     public static void invokeAndWait(Runnable runnable)
-            throws InterruptedException, InvocationTargetException
-    {
+            throws InterruptedException, InvocationTargetException {
+
         if (isDispatchThread()) {
             throw new Error();
         }
 
         final Toolkit toolkit = Toolkit.getDefaultToolkit();
         final Object notifier = new Object();
-        InvocationEvent event = new InvocationEvent(toolkit, runnable, notifier, true);
+        InvocationEvent event = new InvocationEvent(
+                toolkit, runnable, notifier, true);
 
         synchronized (notifier) {
-            toolkit.systemEventQueue.postEvent(event);
+            toolkit.getSystemEventQueueImpl().postEvent(event);
             notifier.wait();
         }
 
@@ -69,248 +74,84 @@
         }
     }
 
-    public static long getMostRecentEventTime() {
-        final Toolkit toolkit = Toolkit.getDefaultToolkit();
-        toolkit.lockAWT();
-        try {
-            return (isDispatchThread() ?
-                    toolkit.eventQueueLastEvent.mostRecentEventTime :
-                    System.currentTimeMillis());
-        } finally {
-            toolkit.unlockAWT();
+    private static EventQueue getSystemEventQueue() {
+        Thread th = Thread.currentThread();
+        if (th instanceof EventDispatchThread) {
+            return ((EventDispatchThread)th).toolkit.getSystemEventQueueImpl();
         }
+        return null;
+    }
+    
+    public static long getMostRecentEventTime() {
+        EventQueue eq = getSystemEventQueue();
+        return (eq != null) ? 
+                eq.getMostRecentEventTimeImpl() : System.currentTimeMillis();
+    }
+    
+    private long getMostRecentEventTimeImpl() {
+        return getCore().getMostRecentEventTime();
     }
 
     public static AWTEvent getCurrentEvent() {
-        final Toolkit toolkit = Toolkit.getDefaultToolkit();
-        toolkit.lockAWT();
-        try {
-            return (isDispatchThread() ?
-                    toolkit.eventQueueLastEvent.curEvent : null);
-        } finally {
-            toolkit.unlockAWT();
-        }
+        EventQueue eq = getSystemEventQueue();
+        return (eq != null) ? 
+                eq.getCurrentEventImpl() : null;
+    }
+
+    private AWTEvent getCurrentEventImpl() {
+        return getCore().getCurrentEvent();
     }
 
     public EventQueue() {
-        this(false, Toolkit.getDefaultToolkit());
+        setCore(new EventQueueCore(this));
     }
 
-    EventQueue(boolean sysEventQueue, Toolkit toolkit) {
-        synchronized (this) {
-            this.toolkit = toolkit;
-            systemEventQueue = sysEventQueue;
-            events = new LinkedList();
-            queues =  new LinkedList();
-            curQueue = null;
-        }
+    EventQueue(Toolkit t) {
+        setCore(new EventQueueCore(this, t));
     }
 
     public void postEvent(AWTEvent event) {
-        synchronized (this) {
-            if (curQueue == null) {
-                AWTEvent eventToAdd = event;
-                Object src = event.getSource();
-
-                if (src instanceof Component) {
-                    Component comp = (Component) src;
-
-                    if (comp.isCoalescer()) {
-                        AWTEvent relative = comp.getRelativeEvent(event.getID());
-
-                        if (relative != null) {
-                            AWTEvent coalisced = comp.coalesceEvents(relative, event);
-
-                            if (coalisced != null) {
-                                events.remove(relative);
-                                comp.removeRelativeEvent();
-                                eventToAdd = coalisced;
-                            }
-                        }
-                        comp.addNewEvent(eventToAdd);
-                    }
-                }
-
-                events.addLast(eventToAdd);
-                notifyAll();
-            } else {
-                curQueue.postEvent(event);
-            }
-        }
-
-        if (systemEventQueue) {
-            if (!isDispatchThread()) {
-                toolkit.getNativeEventQueue().awake();
-            } else {
-                toolkit.validateShutdownThread();
-            }
-        }
+        event.isPosted = true;
+        getCore().postEvent(event);
     }
 
     public AWTEvent getNextEvent() throws InterruptedException {
-        synchronized (this) {
-            if (curQueue == null) {
-                while (events.isEmpty()) {
-                    wait();
-                }
-
-                AWTEvent event = (AWTEvent) events.removeFirst();
-                Object src = event.getSource();
-
-                if (src instanceof Component) {
-                    Component comp = (Component) src;
-
-                    if (comp.isCoalescer()) {
-                        comp.removeNextEvent(event.getID());
-                    }
-                }
-
-                return event;
-            } else {
-                return curQueue.getNextEvent();
-            }
-        }
+        return getCore().getNextEvent();
+    }
+    
+    AWTEvent getNextEventNoWait() {
+        return getCore().getNextEventNoWait();
     }
 
     public AWTEvent peekEvent() {
-        synchronized (this) {
-            if (curQueue == null) {
-                return events.isEmpty() ? null : (AWTEvent) events.getFirst();
-            } else {
-                return curQueue.peekEvent();
-            }
-        }
+        return getCore().peekEvent();
     }
 
     public AWTEvent peekEvent(int id) {
-        synchronized (this) {
-            if (curQueue == null) {
-                for (Iterator i = events.iterator(); i.hasNext(); ) {
-                    AWTEvent event = (AWTEvent) i.next();
-
-                    if (event.getID() == id) {
-                        return event;
-                    }
-                }
-
-                return null;
-            } else {
-                return curQueue.peekEvent(id);
-            }
-        }
+        return getCore().peekEvent(id);
     }
 
     public void push(EventQueue newEventQueue) {
-        synchronized (this) {
-            while (peekEvent() != null) {
-                try {
-                    newEventQueue.postEvent(getNextEvent());
-                } catch (InterruptedException e) {
-                }
-            }
-            queues.addLast(newEventQueue);
-            curQueue = newEventQueue;
-        }
+        getCore().push(newEventQueue);
     }
-
+    
     protected void pop() throws EmptyStackException {
-        synchronized (this) {
-            if (curQueue == null) {
-                throw new EmptyStackException();
-            }
-
-            queues.removeLast();
-            EventQueue destQueue = queues.isEmpty() ? this : (EventQueue) queues.getLast();
-
-            while (curQueue.peekEvent() != null) {
-                try {
-                    destQueue.postEvent(curQueue.getNextEvent());
-                } catch (InterruptedException e) {
-                }
-            }
-            curQueue = queues.isEmpty() ? null : destQueue;
-        }
+        getCore().pop();
     }
 
     protected void dispatchEvent(AWTEvent event) {
-        EventQueue subsequentQueue = null;
-        synchronized (this) {
-            long when = 0l;
-
-            if (event instanceof ActionEvent) {
-                when = ((ActionEvent) event).getWhen();
-            } else if (event instanceof InputEvent) {
-                when = ((InputEvent) event).getWhen();
-            } else if (event instanceof InputMethodEvent) {
-                when = ((InputMethodEvent) event).getWhen();
-            } else if (event instanceof InvocationEvent) {
-                when = ((InvocationEvent) event).getWhen();
-            }
-            if (when != 0l) {
-                toolkit.eventQueueLastEvent.mostRecentEventTime = when;
-            }
-            toolkit.eventQueueLastEvent.curEvent = event;
-
-            subsequentQueue = curQueue;
-        }
-
-        if (subsequentQueue != null) {
-            subsequentQueue.dispatchEvent(event);
-            return;
-        }
-
-        if (event instanceof ActiveEvent) {
-            toolkit.dispatchAWTEvent(event);
-            ((ActiveEvent) event).dispatch();
-            return;
-        }
-
-        Object src = event.getSource();
-
-        if (src instanceof Component) {
-            if (preprocessComponentEvent(event)) {
-                ((Component) src).dispatchEvent(event);
-            }
-        } else {
-            toolkit.dispatchAWTEvent(event);
-            if (src instanceof MenuComponent) {
-                ((MenuComponent) src).dispatchEvent(event);
-            }
-        }
-    }
-
-    private final boolean preprocessComponentEvent(AWTEvent event) {
-        if (event instanceof MouseEvent) {
-            return preprocessMouseEvent((MouseEvent)event);
-        }
-        return true;
-    }
-
-    private final boolean preprocessMouseEvent(MouseEvent event) {
-        if (toolkit.mouseEventPreprocessor != null) {
-            toolkit.lockAWT();
-            try {
-                return toolkit.mouseEventPreprocessor.preprocess(event);
-            } finally {
-                toolkit.unlockAWT();
-            }
-        }
-        return true;
+        getCore().dispatchEventImpl(event);
     }
 
     boolean isEmpty() {
-        synchronized (this) {
-            if ((curQueue == null)) {
-                return events.isEmpty();
-            } else {
-                return (curQueue.peekEvent() == null);
-            }
-        }
+        return getCore().isEmpty();
     }
 
-    static final class LastEvent {
-        long mostRecentEventTime = System.currentTimeMillis();
-        AWTEvent curEvent = null;
+    EventQueueCore getCore() {
+        return coreRef.get();
+    }
+    
+    void setCore(EventQueueCore newCore) {
+        coreRef.set((newCore != null) ? newCore : new EventQueueCore(this));
     }
-
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueueCore.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueueCore.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueueCore.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueueCore.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,234 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Pavel Dolgov
+ * @version $Revision$
+ */
+package java.awt;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.InvocationEvent;
+import java.awt.event.MouseEvent;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * The events storage for EventQueue
+ */
+final class EventQueueCore {
+    
+    private final LinkedList queueStack = new LinkedList();
+    private final LinkedList events = new LinkedList();
+    
+    private Toolkit toolkit;
+    private EventQueue activeQueue;
+    private Thread dispatchThread;
+    
+    AWTEvent currentEvent;
+    long mostRecentEventTime = System.currentTimeMillis();
+    
+    EventQueueCore(EventQueue eq) {
+        synchronized (this) {
+            queueStack.addLast(eq);
+            activeQueue = eq;
+        }
+    }
+
+    EventQueueCore(EventQueue eq, Toolkit t) {
+        synchronized (this) {
+            queueStack.addLast(eq);
+            activeQueue = eq;
+            setToolkit(t);
+        }
+    }
+
+    synchronized long getMostRecentEventTime() {
+        return mostRecentEventTime;
+    }
+    
+    synchronized AWTEvent getCurrentEvent() {
+        return currentEvent;
+    }
+    
+    synchronized boolean isSystemEventQueue() {
+        return toolkit != null;
+    }
+    
+    private void setToolkit(Toolkit t) {
+        toolkit = t;
+        if (toolkit != null) {
+            toolkit.setSystemEventQueueCore(this);
+            dispatchThread = toolkit.dispatchThread;
+        }
+    }
+
+    synchronized void postEvent(AWTEvent event) {
+        events.addLast(event);
+        if ((toolkit == null) && (dispatchThread == null)) {
+            dispatchThread = new EventQueueThread(this);
+            dispatchThread.start();
+        }
+        // TODO: add event coalescing
+        if (toolkit != null) {
+            toolkit.shutdownWatchdog.setAwtQueueEmpty(false);
+            notifyEventMonitor(toolkit);
+        }
+        notifyAll();
+    }
+    
+    void notifyEventMonitor(Toolkit t) {
+        Object em = t.getNativeEventQueue().getEventMonitor();
+        synchronized (em) {
+            em.notifyAll();
+        }
+    }
+    
+    synchronized AWTEvent getNextEvent() throws InterruptedException {
+        while (events.isEmpty()) {
+            wait();
+        }
+        AWTEvent event = (AWTEvent)events.removeFirst();
+        // TODO: add event coalescing
+        return event;
+    }    
+    
+    synchronized AWTEvent peekEvent() {
+        return events.isEmpty() ? null : (AWTEvent)events.getFirst();
+    }
+    
+    synchronized AWTEvent peekEvent(int id) {
+        for (Iterator it = events.iterator(); it.hasNext(); ) {
+            AWTEvent event = (AWTEvent) it.next();
+
+            if (event.getID() == id) {
+                return event;
+            }
+        }
+        return null;
+    }
+    
+    synchronized void dispatchEvent(AWTEvent event) {
+        updateCurrentEventAndTime(event);
+        activeQueue.dispatchEvent(event);
+        currentEvent = null;
+    }
+    
+    void dispatchEventImpl(AWTEvent event) {
+        if (event instanceof ActiveEvent) {
+            ((ActiveEvent) event).dispatch();
+            return;
+        }
+
+        Object src = event.getSource();
+
+        if (src instanceof Component) {
+            if (preprocessComponentEvent(event)) {
+                ((Component) src).dispatchEvent(event);
+            }
+        } else {
+            if (toolkit != null) {
+                toolkit.dispatchAWTEvent(event);
+            }
+            if (src instanceof MenuComponent) {
+                ((MenuComponent) src).dispatchEvent(event);
+            }
+        }
+    }
+
+    private final boolean preprocessComponentEvent(AWTEvent event) {
+      if (event instanceof MouseEvent) {
+          return preprocessMouseEvent((MouseEvent)event);
+      }
+      return true;
+    }
+
+    private final boolean preprocessMouseEvent(MouseEvent event) {
+      if (toolkit != null && toolkit.mouseEventPreprocessor != null) {
+          toolkit.lockAWT();
+          try {
+              return toolkit.mouseEventPreprocessor.preprocess(event);
+          } finally {
+              toolkit.unlockAWT();
+          }
+      }
+      return true;
+  }
+    
+    private void updateCurrentEventAndTime(AWTEvent event) {
+        currentEvent = event;
+        long when = 0;
+        if (event instanceof ActionEvent) {
+            when = ((ActionEvent) event).getWhen();
+        } else if (event instanceof InputEvent) {
+            when = ((InputEvent) event).getWhen();
+        } else if (event instanceof InputMethodEvent) {
+            when = ((InputMethodEvent) event).getWhen();
+        } else if (event instanceof InvocationEvent) {
+            when = ((InvocationEvent) event).getWhen();
+        }
+        if (when != 0) {
+            mostRecentEventTime = when;
+        }
+    }
+    
+    synchronized void push(EventQueue newEventQueue) {
+        // TODO: handle incorrect situations
+        if (queueStack.isEmpty()) {
+            throw new IllegalStateException("Queue stack is empty");
+        }
+        
+        queueStack.addLast(newEventQueue);
+        activeQueue = newEventQueue;
+        activeQueue.setCore(this);
+    }
+    
+    synchronized void pop() {
+        EventQueue removed = (EventQueue)queueStack.removeLast();
+        if (removed != activeQueue) {
+            throw new IllegalStateException("Event queue stack is broken");
+        }
+        activeQueue = (EventQueue)queueStack.getLast();
+        removed.setCore(null);
+    }
+
+    synchronized AWTEvent getNextEventNoWait() {
+        try {
+            return events.isEmpty() ? null : activeQueue.getNextEvent();
+        } catch (InterruptedException e) {
+            return null;
+        }
+    }
+
+    synchronized boolean isEmpty() {
+        return (currentEvent == null) && events.isEmpty();
+    }
+    
+    synchronized boolean isEmpty(long timeout) {
+        if (!isEmpty()) {
+            return false;
+        }
+        try {
+            wait(timeout);
+        } catch (InterruptedException e) {}
+        return isEmpty();
+    }
+    
+    synchronized EventQueue getActiveEventQueue() {
+        return activeQueue;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueueThread.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueueThread.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueueThread.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/EventQueueThread.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,62 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Pavel Dolgov
+ * @version $Revision$
+ */
+package java.awt;
+
+import java.awt.event.ActionEvent;
+
+/**
+ * Thread for dispatching events in non-system EventQueue
+ */
+final class EventQueueThread extends Thread {
+
+    private static final class StopThreadEvent extends ActionEvent {
+        StopThreadEvent(Thread thread) {
+            super(thread, ACTION_PERFORMED, "stopThread");
+        }
+    }
+
+    private final EventQueueCore core;
+
+    EventQueueThread(EventQueueCore core) {
+        super("AWT-EventQueueThread");
+        this.core = core;
+        setDaemon(false);
+    }
+
+    public void run() {
+        while (!core.isEmpty(1000)) {
+            try {
+                AWTEvent e = core.getActiveEventQueue().getNextEvent();
+                if ((e instanceof StopThreadEvent) && e.getSource() == this) {
+                    return;
+                }
+                core.dispatchEvent(e);
+            } catch (InterruptedException e) {
+                // do nothing
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    void postStopEvent() {
+        core.postEvent(new StopThreadEvent(this));
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FileDialog.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FileDialog.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FileDialog.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FileDialog.java Wed Sep  6 09:06:15 2006
@@ -61,6 +61,35 @@
             toolkit.unlockAWT();
         }
     }
+    
+    public FileDialog(Dialog owner) {
+        this(owner, "");
+        toolkit.lockAWT();
+        try {
+        } finally {
+            toolkit.unlockAWT();
+        }
+    }
+
+    public FileDialog(Dialog owner, String title) {
+        this(owner, title, LOAD);
+        toolkit.lockAWT();
+        try {
+        } finally {
+            toolkit.unlockAWT();
+        }
+    }
+
+    public FileDialog(Dialog owner, String title, int mode) {
+        super(owner, title, true); // initially always modal
+        toolkit.lockAWT();
+        try {
+            setMode(mode);
+            setLayout(null);
+        } finally {
+            toolkit.unlockAWT();
+        }
+    }
 
     public String getFile() {
         toolkit.lockAWT();
@@ -164,12 +193,27 @@
     }
 
 
-    public void show() {
+    void showImpl() {
         if (toolkit.theme.showFileDialog(this)) {
-            super.show();
+            super.showImpl();
         }
     }
 
+    void hideImpl() {
+        if (toolkit.theme.hideFileDialog(this)) {        
+            super.hideImpl();
+        }
+    }
+    
+    ComponentBehavior createBehavior() {
+        return new HWBehavior(this) {
+            public void removeNotify() {
+                super.removeNotify();
+                hideImpl();                
+            }
+        };
+    }
+    
     String autoName() {
         return "filedlg" + toolkit.autoNumber.nextFileDialog++;
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FocusDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FocusDispatcher.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FocusDispatcher.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FocusDispatcher.java Wed Sep  6 09:06:15 2006
@@ -36,7 +36,6 @@
  */
 
 class FocusDispatcher {
-    private Window activatingWindow, deactivatingWindow;
     private Window nativeFocusedWindow;
     private final Toolkit toolkit;
 
@@ -84,7 +83,6 @@
         Component other = oppositeComp;
         Window wnd = getWindowAncestor(comp, focusProxyOwner);
         Window oppositeWnd = getWindowAncestor(other, oppositeFocusProxyOwner);
-
         if (focusGained) {
             nativeFocusedWindow = wnd;
         } else if (wnd == nativeFocusedWindow) {
@@ -101,15 +99,6 @@
             return true;
         }
 
-
-        // while activation of Frame/Dialog
-        // [actually focus transfer to focusProxy] is in progress
-        // skip all focus events related to windows being activated/deactivated,
-        // such spurious events are sometimes generated by Win32
-        if (isActivating(comp, other)) {
-            return true;
-        }
-
         // if a non-Frame/Dialog gains native focus, transfer focus
         // to "focus proxy" in a nearest Frame/Dialog to make it look "active"
         if (!DefaultKeyboardFocusManager.isActivateable(wnd) &&
@@ -191,22 +180,11 @@
             return true;
         }
         if (focusGained && isFocusProxy) {
-            if (activatingWindow == wnd) {
-                activatingWindow = null;
-                deactivatingWindow = null;
-            }
             return true;
         }
         return false;
     }
 
-    private boolean isActivating(Component comp, Component other) {
-        return ( (activatingWindow != null) &&
-                ((comp == activatingWindow) || (other == activatingWindow)) ) ||
-               ( (deactivatingWindow != null) &&
-               ((comp == deactivatingWindow || other == deactivatingWindow)) );
-    }
-
     /**
      *  Try to activate nearest Dialog/Frame[if not already active]
      *   by setting native focus to focusProxy[dedicated child of Dialog/Frame]
@@ -214,17 +192,13 @@
     private void activateAncestor(Window wnd) {
 
         Window decorWnd = wnd.getFrameDialogOwner();
-        if ((decorWnd != null) && (decorWnd != nativeFocusedWindow) &&
-            (decorWnd != activatingWindow)) {
+        if ((decorWnd != null) && (decorWnd != nativeFocusedWindow)) {
             NativeWindow nativeWnd = decorWnd.getNativeWindow();
             if (nativeWnd != null) {
                 NativeWindow focusProxyWnd = decorWnd.getFocusProxy();
-                activatingWindow = decorWnd;
-                deactivatingWindow = wnd;
 
-                if ((focusProxyWnd == null) || !focusProxyWnd.setFocus(true)) {
-                    activatingWindow = null;
-                    deactivatingWindow = null;
+                if ((focusProxyWnd != null)) {
+                    focusProxyWnd.setFocus(true);
                 }
             }
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java Wed Sep  6 09:06:15 2006
@@ -90,14 +90,14 @@
 
     // font peer object corresponding to this Font
     private transient FontPeerImpl fontPeer;
-    
-    // number of glyphs in this Font
+
+    // number of glyphs in this Font    
     private transient int numGlyphs = -1;
-    
-    // code for missing glyph for this Font 
+
+    // code for missing glyph for this Font     
     private transient int missingGlyphCode = -1;
 
-    // flag, true if this Font was created from InputStream 
+    // flag, true if this Font was created from InputStream
     private boolean createdFromStream;
 
     /**
@@ -110,7 +110,7 @@
         throws IOException{
         out.defaultWriteObject();
     }
-    
+
     /**
      * Reads object from ObjectInputStream object and set native platform
      * dependent fields to default values.
@@ -134,7 +134,7 @@
 
         // Default values are taken from the documentation of the Font class. 
         // See Font constructor, decode and getFont sections.
-        
+  
         this.name = "default";
         this.size = 12;
         this.pointSize = 12;
@@ -310,7 +310,7 @@
 
 
     }
-    
+
     /**
      * Returns font style constant value corresponding to one of the font style 
      * names ("BOLD", "ITALIC", "BOLDITALIC"). Method returns Font.PLAIN if there 
@@ -508,15 +508,6 @@
         return false;
     }
 
-    protected void finalize() throws Throwable {
-
-        Toolkit.getDefaultToolkit().getGraphicsFactory().freeFontPeer(this);
-
-        super.finalize();
-    }
-
-
-
     public Map getAttributes() {
         return (Map)fRequestedAttributes.clone();
     }
@@ -796,7 +787,7 @@
 
     public FontPeer getPeer() {
         if (fontPeer == null){
-            fontPeer = (FontPeerImpl)Toolkit.getDefaultToolkit().getGraphicsFactory().createFontPeer(this);
+            fontPeer = (FontPeerImpl)Toolkit.getDefaultToolkit().getGraphicsFactory().getFontPeer(this);
         }
         return fontPeer;
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FontMetrics.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FontMetrics.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FontMetrics.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/FontMetrics.java Wed Sep  6 09:06:15 2006
@@ -182,7 +182,7 @@
     public int stringWidth(String str) {
         return 0;
     }
-
+    
     /**
      * Returns FontRenderContext instanse of the Graphics context specified.
      * @param context the specified Graphics context

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Frame.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Frame.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Frame.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Frame.java Wed Sep  6 09:06:15 2006
@@ -35,74 +35,32 @@
 public class Frame extends Window implements MenuContainer {
     private static final long serialVersionUID = 2673458971256075116L;
 
-    /**
-     * @deprecated Please use {@link Cursor#DEFAULT_CURSOR}.
-     */
     public static final int DEFAULT_CURSOR = 0;
 
-    /**
-     * @deprecated Please use {@link Cursor#CROSSHAIR_CURSOR}.
-     */
     public static final int CROSSHAIR_CURSOR = 1;
 
-    /**
-     * @deprecated Please use {@link Cursor#TEXT_CURSOR}.
-     */
     public static final int TEXT_CURSOR = 2;
 
-    /**
-     * @deprecated Please use {@link Cursor#WAIT_CURSOR}.
-     */
     public static final int WAIT_CURSOR = 3;
 
-    /**
-     * @deprecated Please use {@link Cursor#SW_RESIZE_CURSOR}.
-     */
     public static final int SW_RESIZE_CURSOR = 4;
 
-    /**
-     * @deprecated Please use {@link Cursor#SE_RESIZE_CURSOR}.
-     */
     public static final int SE_RESIZE_CURSOR = 5;
 
-    /**
-     * @deprecated Please use {@link Cursor#NW_RESIZE_CURSOR}.
-     */
     public static final int NW_RESIZE_CURSOR = 6;
 
-    /**
-     * @deprecated Please use {@link Cursor#NE_RESIZE_CURSOR}.
-     */
     public static final int NE_RESIZE_CURSOR = 7;
 
-    /**
-     * @deprecated Please use {@link Cursor#N_RESIZE_CURSOR}.
-     */
     public static final int N_RESIZE_CURSOR = 8;
 
-    /**
-     * @deprecated Please use {@link Cursor#S_RESIZE_CURSOR}.
-     */
     public static final int S_RESIZE_CURSOR = 9;
 
-    /**
-     * @deprecated Please use {@link Cursor#W_RESIZE_CURSOR}.
-     */
     public static final int W_RESIZE_CURSOR = 10;
 
-    /**
-     * @deprecated Please use {@link Cursor#E_RESIZE_CURSOR}.
-     */
     public static final int E_RESIZE_CURSOR = 11;
 
-    /**
-     * @deprecated Please use {@link Cursor#HAND_CURSOR}.
-     */
     public static final int HAND_CURSOR = 12;
 
-    /**
-     * @deprecated Please use {@link Cursor#MOVE_CURSOR}.
-     */
     public static final int MOVE_CURSOR = 13;
 
     public static final int NORMAL = 0;
@@ -434,16 +392,32 @@
     public void setIconImage(Image image) {
         toolkit.lockAWT();
         try {
-            iconImage = image;
+            iconImage = prepareIconImage(image);
             NativeWindow win = getNativeWindow();
             if (win != null) {
-                win.setIconImage(image);
+                win.setIconImage(iconImage);
             }
         } finally {
             toolkit.unlockAWT();
         }
     }
 
+    private Image prepareIconImage(Image image) {
+        if (image == null) {
+            return null;
+        }
+
+        MediaTracker mt = new MediaTracker(this);
+        mt.addImage(image, 0);
+        try {
+            if (mt.waitForID(0, 2000)) {
+                return image;
+            }
+        } catch (InterruptedException e) {
+        }
+        return null;
+    }
+
     public void setMaximizedBounds(Rectangle bounds) {
         toolkit.lockAWT();
         try {
@@ -572,24 +546,24 @@
 
 
     static final class AllFrames {
-        private final ArrayList<WeakReference<Frame>> frames = new ArrayList<WeakReference<Frame>>();
+        private final ArrayList frames = new ArrayList();
 
         void add(Frame f) {
-            frames.add(new WeakReference<Frame>(f));
+            frames.add(new WeakReference(f));
         }
 
         Frame[] getFrames() {
-            ArrayList<Frame> aliveFrames = new ArrayList<Frame>();
+            ArrayList aliveFrames = new ArrayList();
 
-            for(Iterator<WeakReference<Frame>> it = frames.iterator(); it.hasNext(); ) {
-                WeakReference<Frame> ref = it.next();
-                Frame f = ref.get();
+            for(Iterator it = frames.iterator(); it.hasNext(); ) {
+                WeakReference ref = (WeakReference)it.next();
+                Frame f = (Frame)ref.get();
                 if (f != null) {
                     aliveFrames.add(f);
                 }
             }
 
-            return aliveFrames.toArray(new Frame[aliveFrames.size()]);
+            return (Frame [])aliveFrames.toArray(new Frame[0]);
         }
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/HWBehavior.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/HWBehavior.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/HWBehavior.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/HWBehavior.java Wed Sep  6 09:06:15 2006
@@ -34,6 +34,9 @@
     HWBehavior(Component comp) {
         component = comp;
         Toolkit.checkHeadless();
+        // implicitly disable IM for all heavyweight components
+        // TextComponents must set this flag back to true
+        component.dispatchToIM = false;
     }
 
     public boolean isOpaque() {

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=440748&r1=440747&r2=440748
==============================================================================
--- 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 Wed Sep  6 09:06:15 2006
@@ -720,7 +720,7 @@
             prevFocusedWindow = (c == null ? actualFocusedWindow : null);
             postWindowEvent(ancestorWnd, oppositeAncestorWnd, focus);
         }
-        if (focus) {
+        if (focus && callCB) {
             c.behaviour.setFocus(focus, opposite);
         }
 
@@ -735,11 +735,19 @@
         if (wnd == null) {
             return false;
         }
-
+        
         Component lastReqFocus = wnd.getRequestedFocus();
+        if ((lastReqFocus != null) && (lastReqFocus.getWindowAncestor() != wnd)) {
+            lastReqFocus = null;
+            wnd.setRequestedFocus(null);
+        }
         Component lastFocusOwner = wnd.getMostRecentFocusOwner();
+        if ((lastFocusOwner != null) && lastFocusOwner.getWindowAncestor() != wnd) {
+            lastFocusOwner = null;
+        }
         Component compToFocus = ((lastReqFocus != null) ? lastReqFocus :
                                                           lastFocusOwner);
+                
 
         if (compToFocus != null) {
             return requestFocus(compToFocus, wnd, false, false, callCB);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/ModalContext.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/ModalContext.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/ModalContext.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/ModalContext.java Wed Sep  6 09:06:15 2006
@@ -50,7 +50,6 @@
      */
     void endModalLoop() {
         running = false;
-        toolkit.getNativeEventQueue().awake();
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/MouseDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/MouseDispatcher.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/MouseDispatcher.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/MouseDispatcher.java Wed Sep  6 09:06:15 2006
@@ -48,7 +48,6 @@
     private Point lastLocalPos = new Point(-1, -1);
 
     private final MouseGrabManager mouseGrabManager;
-    private final EventQueue eventQueue;
     private final Toolkit toolkit;
 
     static Point convertPoint(Component src, int x, int y, Component dest) {
@@ -81,10 +80,9 @@
         return location;
     }
 
-    MouseDispatcher(MouseGrabManager mouseGrabManager, EventQueue queue,
+    MouseDispatcher(MouseGrabManager mouseGrabManager,
                     Toolkit toolkit) {
         this.mouseGrabManager = mouseGrabManager;
-        eventQueue = queue;
         this.toolkit = toolkit;
     }
 
@@ -159,8 +157,8 @@
     private void postMouseEnterExit(int id, int mod, long when,
                                     int x, int y, Component comp) {
         if (comp.isIndirectlyEnabled()) {
-            eventQueue.postEvent(new MouseEvent(comp, id, when, mod,
-                                                x, y, 0, false));
+            toolkit.getSystemEventQueueImpl().postEvent(
+                    new MouseEvent(comp, id, when, mod, x, y, 0, false));
             comp.setMouseExitedExpected(id == MouseEvent.MOUSE_ENTERED);
         } else {
             comp.setMouseExitedExpected(false);
@@ -276,15 +274,17 @@
         if (info.src.isIndirectlyEnabled()) {
             final Point pos = info.position;
             final int mod = event.getInputModifiers();
-            eventQueue.postEvent(new MouseEvent(info.src, id, time, mod, pos.x,
-                                                pos.y, clickCount[index],
-                                                event.getTrigger(), button));
+            toolkit.getSystemEventQueueImpl().postEvent(
+                            new MouseEvent(info.src, id, time, mod, pos.x,
+                            pos.y, clickCount[index],
+                            event.getTrigger(), button));
             if (clickRequired) {
-                eventQueue.postEvent(new MouseEvent(info.src,
-                                                    MouseEvent.MOUSE_CLICKED,
-                                                    time, mod, pos.x, pos.y,
-                                                    clickCount[index], false,
-                                                    button));
+                toolkit.getSystemEventQueueImpl().postEvent(
+                            new MouseEvent(info.src,
+                            MouseEvent.MOUSE_CLICKED,
+                            time, mod, pos.x, pos.y,
+                            clickCount[index], false,
+                            button));
             }
         }
     }
@@ -310,10 +310,11 @@
             lastLocalPos = pos;
 
             if (info.src.isIndirectlyEnabled()) {
-                eventQueue.postEvent(new MouseEvent(info.src, event.getEventId(),
-                                                    event.getTime(),
-                                                    event.getInputModifiers(),
-                                                    pos.x, pos.y, 0, false));
+                toolkit.getSystemEventQueueImpl().postEvent(
+                            new MouseEvent(info.src, event.getEventId(),
+                            event.getTime(),
+                            event.getInputModifiers(),
+                            pos.x, pos.y, 0, false));
             }
         }
     }
@@ -350,8 +351,8 @@
         propagateEvent(info, AWTEvent.MOUSE_WHEEL_EVENT_MASK,
                        MouseWheelListener.class, true);
         if ((info.src != null) && info.src.isIndirectlyEnabled()) {
-            eventQueue.postEvent(createWheelEvent(info.src, event,
-                                                  info.position));
+            toolkit.getSystemEventQueueImpl().postEvent(
+                    createWheelEvent(info.src, event, info.position));
         }
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Point.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Point.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Point.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Point.java Wed Sep  6 09:06:15 2006
@@ -78,7 +78,7 @@
     }
 
     public void setLocation(double x, double y) {
-        setLocation((int)Math.ceil(x), (int)Math.ceil(y));
+        setLocation((int)Math.round(x), (int)Math.round(y));
     }
 
     public void move(int x, int y) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RedrawManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RedrawManager.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RedrawManager.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RedrawManager.java Wed Sep  6 09:06:15 2006
@@ -67,7 +67,6 @@
             addRegion(updateRegions, c, r);
             updateNeeded = true;
         }
-        awake();
     }
 
     public void addUpdateRegion(Component c, MultiRectArea r) {
@@ -75,7 +74,6 @@
             addRegion(updateRegions, c, r);
             updateNeeded = true;
         }
-        awake();
     }
 
     public void addUpdateRegion(Component c) {
@@ -157,9 +155,6 @@
         }
     }
 
-    private void awake() {
-        window.toolkit.getNativeEventQueue().awake();
-    }
 
     /**
      * Post paint events for the collected regions
@@ -184,7 +179,7 @@
     private static void postPaintEvent(Component c, MultiRectArea clip, int eventId) {
         PaintEvent event = new PaintEvent(c, eventId,
                 new ClipRegion(clip));
-        c.toolkit.systemEventQueue.postEvent(event);
+        c.toolkit.getSystemEventQueueImpl().postEvent(event);
     }
 
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/SystemColor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/SystemColor.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/SystemColor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/SystemColor.java Wed Sep  6 09:06:15 2006
@@ -147,24 +147,13 @@
     }
 
     public int getRGB() {
-        return getARGB();
-    }
-
-    public int getRed() {
-        return (getARGB() >> 16) & 0xFF;
-    }
-
-    public int getGreen() {
-        return (getARGB() >> 8) & 0xFF;
-    }
-
-    public int getBlue() {
-        return getARGB() & 0xFF;
+        return value = getARGB();
     }
 
     private SystemColor(int index) {
         super(0, 0, 0);
         this.index = index;
+        value = getRGB();
     }
 
     private int getARGB() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/TextComponent.java Wed Sep  6 09:06:15 2006
@@ -531,6 +531,7 @@
     TextComponent() {
         state = new State();
         editable = true;
+        dispatchToIM = true; // had been disabled by createBehavior()
         setFont(new Font("DialogInput", Font.PLAIN, 12)); // QUICK FIX
         document = new PlainDocument();
 

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=440748&r1=440747&r2=440748
==============================================================================
--- 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 Wed Sep  6 09:06:15 2006
@@ -46,9 +46,9 @@
     private static final ResourceBundle properties = loadResources(RECOURCE_PATH);
 
     final Dispatcher dispatcher;
-    final EventQueue systemEventQueue;
+    private EventQueueCore systemEventQueueCore;
     final EventDispatchThread dispatchThread;
-    private ShutdownThread shutdownThread;
+    NativeEventThread nativeThread;
     private final AWTEventsManager awtEventsManager;
     /* key = nativeWindow, value = Component, should be Map<NativeWindow, Component> */
     private final Map windowComponentMap = new HashMap();
@@ -60,12 +60,11 @@
 
     final Object awtTreeLock = new Object();
     private final Synchronizer synchronizer = ContextStorage.getSynchronizer();
-    private final Object shutdownThreadLock = new Object();
+    final ShutdownWatchdog shutdownWatchdog = new ShutdownWatchdog();
 
     final Theme theme = createTheme();
 
     final AutoNumber autoNumber = new AutoNumber();
-    final EventQueue.LastEvent eventQueueLastEvent = new EventQueue.LastEvent();
     final AWTEvent.EventTypeLookup eventTypeLookup = new AWTEvent.EventTypeLookup();
     final Frame.AllFrames allFrames = new Frame.AllFrames();
 
@@ -99,6 +98,7 @@
     final WindowList windows = new WindowList();
 
     private WTK wtk = null;
+    final DTK dtk;
 
     private final class ComponentInternalsImpl extends ComponentInternals {
 
@@ -261,14 +261,21 @@
         public MultiRectArea getObscuredRegion(Component c) {
             return c.getObscuredRegion(null);
         }
-    }
 
-    void stopShutdownThread() {
-        synchronized(shutdownThreadLock) {
-            if (shutdownThread != null) {
-                shutdownThread.shutdown();
-                shutdownThread = null;
-            }
+        public void setDesktopProperty(String name, Object value) {
+            Toolkit.this.setDesktopProperty(name, value);            
+        }
+
+        public void runModalLoop(Dialog dlg) {
+            dlg.runModalLoop();
+        }
+
+        public void endModalLoop(Dialog dlg) {
+            dlg.endModalLoop();            
+        }
+
+        public void setVisibleFlag(Component comp, boolean visible) {
+            comp.visible = visible;            
         }
     }
 
@@ -364,8 +371,6 @@
                 try {
                     defToolkit = new ToolkitImpl();
                     ContextStorage.setDefaultToolkit(defToolkit);
-                    defToolkit.getNativeEventQueue().awake();
-
                     return defToolkit;
                 } finally {
                     staticUnlockAWT();
@@ -377,21 +382,6 @@
         }
     }
 
-    void validateShutdownThread() {
-        synchronized(shutdownThreadLock) {
-            if (shutdownThread == null) {
-                shutdownThread = new ShutdownThread();
-                shutdownThread.startAndInit();
-                if (systemClipboard != null) {
-                    systemClipboard.onRestart();
-                }
-                if (systemSelection != null) {
-                    systemSelection.onRestart();
-                }
-            }
-        }
-    }
-
     Font getDefaultFont() {
         return wtk.getSystemProperties().getDefaultFont();
     }
@@ -448,25 +438,34 @@
     public Toolkit() {
         lockAWT();
         try {
-            systemEventQueue = new EventQueue(true, this);
-            dispatcher = new Dispatcher(systemEventQueue, this);
+            ComponentInternals.setComponentInternals(new ComponentInternalsImpl());
+            EventQueue eq = new EventQueue(this);
+            dispatcher = new Dispatcher(this);
             final String className = getWTKClassName();
 
             desktopProperties = new HashMap();
             desktopPropsSupport = new PropertyChangeSupport(this);
 
             awtEventsManager = new AWTEventsManager();
-            dispatchThread = new EventDispatchThread(this, systemEventQueue, dispatcher);
-            dispatchThread.startAndInit(new Runnable() {
-                    public void run() {
-                        wtk = createWTK(className);
-                        synchronizer.setEnvironment(wtk, dispatchThread);
-                        ContextStorage.setWTK(wtk);
-                    }
+            dispatchThread = new EventDispatchThread(this, dispatcher);
+            nativeThread = new NativeEventThread();
+            
+            dtk = DTK.getDTK();
+
+            NativeEventThread.Init init = new NativeEventThread.Init() {
+                public WTK init() {
+                    wtk = createWTK(className);
+                    wtk.getNativeEventQueue().setShutdownWatchdog(shutdownWatchdog);
+                    synchronizer.setEnvironment(wtk, nativeThread);
+                    ContextStorage.setWTK(wtk);
+                    dtk.initDragAndDrop();
+                    return wtk;
                 }
-            );
-
-            ComponentInternals.setComponentInternals(new ComponentInternalsImpl());
+            };
+            nativeThread.start(init);
+            
+            dispatchThread.start();
+            wtk.getNativeEventQueue().awake();
         } finally {
             unlockAWT();
         }
@@ -556,7 +555,10 @@
 
     Map mapInputMethodHighlightImpl(InputMethodHighlight highlight)
             throws HeadlessException {
-        return null;
+        checkHeadless();
+        HashMap map = new HashMap();
+        wtk.getSystemProperties().mapInputMethodHighlight(highlight, map);
+        return Collections.unmodifiableMap(map);
     }
 
     public void addPropertyChangeListener(String propName, PropertyChangeListener l) {
@@ -733,14 +735,21 @@
     }
 
     public final EventQueue getSystemEventQueue() {
-        lockAWT();
-        try {
-            return getSystemEventQueueImpl();
-        } finally {
-            unlockAWT();
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkAwtEventQueueAccess();
         }
+        return getSystemEventQueueImpl();
     }
 
+    EventQueueCore getSystemEventQueueCore() {
+        return systemEventQueueCore;
+    }
+    
+    void setSystemEventQueueCore(EventQueueCore core) {
+        systemEventQueueCore = core;
+    }
+    
     public Clipboard getSystemSelection() throws HeadlessException {
         lockAWT();
         try {
@@ -753,7 +762,7 @@
             }
 
             if (systemSelection == null) {
-                systemSelection = DTK.getContextInstance().getNativeSelection();
+                systemSelection = dtk.getNativeSelection();
             }
 
             return systemSelection;
@@ -765,6 +774,7 @@
     protected void initializeDesktopProperties() {
         lockAWT();
         try {
+            wtk.getSystemProperties().init(desktopProperties);
         } finally {
             unlockAWT();
         }
@@ -861,7 +871,7 @@
             if (systemSelection != null) {
                 systemSelection.onShutdown();
             }
-            stopShutdownThread();
+            shutdownWatchdog.setWindowListEmpty(true);
         } else {
             for (Iterator i = windows.iterator(); i.hasNext();) {
                 ((Window) i.next()).redrawAll();
@@ -942,7 +952,7 @@
         NativeWindow win = getWindowFactory().createWindow(cp);
         nativeWindowCreated(win);
 
-        validateShutdownThread();
+        shutdownWatchdog.setWindowListEmpty(false);
 
         return win;
     }
@@ -1024,7 +1034,7 @@
         nativeWindowCreated(win);
 
         if (c instanceof Window) {
-            validateShutdownThread();
+            shutdownWatchdog.setWindowListEmpty(false);
         }
 
         return win;
@@ -1232,7 +1242,7 @@
 
         return new Theme();
     }
-
+    
     final class AWTEventsManager {
 
         AWTPermission permission = new AWTPermission("listenToAllAWTEvents");

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=440748&r1=440747&r2=440748
==============================================================================
--- 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 Wed Sep  6 09:06:15 2006
@@ -218,15 +218,9 @@
         }
     }
 
-    public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent a0)
-            throws InvalidDnDOperationException
-    {
-        lockAWT();
-        try {
-        } finally {
-            unlockAWT();
-        }
-        return null;
+    public DragSourceContextPeer createDragSourceContextPeer(
+            DragGestureEvent dge) throws InvalidDnDOperationException {
+        return dtk.createDragSourceContextPeer(dge);
     }
 
     protected FileDialogPeer createFileDialog(FileDialog a0)
@@ -466,7 +460,7 @@
             }
 
             if (systemClipboard == null) {
-                systemClipboard = DTK.getContextInstance().getNativeClipboard();
+                systemClipboard = DTK.getDTK().getNativeClipboard();
             }
 
             return systemClipboard;
@@ -486,7 +480,7 @@
     }
 
     protected EventQueue getSystemEventQueueImpl() {
-        return systemEventQueue;
+        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=440748&r1=440747&r2=440748
==============================================================================
--- 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 Wed Sep  6 09:06:15 2006
@@ -46,6 +46,7 @@
 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;
 
 
@@ -92,6 +93,8 @@
     private boolean disposed = false;
 
     boolean painted;
+    
+    private transient InputContext inputContext;
 
     protected  class AccessibleAWTWindow extends AccessibleAWTContainer {
 
@@ -288,6 +291,7 @@
                 mapToDisplay(false);
                 disposed = true;
                 opened = false;
+                disposeInputContext();
 
                 finishHierarchyChange(this, parent, 0);
                 postEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSED));
@@ -297,6 +301,15 @@
         }
     }
 
+    private void disposeInputContext() {
+        // only default windows input contexts are disposed
+        // custom input contexts returned by
+        // overridden getInputContext() are not!
+        if (inputContext != null) {
+            inputContext.dispose();
+        }
+    }
+
     /**
      * Remove focus proxy native window
      * from map which is stored in Toolkit
@@ -381,7 +394,10 @@
     public InputContext getInputContext() {
         toolkit.lockAWT();
         try {
-            return null;
+            if (inputContext == null) {
+                inputContext = InputContext.getInstance();
+            }
+            return inputContext;
         } finally {
             toolkit.unlockAWT();
         }
@@ -408,6 +424,7 @@
                     w.hide();
                 }
             }
+            notifyInputMethod(null);
         } finally {
             toolkit.unlockAWT();
         }
@@ -1196,4 +1213,12 @@
         visible = false;
         redrawManager = new RedrawManager(this);
     }
+    
+    void notifyInputMethod(Rectangle bounds) {
+        InputContext ic = getInputContext();
+        if (ic instanceof InputMethodContext) {
+            ((InputMethodContext)ic).notifyClientWindowChange(bounds);
+        }
+    }
+    
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/DataFlavor.java Wed Sep  6 09:06:15 2006
@@ -87,7 +87,7 @@
     public static final DataFlavor getTextPlainUnicodeFlavor() {
         if (plainUnicodeFlavor == null) {
             plainUnicodeFlavor = new DataFlavor("text/plain"
-                    + "; charset=" + DTK.textDescriptor.getDefaultCharset()
+                    + "; charset=" + DTK.getDTK().getDefaultCharset()
                     + "; class=java.io.InputStream",
                     "Plain Text");
         }
@@ -197,7 +197,7 @@
             String charset = mimeInfo.getParameter("charset");
 
             if (isCharsetRequired() && ((charset == null) || (charset.length() == 0))) {
-                return DTK.textDescriptor.getDefaultCharset();
+                return DTK.getDTK().getDefaultCharset();
             } else {
                 if (charset == null) {
                     return "";
@@ -568,7 +568,7 @@
 
         best = getFlavors(list, new String[] {"UTF-16", "UTF-8", "UTF-16BE", "UTF-16LE"});
         if (best == null) {
-            best = getFlavors(list, new String[] {DTK.textDescriptor.getDefaultCharset()});
+            best = getFlavors(list, new String[] {DTK.getDTK().getDefaultCharset()});
             if (best == null) {
                 best = getFlavors(list, new String[] {"US-ASCII"});
                 if (best == null) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/MimeTypeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/MimeTypeProcessor.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/MimeTypeProcessor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/MimeTypeProcessor.java Wed Sep  6 09:06:15 2006
@@ -226,6 +226,16 @@
         }
 
         void addParameter(String name, String value) {
+            if (value == null) {
+                return;
+            }
+            if ((value.charAt(0) == '\"') 
+                    && (value.charAt(value.length() - 1) == '\"')) {
+                value = value.substring(1, value.length() - 2);
+            }
+            if (value.length() == 0) {
+                return;
+            }
             parameters.put(name, value);
         }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/SystemFlavorMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/SystemFlavorMap.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/SystemFlavorMap.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/datatransfer/SystemFlavorMap.java Wed Sep  6 09:06:15 2006
@@ -19,55 +19,42 @@
  */
 package java.awt.datatransfer;
 
-import java.awt.Toolkit;
-import java.awt.datatransfer.MimeTypeProcessor.MimeType;
-import java.util.*;
-import java.net.URL;
-
-import org.apache.harmony.awt.ContextStorage;
-import org.apache.harmony.awt.datatransfer.*;
-import org.apache.harmony.awt.wtk.Synchronizer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.harmony.awt.datatransfer.DTK;
 
 
 public final class SystemFlavorMap implements FlavorMap, FlavorTable {
 
-    private static final String JAVA_PREFIX = 
+    private static final String SERIALIZED_PREFIX = 
         "org.apache.harmony.awt.datatransfer:";
 
-    private static final String EOLN_NAME = "eoln";
-    private static final String EOLN_DEFAULT_VALUE = "\n";
-    private static final String TERMINATORS_NAME = "terminators";
-    private static final Integer TERMINATORS_DEFAULT_VALUE = new Integer(0);
-
-    private static final String LINUX_PROPERTY_CLASS =
-            "org.apache.harmony.awt.datatransfer.linux.LinuxFlavorMap";
-    private static final String WINDOWS_PROPERTY_CLASS =
-            "org.apache.harmony.awt.datatransfer.windows.WinFlavorMap";
-    private static final String FLAVOR_MAP_PROPERTY = "AWT.DnD.flavorMapFileURL";
-
-    private static final DataFlavor[] dummyFlavorArray = new DataFlavor[0];
-
     private final HashMap flavor2Native = new HashMap();
     private final HashMap native2Flavor = new HashMap();
-    private final FlavorsComparator flavorsComparator = new FlavorsComparator();
 
-    private final NativeTranslationManager translationManager;
+    private final DTK dtk;
 
     public static boolean isJavaMIMEType(String str) {
-        return ((str != null) && str.startsWith(JAVA_PREFIX));
+        return ((str != null) && str.startsWith(SERIALIZED_PREFIX));
     }
 
     public static String encodeJavaMIMEType(String mimeType) {
         if (mimeType == null) {
             return null;
         } else {
-            return (JAVA_PREFIX + mimeType);
+            return (SERIALIZED_PREFIX + mimeType);
         }
     }
 
     public static String decodeJavaMIMEType(String nat) {
         if (isJavaMIMEType(nat)) {
-            return nat.substring(JAVA_PREFIX.length());
+            return nat.substring(SERIALIZED_PREFIX.length());
         } else {
             return null;
         }
@@ -77,279 +64,103 @@
         if (flav == null) {
             return null;
         } else {
-            return (JAVA_PREFIX + flav.getMimeType());
+            return (SERIALIZED_PREFIX + flav.getMimeType());
         }
     }
 
-    public static DataFlavor decodeDataFlavor(String nat) throws ClassNotFoundException {
+    public static DataFlavor decodeDataFlavor(String nat)
+            throws ClassNotFoundException {
         if (isJavaMIMEType(nat)) {
-            return new DataFlavor(nat.substring(JAVA_PREFIX.length()));
+            return new DataFlavor(nat.substring(SERIALIZED_PREFIX.length()));
         } else {
             return null;
         }
     }
 
     public static FlavorMap getDefaultFlavorMap() {
-        DTK dtk = DTK.getContextInstance();
-        Synchronizer awtSynchronizer = ContextStorage.getSynchronizer();;
+        DTK dtk = DTK.getDTK();
 
-        awtSynchronizer.lock();
-        try {
-            FlavorMap flavorMap = dtk.getFlavorMap();
+        synchronized (dtk) {
+            SystemFlavorMap flavorMap = dtk.getSystemFlavorMap();
 
             if (flavorMap == null) {
                 flavorMap = new SystemFlavorMap(dtk);
-                dtk.setFlavorMap(flavorMap);
+                dtk.setSystemFlavorMap(flavorMap);
             }
 
             return flavorMap;
-        } finally {
-            awtSynchronizer.unlock();
         }
     }
 
     private SystemFlavorMap(DTK dtk) {
-        ResourceBundle properties = loadProperties();
-        translationManager = dtk.getTranslationManager();
-
-        for (Enumeration i = properties.getKeys(); i.hasMoreElements();) {
-            try {
-                String nat = (String) i.nextElement();
-                Object flavs = properties.getObject(nat);
-
-                if (flavs instanceof String) {
-                    addFlavorNativePair(createSystemFlavor((String) flavs), nat);
-                } else {
-                    for (Iterator j = ((List) flavs).iterator(); j.hasNext();) {
-                        addFlavorNativePair(createSystemFlavor((String) j.next()), nat);
-                    }
-                }
-            } catch (ClassNotFoundException e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    private void addFlavorNativePair(DataFlavor flav, String nat) {
-        List flavors = (List) native2Flavor.get(nat);
-        List natives = (List) flavor2Native.get(flav);
-        MimeType mime = flav.getMimeInfo();
-
-        if (flavors == null) {
-            flavors = new LinkedList();
-            native2Flavor.put(nat, flavors);
-        }
-        if (!flavors.contains(flav)) {
-            flavors.add(flav);
-        }
-        if (natives == null) {
-            natives = new LinkedList();
-            flavor2Native.put(flav, natives);
-        }
-        if (!natives.contains(nat)) {
-            natives.add(nat);
-        }
-
-        translationManager.addSystemParams(new TranslationPoint(flav, nat),
-                (String) mime.getSystemParameter(EOLN_NAME),
-                (Integer) mime.getSystemParameter(TERMINATORS_NAME));
-    }
-
-    private ResourceBundle loadProperties() {
-        String url = Toolkit.getProperty(FLAVOR_MAP_PROPERTY, null);
-
-        if (url == null) {
-            return loadPropertiesFromClass();
-        } else {
-            return loadPropertiesFromFile(url);
-        }
-    }
-
-    private ResourceBundle loadPropertiesFromFile(String url) {
-        try {
-            return new DuplicatedPropertiesResourceBundle(
-                    new URL(url).openConnection().getInputStream());
-        } catch (Exception e) {
-            e.printStackTrace();
-
-            return null;
-        }
-    }
-
-    private ResourceBundle loadPropertiesFromClass() {
-        String osName = System.getProperty("os.name").toLowerCase();
-        String className = null;
-
-        if (osName.startsWith("linux")) {
-            className = LINUX_PROPERTY_CLASS;
-        } else if (osName.startsWith("windows")) {
-            className = WINDOWS_PROPERTY_CLASS;
-        }
-
-        return ResourceBundle.getBundle(className);
-    }
-
-    private DataFlavor createSystemFlavor(String mimeType)
-            throws ClassNotFoundException
-    {
-        DataFlavor flavor = new DataFlavor(mimeType);
-        MimeType mimeInfo = flavor.getMimeInfo();
-        String eoln = mimeInfo.getParameter(EOLN_NAME);
-        String terminators = mimeInfo.getParameter(TERMINATORS_NAME);
-        int termValue = TERMINATORS_DEFAULT_VALUE.intValue();
-
-        if ((eoln == null) || (eoln.length() == 0)) {
-            eoln = EOLN_DEFAULT_VALUE;
-        }
-        mimeInfo.removeParameter(EOLN_NAME);
-        mimeInfo.addSystemParameter(EOLN_NAME, eoln);
-
-        try {
-            int value = Integer.decode(terminators).intValue();
-
-            if (value >= 0) {
-                termValue = value;
-            }
-        } catch (Throwable t) {
-        }
-        mimeInfo.removeParameter(TERMINATORS_NAME);
-        mimeInfo.addSystemParameter(TERMINATORS_NAME, new Integer(termValue));
-
-        return flavor;
+        this.dtk = dtk;
+        dtk.initSystemFlavorMap(this);
     }
 
     public synchronized List getFlavorsForNative(String nat) {
         if (nat == null) {
-            return getAllKnownEntities(flavor2Native, native2Flavor);
+            return new ArrayList(flavor2Native.keySet());
         }
 
-        List flavors = (List) native2Flavor.get(nat);
-
-        if (flavors == null) {
-            flavors = new LinkedList();
-        }
-        if (flavors.isEmpty()) {
-            if (isJavaMIMEType(nat)) {
-                try {
-                    String decodedNat = decodeJavaMIMEType(nat);
-                    DataFlavor flavor = new DataFlavor(decodedNat);
-                    List natives = (List) flavor2Native.get(flavor);
-
-                    flavors.add(flavor);
-                    native2Flavor.put(nat, flavors);
-
-                    if (natives == null) {
-                        natives = new LinkedList();
-                        flavor2Native.put(flavor, natives);
-                    }
-                    if (!natives.contains(nat)) {
-                        natives.add(nat);
-                    }
-                } catch (ClassNotFoundException e) {
-                }
-            }
-        } else if (DTK.textDescriptor.isTextNative(nat)) {
-            flavors = getFlavorsForText(flavors);
-        }
-
-        return flavors;
-    }
-
-    private List getFlavorsForText(List flavors) {
-        if (!flavors.contains(DataFlavor.stringFlavor)) {
-            flavors.add(0, DataFlavor.stringFlavor);
-        }
-        if (!flavors.contains(DataFlavor.plainTextFlavor)) {
-            flavors.add(DataFlavor.plainTextFlavor);
+        List list = (List) native2Flavor.get(nat);
+        if ((list == null || list.isEmpty()) && isJavaMIMEType(nat)) {
+            String decodedNat = decodeJavaMIMEType(nat);
+            try {
+                DataFlavor flavor = new DataFlavor(decodedNat);
+                addMapping(nat, flavor);
+                list = (List) native2Flavor.get(nat);
+            } catch (ClassNotFoundException e) {}
         }
-
-        DataFlavor[] flavorArray = (DataFlavor[]) flavors.toArray(dummyFlavorArray);
-
-        Arrays.sort(flavorArray, flavorsComparator);
-
-        return Arrays.asList(flavorArray);
+        return (list != null) ? new ArrayList(list) : new ArrayList();
     }
 
     public synchronized List getNativesForFlavor(DataFlavor flav) {
         if (flav == null) {
-            return getAllKnownEntities(native2Flavor, flavor2Native);
-        }
-
-        List natives = (List) flavor2Native.get(flav);
-
-        if (natives == null) {
-            natives = new LinkedList();
+            return new ArrayList(native2Flavor.keySet());
         }
-        if (flav.isFlavorTextType()) {
-            getNativesForText(natives);
-        } else if (natives.isEmpty()) {
-            String encodedNat = encodeDataFlavor(flav);
-            List flavors = (List) native2Flavor.get(encodedNat);
-
-            natives.add(encodedNat);
-            flavor2Native.put(flav, natives);
-
-            if (flavors == null) {
-                flavors = new LinkedList();
-                native2Flavor.put(encodedNat, flavors);
-            }
-            if (!flavors.contains(flav)) {
-                flavors.add(flav);
-            }
-        }
-
-        return natives;
-    }
-
-    private void getNativesForText(List natives) {
-        String[] textNatives = DTK.textDescriptor.getTextNatives();
-
-        for (int i = 0; i < textNatives.length; i++) {
-            String nat = textNatives[i];
-
-            if (!natives.contains(nat)) {
-                natives.add(nat);
-            }
+        
+        List list = (List) flavor2Native.get(flav);
+        if ((list == null || list.isEmpty()) 
+                && flav.isFlavorSerializedObjectType()) {
+            String nat = encodeDataFlavor(flav);
+            addMapping(nat, flav);
+            list = (List) flavor2Native.get(flav);
         }
+        return (list != null) ? new ArrayList(list) : new ArrayList();
     }
 
     public synchronized Map getFlavorsForNatives(String[] natives) {
         HashMap map = new HashMap();
-        List nativesList = (natives != null) ?
-                Arrays.asList(natives) :
-                getAllKnownEntities(native2Flavor, flavor2Native);
-
-        for (Iterator i = nativesList.iterator(); i.hasNext();) {
-            String nat = (String) i.next();
-            List flavors = getFlavorsForNative(nat);
-
-            if (!flavors.isEmpty()) {
-                map.put(nat, flavors.get(0));
+        Iterator it = (natives != null) ? 
+                Arrays.asList(natives).iterator() : 
+                    native2Flavor.keySet().iterator();
+        while (it.hasNext()) {
+            String nat = (String)it.next();
+            List list = getFlavorsForNative(nat);
+            if (list.size() > 0) {
+                map.put(nat, list.get(0));
             }
         }
-
         return map;
     }
 
     public synchronized Map getNativesForFlavors(DataFlavor[] flavors) {
         HashMap map = new HashMap();
-        List flavorsList = (flavors != null) ?
-                Arrays.asList(flavors) :
-                getAllKnownEntities(flavor2Native, native2Flavor);
-
-        for (Iterator i = flavorsList.iterator(); i.hasNext();) {
-            DataFlavor flav = (DataFlavor) i.next();
-            List natives = getNativesForFlavor(flav);
-
-            if (!natives.isEmpty()) {
-                map.put(flav, natives.get(0));
+        Iterator it = (flavors != null) ? 
+                Arrays.asList(flavors).iterator() : 
+                    flavor2Native.keySet().iterator();
+        while (it.hasNext()) {
+            DataFlavor flavor = (DataFlavor)it.next();
+            List list = getNativesForFlavor(flavor);
+            if (list.size() > 0) {
+                map.put(flavor, list.get(0));
             }
         }
-
         return map;
     }
 
-    public synchronized void setNativesForFlavor(DataFlavor flav, String[] natives) {
+    public synchronized void setNativesForFlavor(
+            DataFlavor flav, String[] natives) {
         LinkedList list = new LinkedList();
 
         for (int i = 0; i < natives.length; i++) {
@@ -367,7 +178,8 @@
         }
     }
 
-    public synchronized void setFlavorsForNative(String nat, DataFlavor[] flavors) {
+    public synchronized void setFlavorsForNative(
+            String nat, DataFlavor[] flavors) {
         LinkedList list = new LinkedList();
 
         for (int i = 0; i < flavors.length; i++) {
@@ -385,7 +197,8 @@
         }
     }
 
-    public synchronized void addUnencodedNativeForFlavor(DataFlavor flav, String nat) {
+    public synchronized void addUnencodedNativeForFlavor(
+            DataFlavor flav, String nat) {
         List natives = (List) flavor2Native.get(flav);
 
         if (natives == null) {
@@ -397,7 +210,8 @@
         }
     }
 
-    public synchronized void addFlavorForUnencodedNative(String nat, DataFlavor flav) {
+    public synchronized void addFlavorForUnencodedNative(
+            String nat, DataFlavor flav) {
         List flavors = (List) native2Flavor.get(nat);
 
         if (flavors == null) {
@@ -409,15 +223,8 @@
         }
     }
 
-    private List getAllKnownEntities(HashMap from, HashMap to) {
-        HashSet set = new HashSet(from.keySet());
-        List toFrom = new LinkedList(to.keySet());
-
-        for (Iterator i = toFrom.iterator(); i.hasNext();) {
-            set.addAll((List) to.get(i.next()));
-        }
-
-        return new LinkedList(set);
+    private void addMapping(String nat, DataFlavor flav) {
+        addUnencodedNativeForFlavor(flav, nat);
+        addFlavorForUnencodedNative(nat, flav);
     }
-
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DnDConstants.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DnDConstants.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DnDConstants.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DnDConstants.java Wed Sep  6 09:06:15 2006
@@ -22,16 +22,7 @@
 public final class DnDConstants {
 
     static boolean isValidAction(int action) {
-        switch (action) {
-        case ACTION_NONE:
-        case ACTION_COPY:
-        case ACTION_MOVE:
-        case ACTION_COPY_OR_MOVE:
-        case ACTION_LINK:
-            return true;
-        default:
-            return false;
-        }
+        return (action & ~(ACTION_COPY_OR_MOVE|ACTION_LINK)) == 0;
     }
 
     private DnDConstants() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragGestureEvent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragGestureEvent.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragGestureEvent.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragGestureEvent.java Wed Sep  6 09:06:15 2006
@@ -34,7 +34,8 @@
     private final List eventList;
     private final int action;
 
-    public DragGestureEvent(DragGestureRecognizer dgr, int act, Point ori, List evs) {
+    public DragGestureEvent(DragGestureRecognizer dgr, 
+                            int act, Point ori, List evs) {
         super(dgr);
 
         if (dgr.getComponent() == null) {
@@ -101,20 +102,31 @@
     public void startDrag(Cursor dragCursor, Transferable transferable)
             throws InvalidDnDOperationException
     {
-        startDrag(dragCursor, transferable, recognizer.dragSource.getDragSourceListeners()[0]);
-    }
-
-    public void startDrag(Cursor dragCursor, Image dragImage, Point imageOffset,
-            Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException
-    {
-        recognizer.getDragSource().
-                startDrag(this, dragCursor, dragImage, imageOffset, transferable, dsl);
-    }
+        DragSourceListener[] listeners = 
+            recognizer.dragSource.getDragSourceListeners();
+        DragSourceListener dsl = 
+            listeners.length > 0 ? new DragSourceMulticaster(listeners) : null;
+        startDrag(dragCursor, transferable, dsl);
+    }
+
+    public void startDrag(Cursor dragCursor, 
+                          Image dragImage, 
+                          Point imageOffset,
+                          Transferable transferable, 
+                          DragSourceListener dsl) 
+            throws InvalidDnDOperationException {
+
+        recognizer.getDragSource().startDrag(this, dragCursor, dragImage, 
+                                             imageOffset, transferable, dsl);
+    }
+
+    public void startDrag(Cursor dragCursor, 
+                          Transferable transferable, 
+                          DragSourceListener dsl)
+            throws InvalidDnDOperationException {
 
-    public void startDrag(Cursor dragCursor, Transferable transferable, DragSourceListener dsl)
-            throws InvalidDnDOperationException
-    {
-        recognizer.getDragSource().startDrag(this, dragCursor, transferable, dsl);
+        recognizer.getDragSource().startDrag(
+                this, dragCursor, transferable, dsl);
     }
 
 }



Mime
View raw message