Java 类org.openide.util.datatransfer.MultiTransferObject 实例源码

项目:incubator-netbeans    文件:DragDropUtilitiesTest.java   
public void testMultiTransferableForCopy() throws Exception {
    N node = new N();
    N n2 = new N();
    N[] arr = { node, n2 };

    Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_COPY);

    assertEquals("One call to copy", 1, node.copy);
    assertEquals("One call to copy on n2", 1, n2.copy);
    assertEquals("Also one call to drag which delegates to copy", 1, node.drag);
    assertEquals("Also one call to drag which delegates to copy on n2", 1, n2.drag);
    assertEquals("No call to cut", 0, node.cut);
    assertEquals("No call to cut", 0, n2.cut);

    assertNotNull("Call to convertor", last);
    assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
    Object obj = last.getTransferData(ExTransferable.multiFlavor);
    if (!( obj instanceof MultiTransferObject)) {
        fail("It should be MultiTransferObject: " + obj);
    }
    MultiTransferObject m = (MultiTransferObject)obj;

    assertEquals("Two in multi", 2, m.getCount());
    assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
    assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
项目:incubator-netbeans    文件:DragDropUtilitiesTest.java   
public void testMultiTransferableForCut() throws Exception {
    N node = new N();
    N n2 = new N();
    N[] arr = { node, n2 };

    Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_MOVE);

    assertEquals("One call to cut ", 1, node.cut);
    assertEquals("One call to cut on n2", 1, n2.cut);
    assertEquals("No to drag", 0, node.drag);
    assertEquals("No to drag on n2", 0, n2.drag);
    assertEquals("No call to copy", 0, node.copy);
    assertEquals("No call to copy on n2", 0, n2.copy);

    assertNotNull("Call to convertor", last);
    assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
    Object obj = last.getTransferData(ExTransferable.multiFlavor);
    if (!( obj instanceof MultiTransferObject)) {
        fail("It should be MultiTransferObject: " + obj);
    }
    MultiTransferObject m = (MultiTransferObject)obj;

    assertEquals("Two in multi", 2, m.getCount());
    assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
    assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
项目:snap-desktop    文件:FileTable.java   
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
    if(info.isDataFlavorSupported(DataFlavor.stringFlavor))
        return true;
    try {
        if(info.getDataFlavors().length > 0) {

            Object transferData = info.getTransferable().getTransferData(info.getDataFlavors()[0]);
            if (transferData instanceof PNode) {
                return true;
            } else if(transferData instanceof MultiTransferObject) {
                final MultiTransferObject multi = (MultiTransferObject) transferData;
                boolean allPNode = true;
                DataFlavor dataFlavor = multi.getTransferDataFlavors(0)[0];
                for(int i=0; i < multi.getCount(); ++i) {
                    Object data = multi.getTransferData(i, dataFlavor);
                    if(!(data instanceof PNode)) {
                        allPNode = false;
                        break;
                    }
                }
                return allPNode;
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}