harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440748 [3/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/dnd/DragSource.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSource.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSource.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSource.java Wed Sep  6 09:06:15 2006
@@ -53,8 +53,8 @@
 
     static {
         if (GraphicsEnvironment.isHeadless()) {
-            DefaultMoveDrop = DefaultMoveNoDrop = DefaultCopyDrop =
-                    DefaultCopyNoDrop = DefaultLinkDrop = DefaultLinkNoDrop = null;
+            DefaultMoveDrop = DefaultMoveNoDrop = DefaultCopyDrop = null;
+            DefaultCopyNoDrop = DefaultLinkDrop = DefaultLinkNoDrop = null;
         } else {
             Toolkit toolkit = Toolkit.getDefaultToolkit();
 
@@ -117,7 +117,8 @@
 
     public DragSourceMotionListener[] getDragSourceMotionListeners() {
         return (DragSourceMotionListener[])
-                dragSourceMotionListeners.getUserListeners(new DragSourceMotionListener[0]);
+                dragSourceMotionListeners.getUserListeners(
+                        new DragSourceMotionListener[0]);
     }
 
     public void addDragSourceMotionListener(DragSourceMotionListener dsml) {
@@ -131,71 +132,98 @@
     public EventListener[] getListeners(Class listenerType) {
         if (DragSourceListener.class.isAssignableFrom(listenerType)) {
             return getDragSourceListeners();
-        } else if (DragSourceMotionListener.class.isAssignableFrom(listenerType)) {
+        } else if (DragSourceMotionListener.class.isAssignableFrom(
+                listenerType)) {
             return getDragSourceMotionListeners();
         }
 
         return new EventListener[0];
     }
 
-    protected DragSourceContext createDragSourceContext(DragSourceContextPeer dscp,
-            DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset,
+    protected DragSourceContext createDragSourceContext(
+            DragSourceContextPeer dscp,
+            DragGestureEvent dgl, Cursor dragCursor, 
+            Image dragImage, Point imageOffset,
             Transferable t, DragSourceListener dsl)
     {
-        return new DragSourceContext(dscp, dgl, dragCursor, dragImage, imageOffset, t, dsl);
+        return new DragSourceContext(dscp, dgl, dragCursor, 
+                                     dragImage, imageOffset, t, dsl);
     }
 
     public FlavorMap getFlavorMap() {
         return SystemFlavorMap.getDefaultFlavorMap();
     }
 
-    public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage,
-            Point imageOffset, Transferable transferable, DragSourceListener dsl,
-            FlavorMap flavorMap) throws InvalidDnDOperationException
-    {
+    public void startDrag(DragGestureEvent trigger, Cursor dragCursor, 
+                          Image dragImage, Point imageOffset, 
+                          Transferable transferable, DragSourceListener dsl,
+                          FlavorMap flavorMap)
+            throws InvalidDnDOperationException {
+
         if (curContext != null) {
             throw new InvalidDnDOperationException(
-                    "Attempt to start a drag while an existing drag operation is still executing.");
+                    "Attempt to start a drag while an existing " + 
+                    "drag operation is still executing.");
         }
 
         DragSourceContextPeer peer =
-                Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger);
+            Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger);
         curContext = createDragSourceContext(peer, trigger, dragCursor,
-                dragImage, imageOffset, transferable, dsl);
+                                             dragImage, imageOffset,
+                                             transferable, dsl);
 
         peer.startDrag(curContext, dragCursor, dragImage, imageOffset);
+        curContext = null;
     }
 
-    public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage,
-            Point dragOffset, Transferable transferable, DragSourceListener dsl)
-            throws InvalidDnDOperationException
-    {
-        startDrag(trigger, dragCursor, dragImage, dragOffset, transferable, dsl, null);
+    public void startDrag(DragGestureEvent trigger, 
+                          Cursor dragCursor,
+                          Image dragImage, 
+                          Point dragOffset, 
+                          Transferable transferable, 
+                          DragSourceListener dsl)
+            throws InvalidDnDOperationException {
+
+        startDrag(trigger, dragCursor, dragImage, 
+                  dragOffset, transferable, dsl, null);
     }
 
-    public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Transferable transferable,
-            DragSourceListener dsl, FlavorMap flavorMap) throws InvalidDnDOperationException
-    {
-        startDrag(trigger, dragCursor, null, null, transferable, dsl, flavorMap);
+    public void startDrag(DragGestureEvent trigger, 
+                          Cursor dragCursor, 
+                          Transferable transferable, 
+                          DragSourceListener dsl, 
+                          FlavorMap flavorMap)
+            throws InvalidDnDOperationException {
+
+        startDrag(trigger, dragCursor, null, null, 
+                  transferable, dsl, flavorMap);
     }
 
-    public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Transferable transferable,
-            DragSourceListener dsl) throws InvalidDnDOperationException
-    {
+    public void startDrag(DragGestureEvent trigger,
+                          Cursor dragCursor, 
+                          Transferable transferable,
+                          DragSourceListener dsl)
+            throws InvalidDnDOperationException {
+
         startDrag(trigger, dragCursor, transferable, dsl, null);
     }
 
     public DragGestureRecognizer createDragGestureRecognizer(
-                                            Class recognizerAbstractClass, 
-                                            Component c, int 
-                                            actions, 
-                                            DragGestureListener dgl) {
+                            Class recognizerAbstractClass, 
+                            Component c, 
+                            int actions, 
+                            DragGestureListener dgl) {
+
         Toolkit t = Toolkit.getDefaultToolkit();
         return t.createDragGestureRecognizer(
                     recognizerAbstractClass, this, c, actions, dgl);
     }
 
-    public DragGestureRecognizer createDefaultDragGestureRecognizer(Component c, int actions, DragGestureListener dgl) {
+    public DragGestureRecognizer createDefaultDragGestureRecognizer(
+                            Component c, 
+                            int actions, 
+                            DragGestureListener dgl) {
+
         Toolkit t = Toolkit.getDefaultToolkit();
         return t.createDragGestureRecognizer(
                 MouseDragGestureRecognizer.class, this, c, actions, dgl);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSourceDragEvent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSourceDragEvent.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSourceDragEvent.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSourceDragEvent.java Wed Sep  6 09:06:15 2006
@@ -19,7 +19,7 @@
  */
 package java.awt.dnd;
 
-import java.awt.event.KeyEvent;
+import java.awt.event.InputEvent;
 
 public class DragSourceDragEvent extends DragSourceEvent {
 
@@ -44,12 +44,10 @@
     }
 
     private void initFields(int dropAction, int action, int modifiers) {
-        KeyEvent converter = new KeyEvent(null, 0, 0l, modifiers, 0, (char) 0);
-
         userAction = dropAction;
         targetAction = action;
-        modifiers = converter.getModifiers();
-        modifiersEx = converter.getModifiersEx();
+        this.modifiers = getInputModifiers(modifiers);
+        this.modifiersEx = modifiers;
     }
 
     public int getUserAction() {
@@ -72,4 +70,35 @@
         return (userAction & targetAction & getDragSourceContext().getSourceActions());
     }
 
+    private int getInputModifiers(int modifiersEx) {
+        // TODO: share this code with KeyEvent.getModifiers()
+        int modifiers = 0;
+
+        if ((modifiersEx & InputEvent.SHIFT_DOWN_MASK) != 0) {
+            modifiers |= InputEvent.SHIFT_MASK;
+        }
+        if ((modifiersEx & InputEvent.CTRL_DOWN_MASK) != 0) {
+            modifiers |= InputEvent.CTRL_MASK;
+        }
+        if ((modifiersEx & InputEvent.META_DOWN_MASK) != 0) {
+            modifiers |= InputEvent.META_MASK;
+        }
+        if ((modifiersEx & InputEvent.ALT_DOWN_MASK) != 0) {
+            modifiers |= InputEvent.ALT_MASK;
+        }
+        if ((modifiersEx & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
+            modifiers |= InputEvent.ALT_GRAPH_MASK;
+        }
+        if ((modifiersEx & InputEvent.BUTTON1_DOWN_MASK) != 0) {
+            modifiers |= InputEvent.BUTTON1_MASK;
+        }
+        if ((modifiersEx & InputEvent.BUTTON2_DOWN_MASK) != 0) {
+            modifiers |= InputEvent.BUTTON2_MASK;
+        }
+        if ((modifiersEx & InputEvent.BUTTON3_DOWN_MASK) != 0) {
+            modifiers |= InputEvent.BUTTON3_MASK;
+        }
+
+        return modifiers;
+    }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSourceMulticaster.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSourceMulticaster.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSourceMulticaster.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DragSourceMulticaster.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,63 @@
+/*
+ *  Copyright 2005 The Apache 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.dnd;
+
+/**
+ * A wrapper for array of drag source listeners
+ */
+class DragSourceMulticaster implements DragSourceListener {
+
+    final DragSourceListener[] listeners;
+    
+    DragSourceMulticaster(DragSourceListener[] listeners) {
+        this.listeners = listeners;
+    }
+
+    public void dragExit(DragSourceEvent dsde) {
+        for (int i=0; i<listeners.length; i++) {
+            listeners[i].dragExit(dsde);
+        }
+    }
+
+    public void dragDropEnd(DragSourceDropEvent dsde) {
+        for (int i=0; i<listeners.length; i++) {
+            listeners[i].dragDropEnd(dsde);
+        }
+    }
+
+    public void dropActionChanged(DragSourceDragEvent dsde) {
+        for (int i=0; i<listeners.length; i++) {
+            listeners[i].dropActionChanged(dsde);
+        }
+    }
+
+    public void dragOver(DragSourceDragEvent dsde) {
+        for (int i=0; i<listeners.length; i++) {
+            listeners[i].dragOver(dsde);
+        }
+    }
+
+    public void dragEnter(DragSourceDragEvent dsde) {
+        for (int i=0; i<listeners.length; i++) {
+            listeners[i].dragEnter(dsde);
+        }
+    }
+
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DropTarget.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DropTarget.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DropTarget.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DropTarget.java Wed Sep  6 09:06:15 2006
@@ -25,12 +25,15 @@
 import java.awt.Point;
 import java.awt.datatransfer.FlavorMap;
 import java.awt.datatransfer.SystemFlavorMap;
+import java.awt.dnd.peer.DropTargetContextPeer;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.peer.ComponentPeer;
 import java.io.Serializable;
 import java.util.TooManyListenersException;
 
+import org.apache.harmony.awt.datatransfer.DTK;
+
 public class DropTarget implements DropTargetListener, Serializable {
 
     private static final long serialVersionUID = -6283860791671019047L;
@@ -64,7 +67,7 @@
     int actions;
     FlavorMap flavorMap;
     DropTargetListener dropTargetListener;
-    DropTargetContext context;
+    final DropTargetContext context;
     DropTargetAutoScroller autoScroller;
 
     public DropTarget(Component c, int ops, DropTargetListener dtl, 
@@ -108,10 +111,14 @@
     }
 
     public void removeNotify(ComponentPeer peer) {
+        context.removeNotify();
         // TODO: implement
     }
 
     public void addNotify(ComponentPeer peer) {
+        DTK dtk = DTK.getDTK();
+        DropTargetContextPeer dtp = dtk.createDropTargetContextPeer(context);
+        context.addNotify(dtp);
         // TODO: implement
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DropTargetDragEvent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DropTargetDragEvent.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DropTargetDragEvent.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/dnd/DropTargetDragEvent.java Wed Sep  6 09:06:15 2006
@@ -21,6 +21,7 @@
 
 import java.awt.Point;
 import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
 import java.util.List;
 
 public class DropTargetDragEvent extends DropTargetEvent {
@@ -65,4 +66,7 @@
         return context.getCurrentDataFlavors();
     }
 
+    public Transferable getTransferable() {
+        return context.getTransferable();
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/GlyphMetrics.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/GlyphMetrics.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/GlyphMetrics.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/GlyphMetrics.java Wed Sep  6 09:06:15 2006
@@ -24,7 +24,7 @@
 public final class GlyphMetrics {
 
     // advance width of the glyph character cell
-    private float advanceX; 
+    private float advanceX;
     
     // advance height of the glyph character cell
     private float advanceY;
@@ -34,7 +34,7 @@
 
     // glyph type code 
     private byte glyphType;
-
+    
     // bounding box for outline of the glyph
     private Rectangle2D.Float bounds;
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/GraphicAttribute.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/GraphicAttribute.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/GraphicAttribute.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/GraphicAttribute.java Wed Sep  6 09:06:15 2006
@@ -33,7 +33,7 @@
     public static final int CENTER_BASELINE = 1;
 
     public static final int HANGING_BASELINE = 2;
-    
+
     // the alignment of this GraphicAttribute
     private int alignment;
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/ImageGraphicAttribute.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/ImageGraphicAttribute.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/ImageGraphicAttribute.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/ImageGraphicAttribute.java Wed Sep  6 09:06:15 2006
@@ -27,9 +27,10 @@
 
 
 public final class ImageGraphicAttribute extends GraphicAttribute {
+
     // Image object rendered by this ImageGraphicAttribute
     private Image fImage;
-    
+
     // X coordinate of the origin point
     private float fOriginX;
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/NumericShaper.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/NumericShaper.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/NumericShaper.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/NumericShaper.java Wed Sep  6 09:06:15 2006
@@ -73,14 +73,14 @@
      * range constant value. Also script ranges, context names and digits low
      * ranges are indexed with these indices.
      */
-    
+
     // Index of the EUROPEAN range 
     private static final int INDEX_EUROPEAN = 0;
 
     // Index of the ARABIC range 
     private static final int INDEX_ARABIC = 1;
 
-    // Index of the EASTERN_ARABIC range 
+    // Index of the EASTERN_ARABIC range    
     private static final int INDEX_EASTERN_ARABIC = 2;
 
     // Index of the DEVANAGARI range 
@@ -193,7 +193,7 @@
             0x17B0,             // KHMER
             0x17E0              // MONGOLIAN
     };
-    
+
     // Set of context names used in toString method
     private final String[] contexts = {
             "EUROPEAN",
@@ -225,6 +225,7 @@
      * This array was generated using UnicodeData.txt file from  
      * http://www.unicode.org/Public/UNIDATA/ 
      */
+
     private static final int[] STRONG_TEXT_FLAGS = { 0, 0, 134217726, 134217726,
             0, 69207040, -8388609, -8388609, -1, -1, -1, -1, -1, -1, -1, -1,
             -1, -1, -65533, -1, -1, -100663297, 196611, 16415, 0, 0, 0,
@@ -348,13 +349,12 @@
     // index of context range (Serialization support)
     private int key;
     
-    // flag, indicating if shaping is contextual and 
-    // which ranges are specified (Serialization support)
+    // flag, true if shaping contextual (Serialization support)
     private int mask;
-    
+
     // ranges to be shaped
     private int fRanges;
-    
+
     // index of the default context
     private int fDefaultContextIndex;
 
@@ -630,7 +630,7 @@
         }
 
     }
-    
+
     /**
      * Returns the index of the script of the specified char.
      * 
@@ -665,7 +665,7 @@
      * according to the serialized form of this class mentioned in the 
      * documentation.
      */
-    private void updateRangesFields(){
+     private void updateRangesFields(){
         fRanges = (mask & ~(1 << 31));
         fContextual = ((mask &(1 << 31)) != 0);
         if (fContextual){

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/ShapeGraphicAttribute.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/ShapeGraphicAttribute.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/ShapeGraphicAttribute.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/ShapeGraphicAttribute.java Wed Sep  6 09:06:15 2006
@@ -45,7 +45,7 @@
     
     // Y coordinate of the origin point
     private float fOriginY;
-    
+
     // width of the shape
     private float fShapeWidth;
     

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputContext.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputContext.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputContext.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputContext.java Wed Sep  6 09:06:15 2006
@@ -23,12 +23,14 @@
 import java.awt.Component;
 import java.util.Locale;
 
+import org.apache.harmony.awt.im.InputMethodContext;
+
 public class InputContext {
     protected InputContext() {
     }
 
     public static InputContext getInstance() {
-        return null;
+        return new InputMethodContext();
     }
 
     public void dispatchEvent(AWTEvent event) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputMethodHighlight.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputMethodHighlight.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputMethodHighlight.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputMethodHighlight.java Wed Sep  6 09:06:15 2006
@@ -14,7 +14,7 @@
  *  limitations under the License.
  */
 /**
- * @author Pavel Dolgov
+ * @author Dmitry A. Durnev
  * @version $Revision$
  */
 package java.awt.im;
@@ -28,43 +28,58 @@
     public static final int CONVERTED_TEXT = 1;
 
     public static final InputMethodHighlight
-        UNSELECTED_RAW_TEXT_HIGHLIGHT = null;
+        UNSELECTED_RAW_TEXT_HIGHLIGHT = new InputMethodHighlight(false, RAW_TEXT);
 
     public static final InputMethodHighlight
-        SELECTED_RAW_TEXT_HIGHLIGHT = null;
+        SELECTED_RAW_TEXT_HIGHLIGHT = new InputMethodHighlight(true, RAW_TEXT);
 
     public static final InputMethodHighlight
-        UNSELECTED_CONVERTED_TEXT_HIGHLIGHT = null;
+        UNSELECTED_CONVERTED_TEXT_HIGHLIGHT = 
+            new InputMethodHighlight(false, CONVERTED_TEXT);
 
     public static final InputMethodHighlight
-        SELECTED_CONVERTED_TEXT_HIGHLIGHT = null;
-
-    private InputMethodHighlight() {
-    }
+        SELECTED_CONVERTED_TEXT_HIGHLIGHT = 
+            new InputMethodHighlight(true, CONVERTED_TEXT);
+    
+    private boolean selected;
+    private int state;
+    private int variation;
+    private Map style; // Map<TextAttribute,?>
 
     public InputMethodHighlight(boolean selected, int state, int variation) {
+        this(selected, state, variation, null);
     }
 
-    public InputMethodHighlight(boolean selected, int state, int variation, Map style) {
+    public InputMethodHighlight(boolean selected, int state,
+                                int variation, Map style) {
+        if ((state != RAW_TEXT) && (state != CONVERTED_TEXT)) {
+            throw new IllegalArgumentException("unknown input method" +
+                    " highlight state");
+        }
+        this.selected = selected;
+        this.state = state;
+        this.variation = variation;
+        this.style = style;
     }
 
     public InputMethodHighlight(boolean selected, int state) {
+        this(selected, state, 0, null);
     }
 
     public int getState() {
-        return 0;
+        return state;
     }
 
     public Map getStyle() {
-        return null;
+        return style;
     }
 
     public int getVariation() {
-        return 0;
+        return variation;
     }
 
     public boolean isSelected() {
-        return false;
+        return selected;
     }
 }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputSubset.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputSubset.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputSubset.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/im/InputSubset.java Wed Sep  6 09:06:15 2006
@@ -14,33 +14,39 @@
  *  limitations under the License.
  */
 /**
- * @author Pavel Dolgov
+ * @author Dmitry A. Durnev
  * @version $Revision$
  */
 package java.awt.im;
 
 public final class InputSubset extends Character.Subset {
 
-    public static final InputSubset LATIN = null;
+    public static final InputSubset LATIN = new InputSubset("LATIN");
 
-    public static final InputSubset LATIN_DIGITS = null;
+    public static final InputSubset 
+        LATIN_DIGITS = new InputSubset("LATIN_DIGITS");
 
-    public static final InputSubset TRADITIONAL_HANZI = null;
+    public static final InputSubset 
+        TRADITIONAL_HANZI = new InputSubset("TRADITIONAL_HANZI");
 
-    public static final InputSubset SIMPLIFIED_HANZI = null;
+    public static final InputSubset 
+        SIMPLIFIED_HANZI = new InputSubset("SIMPLIFIED_HANZI");
 
-    public static final InputSubset KANJI = null;
+    public static final InputSubset KANJI = new InputSubset("KANJI");
 
-    public static final InputSubset HANJA = null;
+    public static final InputSubset HANJA = new InputSubset("HANJA");
 
-    public static final InputSubset HALFWIDTH_KATAKANA = null;
+    public static final InputSubset 
+        HALFWIDTH_KATAKANA = new InputSubset("HALFWIDTH_KATAKANA");
 
-    public static final InputSubset FULLWIDTH_LATIN = null;
+    public static final InputSubset 
+        FULLWIDTH_LATIN = new InputSubset("FULLWIDTH_LATIN");
 
-    public static final InputSubset FULLWIDTH_DIGITS = null;
+    public static final InputSubset 
+        FULLWIDTH_DIGITS = new InputSubset("FULLWIDTH_DIGITS");
 
-    private InputSubset() {
-        super(null);
+    private InputSubset(String name) {
+        super(name);
     }
 }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/AwtImageBackdoorAccessorImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/AwtImageBackdoorAccessorImpl.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/AwtImageBackdoorAccessorImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/AwtImageBackdoorAccessorImpl.java Wed Sep  6 09:06:15 2006
@@ -33,6 +33,7 @@
 import org.apache.harmony.awt.gl.AwtImageBackdoorAccessor;
 import org.apache.harmony.awt.gl.GLVolatileImage;
 import org.apache.harmony.awt.gl.Surface;
+import org.apache.harmony.awt.gl.image.DataBufferListener;
 
 /**
  * This class not part of public API. It useful for receiving package private
@@ -120,6 +121,22 @@
         } else {
             return null;
         }
+    }
+
+    public void addDataBufferListener(DataBuffer db, DataBufferListener listener) {
+        db.addDataBufferListener(listener);
+    }
+
+    public void removeDataBufferListener(DataBuffer db) {
+        db.removeDataBufferListener();
+    }
+
+    public void validate(DataBuffer db) {
+        db.validate();
+    }
+
+    public void releaseData(DataBuffer db) {
+        db.releaseData();
     }
 
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/BufferedImage.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/BufferedImage.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/BufferedImage.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/BufferedImage.java Wed Sep  6 09:06:15 2006
@@ -37,7 +37,7 @@
 
 
 public class BufferedImage extends 
-Image implements WritableRenderedImage, Transparency {
+Image implements WritableRenderedImage, Transparency{
 
     public static final int TYPE_CUSTOM = 0;
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBuffer.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBuffer.java Wed Sep  6 09:06:15 2006
@@ -19,6 +19,8 @@
  */
 package java.awt.image;
 
+import org.apache.harmony.awt.gl.image.DataBufferListener;
+
 public abstract class DataBuffer {
 
     public static final int TYPE_BYTE = 0;
@@ -44,6 +46,10 @@
     protected int size;
 
     protected int offsets[];
+    
+    boolean dataChanged = true;
+    boolean dataTaken = false;
+    DataBufferListener listener;
 
     static {
         AwtImageBackdoorAccessorImpl.init();
@@ -170,5 +176,39 @@
             throw new IllegalArgumentException("Unknown data type " + type);
         }
     }
+    
+    void notifyChanged(){
+        if(listener != null && !dataChanged){
+            dataChanged = true;
+            listener.dataChanged();
+        }
+    }
+    
+    void notifyTaken(){
+        if(listener != null && !dataTaken){
+            dataTaken = true;
+            listener.dataTaken();
+        }
+    }
+    
+    void releaseData(){
+        if(listener != null && dataTaken){
+            dataTaken = false;
+            listener.dataReleased();
+        }
+    }
+    
+    void addDataBufferListener(DataBufferListener listener){
+        this.listener = listener;
+    }
+    
+    void removeDataBufferListener(){
+        listener = null;
+    }
+    
+    void validate(){
+        dataChanged = false;
+    }
+    
 }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferByte.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferByte.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferByte.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferByte.java Wed Sep  6 09:06:15 2006
@@ -62,10 +62,12 @@
 
     public void setElem(int bank, int i, int val) {
         data[bank][offsets[bank] + i] = (byte) val;
+        notifyChanged();
     }
 
     public void setElem(int i, int val) {
         data[0][offset + i] = (byte) val;
+        notifyChanged();
     }
 
     public int getElem(int bank, int i) {
@@ -73,6 +75,7 @@
     }
 
     public byte[] getData(int bank) {
+        notifyTaken();
         return data[bank];
     }
 
@@ -81,10 +84,12 @@
     }
 
     public byte[][] getBankData() {
+        notifyTaken();
         return (byte[][]) data.clone();
     }
 
     public byte[] getData() {
+        notifyTaken();
         return data[0];
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferDouble.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferDouble.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferDouble.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferDouble.java Wed Sep  6 09:06:15 2006
@@ -62,18 +62,22 @@
 
     public void setElem(int bank, int i, int val) {
         data[bank][offsets[bank] + i] = (double) val;
+        notifyChanged();
     }
 
     public void setElemFloat(int bank, int i, float val) {
         data[bank][offsets[bank] + i] = (double) val;
+        notifyChanged();
     }
 
     public void setElemDouble(int bank, int i, double val) {
         data[bank][offsets[bank] + i] = val;
+        notifyChanged();
     }
 
     public void setElem(int i, int val) {
         data[0][offset + i] = (double) val;
+        notifyChanged();
     }
 
     public int getElem(int bank, int i) {
@@ -90,13 +94,16 @@
 
     public void setElemFloat(int i, float val) {
         data[0][offset + i] = (double) val;
+        notifyChanged();
     }
 
     public void setElemDouble(int i, double val) {
         data[0][offset + i] = val;
+        notifyChanged();
     }
 
     public double[] getData(int bank) {
+        notifyTaken();
         return data[bank];
     }
 
@@ -113,10 +120,12 @@
     }
 
     public double[][] getBankData() {
+        notifyTaken();
         return (double[][]) data.clone();
     }
 
     public double[] getData() {
+        notifyTaken();
         return data[0];
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferFloat.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferFloat.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferFloat.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferFloat.java Wed Sep  6 09:06:15 2006
@@ -62,18 +62,22 @@
 
     public void setElem(int bank, int i, int val) {
         data[bank][offsets[bank] + i] = (float) val;
+        notifyChanged();
     }
 
     public void setElemFloat(int bank, int i, float val) {
         data[bank][offsets[bank] + i] = val;
+        notifyChanged();
     }
 
     public void setElemDouble(int bank, int i, double val) {
         data[bank][offsets[bank] + i] = (float) val;
+        notifyChanged();
     }
 
     public void setElem(int i, int val) {
         data[0][offset + i] = (float) val;
+        notifyChanged();
     }
 
     public int getElem(int bank, int i) {
@@ -90,13 +94,16 @@
 
     public void setElemFloat(int i, float val) {
         data[0][offset + i] = val;
+        notifyChanged();
     }
 
     public void setElemDouble(int i, double val) {
         data[0][offset + i] = (float) val;
+        notifyChanged();
     }
 
     public float[] getData(int bank) {
+        notifyTaken();
         return data[bank];
     }
 
@@ -113,10 +120,12 @@
     }
 
     public float[][] getBankData() {
+        notifyTaken();
         return (float[][]) data.clone();
     }
 
     public float[] getData() {
+        notifyTaken();
         return data[0];
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferInt.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferInt.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferInt.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferInt.java Wed Sep  6 09:06:15 2006
@@ -62,10 +62,12 @@
 
     public void setElem(int bank, int i, int val) {
         data[bank][offsets[bank] + i] = val;
+        notifyChanged();
     }
 
     public void setElem(int i, int val) {
         data[0][offset + i] = val;
+        notifyChanged();
     }
 
     public int getElem(int bank, int i) {
@@ -73,6 +75,7 @@
     }
 
     public int[] getData(int bank) {
+        notifyTaken();
         return data[bank];
     }
 
@@ -81,10 +84,12 @@
     }
 
     public int[][] getBankData() {
+        notifyTaken();
         return (int[][]) data.clone();
     }
 
     public int[] getData() {
+        notifyTaken();
         return data[0];
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferShort.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferShort.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferShort.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferShort.java Wed Sep  6 09:06:15 2006
@@ -62,10 +62,12 @@
 
     public void setElem(int bank, int i, int val) {
         data[bank][offsets[bank] + i] = (short) val;
+        notifyChanged();
     }
 
     public void setElem(int i, int val) {
         data[0][offset + i] = (short) val;
+        notifyChanged();
     }
 
     public int getElem(int bank, int i) {
@@ -73,6 +75,7 @@
     }
 
     public short[] getData(int bank) {
+        notifyTaken();
         return data[bank];
     }
 
@@ -81,10 +84,12 @@
     }
 
     public short[][] getBankData() {
+        notifyTaken();
         return (short[][]) data.clone();
     }
 
     public short[] getData() {
+        notifyTaken();
         return data[0];
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferUShort.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferUShort.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferUShort.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/DataBufferUShort.java Wed Sep  6 09:06:15 2006
@@ -63,10 +63,12 @@
 
     public void setElem(int bank, int i, int val) {
         data[bank][offsets[bank] + i] = (short)val;
+        notifyChanged();
     }
 
     public void setElem(int i, int val) {
         data[0][offset + i] = (short)val;
+        notifyChanged();
     }
 
     public int getElem(int bank, int i) {
@@ -74,6 +76,7 @@
     }
 
     public short[] getData(int bank) {
+        notifyTaken();
         return data[bank];
     }
 
@@ -82,10 +85,12 @@
     }
 
     public short[][] getBankData() {
+        notifyTaken();
         return (short[][])data.clone();
     }
 
     public short[] getData() {
+        notifyTaken();
         return data[0];
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ComponentInternals.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ComponentInternals.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ComponentInternals.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ComponentInternals.java Wed Sep  6 09:06:15 2006
@@ -20,6 +20,7 @@
 package org.apache.harmony.awt;
 
 import java.awt.Component;
+import java.awt.Dialog;
 import java.awt.Dimension;
 import java.awt.Image;
 import java.awt.Insets;
@@ -176,4 +177,24 @@
      * heavyweight components overlapping with passed component
      */
     public abstract MultiRectArea getObscuredRegion(Component c);
+    
+    /**
+     * Makes it possible to call protected Toolkit.setDesktopProperty()
+     * method from any class outside of java.awt package
+     */
+    public abstract void setDesktopProperty(String name, Object value);
+    
+    /**
+     * Makes it possible to start/stop dialog modal loop
+     * from anywhere outside of java.awt package
+     */
+    public abstract void runModalLoop(Dialog dlg);
+    public abstract void endModalLoop(Dialog dlg);
+    
+    /**
+     * Sets component's visible flag only
+     * (the component is not actually shown/hidden)
+     */
+    public abstract void setVisibleFlag(Component comp, boolean visible);
+    
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ContextStorage.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ContextStorage.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ContextStorage.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ContextStorage.java Wed Sep  6 09:06:15 2006
@@ -39,7 +39,7 @@
     private GraphicsEnvironment graphicsEnvironment;
 
     private final Object contextLock = new Object();
-    private final Synchronizer synchronizer = createSynchronizer();
+    private final Synchronizer synchronizer = new Synchronizer();
 
     public static void activateMultiContextMode() {
         // TODO: checkPermission
@@ -90,6 +90,10 @@
         getCurrentContext().wtk = wtk;
     }
 
+    public static NativeIM getNativeIM() {
+        return getCurrentContext().wtk.getNativeIM();
+    }
+
     public static NativeEventQueue getNativeEventQueue() {
         return getCurrentContext().wtk.getNativeEventQueue();
     }
@@ -117,26 +121,6 @@
             group = group.getParent();
         }
         throw new RuntimeException("Application has run out of context thread group");
-    }
-
-    static Synchronizer createSynchronizer() {
-        try {
-            return (Synchronizer) Class.forName(getSynchronizerClassName()).newInstance();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    private static String getSynchronizerClassName() {
-        String osName = System.getProperty("os.name").toLowerCase();
-        String packageBase = "org.apache.harmony.awt.wtk", win = "windows", lin = "linux";
-        if (osName.startsWith(lin)) {
-            return packageBase + "." + lin + ".LinuxSynchronizer";
-        }
-        if (osName.startsWith(win)) {
-            return packageBase + "." + win + ".WinSynchronizer";
-        }
-        return null;
     }
 
     public static boolean shutdownPending() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/Theme.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/Theme.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/Theme.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/Theme.java Wed Sep  6 09:06:15 2006
@@ -196,5 +196,9 @@
         DefaultFileDialog dfd = new DefaultFileDialog(fd);
         return dfd.show();
     }
+    
+    public boolean hideFileDialog(FileDialog fd) {
+        return true;
+    }
 
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DTK.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DTK.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DTK.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DTK.java Wed Sep  6 09:06:15 2006
@@ -19,9 +19,16 @@
  */
 package org.apache.harmony.awt.datatransfer;
 
-import java.awt.datatransfer.FlavorMap;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DropTargetContext;
+import java.awt.dnd.peer.DragSourceContextPeer;
+import java.awt.dnd.peer.DropTargetContextPeer;
+import java.nio.charset.Charset;
 
 import org.apache.harmony.awt.ContextStorage;
+import org.apache.harmony.misc.SystemUtils;
 
 /**
  * Data transfer ToolKit.
@@ -29,24 +36,21 @@
  */
 public abstract class DTK {
 
-    private static final String osName = System.getProperty("os.name").toLowerCase();
-
-    /**
-     * Descriptor of text representation in native platform (common for all application contexts).
-     */
-    public static final NativeTextDescriptor textDescriptor =
-            getContextInstance().newTextDescriptor();
-
-    private NativeTranslationManager translationManager = null;
     private NativeClipboard nativeClipboard = null;
     private NativeClipboard nativeSelection = null;
 
-    private FlavorMap flavorMap = null;
+    protected SystemFlavorMap systemFlavorMap;
 
+    protected final DataTransferThread dataTransferThread;
+
+    protected DTK() {
+        dataTransferThread = new DataTransferThread(this);
+        dataTransferThread.start();
+    }
     /**
      * Returns data transfer toolkit for current application context.
      */
-    public static DTK getContextInstance() {
+    public static DTK getDTK() {
         synchronized(ContextStorage.getContextLock()) {
             if (ContextStorage.shutdownPending()) {
                 return null;
@@ -55,22 +59,7 @@
             DTK instance = ContextStorage.getDTK();
 
             if (instance == null) {
-                String name;
-
-                if (osName.startsWith("linux")) {
-                    name = "org.apache.harmony.awt.datatransfer.linux.LinuxDTK";
-                } else if (osName.startsWith("windows")) {
-                    name = "org.apache.harmony.awt.datatransfer.windows.WinDTK";
-                } else {
-                    throw new RuntimeException("Unknown native platform.");
-                }
-
-                try {
-                    instance = (DTK) Class.forName(name).newInstance();
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
-
+                instance = createDTK();
                 ContextStorage.setDTK(instance);
             }
 
@@ -82,27 +71,16 @@
      * Returns system flavor map for current application context.
      * For use from SystemFlavorMap.getDefaultFlavorMap() only
      */
-    public FlavorMap getFlavorMap() {
-        return flavorMap;
+    public synchronized SystemFlavorMap getSystemFlavorMap() {
+        return systemFlavorMap;
     }
 
     /**
      * Sets system flavor map for current application context.
      * For use from SystemFlavorMap.getDefaultFlavorMap() only.
      */
-    public void setFlavorMap(FlavorMap flavorMap) {
-        this.flavorMap = flavorMap;
-    }
-
-    /**
-     * Returns clipboard translation manager for current application context.
-     */
-    public NativeTranslationManager getTranslationManager() {
-        if (translationManager == null) {
-            translationManager = newTranslationManager();
-        }
-
-        return translationManager;
+    public synchronized void setSystemFlavorMap(SystemFlavorMap newFlavorMap) {
+        this.systemFlavorMap = newFlavorMap;
     }
 
     /**
@@ -136,15 +114,92 @@
      * Creates native selection for current native platform.
      */
     protected abstract NativeClipboard newNativeSelection();
-
-    /**
-     * Creates text descriptor for current native platform.
-     */
-    protected abstract NativeTextDescriptor newTextDescriptor();
-
-    /**
-     * Creates translation manager for current native platform.
-     */
-    protected abstract NativeTranslationManager newTranslationManager();
-
+    
+    public abstract void initDragAndDrop();
+    
+    public abstract void runEventLoop();
+
+    public abstract DropTargetContextPeer createDropTargetContextPeer(
+            DropTargetContext context);
+
+    public abstract DragSourceContextPeer createDragSourceContextPeer(
+            DragGestureEvent dge);
+    
+    private static DTK createDTK() {
+        String name;
+        switch (SystemUtils.getOS()) {
+        case SystemUtils.OS_WINDOWS:
+            name = "org.apache.harmony.awt.datatransfer.windows.WinDTK";
+            break;
+        case SystemUtils.OS_LINUX:
+            name = "org.apache.harmony.awt.datatransfer.linux.LinuxDTK";
+            break;
+        default:
+            throw new RuntimeException("Unknown native platform.");
+        }
+        try {
+            DTK dtk = (DTK) Class.forName(name).newInstance();
+            return dtk;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    public String getDefaultCharset() {
+        return "unicode";
+    }
+
+    protected String[] getCharsets() {
+        return new String[] { 
+                "UTF-16", "UTF-8", "unicode", "ISO-8859-1", "US-ASCII" };
+    }
+
+    public void initSystemFlavorMap(SystemFlavorMap fm) {
+        String[] charsets = getCharsets();
+        
+        appendSystemFlavorMap(fm,
+                DataFlavor.stringFlavor, 
+                DataProvider.FORMAT_TEXT);
+        appendSystemFlavorMap(fm,
+                charsets, "plain",
+                DataProvider.FORMAT_TEXT);
+
+        appendSystemFlavorMap(fm,
+                charsets, "html",
+                DataProvider.FORMAT_HTML);
+        
+        appendSystemFlavorMap(fm,
+                DataProvider.urlFlavor, 
+                DataProvider.FORMAT_URL);
+        appendSystemFlavorMap(fm,
+                charsets, "uri-list",
+                DataProvider.FORMAT_URL);
+        
+        appendSystemFlavorMap(fm,
+                DataFlavor.javaFileListFlavor, 
+                DataProvider.FORMAT_FILE_LIST);
+
+        appendSystemFlavorMap(fm,
+                DataFlavor.imageFlavor, 
+                DataProvider.FORMAT_IMAGE);
+    }
+
+    protected void appendSystemFlavorMap(SystemFlavorMap fm, 
+                                         DataFlavor flav,
+                                         String nat) {
+        fm.addFlavorForUnencodedNative(nat, flav);
+        fm.addUnencodedNativeForFlavor(flav, nat);
+    }
+
+    protected void appendSystemFlavorMap(SystemFlavorMap fm,
+                                         String[] charsets,
+                                         String subType,
+                                         String nat) {
+        TextFlavor.addUnicodeClasses(fm, nat, subType);
+        for (int i = 0; i < charsets.length; i++) {
+            if (charsets[i] != null && Charset.isSupported(charsets[i])) {
+                TextFlavor.addCharsetClasses(fm, nat, subType, charsets[i]);
+            }
+        }
+    }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataProvider.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataProvider.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataProvider.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataProvider.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,75 @@
+/*
+ *  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 org.apache.harmony.awt.datatransfer;
+
+import java.awt.datatransfer.DataFlavor;
+
+
+/**
+ * Unified representation of transferable data,
+ * either obtained from or prepared for native clipboard and/or drag&drop
+ */
+public interface DataProvider {
+    /**
+     * More information about MIME types and Drag&Drop can be found at  
+     * http://java.sun.com/j2se/1.5.0/docs/api/java/awt/datatransfer/DataFlavor.html
+     * http://java.sun.com/j2se/1.5.0/docs/guide/dragndrop/spec/dnd1.html
+     */
+    
+    public static final String FORMAT_TEXT = "text/plain";
+    public static final String FORMAT_FILE_LIST = "application/x-java-file-list";
+    public static final String FORMAT_URL = "application/x-java-url";
+    public static final String FORMAT_HTML = "text/html";
+    public static final String FORMAT_IMAGE = "image/x-java-image";
+
+    public static final String TYPE_IMAGE = "image/x-java-image";
+    public static final String TYPE_SERIALIZED = 
+                                    "application/x-java-serialized-object";
+    public static final String TYPE_PLAINTEXT = "text/plain";
+    public static final String TYPE_HTML = "text/html";
+    public static final String TYPE_URL = "application/x-java-url";
+    public static final String TYPE_TEXTENCODING = 
+                                    "application/x-java-text-encoding";
+    public static final String TYPE_FILELIST = "application/x-java-file-list";
+    public static final String TYPE_URILIST = "text/uri-list";
+
+    public static final DataFlavor urlFlavor = 
+        new DataFlavor("application/x-java-url;class=java.net.URL", "URL");
+    
+    public static final DataFlavor uriFlavor = 
+        new DataFlavor("text/uri-list", "URI");
+
+    
+    public String[] getNativeFormats();
+    
+    public boolean isNativeFormatAtailable(String nativeFormat);
+    
+    public String getText();
+    
+    public String[] getFileList();
+    
+    public String getURL();
+
+    public String getHTML();
+    
+    public RawBitmap getRawBitmap();
+    
+    public byte[] getSerializedObject(Class clazz);
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataProxy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataProxy.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataProxy.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataProxy.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,320 @@
+/*
+ *  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 org.apache.harmony.awt.datatransfer;
+
+import java.awt.Image;
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferByte;
+import java.awt.image.DataBufferInt;
+import java.awt.image.DataBufferUShort;
+import java.awt.image.DirectColorModel;
+import java.awt.image.Raster;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Wrapper for native data
+ */
+public final class DataProxy implements Transferable {
+    
+    public static final Class[] unicodeTextClasses = 
+            { String.class, Reader.class, CharBuffer.class, char[].class }; 
+    public static final Class[] charsetTextClasses = 
+              { byte[].class, ByteBuffer.class, InputStream.class };
+    
+    private final DataProvider data;
+    private final SystemFlavorMap flavorMap;
+    
+    public DataProxy(DataProvider data) {
+        this.data = data;
+        this.flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+    }
+    
+    public DataProvider getDataProvider() {
+        return data;
+    }
+    
+    public Object getTransferData(DataFlavor flavor)
+            throws UnsupportedFlavorException, IOException {
+        
+        String mimeType = flavor.getPrimaryType() + "/" + flavor.getSubType();
+        if (flavor.isFlavorTextType()) {
+            if (mimeType.equalsIgnoreCase(DataProvider.TYPE_HTML)) {
+                return getHTML(flavor);
+            }
+            if (mimeType.equalsIgnoreCase(DataProvider.TYPE_URILIST)) {
+                return getURL(flavor);
+            }
+            return getPlainText(flavor);
+        }
+        if (flavor.isFlavorJavaFileListType()) {
+            return getFileList(flavor);
+        }
+        if (flavor.isFlavorSerializedObjectType()) {
+            return getSerializedObject(flavor);
+        }
+        if (flavor.equals(DataProvider.urlFlavor)) {
+            return getURL(flavor);
+        }
+        if (mimeType.equalsIgnoreCase(DataProvider.TYPE_IMAGE) && 
+                Image.class.isAssignableFrom(flavor.getRepresentationClass())) {
+            return getImage(flavor);
+        }
+        
+        throw new UnsupportedFlavorException(flavor);
+    }
+
+    public DataFlavor[] getTransferDataFlavors() {
+        ArrayList result = new ArrayList();
+        String[] natives = data.getNativeFormats();
+        
+        for (int i = 0; i < natives.length; i++) {
+            List flavors = flavorMap.getFlavorsForNative(natives[i]);
+            for (Iterator it = flavors.iterator(); it.hasNext(); ) {
+                DataFlavor f = (DataFlavor)it.next();
+                if (!result.contains(f)) {
+                    result.add(f);
+                }
+            }
+        }
+        return (DataFlavor[])result.toArray(new DataFlavor[0]);
+    }
+    
+    public boolean isDataFlavorSupported(DataFlavor flavor) {
+        DataFlavor[] flavors = getTransferDataFlavors();
+        for (int i=0; i<flavors.length; i++) {
+            if (flavors[i].equals(flavor)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    private Object getPlainText(DataFlavor f)
+            throws IOException, UnsupportedFlavorException {
+        if (!data.isNativeFormatAtailable(DataProvider.FORMAT_TEXT)) {
+            throw new UnsupportedFlavorException(f);
+        }
+        String str = data.getText();
+        if (str == null) {
+            throw new IOException("Data is not available");
+        }
+        return getTextRepresentation(str, f);
+    }
+
+    private Object getFileList(DataFlavor f) 
+            throws IOException, UnsupportedFlavorException {
+        if (!data.isNativeFormatAtailable(DataProvider.FORMAT_FILE_LIST)) {
+            throw new UnsupportedFlavorException(f);
+        }
+        String[] files = data.getFileList();
+        if (files == null) {
+            throw new IOException("Data is not available");
+        }
+        return Arrays.asList(files);
+    }
+
+    private Object getHTML(DataFlavor f)
+            throws IOException, UnsupportedFlavorException {
+        if (!data.isNativeFormatAtailable(DataProvider.FORMAT_HTML)) {
+            throw new UnsupportedFlavorException(f);
+        }
+        String str = data.getHTML();
+        if (str == null) {
+            throw new IOException("Data is not available");
+        }
+        return getTextRepresentation(str, f);
+    }
+
+    private Object getURL(DataFlavor f)
+            throws IOException, UnsupportedFlavorException {
+        if (!data.isNativeFormatAtailable(DataProvider.FORMAT_URL)) {
+            throw new UnsupportedFlavorException(f);
+        }
+        String str = data.getURL();
+        if (str == null) {
+            throw new IOException("Data is not available");
+        }
+        URL url = new URL(str);
+        if (f.getRepresentationClass().isAssignableFrom(URL.class)) {
+            return url;
+        }
+        if (f.isFlavorTextType()) {
+            return getTextRepresentation(url.toString(), f);
+        }
+        throw new UnsupportedFlavorException(f);
+    }
+    
+    private Object getSerializedObject(DataFlavor f)
+            throws IOException, UnsupportedFlavorException {
+        String nativeFormat = SystemFlavorMap.encodeDataFlavor(f);
+        if ((nativeFormat == null) || 
+                !data.isNativeFormatAtailable(nativeFormat)) {
+            throw new UnsupportedFlavorException(f);
+        }
+        byte bytes[] = data.getSerializedObject(f.getRepresentationClass());
+        if (bytes == null) {
+            throw new IOException("Data is not available");
+        }
+        ByteArrayInputStream str = new ByteArrayInputStream(bytes);
+        try {
+            return new ObjectInputStream(str).readObject();
+        } catch (ClassNotFoundException ex) {
+            throw new IOException(ex.getMessage());
+        }
+    }
+    
+    private String getCharset(DataFlavor f) {
+        return f.getParameter("charset");
+    }
+
+    private Object getTextRepresentation(String text, DataFlavor f)
+            throws UnsupportedFlavorException, IOException {
+        if (f.getRepresentationClass() == String.class) {
+            return text;
+        }
+        if (f.isRepresentationClassReader()) {
+            return new StringReader(text);
+        }
+        if (f.isRepresentationClassCharBuffer()) {
+            return CharBuffer.wrap(text);
+        }
+        if (f.getRepresentationClass() == char[].class) {
+            char[] chars = new char[text.length()];
+            text.getChars(0, text.length(), chars, 0);
+            return chars;
+        }
+        String charset = getCharset(f);
+        if (f.getRepresentationClass() == byte[].class) {
+            byte[] bytes = text.getBytes(charset);
+            return bytes;
+        }
+        if (f.isRepresentationClassByteBuffer()) {
+            byte[] bytes = text.getBytes(charset);
+            return ByteBuffer.wrap(bytes);
+        }
+        if (f.isRepresentationClassInputStream()) {
+            byte[] bytes = text.getBytes(charset);
+            return new ByteArrayInputStream(bytes);
+        }
+        throw new UnsupportedFlavorException(f);
+    }
+
+    private Image getImage(DataFlavor f) 
+            throws IOException, UnsupportedFlavorException {
+        if (!data.isNativeFormatAtailable(DataProvider.FORMAT_IMAGE)) {
+            throw new UnsupportedFlavorException(f);
+        }
+        RawBitmap bitmap = data.getRawBitmap();
+        if (bitmap == null) {
+            throw new IOException("Data is not available");
+        }
+        return createBufferedImage(bitmap);
+    }
+    
+    private boolean isRGB(RawBitmap b) {
+        return b.rMask == 0xFF0000 && b.gMask == 0xFF00 && b.bMask == 0xFF;
+    }
+    
+    private boolean isBGR(RawBitmap b) {
+        return b.rMask == 0xFF && b.gMask == 0xFF00 && b.bMask == 0xFF0000;
+    }
+    
+    private BufferedImage createBufferedImage(RawBitmap b) {
+        if (b == null || b.buffer == null
+                || b.width <= 0 || b.height <= 0) {
+            return null;
+        }
+        
+        ColorModel cm = null;
+        WritableRaster wr = null;
+
+        if (b.bits == 32 && b.buffer instanceof int[]) {
+            if (!isRGB(b) && !isBGR(b)) {
+                return null;
+            }
+            int masks[] = { b.rMask, b.gMask, b.bMask };
+            int buffer[] = (int [])b.buffer;
+            cm = new DirectColorModel(24, b.rMask, b.gMask, b.bMask);
+            wr = Raster.createPackedRaster(
+                    new DataBufferInt(buffer, buffer.length), 
+                    b.width, b.height, b.stride,
+                    masks, null);
+
+        } else  if (b.bits == 24 && b.buffer instanceof byte[]) {
+            int bits[] = { 8, 8, 8 };
+            int offsets[];
+            if (isRGB(b)) {
+                offsets = new int[] { 0, 1, 2 };
+            } else if (isBGR(b)) {
+                offsets = new int[] { 2, 1, 0 };
+            } else {
+                return null;
+            }
+            byte buffer[] = (byte [])b.buffer;
+            cm = new ComponentColorModel(
+                    ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                    bits, false, false, 
+                    Transparency.OPAQUE, 
+                    DataBuffer.TYPE_BYTE);
+
+            wr = Raster.createInterleavedRaster(
+                    new DataBufferByte(buffer, buffer.length),
+                    b.width, b.height, b.stride, 3, offsets, null);
+
+        } else if ((b.bits == 16 || b.bits == 15)
+                && b.buffer instanceof short[]) {
+            int masks[] = { b.rMask, b.gMask, b.bMask };
+            short buffer[] = (short [])b.buffer;
+            cm = new DirectColorModel(b.bits, b.rMask, b.gMask, b.bMask);
+            wr = Raster.createPackedRaster(
+                    new DataBufferUShort(buffer, buffer.length), 
+                    b.width, b.height, b.stride,
+                    masks, null);
+        }
+        
+        if (cm == null || wr == null) {
+            return null;
+        }
+        return new BufferedImage(cm, wr, false, null);
+    }
+}
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataSnapshot.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataSnapshot.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataSnapshot.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataSnapshot.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,155 @@
+/*
+ *  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 org.apache.harmony.awt.datatransfer;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Immutable copy of transferable data, 
+ * safe for use across the threads
+ */
+public class DataSnapshot implements DataProvider {
+    
+    private final String text;
+    private final String[] fileList;
+    private final String url;
+    private final String html;
+    private final RawBitmap rawBitmap;
+    
+    private final String[] nativeFormats;
+    /** Class -> byte[] */
+    private final Map serializedObjects;
+    
+    /**
+     * @param dataObject
+     */
+    public DataSnapshot(DataProvider data) {
+        nativeFormats = data.getNativeFormats();
+        text = data.getText();
+        fileList = data.getFileList();
+        url = data.getURL();
+        html = data.getHTML();
+        rawBitmap = data.getRawBitmap();
+        
+        serializedObjects = Collections.synchronizedMap(new HashMap());
+        
+        for (int i = 0; i < nativeFormats.length; i++) {
+            DataFlavor df = null;
+            try {
+                df = SystemFlavorMap.decodeDataFlavor(nativeFormats[i]);
+            } catch (ClassNotFoundException e) {}
+            if (df != null) {
+                Class clazz = df.getRepresentationClass();
+                byte[] bytes = data.getSerializedObject(clazz);
+                if (bytes != null) {
+                    serializedObjects.put(clazz, bytes);
+                }
+            }
+        }
+        // TODO: refine the list of native formats
+    }
+
+    public boolean isNativeFormatAtailable(String nativeFormat) {
+        if (nativeFormat == null) {
+            return false;
+        }
+        if (nativeFormat.equals(FORMAT_TEXT)) {
+            return (text != null);
+        }
+        if (nativeFormat.equals(FORMAT_FILE_LIST)) {
+            return (fileList != null);
+        }
+        if (nativeFormat.equals(FORMAT_URL)) {
+            return (url != null);
+        }
+        if (nativeFormat.equals(FORMAT_HTML)) {
+            return (html != null);
+        }
+        if (nativeFormat.equals(FORMAT_IMAGE)) {
+            return (rawBitmap != null);
+        }
+        try {
+            DataFlavor df = SystemFlavorMap.decodeDataFlavor(nativeFormat);
+            return serializedObjects.containsKey(df.getRepresentationClass());
+        } catch (Exception e) {
+            return false;
+        }
+    }
+    
+    public String getText() {
+        return text;
+    }
+    
+    public String[] getFileList() {
+        return fileList;
+    }
+    
+    public String getURL() {
+        return url;
+    }
+    
+    public String getHTML() {
+        return html;
+    }
+    
+    public RawBitmap getRawBitmap() {
+        return rawBitmap;
+    }
+    
+    public int[] getRawBitmapHeader() {
+        return (rawBitmap != null) ? rawBitmap.getHeader() : null;
+    }
+    
+    public byte[] getRawBitmapBuffer8() {
+        return (rawBitmap != null) && (rawBitmap.buffer instanceof byte[]) ?
+                (byte[])rawBitmap.buffer : null;
+    }
+    
+    public short[] getRawBitmapBuffer16() {
+        return (rawBitmap != null) && (rawBitmap.buffer instanceof short[]) ?
+                (short[])rawBitmap.buffer : null;
+    }
+    
+    public int[] getRawBitmapBuffer32() {
+        return (rawBitmap != null) && (rawBitmap.buffer instanceof int[]) ?
+                (int[])rawBitmap.buffer : null;
+    }
+    
+    public byte[] getSerializedObject(Class clazz) {
+        return (byte[])serializedObjects.get(clazz);
+    }
+
+    public byte[] getSerializedObject(String nativeFormat) {
+        try {
+            DataFlavor df = SystemFlavorMap.decodeDataFlavor(nativeFormat);
+            return getSerializedObject(df.getRepresentationClass());
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public String[] getNativeFormats() {
+        return nativeFormats;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataSource.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataSource.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataSource.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataSource.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,235 @@
+/*
+ *  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 org.apache.harmony.awt.datatransfer;
+
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.awt.datatransfer.Transferable;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferInt;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Reader;
+import java.io.Serializable;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Convertor from {@link java.awt.datatransfer.Transferable} to 
+ * {@link org.apache.harmony.awt.datatransfer.DataProvider}
+ */
+public class DataSource implements DataProvider {
+
+    // Cached data from transferable object
+    private DataFlavor[] flavors;
+    private List nativeFormats;
+    
+    protected final Transferable contents;
+    
+    public DataSource(Transferable contents) {
+        this.contents = contents;
+    }
+
+    private boolean isHtmlFlavor(DataFlavor f) {
+        return "html".equalsIgnoreCase(f.getSubType());
+    }
+    
+    protected DataFlavor[] getDataFlavors() {
+        if (flavors == null) {
+            flavors = contents.getTransferDataFlavors();
+        }
+        return flavors;
+    }
+    
+    public String[] getNativeFormats() {
+        return (String[])getNativeFormatsList().toArray(new String[0]);
+    }
+    
+    public List getNativeFormatsList() {
+        if (nativeFormats == null) {
+            DataFlavor[] flavors = getDataFlavors();
+            nativeFormats = getNativesForFlavors(flavors);
+        }
+
+        return nativeFormats;
+    }
+    
+    private static List getNativesForFlavors(DataFlavor[] flavors) {
+        ArrayList natives = new ArrayList();
+        
+        SystemFlavorMap flavorMap = 
+            (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+        
+        for (int i = 0; i < flavors.length; i++) {
+            List list = flavorMap.getNativesForFlavor(flavors[i]);
+            for (Iterator it = list.iterator(); it.hasNext(); ) {
+                String nativeFormat = (String)it.next();
+                if (!natives.contains(nativeFormat)) {
+                    natives.add(nativeFormat);
+                }
+            }
+        }
+        return natives;
+    }
+    
+    private String getTextFromReader(Reader r) throws IOException {
+        // TODO: use StringBuilder here
+        StringBuffer buffer = new StringBuffer();
+        char chunk[] = new char[1024];
+        int len;
+        while ((len = r.read(chunk)) > 0) {
+            buffer.append(chunk, 0, len);
+        }
+        return buffer.toString();
+    }
+    
+    private String getText(boolean htmlOnly) {
+        DataFlavor[] flavors = contents.getTransferDataFlavors();
+        for (int i = 0; i < flavors.length; i++) {
+            DataFlavor f = flavors[i];
+            if (!f.isFlavorTextType()) {
+                continue;
+            }
+            if (htmlOnly && !isHtmlFlavor(f)) {
+                continue;
+            }
+            try {
+                if (String.class.isAssignableFrom(
+                        f.getRepresentationClass())) {
+                    return (String)contents.getTransferData(f);
+                }
+                Reader r = f.getReaderForText(contents);
+                return getTextFromReader(r);
+            } catch (Exception e) {}
+        }
+        return null;
+    }
+
+    public String getText() {
+        return getText(false);
+    }
+
+    public String[] getFileList() {
+        try {
+            List list = (List)contents.getTransferData(
+                    DataFlavor.javaFileListFlavor);
+            return (String[])list.toArray(new String[0]);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public String getURL() {
+        try {
+            URL url = (URL)contents.getTransferData(urlFlavor);
+            return url.toString();
+        } catch (Exception e) {}
+        try {
+            URL url = (URL)contents.getTransferData(uriFlavor);
+            return url.toString();
+        } catch (Exception e) {}
+        try {
+            URL url = new URL(getText());
+            return url.toString();
+        } catch (Exception e) {}
+        return null;
+    }
+
+    public String getHTML() {
+        return getText(true);
+    }
+    
+    public RawBitmap getRawBitmap() {
+        DataFlavor[] flavors = contents.getTransferDataFlavors();
+
+        for (int i = 0; i < flavors.length; i++) {
+            DataFlavor f = flavors[i];
+            Class c = f.getRepresentationClass();
+            if (c != null && Image.class.isAssignableFrom(c) && 
+                    (f.isMimeTypeEqual(DataFlavor.imageFlavor) || 
+                            f.isFlavorSerializedObjectType())) {
+                try {
+                    Image im = (Image)contents.getTransferData(f);
+                    return getImageBitmap(im);
+                } catch (Throwable ex) {
+                    continue;
+                }
+            }
+        }
+        return null;
+    }
+    
+    private RawBitmap getImageBitmap(Image im) {
+        if (im instanceof BufferedImage) {
+            BufferedImage bi = (BufferedImage)im;
+            if (bi.getType() == BufferedImage.TYPE_INT_RGB) {
+                return getImageBitmap32(bi);
+            }
+        }
+        int width = im.getWidth(null);
+        int height = im.getHeight(null);
+        if (width <= 0 || height <= 0) {
+            return null;
+        }
+        BufferedImage bi = 
+            new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+        Graphics gr = bi.getGraphics();
+        gr.drawImage(im, 0, 0, null);
+        gr.dispose();
+        return getImageBitmap32(bi);
+    }
+
+    private RawBitmap getImageBitmap32(BufferedImage bi) {
+        int buffer[] = new int[bi.getWidth() * bi.getHeight()];
+        DataBufferInt data = (DataBufferInt)bi.getRaster().getDataBuffer();
+        int bufferPos = 0;
+        int bankCount = data.getNumBanks();
+        int offsets[] = data.getOffsets();
+        for (int i = 0; i < bankCount; i++) {
+            int[] fragment = data.getData(i);
+            System.arraycopy(fragment, offsets[i], buffer, bufferPos, 
+                    fragment.length - offsets[i]);
+            bufferPos += fragment.length - offsets[i];
+        }
+        return new RawBitmap(bi.getWidth(), bi.getHeight(), bi.getWidth(), 
+                32, 0xFF0000, 0xFF00, 0xFF, buffer);
+    }
+
+    public byte[] getSerializedObject(Class clazz) {
+        try {
+            DataFlavor f = new DataFlavor(clazz, null);
+            Serializable s = (Serializable)contents.getTransferData(f);
+            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+            new ObjectOutputStream(bytes).writeObject(s);
+            return bytes.toByteArray();
+        } catch (Throwable e) {
+            return null;
+        }
+    }
+
+    public boolean isNativeFormatAtailable(String nativeFormat) {
+        return getNativeFormatsList().contains(nativeFormat);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataTransferThread.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataTransferThread.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataTransferThread.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DataTransferThread.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,56 @@
+/*
+ *  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 org.apache.harmony.awt.datatransfer;
+
+/**
+ * Thread for handling data transfer native events
+ */
+public class DataTransferThread extends Thread {
+    
+    private final DTK dtk;
+
+    public DataTransferThread(DTK dtk) {
+        super("AWT-DataTransferThread");
+        setDaemon(true);
+        this.dtk = dtk;
+    }
+    
+    public void run() {
+        synchronized (this) {
+            try {
+                dtk.initDragAndDrop();
+            } finally {
+                notifyAll();
+            }
+        }
+        dtk.runEventLoop();
+    }
+    
+    public void start() {
+        synchronized (this) {
+            super.start();
+            try {
+                wait();
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}



Mime
View raw message