Fixed up the API documentation and implemented some more missing
functions according to the API. I will write a demo for this when it is
in a working state.
2006-07-04 Lillian Angel <[EMAIL PROTECTED]>
* java/awt/dnd/DragSourceContext.java:
Removed FIXMEs from fields.
(DragSourceContext): Added code to initialize cursor and
sourceActions.
(getDragSource): Added documentation.
(getComponent): Likewise.
(getTrigger): Likewise.
(getSourceActions): Added documentation and implemented.
(setCursor): Implemented. Added documentation.
(getCursor): Implemented. Added documentation.
(dragEnter): Added code to notify DragSource's listeners.
(dragOver): Likewise.
(dragExit): Likewise.
(dropActionChanged): Likewise.
(dragDropEnd): Likewise.
(dragMouseMoved): Implemented.
(getTransferable): Added API documentation.
(updateCurrentCursor): Added API documentation and partially
implemented.
Index: java/awt/dnd/DragSourceContext.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DragSourceContext.java,v
retrieving revision 1.9
diff -u -r1.9 DragSourceContext.java
--- java/awt/dnd/DragSourceContext.java 4 Jul 2006 18:56:27 -0000 1.9
+++ java/awt/dnd/DragSourceContext.java 4 Jul 2006 20:19:15 -0000
@@ -70,8 +70,8 @@
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;
@@ -109,35 +109,77 @@
this.offset = offset;
this.transferable = trans;
this.dragSourceListener = dsl;
+ this.sourceActions = trigger.getSourceAsDragGestureRecognizer().getSourceActions();
+
+ 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;
@@ -173,57 +215,151 @@
}
/**
- * Calls dragEnter on the DragSourceListener registered with this.
+ * Calls dragEnter on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceDragEvent
*/
public void dragEnter(DragSourceDragEvent e)
{
- dragSourceListener.dragEnter(e);
+ 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 DragSourceListener registered with this.
+ * Calls dragOver on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceDragEvent
*/
public void dragOver(DragSourceDragEvent e)
{
- dragSourceListener.dragOver(e);
+ 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 DragSourceListener registered with this.
+ * Calls dragExit on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceEvent
*/
public void dragExit(DragSourceEvent e)
{
- dragSourceListener.dragExit(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);
}
/**
- * Calls dropActionChanged on the DragSourceListener registered with this.
+ * Calls dropActionChanged on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceDragEvent
*/
public void dropActionChanged(DragSourceDragEvent e)
{
- dragSourceListener.dropActionChanged(e);
+ 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 DragSourceListener registered with this.
+ * Calls dragDropEnd on the listeners registered with this
+ * and with the DragSource.
+ *
+ * @param e - the DragSourceDropEvent
*/
public void dragDropEnd(DragSourceDropEvent e)
{
- dragSourceListener.dragDropEnd(e);
+ 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