Search in sources :

Example 6 with DropTargetDropEvent

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

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

the class DropTargetDropEventBuilder method build.

public DropTargetDropEvent build() {
    DropTargetDropEvent event = mock(DropTargetDropEvent.class);
    when(event.getSource()).thenReturn(mySource);
    when(event.getLocation()).thenReturn(new Point(myX, myY));
    when(event.getDropTargetContext()).thenReturn(myDropTargetContext);
    when(event.getDropAction()).thenReturn(myDropAction);
    when(event.getSourceActions()).thenReturn(mySourceActions);
    when(event.getTransferable()).thenReturn(myTransferable);
    DataFlavor[] flavors = myTransferable.getTransferDataFlavors();
    when(event.getCurrentDataFlavors()).thenReturn(flavors);
    when(event.getCurrentDataFlavorsAsList()).thenReturn(Arrays.asList(flavors));
    return event;
}
Also used : DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 8 with DropTargetDropEvent

use of java.awt.dnd.DropTargetDropEvent 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 9 with DropTargetDropEvent

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

the class DisposeFrameOnDragTest method constructTestUI.

private static void constructTestUI() {
    final JFrame frame = new JFrame("Test frame");
    textArea = new JTextArea("Drag Me!");
    try {
        textArea.getDropTarget().addDropTargetListener(new DropTargetAdapter() {

            @Override
            public void drop(DropTargetDropEvent dtde) {
            //IGNORE
            }

            @Override
            public void dragOver(DropTargetDragEvent dtde) {
                frame.dispose();
            }
        });
    } catch (TooManyListenersException ex) {
        throw new RuntimeException(ex);
    }
    textArea.setSize(100, 100);
    textArea.setDragEnabled(true);
    textArea.select(0, textArea.getText().length());
    frame.add(textArea);
    frame.setBounds(100, 100, 100, 100);
    frame.setVisible(true);
}
Also used : DropTargetAdapter(java.awt.dnd.DropTargetAdapter) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) TooManyListenersException(java.util.TooManyListenersException) JTextArea(javax.swing.JTextArea) JFrame(javax.swing.JFrame) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 10 with DropTargetDropEvent

use of java.awt.dnd.DropTargetDropEvent in project cayenne by apache.

the class CayenneModelerController method initBindings.

protected void initBindings() {
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            PROJECT_STATE_UTIL.saveLastState(projectController);
            getApplication().getActionManager().getAction(ExitAction.class).exit();
        }
    });
    // This is in Mac OSX only.
    if (System.getProperty("os.name").startsWith("Mac OS")) {
        Runnable runner = new Runnable() {

            @Override
            public void run() {
                PROJECT_STATE_UTIL.saveLastState(projectController);
            }
        };
        Runtime.getRuntime().addShutdownHook(new Thread(runner, "Window Prefs Hook"));
    }
    new DropTarget(frame, new DropTargetAdapter() {

        @Override
        public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(dtde.getDropAction());
            Transferable transferable = dtde.getTransferable();
            dtde.dropComplete(processDropAction(transferable));
        }
    });
    ComponentGeometry geometry = new ComponentGeometry(frame.getClass(), null);
    geometry.bind(frame, 1200, 720, 0);
}
Also used : DropTargetAdapter(java.awt.dnd.DropTargetAdapter) ComponentGeometry(org.apache.cayenne.modeler.pref.ComponentGeometry) WindowEvent(java.awt.event.WindowEvent) Transferable(java.awt.datatransfer.Transferable) WindowAdapter(java.awt.event.WindowAdapter) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Aggregations

DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)14 DropTarget (java.awt.dnd.DropTarget)10 DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)9 DropTargetAdapter (java.awt.dnd.DropTargetAdapter)8 EditorFragmentComponent (com.intellij.codeInsight.hint.EditorFragmentComponent)3 JBLayeredPane (com.intellij.ui.components.JBLayeredPane)3 Activatable (com.intellij.util.ui.update.Activatable)3 UiNotifyConnector (com.intellij.util.ui.update.UiNotifyConnector)3 DropTargetContext (java.awt.dnd.DropTargetContext)3 Point (java.awt.Point)2 DataFlavor (java.awt.datatransfer.DataFlavor)2 Transferable (java.awt.datatransfer.Transferable)2 DropTargetListener (java.awt.dnd.DropTargetListener)2 DropTargetDragEventBuilder (com.android.tools.idea.uibuilder.fixtures.DropTargetDragEventBuilder)1 DropTargetDropEventBuilder (com.android.tools.idea.uibuilder.fixtures.DropTargetDropEventBuilder)1 GcResourceFile (com.tagtraum.perf.gcviewer.model.GcResourceFile)1 Component (java.awt.Component)1 DropTargetEvent (java.awt.dnd.DropTargetEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1