Java Code Examples for java.awt.datatransfer.DataFlavor#javaFileListFlavor()
The following examples show how to use
java.awt.datatransfer.DataFlavor#javaFileListFlavor() .
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 |
/** * 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: GenericDialogPlus.java From ij-ridgedetection with GNU General Public License v2.0 | 6 votes |
/** * Gets the string. * * @param event * the event * @return the string * @throws IOException * Signals that an I/O exception has occurred. * @throws UnsupportedFlavorException * the unsupported flavor exception */ @SuppressWarnings("unchecked") static String getString(DropTargetDropEvent event) throws IOException, UnsupportedFlavorException { String text = null; DataFlavor fileList = DataFlavor.javaFileListFlavor; if (event.isDataFlavorSupported(fileList)) { event.acceptDrop(DnDConstants.ACTION_COPY); List<File> list = (List<File>) event.getTransferable().getTransferData(fileList); text = list.get(0).getAbsolutePath(); } else if (event.isDataFlavorSupported(DataFlavor.stringFlavor)) { event.acceptDrop(DnDConstants.ACTION_COPY); text = (String) event.getTransferable().getTransferData(DataFlavor.stringFlavor); if (text.startsWith("file://")) text = text.substring(7); text = stripSuffix(stripSuffix(text, "\n"), "\r").replaceAll("%20", " "); } else { event.rejectDrop(); return null; } event.dropComplete(text != null); return text; }
Example 3
Source File: KeyStoreEntryTransferable.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
/** * Get transfer data. * * @param dataFlavor * Data flavor * @return Transfer data * @throws UnsupportedFlavorException * If the requested data flavor is not supported * @throws IOException * If an I/O problem occurred */ @Override public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException, IOException { if (!isDataFlavorSupported(dataFlavor)) { throw new UnsupportedFlavorException(dataFlavor); } if (dataFlavor == DataFlavor.javaFileListFlavor) { String tempDir = System.getProperty("java.io.tmpdir"); File tmpFile = new File(tempDir, dragEntry.getFileName()); tmpFile.deleteOnExit(); try (FileOutputStream fos = new FileOutputStream(tmpFile)) { fos.write(dragEntry.getContent()); fos.flush(); } List<File> list = new ArrayList<>(); list.add(tmpFile); return list; } else { return dragEntry.getContentString(); } }
Example 4
Source File: DataFolderPasteTypesTest.java From netbeans with Apache License 2.0 | 6 votes |
/** * Test for bug 233673. * * @throws java.io.IOException */ public void testJavaFileListWithRelativePaths() throws IOException { FileObject testFO = FileUtil.createData(testFileSystem.getRoot(), "absoluteTestFile.txt"); File absoluteTestFile = FileUtil.toFile(testFO); File relativeTestFile = new File("relativeFile.txt"); ArrayList fileList = new ArrayList(2); fileList.add(relativeTestFile); fileList.add(absoluteTestFile); Transferable t = new MockTransferable( new DataFlavor[]{DataFlavor.javaFileListFlavor}, fileList); DataFolder.FolderNode node = (DataFolder.FolderNode) folderNode; ArrayList<PasteType> list = new ArrayList<PasteType>(); node.createPasteTypes(t, list); assertEquals("Relative path should be skipped", 1, list.size()); PasteType paste = (PasteType) list.get(0); paste.paste(); FileObject[] children = testFileSystem.getRoot().getFileObject( "testDir").getChildren(); assertEquals(1, children.length); assertEquals(children[0].getNameExt(), "absoluteTestFile.txt"); }
Example 5
Source File: DefaultExternalDropHandlerTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testCanDrop() throws ClassNotFoundException { DefaultExternalDropHandler handler = new DefaultExternalDropHandler(); DataFlavor[] flavors = new DataFlavor[] { DataFlavor.imageFlavor }; assertFalse( handler.canDrop( flavors ) ); flavors = new DataFlavor[] { DataFlavor.imageFlavor, DataFlavor.stringFlavor }; assertFalse( handler.canDrop( flavors ) ); flavors = new DataFlavor[] { DataFlavor.javaFileListFlavor }; assertTrue( handler.canDrop( flavors ) ); flavors = new DataFlavor[] { DataFlavor.javaFileListFlavor, DataFlavor.imageFlavor }; assertTrue( handler.canDrop( flavors ) ); DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String"); flavors = new DataFlavor[] { uriListFlavor }; assertTrue( handler.canDrop( flavors ) ); flavors = new DataFlavor[] { uriListFlavor, DataFlavor.imageFlavor }; assertTrue( handler.canDrop( flavors ) ); flavors = new DataFlavor[] { uriListFlavor, DataFlavor.javaFileListFlavor, DataFlavor.imageFlavor }; assertTrue( handler.canDrop( flavors ) ); }
Example 6
Source File: GhidraFileChooserPanel.java From ghidra with Apache License 2.0 | 5 votes |
private void setupDragAndDrop() { acceptableFlavors = new DataFlavor[] { DataFlavor.javaFileListFlavor, }; // set up drop stuff dropTargetAdapter = new DropTgtAdapter(this, DnDConstants.ACTION_COPY_OR_MOVE, acceptableFlavors); dropTarget = new DropTarget(filenameTextField, DnDConstants.ACTION_COPY_OR_MOVE, dropTargetAdapter, true); dropTarget.setActive(true); }
Example 7
Source File: GhidraFileChooserPanel.java From ghidra with Apache License 2.0 | 5 votes |
/** * @see docking.dnd.Droppable#add(java.lang.Object, java.awt.dnd.DropTargetDropEvent, java.awt.datatransfer.DataFlavor) */ @Override public void add(Object obj, DropTargetDropEvent e, DataFlavor f) { if (f == DataFlavor.javaFileListFlavor) { List<?> files = (java.util.List<?>) obj; if (files.size() > 0) { File file = (File) files.get(0); filenameTextField.setText(file.getAbsolutePath()); if (listener != null) { listener.fileDropped(file); } } } }
Example 8
Source File: DnDEventImpl.java From consulo with Apache License 2.0 | 5 votes |
public DataFlavor[] getTransferDataFlavors() { if (myAttachedObject instanceof Transferable) { return ((Transferable)myAttachedObject).getTransferDataFlavors(); } else if (myAttachedObject instanceof FileFlavorProvider) { return new DataFlavor[]{ourDataFlavor, DataFlavor.javaFileListFlavor, LinuxDragAndDropSupport.uriListFlavor}; } else if (myAttachedObject instanceof DnDNativeTarget.EventInfo) { return ((DnDNativeTarget.EventInfo)myAttachedObject).getFlavors(); } return new DataFlavor[]{ourDataFlavor}; }
Example 9
Source File: FileTransferable.java From pumpernickel with MIT License | 4 votes |
@Override public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { DataFlavor.javaFileListFlavor }; }
Example 10
Source File: FileListTransferable.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 11
Source File: FileListTransferable.java From hottub with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 12
Source File: FileListTransferable.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 13
Source File: FileListTransferable.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 14
Source File: FileListTransferable.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 15
Source File: FileListTransferable.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 16
Source File: FileTransferable.java From netbeans-mmd-plugin with Apache License 2.0 | 4 votes |
public FileTransferable(@Nonnull @MustNotContainNull final Collection<File> files) { this.files = Collections.unmodifiableList(new ArrayList<>(files)); this.flavors = new DataFlavor[]{DataFlavor.javaFileListFlavor}; }
Example 17
Source File: FileListTransferable.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 18
Source File: FileListTransferable.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 19
Source File: FileListTransferable.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }
Example 20
Source File: FileListTransferable.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public DataFlavor[] getTransferDataFlavors() { return new DataFlavor [] {DataFlavor.javaFileListFlavor}; }