Java 类java.awt.dnd.DnDConstants 实例源码

项目:Logisim    文件:ProjectExplorer.java   
@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;
    }
}
项目:jdk8u-jdk    文件:ImageTransferTest.java   
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]);
}
项目:incubator-netbeans    文件:DragDropUtilities.java   
/** 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;
}
项目:incubator-netbeans    文件:CategoryTest.java   
/**
 * 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() );
}
项目:incubator-netbeans    文件:DragAndDropHandlerTest.java   
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 ) );
}
项目:openjdk-jdk10    文件:MissingDragExitEventTest.java   
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);
}
项目:openjdk-jdk10    文件:XMouseDragGestureRecognizer.java   
/**
 * 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);
    }
}
项目:openjdk-jdk10    文件:XMouseDragGestureRecognizer.java   
/**
 * 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());
}
项目:openjdk-jdk10    文件:WMouseDragGestureRecognizer.java   
/**
 * 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());
}
项目:SubtitleDownloader    文件:SubtitleDownloaderUI.java   
@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);
    }
}
项目:jdk8u-jdk    文件:WMouseDragGestureRecognizer.java   
/**
 * 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());
}
项目:OpenJSharp    文件:SunDropTargetContextPeer.java   
/**
 * 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;
}
项目:jdk8u-jdk    文件:XDnDDragSourceProtocol.java   
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;
}
项目:OpenJSharp    文件:XMouseDragGestureRecognizer.java   
/**
 * 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);
    }
}
项目:OpenJSharp    文件:XDragSourceContextPeer.java   
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;
}
项目:Tarski    文件:JTableRenderer.java   
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();
    }
}
项目:openjdk-jdk10    文件:XDnDDragSourceProtocol.java   
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;
}
项目:pdfjumbler    文件:JDragDropList.java   
@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;
}
项目:openjdk-jdk10    文件:MissingEventsOnModalDialogTest.java   
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();
}
项目:alevin-svn2    文件:FileDropTargetListener.java   
@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();
}
项目:incubator-netbeans    文件:PackageViewChildren.java   
/**
 * Copy handling
 */
@Override
public Transferable clipboardCopy () throws IOException {
    try {
        return new PackageTransferable (this, DnDConstants.ACTION_COPY);
    } catch (ClassNotFoundException e) {
        throw new AssertionError(e);
    }
}
项目:incubator-netbeans    文件:PackageViewChildren.java   
@Override
public Transferable clipboardCut () throws IOException {
    try {
        return new PackageTransferable (this, DnDConstants.ACTION_MOVE);
    } catch (ClassNotFoundException e) {
        throw new AssertionError(e);
    }
}
项目:incubator-netbeans    文件:AcceptAction.java   
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;
}
项目:incubator-netbeans    文件:AcceptAction.java   
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;
}
项目:openjdk-jdk10    文件:ImageTransferTest.java   
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);
    }
}
项目:incubator-netbeans    文件:DragDropUtilities.java   
/** 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;
    }
}
项目:incubator-netbeans    文件:QuietEditorPane.java   
@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;
}
项目:incubator-netbeans    文件:QuietEditorPane.java   
@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;

}
项目:jdk8u-jdk    文件:SunDropTargetContextPeer.java   
/**
 * rejectDrag
 */

public synchronized void rejectDrag() {
    if (currentDT == null) {
        throw new InvalidDnDOperationException("No Drag pending");
    }
    currentDA = DnDConstants.ACTION_NONE;
    dragRejected = true;
}
项目:openjdk-jdk10    文件:WMouseDragGestureRecognizer.java   
/**
 * 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();
        }
    }
}
项目:incubator-netbeans    文件:CategoryTest.java   
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() );
}
项目:jdk8u-jdk    文件:MotifDnDConstants.java   
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;
}
项目:incubator-netbeans    文件:DragAndDropHandlerTest.java   
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 ) );
}
项目:incubator-netbeans    文件:DragAndDropHandlerTest.java   
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() );
}
项目:incubator-netbeans    文件:DnDSupport.java   
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 );
        }
    }
}
项目:incubator-netbeans    文件:DnDSupport.java   
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();
    }
}
项目:incubator-netbeans    文件:DnDSupport.java   
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();
    }
}
项目:jdk8u-jdk    文件:SunDropTargetContextPeer.java   
/**
 * 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;
    }
}
项目:incubator-netbeans    文件:IndexedCustomizer.java   
/** 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
    }
}
项目:incubator-netbeans    文件:IndexedCustomizer.java   
/** 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;
        }
    }
}