summaryrefslogtreecommitdiff
path: root/libjava/classpath/java/awt/dnd/DragSourceContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/awt/dnd/DragSourceContext.java')
-rw-r--r--libjava/classpath/java/awt/dnd/DragSourceContext.java191
1 files changed, 172 insertions, 19 deletions
diff --git a/libjava/classpath/java/awt/dnd/DragSourceContext.java b/libjava/classpath/java/awt/dnd/DragSourceContext.java
index 88607b090ea..1fee5c0c304 100644
--- a/libjava/classpath/java/awt/dnd/DragSourceContext.java
+++ b/libjava/classpath/java/awt/dnd/DragSourceContext.java
@@ -70,8 +70,8 @@ public class DragSourceContext
private Transferable transferable;
private DragGestureEvent trigger;
private DragSourceListener dragSourceListener;
- private boolean useCustomCursor; // FIXME: currently unused but needed for serialization.
- private int sourceActions; // FIXME: currently unused but needed for serialization.
+ private boolean useCustomCursor;
+ private int sourceActions;
private Image image;
private Point offset;
@@ -82,16 +82,17 @@ public class DragSourceContext
* are null, the drag action for the trigger event is DnDConstants.ACTION_NONE
* or if the source actions for the DragGestureRecognizer associated with the
* trigger event are equal to DnDConstants.ACTION_NONE.
- * @exception NullPointerException If peer or trigger is null.
+ * @exception NullPointerException If peer, trans or trigger is null or if the
+ * image is not null but the offset is.
*/
public DragSourceContext (DragSourceContextPeer peer,
DragGestureEvent trigger, Cursor cursor,
Image image, Point offset, Transferable trans,
DragSourceListener dsl)
- throws NotImplementedException
- {
+ {
if (peer == null
- || trigger == null)
+ || trigger == null || trans == null
+ || (image != null && offset == null))
throw new NullPointerException ();
if (trigger.getComponent () == null
@@ -108,37 +109,77 @@ public class DragSourceContext
this.offset = offset;
this.transferable = trans;
this.dragSourceListener = dsl;
+ this.sourceActions = trigger.getSourceAsDragGestureRecognizer().getSourceActions();
- throw new Error ("not implemented");
+ setCursor(cursor);
+ updateCurrentCursor(trigger.getDragAction(), sourceActions, DEFAULT);
}
+ /**
+ * Returns the DragSource object associated with the
+ * DragGestureEvent.
+ *
+ * @return the DragSource associated with the trigger.
+ */
public DragSource getDragSource()
{
return trigger.getDragSource ();
}
+ /**
+ * Returns the component associated with this.
+ *
+ * @return the component associated with the trigger.
+ */
public Component getComponent()
{
return trigger.getComponent ();
}
+ /**
+ * Gets the trigger associated with this.
+ *
+ * @return the trigger.
+ */
public DragGestureEvent getTrigger()
{
return trigger;
}
+ /**
+ * Returns the source actions for the DragGestureRecognizer.
+ *
+ * @return the source actions for DragGestureRecognizer.
+ */
public int getSourceActions()
{
- return trigger.getSourceAsDragGestureRecognizer ().getSourceActions ();
+ if (sourceActions == 0)
+ sourceActions = trigger.getSourceAsDragGestureRecognizer().getSourceActions();
+ return sourceActions;
}
- public void setCursor (Cursor cursor)
- throws NotImplementedException
+ /**
+ * Sets the cursor for this drag operation to the specified cursor.
+ *
+ * @param cursor c - the Cursor to use, or null to use the default drag
+ * cursor.
+ */
+ public void setCursor(Cursor cursor)
{
+ if (cursor == null)
+ useCustomCursor = false;
+ else
+ useCustomCursor = true;
this.cursor = cursor;
- // FIXME: Check if we need to do more here
+ peer.setCursor(cursor);
}
+ /**
+ * Returns the current cursor or null if the default
+ * drag cursor is used.
+ *
+ * @return the current cursor or null.
+ */
public Cursor getCursor()
{
return cursor;
@@ -165,48 +206,160 @@ public class DragSourceContext
dragSourceListener = null;
}
+ /**
+ * This function tells the peer that the DataFlavors have been modified.
+ */
public void transferablesFlavorsChanged()
- throws NotImplementedException
{
+ peer.transferablesFlavorsChanged();
}
+ /**
+ * Calls dragEnter on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceDragEvent
+ */
public void dragEnter(DragSourceDragEvent e)
- throws NotImplementedException
{
+ if (dragSourceListener != null)
+ dragSourceListener.dragEnter(e);
+
+ DragSource ds = getDragSource();
+ DragSourceListener[] dsl = ds.getDragSourceListeners();
+ for (int i = 0; i < dsl.length; i++)
+ dsl[i].dragEnter(e);
+
+ updateCurrentCursor(e.getDropAction(), e.getTargetActions(), ENTER);
}
+ /**
+ * Calls dragOver on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceDragEvent
+ */
public void dragOver(DragSourceDragEvent e)
- throws NotImplementedException
{
+ if (dragSourceListener != null)
+ dragSourceListener.dragOver(e);
+
+ DragSource ds = getDragSource();
+ DragSourceListener[] dsl = ds.getDragSourceListeners();
+ for (int i = 0; i < dsl.length; i++)
+ dsl[i].dragOver(e);
+
+ updateCurrentCursor(e.getDropAction(), e.getTargetActions(), OVER);
}
-
+
+ /**
+ * Calls dragExit on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceEvent
+ */
public void dragExit(DragSourceEvent e)
- throws NotImplementedException
{
+ 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);
}
+ /**
+ * Calls dropActionChanged on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceDragEvent
+ */
public void dropActionChanged(DragSourceDragEvent e)
- throws NotImplementedException
{
+ if (dragSourceListener != null)
+ dragSourceListener.dropActionChanged(e);
+
+ DragSource ds = getDragSource();
+ DragSourceListener[] dsl = ds.getDragSourceListeners();
+ for (int i = 0; i < dsl.length; i++)
+ dsl[i].dropActionChanged(e);
+
+ updateCurrentCursor(e.getDropAction(), e.getTargetActions(), CHANGED);
}
+ /**
+ * Calls dragDropEnd on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceDropEvent
+ */
public void dragDropEnd(DragSourceDropEvent e)
- throws NotImplementedException
{
+ if (dragSourceListener != null)
+ dragSourceListener.dragDropEnd(e);
+
+ DragSource ds = getDragSource();
+ DragSourceListener[] dsl = ds.getDragSourceListeners();
+ for (int i = 0; i < dsl.length; i++)
+ dsl[i].dragDropEnd(e);
}
+ /**
+ * Calls dragMouseMoved on the listeners registered with the DragSource.
+ *
+ * @param e - the DragSourceDragEvent
+ */
public void dragMouseMoved(DragSourceDragEvent e)
- throws NotImplementedException
{
+ DragSource ds = getDragSource();
+ DragSourceMotionListener[] dsml = ds.getDragSourceMotionListeners();
+ for (int i = 0; i < dsml.length; i++)
+ dsml[i].dragMouseMoved(e);
}
+ /**
+ * Returns the Transferable set with this object.
+ *
+ * @return the transferable.
+ */
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)
+ {
+ Cursor cursor = null;
+ switch (status)
+ {
+ case ENTER:
+ break;
+ case CHANGED:
+ break;
+ case OVER:
+ break;
+ default:
+ break;
+ }
+
+ this.cursor = cursor;
+ peer.setCursor(cursor);
+ }
}
} // class DragSourceContext