Search in sources :

Example 11 with DropTargetDropEvent

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

Example 12 with DropTargetDropEvent

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

the class DropHandler method getDropAction.

/** Calculate the effective action.  The default implementation 
     * checks whether any {@link DataFlavor}s are supported, and if so,
     * will change the current action from {@link DnDConstants#ACTION_NONE} to 
     * something in common between the source and destination.  Refuse 
     * user-requested actions if they are not supported (rather than silently 
     * accepting a non-user-requested action, which is the Java's DnD default 
     * behavior).  The drop action is forced to {@link DnDConstants#ACTION_NONE} 
     * if there is no supported data flavor.
     * @param e {@link DropTargetEvent}
     * @return effective drop action
     * @see #isSupported(DataFlavor[])
     * @see #getDropActionsForFlavors
     * @see #getDropAction(DropTargetEvent, int, int, int)
     * @see #canDrop(DropTargetEvent, int, Point)
     */
protected int getDropAction(DropTargetEvent e) {
    int currentAction = DragHandler.NONE;
    int sourceActions = DragHandler.NONE;
    Point location = null;
    DataFlavor[] flavors = new DataFlavor[0];
    if (e instanceof DropTargetDragEvent) {
        DropTargetDragEvent ev = (DropTargetDragEvent) e;
        currentAction = ev.getDropAction();
        sourceActions = ev.getSourceActions();
        flavors = ev.getCurrentDataFlavors();
        location = ev.getLocation();
    } else if (e instanceof DropTargetDropEvent) {
        DropTargetDropEvent ev = (DropTargetDropEvent) e;
        currentAction = ev.getDropAction();
        sourceActions = ev.getSourceActions();
        flavors = ev.getCurrentDataFlavors();
        location = ev.getLocation();
    }
    if (isSupported(flavors)) {
        int availableActions = getDropActionsForFlavors(flavors);
        currentAction = getDropAction(e, currentAction, sourceActions, availableActions);
        if (currentAction != DragHandler.NONE) {
            if (canDrop(e, currentAction, location)) {
                return currentAction;
            }
        }
    }
    return DragHandler.NONE;
}
Also used : DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) Point(java.awt.Point) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) Point(java.awt.Point) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 13 with DropTargetDropEvent

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

the class ExtraDragEnterTest method initAndShowUI.

private static void initAndShowUI() {
    f = new Frame("Test frame");
    f.setBounds(FRAME_LOCATION, FRAME_LOCATION, FRAME_SIZE, FRAME_SIZE);
    mainPanel = new Panel();
    mainPanel.setBounds(0, 0, FRAME_SIZE, FRAME_SIZE);
    mainPanel.setBackground(Color.black);
    mainPanel.setLayout(new GridLayout(2, 1));
    final DraggablePanel dragSource = new DraggablePanel();
    dragSource.setBackground(Color.yellow);
    dragSource.setDropTarget(null);
    mainPanel.add(dragSource);
    Panel dropTarget = new Panel();
    dropTarget.setBackground(Color.red);
    DropTarget dt = new DropTarget(dropTarget, new DropTargetAdapter() {

        @Override
        public void drop(DropTargetDropEvent dtde) {
        }

        @Override
        public void dragEnter(DropTargetDragEvent dtde) {
            dragEnterCalled.incrementAndGet();
        }
    });
    dropTarget.setDropTarget(dt);
    mainPanel.add(dropTarget);
    f.add(mainPanel);
    f.setVisible(true);
}
Also used : DropTargetAdapter(java.awt.dnd.DropTargetAdapter) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 14 with DropTargetDropEvent

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

the class MissedDragExitTest method initAndShowUI.

private static void initAndShowUI() {
    f = new Frame("Test frame");
    f.setBounds(FRAME_LOCATION, FRAME_LOCATION, FRAME_SIZE, FRAME_SIZE);
    final DraggablePanel dragSource = new DraggablePanel();
    dragSource.setBackground(Color.yellow);
    DropTarget dt = new DropTarget(dragSource, new DropTargetAdapter() {

        @Override
        public void drop(DropTargetDropEvent dtde) {
        }

        @Override
        public void dragExit(DropTargetEvent dte) {
            dragExitCalled = true;
        }

        @Override
        public void dragOver(DropTargetDragEvent dtde) {
            Panel newDropTarget = new Panel();
            newDropTarget.setDropTarget(new DropTarget());
            newDropTarget.setBackground(Color.red);
            newDropTarget.setBounds(0, 0, FRAME_SIZE, FRAME_SIZE);
            dragSource.add(newDropTarget);
        }
    });
    dragSource.setDropTarget(dt);
    f.add(dragSource);
    f.setVisible(true);
}
Also used : DropTargetAdapter(java.awt.dnd.DropTargetAdapter) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) DropTargetEvent(java.awt.dnd.DropTargetEvent) 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