I implemented and fixed up a bunch of DnD code. It is still not in a
testable state because the peers for these classes have not been
implemented. Once it is working, I will write a demo and a bunch of
mauve tests.
2006-07-05 Lillian Angel <[EMAIL PROTECTED]>
* java/awt/dnd/DragGestureEvent.java:
Added new fields.
(DragGestureEvent): Initialized new fields, added to check and
added documentation.
(getSourceAsDragGestureRecognizer): Added documentation and
changed to use getSource.
(getComponent): Added documentation and fixed to return the
proper value.
(getDragSource): Likewise.
(getDragOrigin): Added documentation.
(iterator): Implemented and added documentation.
(toArray): Likewise.
(toArray): Likewise.
(getDragAction): Likewise.
(getTriggerEvent): Likewise.
(startDrag): Likewise.
* java/awt/dnd/DragGestureRecognizer.java
(resetRecognizer): Added FIXME.
* java/awt/dnd/DragSource.java:
Added new field.
(DragSource): Set ds to be null if headless.
(getDefaultDragSource): Added documentation and implemented.
(isDragImageSupported): Marked as unimplemented.
(startDrag): Likewise.
(createDragSourceContext): Implemented.
(NoDragGestureRecognizer): Formatted inner class.
* java/awt/dnd/DropTarget.java
(stop): Marked as unimplemented.
(actionPerformed): Likewise.
(addDropTargetListener): Added code to throw exception.
(removeDropTargetListener): Added check, removed FIXME.
(dragEnter): Implemented.
(dragOver): Implemented.
(dropActionChanged): Implemented.
(dragExit): Implemented.
(drop): Implemented.
(addNotify): Implemented.
(removeNotify): Implemented.
(createDropTargetContext): Implemented.
(createDropTargetAutoScroller): Implemented.
(initializeAutoscrolling): Implemented.
(updateAutoscroll): Implemented.
(clearAutoscroll): Implemented.
* java/awt/dnd/DropTargetContext.java
(dropComplete): Implemented.
(acceptDrag): Implemented.
(rejectDrag): Implemented.
(acceptDrop): Implemented.
(rejectDrop): Implemented.
(getCurrentDataFlavors): Implemented.
(getTransferable): Partially implemented.
* java/awt/dnd/DropTargetDragEvent.java
(getDropAction): Uncommented correct code.
* java/awt/dnd/DropTargetDropEvent.java
(dropComplete) :Implemented.
* java/awt/dnd/InvalidDnDOperationException.java
(InvalidDnDOperationException): Added call to super.
Index: java/awt/dnd/DragGestureEvent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DragGestureEvent.java,v
retrieving revision 1.3
diff -u -r1.3 DragGestureEvent.java
--- java/awt/dnd/DragGestureEvent.java 2 Jul 2005 20:32:26 -0000 1.3
+++ java/awt/dnd/DragGestureEvent.java 5 Jul 2006 17:32:30 -0000
@@ -48,13 +48,6 @@
import java.util.Iterator;
import java.util.List;
-/**
- * STUBBED
- * @see DragGestureRecognizer
- * @see DragGestureListener
- * @see DragSource
- * @since 1.2
- */
public class DragGestureEvent extends EventObject
{
/**
@@ -66,52 +59,121 @@
private Component component;
private final Point origin;
private final int action;
+ private List events;
+ private DragGestureRecognizer dgr;
+ /**
+ * Constructs a new DragGestureEvent.
+ * @param dgr - DragGestureRecognizer firing this event
+ * @param action - user's preferred action
+ * @param origin - origin of the drag
+ * @param events - List of events that make up the gesture
+ * @throws IllegalArgumentException - if input parameters are null
+ */
public DragGestureEvent(DragGestureRecognizer dgr, int action, Point origin,
List events)
- {
+ {
super(dgr);
- if (origin == null || events == null)
+ if (origin == null || events == null || dgr == null)
throw new IllegalArgumentException();
+
this.origin = origin;
this.action = action;
+ this.events = events;
+ this.dgr = dgr;
+ this.component = dgr.getComponent();
+ this.dragSource = dgr.getDragSource();
}
+ /**
+ * Returns the source casted as a DragGestureRecognizer.
+ *
+ * @return the source casted as a DragGestureRecognizer.
+ */
public DragGestureRecognizer getSourceAsDragGestureRecognizer()
{
- return (DragGestureRecognizer) source;
+ return (DragGestureRecognizer) getSource();
}
+
+ /**
+ * Returns the Component corresponding to this.
+ *
+ * @return the Component corresponding to this.
+ */
public Component getComponent()
{
- return null;
+ return component;
}
+
+ /**
+ * Gets the DragSource corresponding to this.
+ *
+ * @return the DragSource corresponding to this.
+ */
public DragSource getDragSource()
{
- return null;
+ return dragSource;
}
+
+ /**
+ * Returns the origin of the drag.
+ *
+ * @return the origin of the drag.
+ */
public Point getDragOrigin()
{
return origin;
}
+
+ /**
+ * Gets an iterator representation of the List of events.
+ *
+ * @return an iterator representation of the List of events.
+ */
public Iterator iterator()
{
- return null;
+ return events.iterator();
}
+
+ /**
+ * Gets an array representation of the List of events.
+ *
+ * @return an array representation of the List of events.
+ */
public Object[] toArray()
{
- return null;
+ return events.toArray();
}
+
+ /**
+ * Gets an array representation of the List of events.
+ *
+ * @param array - the array to store the events in.
+ * @return an array representation of the List of events.
+ */
public Object[] toArray(Object[] array)
{
- return array;
+ return events.toArray(array);
}
+
+ /**
+ * Gets the user's preferred action.
+ *
+ * @return the user's preferred action.
+ */
public int getDragAction()
{
- return 0;
+ return action;
}
+
+ /**
+ * Get the event that triggered this gesture.
+ *
+ * @return the event that triggered this gesture.
+ */
public InputEvent getTriggerEvent()
{
- return null;
+ return dgr.getTriggerEvent();
}
/**
@@ -152,5 +214,6 @@
public void startDrag(Cursor dragCursor, Image dragImage, Point imageOffset,
Transferable trans, DragSourceListener l)
{
+ dragSource.startDrag(this, dragCursor, dragImage, imageOffset, trans, l);
}
} // class DragGestureEvent
Index: java/awt/dnd/DragGestureRecognizer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DragGestureRecognizer.java,v
retrieving revision 1.5
diff -u -r1.5 DragGestureRecognizer.java
--- java/awt/dnd/DragGestureRecognizer.java 24 May 2006 19:36:06 -0000 1.5
+++ java/awt/dnd/DragGestureRecognizer.java 5 Jul 2006 17:32:30 -0000
@@ -131,6 +131,7 @@
throws NotImplementedException
{
events = new ArrayList();
+ // FIXME: Not implemented fully.
}
/**
Index: java/awt/dnd/DragSource.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DragSource.java,v
retrieving revision 1.6
diff -u -r1.6 DragSource.java
--- java/awt/dnd/DragSource.java 18 Feb 2006 15:23:32 -0000 1.6
+++ java/awt/dnd/DragSource.java 5 Jul 2006 17:32:30 -0000
@@ -38,6 +38,8 @@
package java.awt.dnd;
+import gnu.classpath.NotImplementedException;
+
import java.awt.Component;
import java.awt.Cursor;
import java.awt.GraphicsEnvironment;
@@ -70,9 +72,10 @@
public static final Cursor DefaultLinkNoDrop = null;
private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap ();
-
private transient DragSourceListener dragSourceListener;
private transient DragSourceMotionListener dragSourceMotionListener;
+
+ private static DragSource ds;
/**
* Initializes the drag source.
@@ -82,19 +85,34 @@
public DragSource()
{
if (GraphicsEnvironment.isHeadless())
- throw new HeadlessException ();
+ {
+ ds = null;
+ throw new HeadlessException();
+ }
}
/**
+ * Gets the default drag source.
+ *
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
*/
public static DragSource getDefaultDragSource()
{
- return new DragSource();
+ if (GraphicsEnvironment.isHeadless())
+ {
+ ds = null;
+ throw new HeadlessException();
+ }
+
+ if (ds == null)
+ ds = new DragSource();
+ return ds;
}
public static boolean isDragImageSupported()
+ throws NotImplementedException
{
+ // FIXME: Implement this
return false;
}
@@ -109,7 +127,9 @@
Image dragImage, Point imageOffset,
Transferable trans, DragSourceListener dsl,
FlavorMap map)
+ throws NotImplementedException
{
+ // FIXME: Implement this
}
/**
@@ -156,7 +176,7 @@
/**
* Creates the DragSourceContext to handle this drag.
*
- * @exception IllegalArgumentException FIXME
+ * @exception IllegalArgumentException
* @exception NullPointerException If dscp, dgl, dragImage or t is null.
*/
protected DragSourceContext
@@ -164,7 +184,7 @@
Cursor cursor, Image image, Point offset,
Transferable t, DragSourceListener dsl)
{
- return null;
+ return new DragSourceContext(peer, dge, cursor, image, offset, t, dsl);
}
public FlavorMap getFlavorMap()
@@ -175,7 +195,8 @@
/**
* Dummy DragGestureRecognizer when Toolkit doesn't support drag and drop.
*/
- static class NoDragGestureRecognizer extends DragGestureRecognizer
+ static class NoDragGestureRecognizer
+ extends DragGestureRecognizer
{
NoDragGestureRecognizer(DragSource ds, Component c, int actions,
DragGestureListener dgl)
@@ -183,8 +204,13 @@
super(ds, c, actions, dgl);
}
- protected void registerListeners() { }
- protected void unregisterListeners() { }
+ protected void registerListeners()
+ {
+ }
+
+ protected void unregisterListeners()
+ {
+ }
}
public DragGestureRecognizer
Index: java/awt/dnd/DropTarget.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DropTarget.java,v
retrieving revision 1.12
diff -u -r1.12 DropTarget.java
--- java/awt/dnd/DropTarget.java 16 Mar 2006 00:50:23 -0000 1.12
+++ java/awt/dnd/DropTarget.java 5 Jul 2006 17:32:30 -0000
@@ -38,13 +38,17 @@
package java.awt.dnd;
+import gnu.classpath.NotImplementedException;
+
import java.awt.Component;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Point;
import java.awt.datatransfer.FlavorMap;
+import java.awt.dnd.peer.DropTargetPeer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.peer.ComponentPeer;
import java.io.Serializable;
import java.util.EventListener;
import java.util.TooManyListenersException;
@@ -79,19 +83,25 @@
}
protected void stop ()
+ throws NotImplementedException
{
+ // FIXME: implement this
}
public void actionPerformed (ActionEvent e)
+ throws NotImplementedException
{
+ // FIXME: implement this
}
}
private Component component;
private FlavorMap flavorMap;
private int actions;
+ private DropTargetPeer peer;
private DropTargetContext dropTargetContext;
private DropTargetListener dropTargetListener;
+ private DropTarget.DropTargetAutoScroller autoscroller;
private boolean active = true;
/**
@@ -211,33 +221,46 @@
public void addDropTargetListener (DropTargetListener dtl)
throws TooManyListenersException
{
+ if (dropTargetListener != null)
+ throw new TooManyListenersException ();
+
dropTargetListener = dtl;
}
public void removeDropTargetListener(DropTargetListener dtl)
{
- // FIXME: Do we need to do something with dtl ?
- dropTargetListener = null;
+ if (dropTargetListener != null)
+ dropTargetListener = null;
}
public void dragEnter(DropTargetDragEvent dtde)
{
+ if (dropTargetListener != null)
+ dropTargetListener.dragEnter(dtde);
}
public void dragOver(DropTargetDragEvent dtde)
{
+ if (dropTargetListener != null)
+ dropTargetListener.dragOver(dtde);
}
public void dropActionChanged(DropTargetDragEvent dtde)
{
+ if (dropTargetListener != null)
+ dropTargetListener.dropActionChanged(dtde);
}
public void dragExit(DropTargetEvent dte)
{
+ if (dropTargetListener != null)
+ dropTargetListener.dragExit(dte);
}
public void drop(DropTargetDropEvent dtde)
{
+ if (dropTargetListener != null)
+ dropTargetListener.drop(dtde);
}
public FlavorMap getFlavorMap()
@@ -250,12 +273,14 @@
flavorMap = fm;
}
- public void addNotify(java.awt.peer.ComponentPeer peer)
+ public void addNotify(ComponentPeer p)
{
+ peer = (DropTargetPeer) p;
}
- public void removeNotify(java.awt.peer.ComponentPeer peer)
+ public void removeNotify(ComponentPeer peer)
{
+ peer = null;
}
public DropTargetContext getDropTargetContext()
@@ -268,24 +293,34 @@
protected DropTargetContext createDropTargetContext()
{
- return new DropTargetContext (this);
+ if (dropTargetContext == null)
+ dropTargetContext = new DropTargetContext (this);
+
+ return dropTargetContext;
}
protected DropTarget.DropTargetAutoScroller createDropTargetAutoScroller
(Component c, Point p)
{
- return new DropTarget.DropTargetAutoScroller (c, p);
+ if (autoscroller == null)
+ autoscroller = new DropTarget.DropTargetAutoScroller (c, p);
+
+ return autoscroller;
}
protected void initializeAutoscrolling(Point p)
{
+ createDropTargetAutoScroller (component, p);
}
protected void updateAutoscroll(Point dragCursorLocn)
{
+ if (autoscroller != null)
+ autoscroller.updateLocation(dragCursorLocn);
}
protected void clearAutoscroll()
{
+ autoscroller = null;
}
} // class DropTarget
Index: java/awt/dnd/DropTargetContext.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DropTargetContext.java,v
retrieving revision 1.11
diff -u -r1.11 DropTargetContext.java
--- java/awt/dnd/DropTargetContext.java 9 Jun 2006 13:09:15 -0000 1.11
+++ java/awt/dnd/DropTargetContext.java 5 Jul 2006 17:32:30 -0000
@@ -37,12 +37,11 @@
package java.awt.dnd;
-import gnu.classpath.NotImplementedException;
-
import java.awt.Component;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.dnd.peer.DropTargetContextPeer;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
@@ -86,7 +85,7 @@
private DropTarget dropTarget;
private int targetActions;
- private java.awt.dnd.peer.DropTargetContextPeer dtcp;
+ private DropTargetContextPeer dtcp;
// package private
DropTargetContext(DropTarget dropTarget)
@@ -104,7 +103,7 @@
return dropTarget.getComponent();
}
- public void addNotify(java.awt.dnd.peer.DropTargetContextPeer dtcp)
+ public void addNotify(DropTargetContextPeer dtcp)
{
this.dtcp = dtcp;
}
@@ -130,39 +129,39 @@
* @exception InvalidDnDOperationException If a drop is not outstanding.
*/
public void dropComplete(boolean success)
- throws NotImplementedException
{
- // FIXME: implement this
+ if (dtcp != null)
+ dtcp.dropComplete(success);
}
protected void acceptDrag(int dragOperation)
- throws NotImplementedException
{
- // FIXME: implement this
+ if (dtcp != null)
+ dtcp.acceptDrag(dragOperation);
}
protected void rejectDrag()
- throws NotImplementedException
{
- // FIXME: implement this
+ if (dtcp != null)
+ dtcp.rejectDrag();
}
protected void acceptDrop(int dropOperation)
- throws NotImplementedException
{
- // FIXME: implement this
+ if (dtcp != null)
+ dtcp.acceptDrop(dropOperation);
}
protected void rejectDrop()
- throws NotImplementedException
{
- // FIXME: implement this
+ if (dtcp != null)
+ dtcp.rejectDrop();
}
protected DataFlavor[] getCurrentDataFlavors()
- throws NotImplementedException
{
- // FIXME: implement this
+ if (dtcp != null)
+ dtcp.getTransferDataFlavors();
return null;
}
@@ -182,9 +181,11 @@
* @exception InvalidDnDOperationException If a drag is not outstanding.
*/
protected Transferable getTransferable()
- throws InvalidDnDOperationException, NotImplementedException
+ throws InvalidDnDOperationException
{
- // FIXME: implement this
+ // FIXME: Implement this
+ if (dtcp != null)
+ return dtcp.getTransferable();
return null;
}
Index: java/awt/dnd/DropTargetDragEvent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DropTargetDragEvent.java,v
retrieving revision 1.4
diff -u -r1.4 DropTargetDragEvent.java
--- java/awt/dnd/DropTargetDragEvent.java 2 Jul 2005 20:32:26 -0000 1.4
+++ java/awt/dnd/DropTargetDragEvent.java 5 Jul 2006 17:32:30 -0000
@@ -114,8 +114,7 @@
public int getDropAction()
{
- return 0;
- //return dropAction & ((DropTargetContext) source).getTargetActions();
+ return dropAction & ((DropTargetContext) source).getTargetActions();
}
public Point getLocation ()
Index: java/awt/dnd/DropTargetDropEvent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DropTargetDropEvent.java,v
retrieving revision 1.4
diff -u -r1.4 DropTargetDropEvent.java
--- java/awt/dnd/DropTargetDropEvent.java 9 Jun 2006 13:09:15 -0000 1.4
+++ java/awt/dnd/DropTargetDropEvent.java 5 Jul 2006 17:32:30 -0000
@@ -37,8 +37,6 @@
package java.awt.dnd;
-import gnu.classpath.NotImplementedException;
-
import java.awt.Point;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
@@ -161,9 +159,8 @@
}
public void dropComplete(boolean success)
- throws NotImplementedException
{
- // FIXME: implement this
+ context.dropComplete(success);
}
public boolean isLocalTransfer()
Index: java/awt/dnd/InvalidDnDOperationException.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/InvalidDnDOperationException.java,v
retrieving revision 1.3
diff -u -r1.3 InvalidDnDOperationException.java
--- java/awt/dnd/InvalidDnDOperationException.java 2 Jul 2005 20:32:26 -0000 1.3
+++ java/awt/dnd/InvalidDnDOperationException.java 5 Jul 2006 17:32:30 -0000
@@ -59,6 +59,7 @@
*/
public InvalidDnDOperationException()
{
+ super();
}
/**