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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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;
        }
    }
}