Search in sources :

Example 1 with DropTargetContext

use of java.awt.dnd.DropTargetContext in project jna by java-native-access.

the class DropHandler method describe.

private void describe(String type, DropTargetEvent e) {
    if (false) {
        String msg = "drop: " + type;
        if (e instanceof DropTargetDragEvent) {
            DropTargetContext dtc = e.getDropTargetContext();
            DropTarget dt = dtc.getDropTarget();
            DropTargetDragEvent ev = (DropTargetDragEvent) e;
            msg += ": src=" + DragHandler.actionString(ev.getSourceActions()) + " tgt=" + DragHandler.actionString(dt.getDefaultActions()) + " act=" + DragHandler.actionString(ev.getDropAction());
        } else if (e instanceof DropTargetDropEvent) {
            DropTargetContext dtc = e.getDropTargetContext();
            DropTarget dt = dtc.getDropTarget();
            DropTargetDropEvent ev = (DropTargetDropEvent) e;
            msg += ": src=" + DragHandler.actionString(ev.getSourceActions()) + " tgt=" + DragHandler.actionString(dt.getDefaultActions()) + " act=" + DragHandler.actionString(ev.getDropAction());
        }
        if (!msg.equals(lastAction)) {
            System.out.println(lastAction = msg);
        }
    }
}
Also used : DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) DropTargetContext(java.awt.dnd.DropTargetContext) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 2 with DropTargetContext

use of java.awt.dnd.DropTargetContext 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 3 with DropTargetContext

use of java.awt.dnd.DropTargetContext 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 DropTargetContext

use of java.awt.dnd.DropTargetContext 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)

Example 5 with DropTargetContext

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

the class SunDropTargetContextPeer method processExitMessage.

/**
     *
     */
protected void processExitMessage(SunDropTargetEvent event) {
    Component c = (Component) event.getSource();
    DropTarget dt = c.getDropTarget();
    DropTargetContext dtc = null;
    if (dt == null) {
        currentDT = null;
        currentT = null;
        if (currentDTC != null) {
            currentDTC.removeNotify();
        }
        currentDTC = null;
        return;
    }
    if (dt != currentDT) {
        if (currentDTC != null) {
            currentDTC.removeNotify();
        }
        currentDT = dt;
        currentDTC = dt.getDropTargetContext();
        currentDTC.addNotify(this);
    }
    dtc = currentDTC;
    if (dt.isActive())
        try {
            ((DropTargetListener) dt).dragExit(new DropTargetEvent(dtc));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            currentA = DnDConstants.ACTION_NONE;
            currentSA = DnDConstants.ACTION_NONE;
            currentDA = DnDConstants.ACTION_NONE;
            currentDT = null;
            currentT = null;
            currentDTC.removeNotify();
            currentDTC = null;
            local = null;
            dragRejected = false;
        }
}
Also used : DropTargetContext(java.awt.dnd.DropTargetContext) DropTargetEvent(java.awt.dnd.DropTargetEvent) DropTarget(java.awt.dnd.DropTarget) Component(java.awt.Component) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException)

Aggregations

DropTargetContext (java.awt.dnd.DropTargetContext)5 DropTarget (java.awt.dnd.DropTarget)4 Component (java.awt.Component)3 DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)3 DropTargetListener (java.awt.dnd.DropTargetListener)3 Point (java.awt.Point)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)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 DropTargetEvent (java.awt.dnd.DropTargetEvent)1