summaryrefslogtreecommitdiff
path: root/javax
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2007-02-10 13:32:57 +0000
committerRoman Kennke <roman@kennke.org>2007-02-10 13:32:57 +0000
commit71a9befa56fb06adceec1e38e773dbe5f342485a (patch)
treec5d5246dbe1d40d1fdb8cec7ab0ec56ed7dfb975 /javax
parent849a406080c6ebf785064b3f9f59bd6505c0c1bf (diff)
downloadclasspath-71a9befa56fb06adceec1e38e773dbe5f342485a.tar.gz
2007-02-10 Roman Kennke <kennke@aicas.com>
* javax/swing/TransferHandler.java (SwingDragGestureRecognizer): New inner class. (SwingDragHandler): New inner class. (recognizer): New field. (exportAsDrag): Implemented missing method.
Diffstat (limited to 'javax')
-rw-r--r--javax/swing/TransferHandler.java136
1 files changed, 130 insertions, 6 deletions
diff --git a/javax/swing/TransferHandler.java b/javax/swing/TransferHandler.java
index d594a8244..2e5963f44 100644
--- a/javax/swing/TransferHandler.java
+++ b/javax/swing/TransferHandler.java
@@ -38,15 +38,23 @@ exception statement from your version. */
package javax.swing;
-import gnu.classpath.NotImplementedException;
-
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragGestureRecognizer;
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DragSourceContext;
+import java.awt.dnd.DragSourceDragEvent;
+import java.awt.dnd.DragSourceDropEvent;
+import java.awt.dnd.DragSourceEvent;
+import java.awt.dnd.DragSourceListener;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@@ -210,7 +218,101 @@ public class TransferHandler implements Serializable
}
}
}
-
+
+ private static class SwingDragGestureRecognizer extends DragGestureRecognizer
+ {
+
+ protected SwingDragGestureRecognizer(DragGestureListener dgl)
+ {
+ super(DragSource.getDefaultDragSource(), null, NONE, dgl);
+ }
+
+ void gesture(JComponent c, MouseEvent e, int src, int drag)
+ {
+ setComponent(c);
+ setSourceActions(src);
+ appendEvent(e);
+ fireDragGestureRecognized(drag, e.getPoint());
+ }
+
+ protected void registerListeners()
+ {
+ // Nothing to do here.
+ }
+
+ protected void unregisterListeners()
+ {
+ // Nothing to do here.
+ }
+
+ }
+
+ private static class SwingDragHandler
+ implements DragGestureListener, DragSourceListener
+ {
+
+ private boolean autoscrolls;
+
+ public void dragGestureRecognized(DragGestureEvent e)
+ {
+ JComponent c = (JComponent) e.getComponent();
+ TransferHandler th = c.getTransferHandler();
+ Transferable t = th.createTransferable(c);
+ if (t != null)
+ {
+ autoscrolls = c.getAutoscrolls();
+ c.setAutoscrolls(false);
+ try
+ {
+ e.startDrag(null, t, this);
+ return;
+ }
+ finally
+ {
+ c.setAutoscrolls(autoscrolls);
+ }
+ }
+ th.exportDone(c, t, NONE);
+ }
+
+ public void dragDropEnd(DragSourceDropEvent e)
+ {
+ DragSourceContext ctx = e.getDragSourceContext();
+ JComponent c = (JComponent) ctx.getComponent();
+ TransferHandler th = c.getTransferHandler();
+ if (e.getDropSuccess())
+ {
+ th.exportDone(c, ctx.getTransferable(), e.getDropAction());
+ }
+ else
+ {
+ th.exportDone(c, ctx.getTransferable(), e.getDropAction());
+ }
+ c.setAutoscrolls(autoscrolls);
+ }
+
+ public void dragEnter(DragSourceDragEvent e)
+ {
+ // Nothing to do here.
+ }
+
+ public void dragExit(DragSourceEvent e)
+ {
+ // Nothing to do here.
+ }
+
+ public void dragOver(DragSourceDragEvent e)
+ {
+ // Nothing to do here.
+ }
+
+ public void dropActionChanged(DragSourceDragEvent e)
+ {
+ // Nothing to do here.
+ }
+
+ }
+
private static final long serialVersionUID = -967749805571669910L;
private static final String COMMAND_COPY = "copy";
@@ -235,6 +337,11 @@ public class TransferHandler implements Serializable
*/
private String propertyName;
+ /**
+ * The DragGestureRecognizer for Swing.
+ */
+ private SwingDragGestureRecognizer recognizer;
+
public static Action getCopyAction()
{
return copyAction;
@@ -331,10 +438,27 @@ public class TransferHandler implements Serializable
return transferable;
}
- public void exportAsDrag(JComponent c, InputEvent e, int action)
- throws NotImplementedException
+ public void exportAsDrag(JComponent c, InputEvent e, int action)
{
- // TODO: Implement this properly
+ int src = getSourceActions(c);
+ int drag = src & action;
+ if (! (e instanceof MouseEvent))
+ {
+ drag = NONE;
+ }
+ if (drag != NONE)
+ {
+ if (recognizer == null)
+ {
+ SwingDragHandler ds = new SwingDragHandler();
+ recognizer = new SwingDragGestureRecognizer(ds);
+ }
+ recognizer.gesture(c, (MouseEvent) e, src, drag);
+ }
+ else
+ {
+ exportDone(c, null, NONE);
+ }
}
/**