Search in sources :

Example 1 with DropTargetListener

use of java.awt.dnd.DropTargetListener in project android by JetBrains.

the class LayoutTestUtilities method dragDrop.

public static void dragDrop(InteractionManager manager, int x1, int y1, int x2, int y2, Transferable transferable) {
    Object listener = manager.getListener();
    assertTrue(listener instanceof DropTargetListener);
    DropTargetListener dropListener = (DropTargetListener) listener;
    int frames = 5;
    double x = x1;
    double y = y1;
    double xSlope = (x2 - x) / frames;
    double ySlope = (y2 - y) / frames;
    DropTargetContext context = createDropTargetContext();
    dropListener.dragEnter(new DropTargetDragEventBuilder(context, (int) x, (int) y, transferable).build());
    for (int i = 0; i < frames + 1; i++) {
        dropListener.dragOver(new DropTargetDragEventBuilder(context, (int) x, (int) y, transferable).build());
        x += xSlope;
        y += ySlope;
    }
    DropTargetDropEvent dropEvent = new DropTargetDropEventBuilder(context, (int) x, (int) y, transferable).build();
    dropListener.drop(dropEvent);
    verify(dropEvent, times(1)).acceptDrop(anyInt());
    verify(dropEvent, times(1)).dropComplete(true);
}
Also used : DropTargetListener(java.awt.dnd.DropTargetListener) DropTargetContext(java.awt.dnd.DropTargetContext) DropTargetDragEventBuilder(com.android.tools.idea.uibuilder.fixtures.DropTargetDragEventBuilder) DropTargetDropEventBuilder(com.android.tools.idea.uibuilder.fixtures.DropTargetDropEventBuilder) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 2 with DropTargetListener

use of java.awt.dnd.DropTargetListener in project jdk8u_jdk by JetBrains.

the class SunDropTargetContextPeer method processEnterMessage.

/**
     * actual processing on EventQueue Thread
     */
protected void processEnterMessage(SunDropTargetEvent event) {
    Component c = (Component) event.getSource();
    DropTarget dt = c.getDropTarget();
    Point hots = event.getPoint();
    local = getJVMLocalSourceTransferable();
    if (currentDTC != null) {
        // some wreckage from last time
        currentDTC.removeNotify();
        currentDTC = null;
    }
    if (c.isShowing() && dt != null && dt.isActive()) {
        currentDT = dt;
        currentDTC = currentDT.getDropTargetContext();
        currentDTC.addNotify(this);
        currentA = dt.getDefaultActions();
        try {
            ((DropTargetListener) dt).dragEnter(new DropTargetDragEvent(currentDTC, hots, currentDA, currentSA));
        } catch (Exception e) {
            e.printStackTrace();
            currentDA = DnDConstants.ACTION_NONE;
        }
    } else {
        currentDT = null;
        currentDTC = null;
        currentDA = DnDConstants.ACTION_NONE;
        currentSA = DnDConstants.ACTION_NONE;
        currentA = DnDConstants.ACTION_NONE;
    }
}
Also used : DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) DropTargetListener(java.awt.dnd.DropTargetListener) DropTarget(java.awt.dnd.DropTarget) Point(java.awt.Point) Component(java.awt.Component) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException)

Example 3 with DropTargetListener

use of java.awt.dnd.DropTargetListener in project jdk8u_jdk by JetBrains.

the class SunDropTargetContextPeer method processMotionMessage.

/**
     *
     */
protected void processMotionMessage(SunDropTargetEvent event, boolean operationChanged) {
    Component c = (Component) event.getSource();
    Point hots = event.getPoint();
    int id = event.getID();
    DropTarget dt = c.getDropTarget();
    DropTargetContext dtc = null;
    if (c.isShowing() && (dt != null) && dt.isActive()) {
        if (currentDT != dt) {
            if (currentDTC != null) {
                currentDTC.removeNotify();
            }
            currentDT = dt;
            currentDTC = null;
        }
        dtc = currentDT.getDropTargetContext();
        if (dtc != currentDTC) {
            if (currentDTC != null) {
                currentDTC.removeNotify();
            }
            currentDTC = dtc;
            currentDTC.addNotify(this);
        }
        currentA = currentDT.getDefaultActions();
        try {
            DropTargetDragEvent dtde = new DropTargetDragEvent(dtc, hots, currentDA, currentSA);
            DropTargetListener dtl = (DropTargetListener) dt;
            if (operationChanged) {
                dtl.dropActionChanged(dtde);
            } else {
                dtl.dragOver(dtde);
            }
            if (dragRejected) {
                currentDA = DnDConstants.ACTION_NONE;
            }
        } catch (Exception e) {
            e.printStackTrace();
            currentDA = DnDConstants.ACTION_NONE;
        }
    } else {
        currentDA = DnDConstants.ACTION_NONE;
    }
}
Also used : DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) DropTargetListener(java.awt.dnd.DropTargetListener) DropTargetContext(java.awt.dnd.DropTargetContext) Point(java.awt.Point) DropTarget(java.awt.dnd.DropTarget) Component(java.awt.Component) Point(java.awt.Point) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException)

Example 4 with DropTargetListener

use of java.awt.dnd.DropTargetListener in project jdk8u_jdk by JetBrains.

the class SunDropTargetContextPeer method processDropMessage.

/**
     *
     */
protected void processDropMessage(SunDropTargetEvent event) {
    Component c = (Component) event.getSource();
    Point hots = event.getPoint();
    DropTarget dt = c.getDropTarget();
    // drop pending ACK
    dropStatus = STATUS_WAIT;
    dropComplete = false;
    if (c.isShowing() && dt != null && dt.isActive()) {
        DropTargetContext dtc = dt.getDropTargetContext();
        currentDT = dt;
        if (currentDTC != null) {
            currentDTC.removeNotify();
        }
        currentDTC = dtc;
        currentDTC.addNotify(this);
        currentA = dt.getDefaultActions();
        synchronized (_globalLock) {
            if ((local = getJVMLocalSourceTransferable()) != null)
                setCurrentJVMLocalSourceTransferable(null);
        }
        dropInProcess = true;
        try {
            ((DropTargetListener) dt).drop(new DropTargetDropEvent(dtc, hots, currentDA, currentSA, local != null));
        } finally {
            if (dropStatus == STATUS_WAIT) {
                rejectDrop();
            } else if (dropComplete == false) {
                dropComplete(false);
            }
            dropInProcess = false;
        }
    } else {
        rejectDrop();
    }
}
Also used : DropTargetListener(java.awt.dnd.DropTargetListener) DropTargetContext(java.awt.dnd.DropTargetContext) Point(java.awt.Point) DropTarget(java.awt.dnd.DropTarget) Component(java.awt.Component) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Aggregations

DropTargetListener (java.awt.dnd.DropTargetListener)4 Component (java.awt.Component)3 Point (java.awt.Point)3 DropTarget (java.awt.dnd.DropTarget)3 DropTargetContext (java.awt.dnd.DropTargetContext)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)2 DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)2 InvalidDnDOperationException (java.awt.dnd.InvalidDnDOperationException)2 IOException (java.io.IOException)2 DropTargetDragEventBuilder (com.android.tools.idea.uibuilder.fixtures.DropTargetDragEventBuilder)1 DropTargetDropEventBuilder (com.android.tools.idea.uibuilder.fixtures.DropTargetDropEventBuilder)1