Java Code Examples for java.awt.datatransfer.Transferable#getTransferDataFlavors()

The following examples show how to use java.awt.datatransfer.Transferable#getTransferDataFlavors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqueakDisplay.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Override
public void drop(final DropTargetDropEvent dtde) {
    final Transferable transferable = dtde.getTransferable();
    for (final DataFlavor flavor : transferable.getTransferDataFlavors()) {
        if (DataFlavor.javaFileListFlavor.equals(flavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
            try {
                @SuppressWarnings("unchecked")
                final List<File> fileList = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
                final String[] fileArray = new String[fileList.size()];
                int i = 0;
                for (final File file : fileList) {
                    fileArray[i++] = file.getCanonicalPath();
                }
                image.dropPluginFileList = fileArray;
                addDragEvent(DRAG.DROP, dtde.getLocation());
                dtde.getDropTargetContext().dropComplete(true);
                return;
            } catch (final IOException | UnsupportedFlavorException e) {
                CompilerDirectives.transferToInterpreter();
                e.printStackTrace();
            }
        }
    }
    dtde.rejectDrop();
}
 
Example 2
Source File: ExplorerPanelTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public synchronized Transferable getLastTransferable(Transferable waitFor) throws Exception {
    WAIT: for (int loop = 0; loop < 60; loop++) {
        if (loop > 0) {
            wait(500);
        }
        if (lastTransferable != null) {
            java.awt.datatransfer.DataFlavor[] arr1 = lastTransferable.getTransferDataFlavors();
            java.awt.datatransfer.DataFlavor[] arr2 = waitFor.getTransferDataFlavors();

            if (Arrays.asList(arr1).equals(Arrays.asList(arr2))) {
                for (int i = 0; i < arr1.length; i++) {
                    Object f1 = convert(lastTransferable.getTransferData(arr1[i]));
                    Object f2 = convert(waitFor.getTransferData(arr1[i]));

                    if (!f1.equals(f2)) {
                        continue WAIT;
                    }
                }
                
                return lastTransferable;
            }
        }
    }
    return null;
}
 
Example 3
Source File: ColumnNodeTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testClipboardCopy() throws Exception {
    String tablename = "testtable";
    String pkName = "id";
    createBasicTable(tablename, pkName);

    TableNode tableNode = getTableNode(tablename);
    assertNotNull(tableNode);

    ColumnNode columnNode = getColumnNode(tableNode);
    assertNotNull(columnNode);
    assertTrue(columnNode.canCopy());

    Transferable transferable = (Transferable)columnNode.clipboardCopy();
    Set mimeTypes = new HashSet();
    DataFlavor[] flavors = transferable.getTransferDataFlavors();
    for (int i = 0; i < flavors.length; i++) {
        mimeTypes.add(flavors[i].getMimeType());
    }
    assertTrue(mimeTypes.contains("application/x-java-netbeans-dbexplorer-column; class=org.netbeans.api.db.explorer.DatabaseMetaDataTransfer$Column"));
    assertTrue(mimeTypes.contains("application/x-java-openide-nodednd; mask=1; class=org.openide.nodes.Node"));

    dropTable(tablename);
}
 
Example 4
Source File: TableNodeTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testClipboardCopy() throws Exception {
    String tablename = "testtable";
    String pkName = "id";
    createBasicTable(tablename, pkName);

    TableNode tableNode = getTableNode(tablename);
    assertNotNull(tableNode);
    assertTrue(tableNode.canCopy());

    Transferable transferable = (Transferable)tableNode.clipboardCopy();
    Set mimeTypes = new HashSet();
    DataFlavor[] flavors = transferable.getTransferDataFlavors();
    for (int i = 0; i < flavors.length; i++) {
        mimeTypes.add(flavors[i].getMimeType());
    }
    assertTrue(mimeTypes.contains("application/x-java-netbeans-dbexplorer-table; class=org.netbeans.api.db.explorer.DatabaseMetaDataTransfer$Table"));
    assertTrue(mimeTypes.contains("application/x-java-openide-nodednd; mask=1; class=org.openide.nodes.Node"));

    dropTable(tablename);
}
 
Example 5
Source File: ViewNodeTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testClipboardCopy() throws Exception {
    String tablename = "testtable";
    String pkName = "id";
    createBasicTable(tablename, pkName);

    String viewname = "testview";
    createView(viewname, "select id from testtable");

    ViewNode viewNode = getViewNode(viewname);
    assertNotNull(viewNode);
    assertTrue(viewNode.canCopy());

    Transferable transferable = (Transferable)viewNode.clipboardCopy();
    Set mimeTypes = new HashSet();
    DataFlavor[] flavors = transferable.getTransferDataFlavors();
    for (int i = 0; i < flavors.length; i++) {
        mimeTypes.add(flavors[i].getMimeType());
    }

    assertTrue(mimeTypes.contains("application/x-java-netbeans-dbexplorer-view; class=org.netbeans.api.db.explorer.DatabaseMetaDataTransfer$View"));
    assertTrue(mimeTypes.contains("application/x-java-openide-nodednd; mask=1; class=org.openide.nodes.Node"));

    dropView(viewname);
    dropTable(tablename);
}
 
Example 6
Source File: DataTransferer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map whose keys are all of the possible formats into which the
 * Transferable's transfer data flavors can be translated. The value of
 * each key is the DataFlavor in which the Transferable's data should be
 * requested when converting to the format.
 * <p>
 * The map keys are sorted according to the native formats preference
 * order.
 */
public SortedMap<Long,DataFlavor> getFormatsForTransferable(
                           Transferable contents, FlavorTable map)
{
    DataFlavor[] flavors = contents.getTransferDataFlavors();
    if (flavors == null) {
        return new TreeMap();
    }
    return getFormatsForFlavors(flavors, map);
}
 
Example 7
Source File: PageFlowAcceptProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ConnectorState isAcceptable(Widget widget, Point point, Transferable transferable) {
    
    System.out.print("\nPageFlowAcceptProvider: IS ACCEPTABLE HAS BEEN CALLED.");
    System.out.println("Widget: " + widget);
    System.out.println("Point: " + point);
    System.out.println("Transferable: " + transferable);
    DataFlavor[] dfs = transferable.getTransferDataFlavors();
    for( DataFlavor flavor: dfs){
        System.out.println("Data Flavor: " + flavor);
    }
    return ConnectorState.REJECT_AND_STOP;
}
 
Example 8
Source File: SunClipboard.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * @see java.awt.datatransfer.Clipboard#getAvailableDataFlavors
 * @since 1.5
 */
public DataFlavor[] getAvailableDataFlavors() {
    Transferable cntnts = getContextContents();
    if (cntnts != null) {
        return cntnts.getTransferDataFlavors();
    }

    long[] formats = getClipboardFormatsOpenClose();

    return DataTransferer.getInstance().
        getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable());
}
 
Example 9
Source File: SunDropTargetContextPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return current DataFlavors available
 */
// NOTE: This method may be called by privileged threads.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!

public DataFlavor[] getTransferDataFlavors() {
    final Transferable    localTransferable = local;

    if (localTransferable != null) {
        return localTransferable.getTransferDataFlavors();
    } else {
        return DataTransferer.getInstance().getFlavorsForFormatsAsArray
            (currentT, DataTransferer.adaptFlavorMap
                (currentDT.getFlavorMap()));
    }
}
 
Example 10
Source File: SunDropTargetContextPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return current DataFlavors available
 */
// NOTE: This method may be called by privileged threads.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!

public DataFlavor[] getTransferDataFlavors() {
    final Transferable    localTransferable = local;

    if (localTransferable != null) {
        return localTransferable.getTransferDataFlavors();
    } else {
        return DataTransferer.getInstance().getFlavorsForFormatsAsArray
            (currentT, DataTransferer.adaptFlavorMap
                (currentDT.getFlavorMap()));
    }
}
 
Example 11
Source File: SunClipboard.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see java.awt.Clipboard#getAvailableDataFlavors
 * @since 1.5
 */
public DataFlavor[] getAvailableDataFlavors() {
    Transferable cntnts = getContextContents();
    if (cntnts != null) {
        return cntnts.getTransferDataFlavors();
    }

    long[] formats = getClipboardFormatsOpenClose();

    return DataTransferer.getInstance().
        getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable());
}
 
Example 12
Source File: DataTransferer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map whose keys are all of the possible formats into which the
 * Transferable's transfer data flavors can be translated. The value of
 * each key is the DataFlavor in which the Transferable's data should be
 * requested when converting to the format.
 * <p>
 * The map keys are sorted according to the native formats preference
 * order.
 */
public SortedMap<Long,DataFlavor> getFormatsForTransferable(
                           Transferable contents, FlavorTable map)
{
    DataFlavor[] flavors = contents.getTransferDataFlavors();
    if (flavors == null) {
        return new TreeMap();
    }
    return getFormatsForFlavors(flavors, map);
}
 
Example 13
Source File: DataTransferer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map whose keys are all of the possible formats into which the
 * Transferable's transfer data flavors can be translated. The value of
 * each key is the DataFlavor in which the Transferable's data should be
 * requested when converting to the format.
 * <p>
 * The map keys are sorted according to the native formats preference
 * order.
 */
public SortedMap<Long,DataFlavor> getFormatsForTransferable(
                           Transferable contents, FlavorTable map)
{
    DataFlavor[] flavors = contents.getTransferDataFlavors();
    if (flavors == null) {
        return new TreeMap();
    }
    return getFormatsForFlavors(flavors, map);
}
 
Example 14
Source File: SunDropTargetContextPeer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * @return current DataFlavors available
 */
// NOTE: This method may be called by privileged threads.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!

public DataFlavor[] getTransferDataFlavors() {
    final Transferable    localTransferable = local;

    if (localTransferable != null) {
        return localTransferable.getTransferDataFlavors();
    } else {
        return DataTransferer.getInstance().getFlavorsForFormatsAsArray
            (currentT, DataTransferer.adaptFlavorMap
                (currentDT.getFlavorMap()));
    }
}
 
Example 15
Source File: FileDrop.java    From PDF4Teachers with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public void drop(DropTargetDropEvent e){
	
	Transferable transferable = e.getTransferable();
	DataFlavor[] types = transferable.getTransferDataFlavors();
	
       for(DataFlavor type : types){
          try{
             if(type.equals(DataFlavor.javaFileListFlavor)){
           	 e.acceptDrop(DnDConstants.ACTION_COPY);

			  for(Object o : (List) transferable.getTransferData(type)){
				  File file = (File) o;

				  if (isFileAcceptable(file)) {

					  if (component == 1) {
						  MainWindow.mainScreen.openFile(file);
					  } else if (component == 2) {
						  MainWindow.lbFilesTab.openFiles(new File[]{file});
					  }
				  }

			  }
             }
          }catch (Exception e1){ e1.printStackTrace(); }
       }
       
       e.dropComplete(true);
}
 
Example 16
Source File: SunDropTargetContextPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return current DataFlavors available
 */
// NOTE: This method may be called by privileged threads.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!

public DataFlavor[] getTransferDataFlavors() {
    final Transferable    localTransferable = local;

    if (localTransferable != null) {
        return localTransferable.getTransferDataFlavors();
    } else {
        return DataTransferer.getInstance().getFlavorsForFormatsAsArray
            (currentT, DataTransferer.adaptFlavorMap
                (currentDT.getFlavorMap()));
    }
}
 
Example 17
Source File: SunClipboard.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see java.awt.Clipboard#getAvailableDataFlavors
 * @since 1.5
 */
public DataFlavor[] getAvailableDataFlavors() {
    Transferable cntnts = getContextContents();
    if (cntnts != null) {
        return cntnts.getTransferDataFlavors();
    }

    long[] formats = getClipboardFormatsOpenClose();

    return DataTransferer.getInstance().
        getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable());
}
 
Example 18
Source File: DataTransferer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Map whose keys are all of the possible formats into which the
 * Transferable's transfer data flavors can be translated. The value of
 * each key is the DataFlavor in which the Transferable's data should be
 * requested when converting to the format.
 * <p>
 * The map keys are sorted according to the native formats preference
 * order.
 */
public SortedMap<Long,DataFlavor> getFormatsForTransferable(
                           Transferable contents, FlavorTable map)
{
    DataFlavor[] flavors = contents.getTransferDataFlavors();
    if (flavors == null) {
        return new TreeMap();
    }
    return getFormatsForFlavors(flavors, map);
}
 
Example 19
Source File: SunDropTargetContextPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return current DataFlavors available
 */
// NOTE: This method may be called by privileged threads.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!

public DataFlavor[] getTransferDataFlavors() {
    final Transferable    localTransferable = local;

    if (localTransferable != null) {
        return localTransferable.getTransferDataFlavors();
    } else {
        return DataTransferer.getInstance().getFlavorsForFormatsAsArray
            (currentT, DataTransferer.adaptFlavorMap
                (currentDT.getFlavorMap()));
    }
}
 
Example 20
Source File: SunClipboard.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see java.awt.Clipboard#getAvailableDataFlavors
 * @since 1.5
 */
public DataFlavor[] getAvailableDataFlavors() {
    Transferable cntnts = getContextContents();
    if (cntnts != null) {
        return cntnts.getTransferDataFlavors();
    }

    long[] formats = getClipboardFormatsOpenClose();

    return DataTransferer.getInstance().
        getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable());
}