Search in sources :

Example 11 with DropTarget

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

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

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

the class CDropTargetContextPeer method processEnterMessage.

/**
     * Could be called when DnD enters a heavyweight or synthesized in processMotionMessage
     */
@Override
protected void processEnterMessage(SunDropTargetEvent event) {
    Component c = event.getComponent();
    DropTarget dt = event.getComponent().getDropTarget();
    if (isEventInsideTarget(event) && dt != insideTarget && c.isShowing() && dt != null && dt.isActive()) {
        insideTarget = dt;
        super.processEnterMessage(event);
    }
}
Also used : DropTarget(java.awt.dnd.DropTarget)

Example 14 with DropTarget

use of java.awt.dnd.DropTarget in project GCViewer by chewiebug.

the class GCModelLoaderControllerImpl method openGCResource.

private void openGCResource(GCResource gcResource, GCModelLoader loader) {
    GCDocument document = new GCDocument(gcViewerGui.getPreferences(), gcResource.getResourceName());
    document.setDropTarget(new DropTarget(document, DnDConstants.ACTION_COPY, new FileDropTargetListener(this, DropFlavor.ADD)));
    document.addInternalFrameListener(new GCViewerGuiInternalFrameController());
    gcViewerGui.addDocument(document);
    GCDocumentController docController = new GCDocumentController(document);
    docController.addGCResource(loader, getViewMenuController());
    loader.execute();
}
Also used : GCDocument(com.tagtraum.perf.gcviewer.view.GCDocument) DropTarget(java.awt.dnd.DropTarget)

Example 15 with DropTarget

use of java.awt.dnd.DropTarget in project GCViewer by chewiebug.

the class TestGCModelLoaderController method dropOnDesktopPane.

/**
     * Test drag and drop action on GCViewerGui.
     */
@Test
public void dropOnDesktopPane() throws Exception {
    // TODO SWINGWORKER: test drag and drop on GCDocument
    assertThat("number of gcdocuments before", controller.getGCViewerGui().getDesktopPane().getAllFrames().length, is(0));
    List<File> fileList = new ArrayList<File>();
    fileList.add(new File(UnittestHelper.getResource(UnittestHelper.FOLDER_OPENJDK, "SampleSun1_6_0G1_MarkStackFull.txt").getPath()));
    Transferable tr = Mockito.mock(Transferable.class);
    Mockito.when(tr.getTransferData(DataFlavor.javaFileListFlavor)).thenReturn(fileList);
    DropTargetDropEvent dte = Mockito.mock(DropTargetDropEvent.class);
    Mockito.when(dte.isDataFlavorSupported(DataFlavor.javaFileListFlavor)).thenReturn(true);
    Mockito.when(dte.getTransferable()).thenReturn(tr);
    DropTarget target = controller.getGCViewerGui().getDesktopPane().getDropTarget();
    target.drop(dte);
    assertThat("number of gcdocuments after drop", controller.getGCViewerGui().getDesktopPane().getAllFrames().length, is(1));
}
Also used : ArrayList(java.util.ArrayList) Transferable(java.awt.datatransfer.Transferable) DropTarget(java.awt.dnd.DropTarget) File(java.io.File) GcResourceFile(com.tagtraum.perf.gcviewer.model.GcResourceFile) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) Test(org.junit.Test)

Aggregations

DropTarget (java.awt.dnd.DropTarget)25 DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)9 DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)9 DropTargetAdapter (java.awt.dnd.DropTargetAdapter)6 Component (java.awt.Component)5 Point (java.awt.Point)5 DropTargetContext (java.awt.dnd.DropTargetContext)4 IOException (java.io.IOException)4 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 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 DropTargetListener (java.awt.dnd.DropTargetListener)3 InvalidDnDOperationException (java.awt.dnd.InvalidDnDOperationException)3 DropTargetEvent (java.awt.dnd.DropTargetEvent)2 KeyEvent (java.awt.event.KeyEvent)2 MouseEvent (java.awt.event.MouseEvent)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2