Java Code Examples for java.awt.dnd.DnDConstants

The following are top voted examples for showing how to use java.awt.dnd.DnDConstants. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Logisim   File: ProjectExplorer.java   Source Code and License 6 votes vote down vote up
@Override
public boolean executeDrop(JTree targetTree, Object draggedNode, Object targetNode, int action) {
	if (action == DnDConstants.ACTION_COPY) {
		return false;
	} else if (action == DnDConstants.ACTION_MOVE) {
		if (canMove(draggedNode, targetNode)) {
			if (draggedNode == targetNode)
				return true;
			listener.moveRequested(new Event(null), (AddTool) draggedNode, (AddTool) targetNode);
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
 
Example 2
Project: jdk8u-jdk   File: ImageTransferTest.java   Source Code and License 6 votes vote down vote up
ImageDragSource() {
    formats = retrieveFormatsToTest();
    passedArray = new boolean[formats.length];
    final DragSourceListener dsl = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            System.err.println("Drop was successful=" + e.getDropSuccess());
            notifyTransferSuccess(e.getDropSuccess());
            if (++fi < formats.length) {
                leaveFormat(formats[fi]);
            }
        }
    };

    new DragSource().createDefaultDragGestureRecognizer(frame,
            DnDConstants.ACTION_COPY,
            dge -> dge.startDrag(null, new ImageSelection(image), dsl));
    leaveFormat(formats[fi]);
}
 
Example 3
Project: incubator-netbeans   File: DragDropUtilities.java   Source Code and License 6 votes vote down vote up
/** Utility method.
* @return true if given node supports given action,
* false otherwise.
*/
static boolean checkNodeForAction(Node node, int dragAction) {
    if (
        node.canCut() &&
            ((dragAction == DnDConstants.ACTION_MOVE) || (dragAction == DnDConstants.ACTION_COPY_OR_MOVE))
    ) {
        return true;
    }

    if (
        node.canCopy() &&
            ((dragAction == DnDConstants.ACTION_COPY) || (dragAction == DnDConstants.ACTION_COPY_OR_MOVE) ||
            (dragAction == DnDConstants.ACTION_LINK) || (dragAction == DnDConstants.ACTION_REFERENCE))
    ) {
        return true;
    }

    // hmmm, conditions not satisfied..
    return false;
}
 
Example 4
Project: incubator-netbeans   File: CategoryTest.java   Source Code and License 6 votes vote down vote up
/**
 * Test of moveItem method, of class org.netbeans.modules.palette.Category.
 */
public void testMoveItemAfter() throws IOException {
    PaletteActions actions = new DummyActions();
    PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
    Model model = pc.getModel();

    Category[] categories = model.getCategories();
    
    Category cat = categories[0];
    Item[] itemsBeforeMove = cat.getItems();
    
    Item source = itemsBeforeMove[0];
    Item target = itemsBeforeMove[itemsBeforeMove.length-1];
    
    cat.dropItem( createTransferable( source ), DnDConstants.ACTION_COPY_OR_MOVE, target, false );
    
    Item[] itemsAfterMove = cat.getItems();
    
    assertEquals( itemsBeforeMove.length, itemsAfterMove.length );
    assertEquals( source.getName(), itemsAfterMove[itemsAfterMove.length-1].getName() );
    assertEquals( itemsBeforeMove[1].getName(), itemsAfterMove[0].getName() );
    assertEquals( target.getName(), itemsAfterMove[itemsAfterMove.length-1-1].getName() );
}
 
Example 5
Project: incubator-netbeans   File: DragAndDropHandlerTest.java   Source Code and License 6 votes vote down vote up
public void testCanDropText() throws Exception {
    PaletteActions actions = new DummyActions();
    PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
    Model model = pc.getModel();

    Category cat = model.getCategories()[0];
    
    DragAndDropHandler handler = new TextDragAndDropHandler();
    
    DataFlavor[] flavors = new DataFlavor[] { new DataFlavor( "text/xml" )  };
    assertTrue( handler.canDrop( cat.getLookup(), flavors, DnDConstants.ACTION_COPY_OR_MOVE ) );
    
    flavors = new DataFlavor[] { new DataFlavor( "text/html" )  };
    assertTrue( handler.canDrop( cat.getLookup(), flavors, DnDConstants.ACTION_COPY_OR_MOVE ) );
    
    flavors = new DataFlavor[] { new DataFlavor( "unsupported/mimetype" )  };
    assertFalse( handler.canDrop( cat.getLookup(), flavors, DnDConstants.ACTION_COPY_OR_MOVE ) );
}
 
Example 6
Project: openjdk-jdk10   File: MissingDragExitEventTest.java   Source Code and License 6 votes vote down vote up
private static void initAndShowUI() {
    frame = new JFrame("Test frame");

    frame.setSize(SIZE, SIZE);
    frame.setLocationRelativeTo(null);
    final JTextArea jta = new JTextArea();
    jta.setBackground(Color.RED);
    frame.add(jta);
    jta.setText("1234567890");
    jta.setFont(jta.getFont().deriveFont(150f));
    jta.setDragEnabled(true);
    jta.selectAll();
    jta.setDropTarget(new DropTarget(jta, DnDConstants.ACTION_COPY,
                                     new TestdropTargetListener()));
    jta.addMouseListener(new TestMouseAdapter());
    frame.setVisible(true);
}
 
Example 7
Project: openjdk-jdk10   File: XMouseDragGestureRecognizer.java   Source Code and License 6 votes vote down vote up
/**
 * Invoked when a mouse button is pressed on a component.
 */

public void mouseDragged(MouseEvent e) {
    if (!events.isEmpty()) { // gesture pending
        int dop = mapDragOperationFromModifiers(e);


        if (dop == DnDConstants.ACTION_NONE) {
            return;
        }

        MouseEvent trigger = (MouseEvent)events.get(0);

        Point      origin  = trigger.getPoint();
        Point      current = e.getPoint();

        int        dx      = Math.abs(origin.x - current.x);
        int        dy      = Math.abs(origin.y - current.y);

        if (dx > motionThreshold || dy > motionThreshold) {
            fireDragGestureRecognized(dop, ((MouseEvent)getTriggerEvent()).getPoint());
        } else
            appendEvent(e);
    }
}
 
Example 8
Project: openjdk-jdk10   File: XMouseDragGestureRecognizer.java   Source Code and License 6 votes vote down vote up
/**
 * determine the drop action from the event
 */

protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();
    int btns = mods & ButtonMask;

    // Do not allow right mouse button drag since Motif DnD does not
    // terminate drag operation on right mouse button release.
    if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
          btns == InputEvent.BUTTON2_DOWN_MASK)) {
        return DnDConstants.ACTION_NONE;
    }

    return
        SunDragSourceContextPeer.convertModifiersToDropAction(mods,
                                                              getSourceActions());
}
 
Example 9
Project: openjdk-jdk10   File: WMouseDragGestureRecognizer.java   Source Code and License 6 votes vote down vote up
/**
 * determine the drop action from the event
 */

protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();
    int btns = mods & ButtonMask;

    // Prohibit multi-button drags.
    if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
          btns == InputEvent.BUTTON2_DOWN_MASK ||
          btns == InputEvent.BUTTON3_DOWN_MASK)) {
        return DnDConstants.ACTION_NONE;
    }

    return
        SunDragSourceContextPeer.convertModifiersToDropAction(mods,
                                                              getSourceActions());
}
 
Example 10
Project: SubtitleDownloader   File: SubtitleDownloaderUI.java   Source Code and License 6 votes vote down vote up
@Override
public void drop(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY);
    try {
        Transferable t = dtde.getTransferable();
        DataFlavor[] dataFlavors = t.getTransferDataFlavors();
        for (DataFlavor df : dataFlavors) {
            if (df.isFlavorJavaFileListType()) {
                File[] filesArray = (File[]) ((List<File>) t.getTransferData(df)).toArray();
                pathNameTextField.setText(getFilesName(filesArray));
            }
        }
    } catch (UnsupportedFlavorException e2) {
    } catch (IOException ex) {
        Logger.getLogger(SubtitleDownloaderUI.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 11
Project: jdk8u-jdk   File: WMouseDragGestureRecognizer.java   Source Code and License 6 votes vote down vote up
/**
 * determine the drop action from the event
 */

protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();
    int btns = mods & ButtonMask;

    // Prohibit multi-button drags.
    if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
          btns == InputEvent.BUTTON2_DOWN_MASK ||
          btns == InputEvent.BUTTON3_DOWN_MASK)) {
        return DnDConstants.ACTION_NONE;
    }

    return
        SunDragSourceContextPeer.convertModifiersToDropAction(mods,
                                                              getSourceActions());
}
 
Example 12
Project: OpenJSharp   File: SunDropTargetContextPeer.java   Source Code and License 6 votes vote down vote up
/**
 * mapOperation
 */

private int mapOperation(int operation) {
    int[] operations = {
            DnDConstants.ACTION_MOVE,
            DnDConstants.ACTION_COPY,
            DnDConstants.ACTION_LINK,
    };
    int   ret = DnDConstants.ACTION_NONE;

    for (int i = 0; i < operations.length; i++) {
        if ((operation & operations[i]) == operations[i]) {
                ret = operations[i];
                break;
        }
    }

    return ret;
}
 
Example 13
Project: jdk8u-jdk   File: XDnDDragSourceProtocol.java   Source Code and License 6 votes vote down vote up
private boolean processXdndStatus(XClientMessageEvent xclient) {
    int action = DnDConstants.ACTION_NONE;

    /* Ignore XDnD messages from all other windows. */
    if (xclient.get_data(0) != getTargetWindow()) {
        return true;
    }

    if ((xclient.get_data(1) & XDnDConstants.XDND_ACCEPT_DROP_FLAG) != 0) {
        /* This feature is new in XDnD version 2, but we can use it as XDnD
           compliance only requires supporting version 3 and up. */
        action = XDnDConstants.getJavaActionForXDnDAction(xclient.get_data(4));
    }

    getProtocolListener().handleDragReply(action);

    return true;
}
 
Example 14
Project: OpenJSharp   File: XMouseDragGestureRecognizer.java   Source Code and License 6 votes vote down vote up
/**
 * Invoked when a mouse button is pressed on a component.
 */

public void mouseDragged(MouseEvent e) {
    if (!events.isEmpty()) { // gesture pending
        int dop = mapDragOperationFromModifiers(e);


        if (dop == DnDConstants.ACTION_NONE) {
            return;
        }

        MouseEvent trigger = (MouseEvent)events.get(0);

        Point      origin  = trigger.getPoint();
        Point      current = e.getPoint();

        int        dx      = Math.abs(origin.x - current.x);
        int        dy      = Math.abs(origin.y - current.y);

        if (dx > motionThreshold || dy > motionThreshold) {
            fireDragGestureRecognized(dop, ((MouseEvent)getTriggerEvent()).getPoint());
        } else
            appendEvent(e);
    }
}
 
Example 15
Project: OpenJSharp   File: XDragSourceContextPeer.java   Source Code and License 6 votes vote down vote up
private void doUpdateTargetWindow(long subwindow, long time) {
    long clientWindow = 0;
    long proxyWindow = 0;
    XDragSourceProtocol protocol = null;
    boolean isReceiver = false;

    if (subwindow != 0) {
        clientWindow = findClientWindow(subwindow);
    }

    if (clientWindow != 0) {
        Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
        while (dragProtocols.hasNext()) {
            XDragSourceProtocol dragProtocol = (XDragSourceProtocol)dragProtocols.next();
            if (dragProtocol.attachTargetWindow(clientWindow, time)) {
                protocol = dragProtocol;
                break;
            }
        }
    }

    /* Update the global state. */
    dragProtocol = protocol;
    targetAction = DnDConstants.ACTION_NONE;
    targetRootSubwindow = subwindow;
}
 
Example 16
Project: Tarski   File: JTableRenderer.java   Source Code and License 6 votes vote down vote up
public void drop(DropTargetDropEvent e)
{
	if (dragSource != null)
	{
		e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
		Point p = e.getLocation();
		int targetRow = rowAtPoint(p);

		Object edge = graph.insertEdge(null, null, null,
				dragSource.cell, JTableRenderer.this.cell, "sourceRow="
						+ sourceRow + ";targetRow=" + targetRow);
		graph.setSelectionCell(edge);

		// System.out.println("clearing drag source");
		dragSource = null;
		e.dropComplete(true);
	}
	else
	{
		e.rejectDrop();
	}
}
 
Example 17
Project: openjdk-jdk10   File: XDnDDragSourceProtocol.java   Source Code and License 6 votes vote down vote up
private boolean processXdndStatus(XClientMessageEvent xclient) {
    int action = DnDConstants.ACTION_NONE;

    /* Ignore XDnD messages from all other windows. */
    if (xclient.get_data(0) != getTargetWindow()) {
        return true;
    }

    if ((xclient.get_data(1) & XDnDConstants.XDND_ACCEPT_DROP_FLAG) != 0) {
        /* This feature is new in XDnD version 2, but we can use it as XDnD
           compliance only requires supporting version 3 and up. */
        action = XDnDConstants.getJavaActionForXDnDAction(xclient.get_data(4));
    }

    getProtocolListener().handleDragReply(action);

    return true;
}
 
Example 18
Project: pdfjumbler   File: JDragDropList.java   Source Code and License 5 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport info) {
	if (!info.isDrop()) {
		return false;
	}
	if (!canImportHere(info)) {
		if (
			(JDragDropList.this.dropListener != null) &&
			JDragDropList.this.dropListener.acceptDrop(JDragDropList.this, info)
		) {
			return JDragDropList.this.dropListener.handleDrop(JDragDropList.this, info);
		} else {
			return false;
		}
	}

	JDDLTransferData<T> data = getData(info);
	int destIndex = JDragDropList.this.getDropLocation().getIndex();		
	
	/*
	System.err.print("[ ");
	for (int index : data.getIndices()) {
		System.err.print(index + " ");
	}
	System.err.print("] -> ");
	System.err.println(destIndex);
	*/
	 
	if ((info.getDropAction() & DnDConstants.ACTION_COPY) != 0) {
		copyItems(data.getSourceList(), JDragDropList.this, data.getValuesList(), destIndex);
	} else if ((info.getDropAction() & DnDConstants.ACTION_MOVE) != 0) {
		moveItems(data.getSourceList(), JDragDropList.this, data.getIndices(), destIndex);	
	} else {
		return false;
	}
	
	return true;
}
 
Example 19
Project: openjdk-jdk10   File: MissingEventsOnModalDialogTest.java   Source Code and License 5 votes vote down vote up
private static void runTest() throws Exception {
    Frame sourceFrame = createFrame("Source Frame", 100, 100);
    Frame targetFrame = createFrame("Target Frame", 350, 350);

    DragSource defaultDragSource
            = DragSource.getDefaultDragSource();
    defaultDragSource.createDefaultDragGestureRecognizer(sourceFrame,
            DnDConstants.ACTION_COPY_OR_MOVE,
            new TestDragGestureListener());
    new DropTarget(targetFrame, DnDConstants.ACTION_COPY_OR_MOVE,
            new TestDropTargetListener(targetFrame));

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    sourceFrame.toFront();
    robot.waitForIdle();

    Point point = getCenterPoint(sourceFrame);
    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    mouseDragAndDrop(robot, point, getCenterPoint(targetFrame));

    long time = System.currentTimeMillis() + 1000;

    while (!passed) {
        if (time < System.currentTimeMillis()) {
            sourceFrame.dispose();
            targetFrame.dispose();
            throw new RuntimeException("Mouse clicked event is lost!");
        }
        Thread.sleep(10);
    }
    sourceFrame.dispose();
    targetFrame.dispose();
}
 
Example 20
Project: alevin-svn2   File: FileDropTargetListener.java   Source Code and License 5 votes vote down vote up
@Override
public void dragOver(DropTargetDragEvent dtde) {
	if ((dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor) || (uriFlavor != null && dtde
			.isDataFlavorSupported(uriFlavor)))
			&& canOpenFile())
		dtde.acceptDrag(DnDConstants.ACTION_REFERENCE);
	else
		dtde.rejectDrag();
}
 
Example 21
Project: incubator-netbeans   File: PackageViewChildren.java   Source Code and License 5 votes vote down vote up
/**
 * Copy handling
 */
@Override
public Transferable clipboardCopy () throws IOException {
    try {
        return new PackageTransferable (this, DnDConstants.ACTION_COPY);
    } catch (ClassNotFoundException e) {
        throw new AssertionError(e);
    }
}
 
Example 22
Project: incubator-netbeans   File: PackageViewChildren.java   Source Code and License 5 votes vote down vote up
@Override
public Transferable clipboardCut () throws IOException {
    try {
        return new PackageTransferable (this, DnDConstants.ACTION_MOVE);
    } catch (ClassNotFoundException e) {
        throw new AssertionError(e);
    }
}
 
Example 23
Project: incubator-netbeans   File: AcceptAction.java   Source Code and License 5 votes vote down vote up
public State dragEnter (Widget widget, WidgetDropTargetDragEvent event) {
    ConnectorState acceptable = provider.isAcceptable (widget, event.getPoint (), event.getTransferable ());

    if (acceptable == ConnectorState.ACCEPT) {
        event.acceptDrag (DnDConstants.ACTION_COPY_OR_MOVE);
        return State.CONSUMED;
    } else if (acceptable == ConnectorState.REJECT_AND_STOP) {
        event.rejectDrag ();
        return State.CONSUMED;
    }
    return State.REJECTED;
}
 
Example 24
Project: incubator-netbeans   File: AcceptAction.java   Source Code and License 5 votes vote down vote up
public State dragOver (Widget widget, WidgetDropTargetDragEvent event) {
    ConnectorState acceptable = provider.isAcceptable (widget, event.getPoint (), event.getTransferable ());

    if (acceptable == ConnectorState.ACCEPT) {
        event.acceptDrag (DnDConstants.ACTION_COPY_OR_MOVE);
        return State.CONSUMED;
    } else if (acceptable == ConnectorState.REJECT_AND_STOP) {
        event.rejectDrag ();
        return State.CONSUMED;
    }
    return State.REJECTED;
}
 
Example 25
Project: openjdk-jdk10   File: ImageTransferTest.java   Source Code and License 5 votes vote down vote up
void checkImage(DropTargetDropEvent dtde) {
    final Transferable t = dtde.getTransferable();
    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY);
        Image im;
        try {
            im = (Image) t.getTransferData(DataFlavor.imageFlavor);
            System.err.println("getTransferData was successful");
        } catch (Exception e) {
            System.err.println("Can't getTransferData: " + e);
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
            return;
        }

        if (im == null) {
            System.err.println("getTransferData returned null");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        } else if (areImagesIdentical(image, im)) {
            dtde.dropComplete(true);
            notifyTransferSuccess(true);
        } else {
            System.err.println("transferred image is different from initial image");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        }

    } else {
        System.err.println("imageFlavor is not supported by Transferable");
        dtde.rejectDrop();
        notifyTransferSuccess(false);
    }
}
 
Example 26
Project: incubator-netbeans   File: DragDropUtilities.java   Source Code and License 5 votes vote down vote up
/** Gets right transferable of given nodes (according to given
* drag action) and also converts the transferable.<br>
* Can be called only with correct action constant.
* @return The transferable.
*/
static Transferable getNodeTransferable(Node[] nodes, int dragAction)
throws IOException {
    Transferable[] tArray = new Transferable[nodes.length];

    for (int i = 0; i < nodes.length; i++) {
        if ((dragAction & DnDConstants.ACTION_MOVE) != 0) {
            tArray[i] = nodes[i].clipboardCut();
        } else {
            tArray[i] = nodes[i].drag ();
        }
    }
    Transferable result;
    if (tArray.length == 1) {
        // only one node, so return regular single transferable
        result = tArray[0];
    } else {
        // enclose the transferables into multi transferable
        result = ExternalDragAndDrop.maybeAddExternalFileDnd( new Multi(tArray) );
    }

    Clipboard c = getClipboard();
    if (c instanceof ExClipboard) {
        return ((ExClipboard) c).convert(result);
    } else {
        return result;
    }
}
 
Example 27
Project: incubator-netbeans   File: QuietEditorPane.java   Source Code and License 5 votes vote down vote up
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    Collection<? extends ExternalDropHandler> handlers = Lookup.getDefault().lookupAll(ExternalDropHandler.class);
    for (ExternalDropHandler handler : handlers) {
        if (handler.canDrop(dtde)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY);
            isDragging = false;
            return;
        }
    }

    orig.dragEnter(dtde);
    isDragging = true;
}
 
Example 28
Project: incubator-netbeans   File: QuietEditorPane.java   Source Code and License 5 votes vote down vote up
@Override
public void dragOver(DropTargetDragEvent dtde) {
    Collection<? extends ExternalDropHandler> handlers = Lookup.getDefault().lookupAll(ExternalDropHandler.class);
    for (ExternalDropHandler handler : handlers) {
        if (handler.canDrop(dtde)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY);
            isDragging = false;
            return;
        }
    }

    orig.dragOver(dtde);
    isDragging = true;

}
 
Example 29
Project: jdk8u-jdk   File: SunDropTargetContextPeer.java   Source Code and License 5 votes vote down vote up
/**
 * rejectDrag
 */

public synchronized void rejectDrag() {
    if (currentDT == null) {
        throw new InvalidDnDOperationException("No Drag pending");
    }
    currentDA = DnDConstants.ACTION_NONE;
    dragRejected = true;
}
 
Example 30
Project: openjdk-jdk10   File: WMouseDragGestureRecognizer.java   Source Code and License 5 votes vote down vote up
/**
 * Invoked when the mouse exits a component.
 */

@Override
public void mouseExited(MouseEvent e) {

    if (!events.isEmpty()) { // gesture pending
        int dragAction = mapDragOperationFromModifiers(e);

        if (dragAction == DnDConstants.ACTION_NONE) {
            events.clear();
        }
    }
}
 
Example 31
Project: incubator-netbeans   File: CategoryTest.java   Source Code and License 5 votes vote down vote up
public void testDropItemBefore() throws IOException {
    PaletteActions actions = new DummyActions();
    PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
    Model model = pc.getModel();

    Category[] categories = model.getCategories();
    
    Category srcCat = categories[0];
    Item[] srcItemsBefore = srcCat.getItems();
    Item dropItem = srcItemsBefore[0];

    Category tgtCat = categories[1];
    Item[] tgtItemsBefore = tgtCat.getItems();
    Item target = tgtItemsBefore[5];
    
    tgtCat.dropItem( dropItem.cut(), DnDConstants.ACTION_COPY_OR_MOVE, target, true );
    
    //force all nodes in the palette to update their children
    pc.refresh();
    categories = model.getCategories();
    srcCat = categories[0];
    tgtCat = categories[1];
    
    Item[] srcItemsAfter = srcCat.getItems();
    Item[] tgtItemsAfter = tgtCat.getItems();
    
    assertEquals( srcItemsBefore.length, srcItemsAfter.length+1 );
    for( int i=0; i<srcItemsAfter.length; i++ ) {
        assertEquals( srcItemsBefore[i+1].getName(), srcItemsAfter[i].getName() );
    }
    
    assertEquals( tgtItemsBefore.length, tgtItemsAfter.length-1 );
    assertEquals( target.getName(), tgtItemsAfter[5+1].getName() );
    assertEquals( dropItem.getName(), tgtItemsAfter[5].getName() );
}
 
Example 32
Project: jdk8u-jdk   File: MotifDnDConstants.java   Source Code and License 5 votes vote down vote up
public static int getMotifActionsForJavaActions(int javaActions) {
    int motifActions = MOTIF_DND_NOOP;

    if ((javaActions & DnDConstants.ACTION_MOVE) != 0) {
        motifActions |= MOTIF_DND_MOVE;
    }
    if ((javaActions & DnDConstants.ACTION_COPY) != 0) {
        motifActions |= MOTIF_DND_COPY;
    }
    if ((javaActions & DnDConstants.ACTION_LINK) != 0) {
        motifActions |= MOTIF_DND_LINK;
    }

    return motifActions;
}
 
Example 33
Project: incubator-netbeans   File: DragAndDropHandlerTest.java   Source Code and License 5 votes vote down vote up
public void testCanDrop() throws Exception {
    PaletteActions actions = new DummyActions();
    PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
    Model model = pc.getModel();

    Category cat = model.getCategories()[0];
    
    DragAndDropHandler handler = DragAndDropHandler.getDefault();
    
    DataFlavor[] flavors = new DataFlavor[] { PaletteController.ITEM_DATA_FLAVOR };
    assertTrue( handler.canDrop( cat.getLookup(), flavors, DnDConstants.ACTION_COPY_OR_MOVE ) );
    
    flavors = new DataFlavor[] { new DataFlavor( "text/xml" )  };
    assertFalse( handler.canDrop( cat.getLookup(), flavors, DnDConstants.ACTION_COPY_OR_MOVE ) );
}
 
Example 34
Project: incubator-netbeans   File: DragAndDropHandlerTest.java   Source Code and License 5 votes vote down vote up
public void testDoDropItemToOtherCategory() throws Exception {
    PaletteActions actions = new DummyActions();
    PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
    Model model = pc.getModel();

    Category[] categories = model.getCategories();
    
    Category srcCat = categories[0];
    Item[] srcItemsBefore = srcCat.getItems();
    Item dropItem = srcItemsBefore[0];

    Category tgtCat = categories[1];
    Item[] tgtItemsBefore = tgtCat.getItems();
    Item target = tgtItemsBefore[5];
    
    DragAndDropHandler handler = DragAndDropHandler.getDefault();
    
    assertTrue( handler.doDrop( tgtCat.getLookup(), dropItem.cut(), DnDConstants.ACTION_COPY_OR_MOVE, 5 ) );
    
    //force all nodes in the palette to update their children
    pc.refresh();
    categories = model.getCategories();
    srcCat = categories[0];
    tgtCat = categories[1];
    
    Item[] srcItemsAfter = srcCat.getItems();
    Item[] tgtItemsAfter = tgtCat.getItems();
    
    assertEquals( srcItemsBefore.length, srcItemsAfter.length+1 );
    for( int i=0; i<srcItemsAfter.length; i++ ) {
        assertEquals( srcItemsBefore[i+1].getName(), srcItemsAfter[i].getName() );
    }
    
    assertEquals( tgtItemsBefore.length, tgtItemsAfter.length-1 );
    assertEquals( target.getName(), tgtItemsAfter[5+1].getName() );
    assertEquals( dropItem.getName(), tgtItemsAfter[5].getName() );
}
 
Example 35
Project: incubator-netbeans   File: DnDSupport.java   Source Code and License 5 votes vote down vote up
public void register(Component c) {
    synchronized( recognizers ) {
        DragGestureRecognizer dgr = recognizers.get( c );
        if( null == dgr ) {
            dgr = dragSource.createDefaultDragGestureRecognizer(c, DnDConstants.ACTION_MOVE, this);
            recognizers.put( c, dgr );
        }
    }
}
 
Example 36
Project: incubator-netbeans   File: DnDSupport.java   Source Code and License 5 votes vote down vote up
public void dragEnter(DropTargetDragEvent e) {
    if( e.isDataFlavorSupported( buttonDataFlavor ) || e.isDataFlavorSupported( actionDataFlavor ) ) {
        e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        isButtonDrag = true; //in case use is dragging something from the customizer window
    } else if( e.isDataFlavorSupported( toolbarDataFlavor ) ) {
        e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    } else {
        e.rejectDrag();
    }
}
 
Example 37
Project: incubator-netbeans   File: DnDSupport.java   Source Code and License 5 votes vote down vote up
public void dragOver(DropTargetDragEvent e) {
    if( e.isDataFlavorSupported( buttonDataFlavor ) || e.isDataFlavorSupported( actionDataFlavor ) ) {
        updateDropGesture( e );
        if( !validateDropPosition() ) {
            e.rejectDrag();
        } else {
            e.acceptDrag( DnDConstants.ACTION_COPY_OR_MOVE );
        }
    } else if( e.isDataFlavorSupported( toolbarDataFlavor ) ) {
        e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    } else {
        e.rejectDrag();
    }
}
 
Example 38
Project: jdk8u-jdk   File: SunDropTargetContextPeer.java   Source Code and License 5 votes vote down vote up
/**
 * acceptDrag
 */

public synchronized void acceptDrag(int dragOperation) {
    if (currentDT == null) {
        throw new InvalidDnDOperationException("No Drag pending");
    }
    currentDA = mapOperation(dragOperation);
    if (currentDA != DnDConstants.ACTION_NONE) {
        dragRejected = false;
    }
}
 
Example 39
Project: incubator-netbeans   File: IndexedCustomizer.java   Source Code and License 5 votes vote down vote up
/** Initiating the drag */
public void dragGestureRecognized(DragGestureEvent dge) {
    // check allowed actions
    if ((dge.getDragAction() & DnDConstants.ACTION_MOVE) == 0) {
        return;
    }

    // prepare transferable and start the drag
    int index = comp.locationToIndex(dge.getDragOrigin());

    // no index, then no dragging...
    if (index < 0) {
        return;
    }

    //      System.out.println("Starting drag..."); // NOI18N
    // create our flavor for transferring the index
    myFlavor = new DataFlavor(
            String.class, NbBundle.getBundle(IndexedCustomizer.class).getString("IndexedFlavor")
        );

    try {
        dge.startDrag(DragSource.DefaultMoveDrop, new IndexTransferable(myFlavor, index), this);

        // remember the gesture
        this.dge = dge;
    } catch (InvalidDnDOperationException exc) {
        Logger.getLogger(IndexedCustomizer.class.getName()).log(Level.WARNING, null, exc);

        // PENDING notify user - cannot start the drag
    }
}
 
Example 40
Project: incubator-netbeans   File: IndexedCustomizer.java   Source Code and License 5 votes vote down vote up
/** User drag over us */
public void dragOver(DropTargetDragEvent dtde) {
    if (!checkConditions(dtde)) {
        dtde.rejectDrag();

        if (lastIndex >= 0) {
            cellRenderer.draggingExit();
            comp.repaint(comp.getCellBounds(lastIndex, lastIndex));
            lastIndex = -1;
        }
    } else {
        dtde.acceptDrag(DnDConstants.ACTION_MOVE);

        int index = comp.locationToIndex(dtde.getLocation());

        if (lastIndex == index) {
            cellRenderer.draggingOver(index, ids.getDragGestureEvent().getDragOrigin(), dtde.getLocation());
        } else {
            if (lastIndex < 0) {
                lastIndex = index;
            }

            cellRenderer.draggingExit();
            cellRenderer.draggingEnter(index, ids.getDragGestureEvent().getDragOrigin(), dtde.getLocation());
            comp.repaint(comp.getCellBounds(lastIndex, index));
            lastIndex = index;
        }
    }
}
 
Example 41
Project: openjdk-jdk10   File: SunDragSourceContextPeer.java   Source Code and License 5 votes vote down vote up
public static int convertModifiersToDropAction(final int modifiers,
                                               final int supportedActions) {
    int dropAction = DnDConstants.ACTION_NONE;

    /*
     * Fix for 4285634.
     * Calculate the drop action to match Motif DnD behavior.
     * If the user selects an operation (by pressing a modifier key),
     * return the selected operation or ACTION_NONE if the selected
     * operation is not supported by the drag source.
     * If the user doesn't select an operation search the set of operations
     * supported by the drag source for ACTION_MOVE, then for
     * ACTION_COPY, then for ACTION_LINK and return the first operation
     * found.
     */
    switch (modifiers & (InputEvent.SHIFT_DOWN_MASK |
                         InputEvent.CTRL_DOWN_MASK)) {
    case InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK:
        dropAction = DnDConstants.ACTION_LINK; break;
    case InputEvent.CTRL_DOWN_MASK:
        dropAction = DnDConstants.ACTION_COPY; break;
    case InputEvent.SHIFT_DOWN_MASK:
        dropAction = DnDConstants.ACTION_MOVE; break;
    default:
        if ((supportedActions & DnDConstants.ACTION_MOVE) != 0) {
            dropAction = DnDConstants.ACTION_MOVE;
        } else if ((supportedActions & DnDConstants.ACTION_COPY) != 0) {
            dropAction = DnDConstants.ACTION_COPY;
        } else if ((supportedActions & DnDConstants.ACTION_LINK) != 0) {
            dropAction = DnDConstants.ACTION_LINK;
        }
    }

    return dropAction & supportedActions;
}
 
Example 42
Project: Logisim   File: JTreeUtil.java   Source Code and License 5 votes vote down vote up
@Override
public final void dropActionChanged(DragSourceDragEvent dsde) {
	int action = dsde.getDropAction();
	if (action == DnDConstants.ACTION_COPY) {
		dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop);
	} else {
		if (action == DnDConstants.ACTION_MOVE) {
			dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveDrop);
		} else {
			dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveNoDrop);
		}
	}
}
 
Example 43
Project: jdk8u-jdk   File: MotifDnDConstants.java   Source Code and License 5 votes vote down vote up
public static int getJavaActionsForMotifActions(int motifActions) {
    int javaActions = DnDConstants.ACTION_NONE;

    if ((motifActions & MOTIF_DND_MOVE) != 0) {
        javaActions |= DnDConstants.ACTION_MOVE;
    }
    if ((motifActions & MOTIF_DND_COPY) != 0) {
        javaActions |= DnDConstants.ACTION_COPY;
    }
    if ((motifActions & MOTIF_DND_LINK) != 0) {
        javaActions |= DnDConstants.ACTION_LINK;
    }

    return javaActions;
}
 
Example 44
Project: incubator-netbeans   File: DBColumnDrop.java   Source Code and License 5 votes vote down vote up
/**
 * Returns <code>JTextField</code> palette item.
 *
 * @param dtde corresponding drop target drag event.
 * @return <code>JTextField</code> palette item.
 */
@Override
public PaletteItem getPaletteItem(DropTargetDragEvent dtde) {
    PaletteItem pItem;
    if (!assistantInitialized) {
        initAssistant();
    }
    if (!J2EEUtils.hasPrimaryKey(column.getDatabaseConnection(), column.getTableName())) {
        FormEditor.getAssistantModel(model).setContext("tableWithoutPK"); // NOI18N
        return null;
    }
    if (FormJavaSource.isInDefaultPackage(model)) {
        // 97982: default package
        FormEditor.getAssistantModel(model).setContext("columnDefaultPackage"); // NOI18N
        return null;
    }
    setBindingOnly(dtde.getDropAction() == DnDConstants.ACTION_MOVE);
    if (isBindingOnly()) {
        FormEditor.getAssistantModel(model).setContext("columnDropBinding", "columnDropComponent"); // NOI18N
        pItem = new PaletteItem(new ClassSource("javax.persistence.EntityManager", // NOI18N
                    new ClassSourceResolver.LibraryEntry(LibraryManager.getDefault().getLibrary("eclipselink"))), // NOI18N
                    null);
        pItem.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/j2ee/resources/binding.gif", false).getImage()); // NOI18N
    } else {
        pItem = new PaletteItem(new ClassSource("javax.swing.JTextField"), null); // NOI18N
    }
    return pItem;
}
 
Example 45
Project: marathonv5   File: EventQueueDevice.java   Source Code and License 5 votes vote down vote up
private Boolean handleDnD(Component component, int xoffset, int yoffset) {
    int dropAction;
    if (deviceState.isDnDCopyPressed()) {
        dropAction = DnDConstants.ACTION_COPY;
    } else {
        dropAction = DnDConstants.ACTION_MOVE;
    }
    Logger.getLogger(EventQueueDevice.class.getName()).info("Performing Drop");
    DnDHandler dnd = new DnDHandler(deviceState.getDragSource(), component, xoffset, yoffset, dropAction);
    return dnd.performDrop();
}
 
Example 46
Project: openjdk-jdk10   File: SourceFileListFrame.java   Source Code and License 5 votes vote down vote up
SourceFileListFrame() {
    super("Source File List Frame");
    extractFilesFromTheWorkingDirectory();
    initList();
    initGUI();
    new DragSource().createDefaultDragGestureRecognizer(list,
            DnDConstants.ACTION_COPY,this);
}
 
Example 47
Project: onprom   File: UMLDiagramPanel.java   Source Code and License 5 votes vote down vote up
public UMLDiagramPanel(DiagramEditor _editorLoader) {
  diagramEditor = _editorLoader;
  isOpenGLEnabled = Boolean.parseBoolean(System.getProperty("sun.java2d.opengl"));
  if (!isOpenGLEnabled) {
    logger.warn("OpenGL is not enabled, there could be some performance and quality issues. It can be enabled using -Dsun.java2d.opengl=true runtime argument.");
  }
  // we are going to listen mouse clicks and movements for various operations
  this.addMouseListener(this);
  this.addMouseMotionListener(this);
  this.addMouseWheelListener(this);
  this.setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() {
    @Override
    public void drop(DropTargetDropEvent dtde) {
      if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        try {
          dtde.acceptDrop(dtde.getDropAction());
          Object transferData = dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
          if (transferData != null && transferData instanceof List) {
            List files = (List) transferData;
            if (files.size() > 0) {
              diagramEditor.open((File) files.get(0));
              dtde.dropComplete(true);
            }
          }
        } catch (Exception e) {
          logger.error(e.getMessage(), e);
          InformationDialog.display(e.getMessage());
        }
      } else {
        dtde.rejectDrop();
      }
    }
  }));
  this.setBackground(Color.WHITE);
}
 
Example 48
Project: VASSAL-src   File: SetupStack.java   Source Code and License 5 votes vote down vote up
public View(Board b, SetupStack s) {
  myBoard = b;
  myGrid = b.getGrid();
  myStack = s;
  slot = myStack.getTopPiece();
  if (slot != null) {
    myPiece = slot.getPiece();
  }
  new DropTarget(this, DnDConstants.ACTION_MOVE, this);
  ds.createDefaultDragGestureRecognizer(this,
    DnDConstants.ACTION_MOVE, this);
  setFocusTraversalKeysEnabled(false);
}
 
Example 49
Project: Method_Trace_Tool   File: Trace.java   Source Code and License 5 votes vote down vote up
public static void drag()//定义的拖拽方法
{
    //panel表示要接受拖拽的控件
    new DropTarget(JlPath, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde)//重写适配器的drop方法
        {
            try {
                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor))//如果拖入的文件格式受支持
                {
                    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);//接收拖拽来的数据
                    List<File> list = (List<File>) (dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor));
                    String temp = "";
                    for (File file : list) {
                        temp = file.getAbsolutePath();
                        JlPath.setText(temp);
                        break;
                    }
                    //JOptionPane.showMessageDialog(null, temp);
                    dtde.dropComplete(true);//指示拖拽操作已完成
                } else {
                    dtde.rejectDrop();//否则拒绝拖拽来的数据
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example 50
Project: Logisim   File: JTreeUtil.java   Source Code and License 5 votes vote down vote up
@Override
public final void dragEnter(DragSourceDragEvent dsde) {
	int action = dsde.getDropAction();
	if (action == DnDConstants.ACTION_COPY) {
		dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop);
	} else {
		if (action == DnDConstants.ACTION_MOVE) {
			dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveDrop);
		} else {
			dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveNoDrop);
		}
	}
}
 
Example 51
Project: KernelHive   File: RepositoryViewerDragGestureListener.java   Source Code and License 5 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
	Cursor cursor = null;
	if(dge.getComponent() instanceof RepositoryViewer){
		RepositoryViewer rv = (RepositoryViewer) dge.getComponent();
		KernelRepositoryEntry kre = (KernelRepositoryEntry) rv.getSelectedValue();
		
		if(dge.getDragAction()==DnDConstants.ACTION_COPY){
			cursor = DragSource.DefaultCopyDrop;
		}
		
		dge.startDrag(cursor, new TransferableKernelRepositoryEntry(kre));
	}
}
 
Example 52
Project: Equella   File: FileListPanel.java   Source Code and License 5 votes vote down vote up
private void registerDndHandlers()
{
	new DragSource().createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY, new DragGestureListener()
	{
		@Override
		public void dragGestureRecognized(DragGestureEvent dge)
		{
			Transferable t = new FileInfoTransferable(getSelectedFile());
			dge.startDrag(DragSource.DefaultMoveDrop, t);
		}
	});

	DnDUtils.registerDropHandler(this, dropHandlers, new HoverHandler()
	{
		@Override
		public void hovering(DropTargetDragEvent e)
		{
			FileInfo fi = getFileUnderMouseCursor();
			if( fi == null )
			{
				int i = getListIndexUnderPoint(e.getLocation());
				if( i >= 0 )
				{
					fi = model.get(i);
				}
			}

			if( fi != null && fi.isDirectory() )
			{
				list.setSelectedValue(fi, true);
			}
			else
			{
				list.getSelectionModel().clearSelection();
			}
		}
	});
}
 
Example 53
Project: jdk8u-jdk   File: XMouseDragGestureRecognizer.java   Source Code and License 5 votes vote down vote up
/**
 * Invoked when a mouse button has been pressed on a component.
 */

public void mousePressed(MouseEvent e) {
    events.clear();

    if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
        try {
            motionThreshold = DragSource.getDragThreshold();
        } catch (Exception exc) {
            motionThreshold = 5;
        }
        appendEvent(e);
    }
}
 
Example 54
Project: OpenJSharp   File: SunDropTargetContextPeer.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
    }

}
 
Example 55
Project: OpenJSharp   File: SunDropTargetContextPeer.java   Source Code and License 5 votes vote down vote up
/**
 * upcall to handle exit messages
 */

private void handleExitMessage(final Component component,
                               final long nativeCtxt) {
    /*
     * Even though the return value is irrelevant for this event, it is
     * dispatched synchronously to fix 4393148 properly.
     */
    postDropTargetEvent(component, 0, 0, DnDConstants.ACTION_NONE,
                        DnDConstants.ACTION_NONE, null, nativeCtxt,
                        SunDropTargetEvent.MOUSE_EXITED,
                        SunDropTargetContextPeer.DISPATCH_SYNC);
}
 
Example 56
Project: jdk8u-jdk   File: SunDropTargetContextPeer.java   Source Code and License 5 votes vote down vote up
/**
 * signal drop complete
 */

public synchronized void dropComplete(boolean success) {
    if (dropStatus == STATUS_NONE) {
        throw new InvalidDnDOperationException("No Drop pending");
    }

    if (currentDTC != null) currentDTC.removeNotify();

    currentDT  = null;
    currentDTC = null;
    currentT   = null;
    currentA   = DnDConstants.ACTION_NONE;

    synchronized(_globalLock) {
        currentJVMLocalSourceTransferable = null;
    }

    dropStatus   = STATUS_NONE;
    dropComplete = true;

    try {
        doDropDone(success, currentDA, local != null);
    } finally {
        currentDA = DnDConstants.ACTION_NONE;
        // The native context is invalid after the drop is done.
        // Clear the reference to prohibit access.
        nativeDragContext = 0;
    }
}
 
Example 57
Project: openjdk-jdk10   File: SunDropTargetContextPeer.java   Source Code and License 5 votes vote down vote up
/**
 * acceptDrop
 */

public synchronized void acceptDrop(int dropOperation) {
    if (dropOperation == DnDConstants.ACTION_NONE)
        throw new IllegalArgumentException("invalid acceptDrop() action");

    if (dropStatus == STATUS_WAIT || dropStatus == STATUS_ACCEPT) {
        currentDA = currentA = mapOperation(dropOperation & currentSA);

        dropStatus   = STATUS_ACCEPT;
        dropComplete = false;
    } else {
        throw new InvalidDnDOperationException("invalid acceptDrop()");
    }
}
 
Example 58
Project: openjdk-jdk10   File: SourceFileListFrame.java   Source Code and License 5 votes vote down vote up
SourceFileListFrame() {
    super("Source File List Frame");
    extractFilesFromTheWorkingDirectory();
    initList();
    initGUI();
    new DragSource().createDefaultDragGestureRecognizer(list,
            DnDConstants.ACTION_COPY,this);
}
 
Example 59
Project: OpenJSharp   File: SunDropTargetContextPeer.java   Source Code and License 5 votes vote down vote up
/**
 * signal drop complete
 */

public synchronized void dropComplete(boolean success) {
    if (dropStatus == STATUS_NONE) {
        throw new InvalidDnDOperationException("No Drop pending");
    }

    if (currentDTC != null) currentDTC.removeNotify();

    currentDT  = null;
    currentDTC = null;
    currentT   = null;
    currentA   = DnDConstants.ACTION_NONE;

    synchronized(_globalLock) {
        currentJVMLocalSourceTransferable = null;
    }

    dropStatus   = STATUS_NONE;
    dropComplete = true;

    try {
        doDropDone(success, currentDA, local != null);
    } finally {
        currentDA = DnDConstants.ACTION_NONE;
        // The native context is invalid after the drop is done.
        // Clear the reference to prohibit access.
        nativeDragContext = 0;
    }
}
 
Example 60
Project: OpenJSharp   File: SunDragSourceContextPeer.java   Source Code and License 5 votes vote down vote up
public static int convertModifiersToDropAction(final int modifiers,
                                               final int supportedActions) {
    int dropAction = DnDConstants.ACTION_NONE;

    /*
     * Fix for 4285634.
     * Calculate the drop action to match Motif DnD behavior.
     * If the user selects an operation (by pressing a modifier key),
     * return the selected operation or ACTION_NONE if the selected
     * operation is not supported by the drag source.
     * If the user doesn't select an operation search the set of operations
     * supported by the drag source for ACTION_MOVE, then for
     * ACTION_COPY, then for ACTION_LINK and return the first operation
     * found.
     */
    switch (modifiers & (InputEvent.SHIFT_DOWN_MASK |
                         InputEvent.CTRL_DOWN_MASK)) {
    case InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK:
        dropAction = DnDConstants.ACTION_LINK; break;
    case InputEvent.CTRL_DOWN_MASK:
        dropAction = DnDConstants.ACTION_COPY; break;
    case InputEvent.SHIFT_DOWN_MASK:
        dropAction = DnDConstants.ACTION_MOVE; break;
    default:
        if ((supportedActions & DnDConstants.ACTION_MOVE) != 0) {
            dropAction = DnDConstants.ACTION_MOVE;
        } else if ((supportedActions & DnDConstants.ACTION_COPY) != 0) {
            dropAction = DnDConstants.ACTION_COPY;
        } else if ((supportedActions & DnDConstants.ACTION_LINK) != 0) {
            dropAction = DnDConstants.ACTION_LINK;
        }
    }

    return dropAction & supportedActions;
}