Java Code Examples for java.awt.datatransfer.DataFlavor#imageFlavor()

The following examples show how to use java.awt.datatransfer.DataFlavor#imageFlavor() . 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: ImageUtils.java    From markdown-image-kit with MIT License 6 votes vote down vote up
/**
 * Gets data from clipboard.
 *
 * @return the data from clipboard  map 中只有一对 kev-value
 */
@Nullable
public static Map<DataFlavor, Object> getDataFromClipboard() {
    Map<DataFlavor, Object> data = new HashMap<>(1);
    Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    if (transferable != null) {
        // 如果剪切板的内容是文件
        try {
            DataFlavor dataFlavor;
            if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                // List<File>
                dataFlavor = DataFlavor.javaFileListFlavor;
            } else if (transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                // Image
                dataFlavor = DataFlavor.imageFlavor;
            } else {
                return null;
            }
            Object object = transferable.getTransferData(dataFlavor);
            data.put(dataFlavor, object);
        } catch (IOException | UnsupportedFlavorException ignored) {
            // 如果 clipboard 没有文件, 不处理
        }
    }
    return data;
}
 
Example 2
Source File: FileDropDecorator.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
public DataFlavor[] getTransferDataFlavors() 
{   
    if( customFlavor != null )
        return new DataFlavor[]
        {   
           customFlavor,
           DATA_FLAVOR,
           DataFlavor.imageFlavor
        }; 
    else
        return new DataFlavor[]
        {   
        	DATA_FLAVOR,
            DataFlavor.imageFlavor
        }; 
}
 
Example 3
Source File: DataFlavorComparatorTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DataTransferer.DataFlavorComparator comparator = new DataTransferer.DataFlavorComparator();
    DataFlavor flavor1 = DataFlavor.imageFlavor;
    DataFlavor flavor2 = DataFlavor.selectionHtmlFlavor;
    if (comparator.compare(flavor1, flavor2) == 0) {
        throw new RuntimeException(flavor1.getMimeType() + " and " + flavor2.getMimeType() +
            " should not be equal");
    }
}
 
Example 4
Source File: DataFlavorComparatorTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DataTransferer.DataFlavorComparator comparator = new DataTransferer.DataFlavorComparator();
    DataFlavor flavor1 = DataFlavor.imageFlavor;
    DataFlavor flavor2 = DataFlavor.selectionHtmlFlavor;
    if (comparator.compare(flavor1, flavor2) == 0) {
        throw new RuntimeException(flavor1.getMimeType() + " and " + flavor2.getMimeType() +
            " should not be equal");
    }
}
 
Example 5
Source File: DataFlavorComparatorTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DataTransferer.DataFlavorComparator comparator = new DataTransferer.DataFlavorComparator();
    DataFlavor flavor1 = DataFlavor.imageFlavor;
    DataFlavor flavor2 = DataFlavor.selectionHtmlFlavor;
    if (comparator.compare(flavor1, flavor2) == 0) {
        throw new RuntimeException(flavor1.getMimeType() + " and " + flavor2.getMimeType() +
            " should not be equal");
    }
}
 
Example 6
Source File: DefaultExternalDropHandlerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testGetFileList() throws ClassNotFoundException, URISyntaxException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    DefaultExternalDropHandler handler = new DefaultExternalDropHandler();
    DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");

    Transferable t = new TransferableImpl( new ArrayList(), new DataFlavor[] { DataFlavor.imageFlavor, DataFlavor.stringFlavor } );
    assertNull( handler.getFileList( t ) );

    List<File> list = new ArrayList<File>( 2 );
    list.add( new File("//somedir/somefile.someext") );
    list.add( new File("c:\\somedir\\somefile.someext") );
    t = new TransferableImpl( list, new DataFlavor[] { DataFlavor.javaFileListFlavor, DataFlavor.stringFlavor } );

    List<File> extractedList = handler.getFileList( t );
    assertNotNull( extractedList );
    assertEquals( 2, extractedList.size() );
    for( Iterator i=list.iterator(); i.hasNext(); ) {
        assertTrue( extractedList.contains( i.next() ) );
    }

    String uriList = "file:///somedir/somefile.someext\r\nfile:/c:/somedir/somefile.someext";
    t = new TransferableImpl( uriList, new DataFlavor[] { uriListFlavor, DataFlavor.stringFlavor } );
    extractedList = handler.getFileList( t );
    assertNotNull( extractedList );
    assertEquals( 2, extractedList.size() );
    assertTrue( extractedList.contains( new File( new URI("file:///somedir/somefile.someext") ) ) );
    assertTrue( extractedList.contains( new File( new URI("file:/c:/somedir/somefile.someext") ) ) );
}
 
Example 7
Source File: DataFlavorComparatorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Comparator<DataFlavor> comparator = DataFlavorUtil.getDataFlavorComparator();
    DataFlavor flavor1 = DataFlavor.imageFlavor;
    DataFlavor flavor2 = DataFlavor.selectionHtmlFlavor;
    if (comparator.compare(flavor1, flavor2) == 0) {
        throw new RuntimeException(flavor1.getMimeType() + " and " + flavor2.getMimeType() +
            " should not be equal");
    }
}
 
Example 8
Source File: DataFlavorComparatorTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DataTransferer.DataFlavorComparator comparator = new DataTransferer.DataFlavorComparator();
    DataFlavor flavor1 = DataFlavor.imageFlavor;
    DataFlavor flavor2 = DataFlavor.selectionHtmlFlavor;
    if (comparator.compare(flavor1, flavor2) == 0) {
        throw new RuntimeException(flavor1.getMimeType() + " and " + flavor2.getMimeType() +
            " should not be equal");
    }
}
 
Example 9
Source File: ImageTransferable.java    From PyramidShader with GNU General Public License v3.0 4 votes vote down vote up
public DataFlavor[] getTransferDataFlavors() {
	return new DataFlavor[] {DataFlavor.imageFlavor};
}
 
Example 10
Source File: TransferableImage.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public DataFlavor[] getTransferDataFlavors() {
	DataFlavor[] flavors = new DataFlavor[1];
	flavors[0] = DataFlavor.imageFlavor;
	return flavors;
}
 
Example 11
Source File: SnapshotTool.java    From osp with GNU General Public License v3.0 4 votes vote down vote up
public DataFlavor[] getTransferDataFlavors() {
  return new DataFlavor[] {DataFlavor.imageFlavor};
}
 
Example 12
Source File: SystemUtil.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
public DataFlavor[] getTransferDataFlavors() { 
	return new DataFlavor[]{DataFlavor.imageFlavor}; 
}
 
Example 13
Source File: TransferableBufferedImage.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public DataFlavor[] getTransferDataFlavors()
{
	return new DataFlavor[]{DataFlavor.imageFlavor};
}
 
Example 14
Source File: DesktopTransferHandler.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public DataFlavor[] getTransferDataFlavors() {
    return new DataFlavor[]{
            DataFlavor.imageFlavor};
}
 
Example 15
Source File: PlayerControls.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DataFlavor[] getTransferDataFlavors() {
    DataFlavor[] flavors = new DataFlavor[1];
    flavors[0] = DataFlavor.imageFlavor;
    return flavors;
}
 
Example 16
Source File: ContactGroupTransferHandler.java    From Spark with Apache License 2.0 4 votes vote down vote up
@Override
public DataFlavor[] getTransferDataFlavors() {
          return new DataFlavor[]{DataFlavor.imageFlavor};
      }
 
Example 17
Source File: ClipImage.java    From energy2d with GNU Lesser General Public License v3.0 4 votes vote down vote up
public DataFlavor[] getTransferDataFlavors() {
	return new DataFlavor[] { DataFlavor.imageFlavor };
}
 
Example 18
Source File: ImageSelection.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
@MustNotContainNull
public DataFlavor[] getTransferDataFlavors() {
  return new DataFlavor[] {DataFlavor.imageFlavor};
}
 
Example 19
Source File: ClipboardHandler.java    From Spade with GNU General Public License v3.0 4 votes vote down vote up
public DataFlavor[] getTransferDataFlavors()
{
	return new DataFlavor[]{DataFlavor.imageFlavor};
}
 
Example 20
Source File: ImageUtilsTest.java    From markdown-image-kit with MIT License 4 votes vote down vote up
public DataFlavor[] getTransferDataFlavors() {
    return new DataFlavor[] {DataFlavor.imageFlavor};
}