List of usage examples for java.awt.datatransfer DataFlavor javaFileListFlavor
DataFlavor javaFileListFlavor
To view the source code for java.awt.datatransfer DataFlavor javaFileListFlavor.
Click Source Link
From source file:MyTree.java
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { if (comp instanceof MyTree) { for (int i = 0; i < transferFlavors.length; i++) { if (!transferFlavors[i].equals(DataFlavor.javaFileListFlavor)) { return false; }/* www . j av a 2s . com*/ } return true; } return false; }
From source file:Main.java
public boolean importData(JComponent comp, Transferable t) { DataFlavor[] flavors = t.getTransferDataFlavors(); System.out.println("Trying to import:" + t); for (int i = 0; i < flavors.length; i++) { DataFlavor flavor = flavors[i]; try {//from w w w. j av a 2s .c om if (flavor.equals(DataFlavor.javaFileListFlavor)) { System.out.println("importData: FileListFlavor"); List l = (List) t.getTransferData(DataFlavor.javaFileListFlavor); Iterator iter = l.iterator(); while (iter.hasNext()) { File file = (File) iter.next(); System.out.println("GOT FILE: " + file.getCanonicalPath()); } return true; } else if (flavor.equals(DataFlavor.stringFlavor)) { System.out.println("importData: String Flavor"); String fileOrURL = (String) t.getTransferData(flavor); System.out.println("GOT STRING: " + fileOrURL); try { URL url = new URL(fileOrURL); System.out.println("Valid URL: " + url.toString()); return true; } catch (MalformedURLException ex) { System.err.println("Not a valid URL"); return false; } } else { System.out.println("importData rejected: " + flavor); } } catch (IOException ex) { System.err.println("IOError getting data: " + ex); } catch (UnsupportedFlavorException e) { System.err.println("Unsupported Flavor: " + e); } } return false; }
From source file:net.sf.keystore_explorer.gui.dnd.KeyStoreEntryTransferable.java
/** * Get supported transfer data flavors./* w w w .ja v a2 s . c o m*/ * * @return Supported data flavors */ @Override public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { DataFlavor.javaFileListFlavor, DataFlavor.stringFlavor }; }
From source file:com.mirth.connect.client.ui.components.ChannelTableTransferHandler.java
@Override public boolean importData(TransferSupport support) { if (canImport(support)) { try {/*from ww w.ja v a2s . com*/ if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { List<File> fileList = (List<File>) support.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); final boolean showAlerts = (fileList.size() == 1); // Submit each import task to a single-threaded executor so they always import one at a time. Executor executor = Executors.newSingleThreadExecutor(); for (final File file : fileList) { if (FilenameUtils.isExtension(file.getName(), "xml")) { executor.execute(new Runnable() { @Override public void run() { importFile(file, showAlerts); } }); } } return true; } else if (support.isDataFlavorSupported(ChannelTableTransferable.CHANNEL_DATA_FLAVOR)) { List<Object> list = (List<Object>) support.getTransferable() .getTransferData(ChannelTableTransferable.CHANNEL_DATA_FLAVOR); List<Channel> channels = new ArrayList<Channel>(); for (Object obj : list) { if (obj instanceof Channel) { channels.add((Channel) obj); } else { return false; } } if (support.getDropLocation() instanceof JTable.DropLocation) { return moveChannels(channels, ((JTable.DropLocation) support.getDropLocation()).getRow()); } } } catch (Exception e) { // Let it return false } } return false; }
From source file:org.feistymeow.dragdrop.DragonTransferHandler.java
@Override public boolean importData(TransferSupport support) { if (support == null) return false; logger.debug("importData: at base..."); if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { logger.debug("importing data with java files flavor"); List<Object> files = ListTransferable.extractData(support.getTransferable()); if ((files != null) && (files.size() != 0)) { c_provider.consumeDropList(files, support.getDropLocation().getDropPoint()); return true; }/* w w w. j a v a2 s .c om*/ } else if (support.isDataFlavorSupported(ListTransferable.getURIListFlavor1()) || support.isDataFlavorSupported(ListTransferable.getURIListFlavor2())) { logger.debug("importing data with uri list flavor"); List<Object> files = ListTransferable.extractData(support.getTransferable()); if ((files != null) && (files.size() != 0)) { c_provider.consumeDropList(files, support.getDropLocation().getDropPoint()); return true; } } logger.warn("passing importData request to superclass, which will probably fail."); return super.importData(support); }
From source file:net.sf.keystore_explorer.gui.dnd.KeyStoreEntryTransferable.java
/** * Is supplied data flavor supported?//from ww w.j a va 2 s . co m * * @param dataFlavor * Data flavor * @return True if it is */ @Override public boolean isDataFlavorSupported(DataFlavor dataFlavor) { return (dataFlavor == DataFlavor.javaFileListFlavor) || (dataFlavor == DataFlavor.stringFlavor); }
From source file:net.sf.jabref.external.TransferableFileLinkSelection.java
@Override public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { DataFlavor.javaFileListFlavor };//, DataFlavor.stringFlavor}; }
From source file:se.trixon.pacoma.ui.PagePanel.java
private void init() { mDropTarget = new DropTarget() { @Override/*from w w w.jav a2s . c om*/ public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); LinkedList<File> droppedFiles = new LinkedList<>( (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)); List<File> invalidFiles = new LinkedList<>(); droppedFiles.forEach((droppedFile) -> { if (droppedFile.isFile() && FilenameUtils.isExtension(droppedFile.getName().toLowerCase(Locale.getDefault()), new String[] { "jpg", "jpeg", "png" })) { //all ok } else { invalidFiles.add(droppedFile); } }); invalidFiles.forEach((invalidFile) -> { droppedFiles.remove(invalidFile); System.out.println("remomve invalid file: " + invalidFile.getAbsolutePath()); }); droppedFiles.forEach((droppedFile) -> { System.out.println("accept: " + droppedFile.getAbsolutePath()); }); mCollage.addFiles(droppedFiles); } catch (UnsupportedFlavorException | IOException ex) { System.err.println(ex.getMessage()); } } }; setDropTarget(mDropTarget); }
From source file:se.trixon.solos.core.panel.NavigatorPanel.java
private void init() { DropTarget dropTarget = new DropTarget() { @Override//from w w w .j a va 2 s. c o m public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); List<File> droppedFiles = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); File file = droppedFiles.get(0); if (droppedFiles.size() == 1) { if (file.isDirectory()) { setPath(file); } else if (file.isFile()) { setPath(file.getParentFile()); } } else { setPath(file.getParentFile()); } directoryChanged(); } catch (UnsupportedFlavorException | IOException ex) { } } }; textField.setDropTarget(dropTarget); }
From source file:javazoom.jlgui.player.amp.skin.DropTargetAdapter.java
protected boolean isDragOk(DropTargetDragEvent e) { // Check DataFlavor DataFlavor[] dfs = e.getCurrentDataFlavors(); DataFlavor tdf = null;//from w w w . j a v a2s.co m for (int i = 0; i < dfs.length; i++) { if (DataFlavor.javaFileListFlavor.equals(dfs[i])) { tdf = dfs[i]; break; } else if (DataFlavor.stringFlavor.equals(dfs[i])) { tdf = dfs[i]; break; } } // Only file list allowed. if (tdf != null) { // Only DnD COPY allowed. if ((e.getSourceActions() & DnDConstants.ACTION_COPY) != 0) { return true; } else return false; } else return false; }