List of usage examples for java.awt.datatransfer DataFlavor DataFlavor
public DataFlavor(String mimeType) throws ClassNotFoundException
From source file:pkgrenamer.Main.java
static void onDropFiles(DropTargetDropEvent dtde, FileDropListener onDrop) { try {/*from ww w . ja v a 2s. c o m*/ Transferable transferable = dtde.getTransferable(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_MOVE); java.util.List<?> files = (java.util.List<?>) transferable .getTransferData(DataFlavor.javaFileListFlavor); File[] fa = new File[files.size()]; for (int i = 0; i < fa.length; i++) { fa[i] = (File) files.get(i); } onDrop.onDropFile(fa); dtde.getDropTargetContext().dropComplete(true); } else { if (sNixFileDataFlavor == null) { sNixFileDataFlavor = new DataFlavor("text/uri-list;class=java.lang.String"); } dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String data = (String) transferable.getTransferData(sNixFileDataFlavor); if (data != null) { ArrayList<File> fs = new ArrayList<>(); for (StringTokenizer st = new StringTokenizer(data, "\r\n"); st.hasMoreTokens();) { String token = st.nextToken().trim(); if (token.startsWith("#") || token.isEmpty()) { continue; } try { fs.add(new File(new URI(token))); } catch (Exception e) { } } onDrop.onDropFile(fs.toArray(new File[0])); dtde.getDropTargetContext().dropComplete(true); } else { dtde.rejectDrop(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:pl.otros.logview.gui.actions.read.DragAndDropFilesHandler.java
private void tryToImportUrl(TransferSupport support) throws UnsupportedFlavorException, IOException, ClassNotFoundException { URL transferData = (URL) support.getTransferable() .getTransferData(new DataFlavor(APPLICATION_X_JAVA_URL_DATA_FLAVOR)); openLogFile(VFS.getManager().resolveFile(transferData.toString())); }
From source file:pl.otros.logview.gui.actions.read.DragAndDropFilesHandler.java
private void tryToImportUriList(TransferSupport support) throws UnsupportedFlavorException, IOException, ClassNotFoundException { String transferData = (String) support.getTransferable().getTransferData(new DataFlavor(TEXT_URI_LIST)); String[] split = transferData.split("\n"); for (String string : split) { string = string.trim();/* w w w . j a v a 2s . c o m*/ if (StringUtils.isNotBlank(string)) { openLogFile(VFS.getManager().resolveFile(string)); } } }