This implements the missing updateCurrentCursor() method in
DragSourceContext. I couldn't think of an easy Mauve test for this. So I
implemented this like it seemed most reasonable.

2006-10-30  Roman Kennke  <[EMAIL PROTECTED]>

        * java/awt/dnd/DragSourceContext.java
        (dragExit): Use constant fields instead of 0.
        (updateCurrentCursor): Completed implementation.

/Roman
Index: java/awt/dnd/DragSourceContext.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DragSourceContext.java,v
retrieving revision 1.10
diff -u -1 -5 -r1.10 DragSourceContext.java
--- java/awt/dnd/DragSourceContext.java	4 Jul 2006 20:23:14 -0000	1.10
+++ java/awt/dnd/DragSourceContext.java	30 Oct 2006 15:43:31 -0000
@@ -26,32 +26,30 @@
 As a special exception, the copyright holders of this library give you
 permission to link this library with independent modules to produce an
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 
 package java.awt.dnd;
 
-import gnu.classpath.NotImplementedException;
-
 import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Image;
 import java.awt.Point;
 import java.awt.datatransfer.Transferable;
 import java.awt.dnd.peer.DragSourceContextPeer;
 import java.io.Serializable;
 import java.util.TooManyListenersException;
 
 /**
  * @since 1.2
  */
 public class DragSourceContext
   implements DragSourceListener, DragSourceMotionListener, Serializable
 {
@@ -256,31 +254,32 @@
    * Calls dragExit on the listeners registered with this
    * and with the DragSource.
    * 
    * @param e - the DragSourceEvent
    */
   public void dragExit(DragSourceEvent e)
   {
     if (dragSourceListener != null)
       dragSourceListener.dragExit(e);
     
     DragSource ds = getDragSource();
     DragSourceListener[] dsl = ds.getDragSourceListeners();
     for (int i = 0; i < dsl.length; i++)
       dsl[i].dragExit(e);
     
-    updateCurrentCursor(0, 0, DEFAULT);
+    updateCurrentCursor(DnDConstants.ACTION_NONE, DnDConstants.ACTION_NONE,
+                        DEFAULT);
   }
 
   /**
    * Calls dropActionChanged on the listeners registered with this
    * and with the DragSource.
    * 
    * @param e - the DragSourceDragEvent
    */
   public void dropActionChanged(DragSourceDragEvent e)
   {
     if (dragSourceListener != null)
       dragSourceListener.dropActionChanged(e);
     
     DragSource ds = getDragSource();
     DragSourceListener[] dsl = ds.getDragSourceListeners();
@@ -328,38 +327,57 @@
   public Transferable getTransferable()
   {
     return transferable;
   }
 
   /**
    * This function sets the drag cursor for the specified operation, actions and
    * status if the default drag cursor is active. Otherwise, the cursor is not
    * updated in any way.
    * 
    * @param dropOp - the current operation.
    * @param targetAct - the supported actions.
    * @param status - the status of the cursor (constant).
    */
   protected void updateCurrentCursor(int dropOp, int targetAct, int status)
-    throws NotImplementedException
   {
-    // FIXME: Not implemented fully
-    if (!useCustomCursor)
+    if (! useCustomCursor)
       {
-        Cursor cursor = null;
+        Cursor newCursor = null;
         switch (status)
           {
+          default:
+            targetAct = DnDConstants.ACTION_NONE;
           case ENTER:
-            break;
           case CHANGED:
-            break;
           case OVER:
-            break;
-          default:
-            break;
+            int action = dropOp & targetAct;
+            if (action == DnDConstants.ACTION_NONE)
+              {
+                if ((dropOp & DnDConstants.ACTION_LINK) != 0)
+                  newCursor = DragSource.DefaultLinkNoDrop;
+                else if ((dropOp & DnDConstants.ACTION_MOVE) != 0)
+                  newCursor = DragSource.DefaultMoveNoDrop;
+                else
+                  newCursor = DragSource.DefaultCopyNoDrop;
+              }
+            else
+              {
+                if ((dropOp & DnDConstants.ACTION_LINK) != 0)
+                  newCursor = DragSource.DefaultLinkDrop;
+                else if ((dropOp & DnDConstants.ACTION_MOVE) != 0)
+                  newCursor = DragSource.DefaultMoveDrop;
+                else
+                  newCursor = DragSource.DefaultCopyDrop;
+              }
           }
         
-        this.cursor = cursor;
-        peer.setCursor(cursor);
+        if (cursor == null || ! cursor.equals(newCursor))
+          {
+            cursor = newCursor;
+            DragSourceContextPeer p = peer;
+            if (p != null)
+              p.setCursor(cursor);
+          }
       }
   }
 } // class DragSourceContext

Reply via email to