List of usage examples for java.awt.datatransfer DataFlavor equals
@Deprecated public boolean equals(String s)
From source file:DnDDemo2.java
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (flavor.equals(flavors[0])) { return text; } else if (flavor.equals(flavors[1])) { return color; } else {/*from w ww .j ava 2 s .co m*/ throw new UnsupportedFlavorException(flavor); } }
From source file:DragImage.java
public boolean isDataFlavorSupported(DataFlavor flavor) { return flavor.equals(DataFlavor.imageFlavor); }
From source file:Dropper.java
/** * @see javax.swing.TransferHandler#canImport(javax.swing.JComponent, * java.awt.datatransfer.DataFlavor[]) *//*from w w w.j a va 2s . c o m*/ public boolean canImport(JComponent arg0, DataFlavor[] arg1) { for (int i = 0; i < arg1.length; i++) { DataFlavor flavor = arg1[i]; if (flavor.equals(DataFlavor.javaFileListFlavor)) { System.out.println("canImport: JavaFileList FLAVOR: " + flavor); return true; } if (flavor.equals(DataFlavor.stringFlavor)) { System.out.println("canImport: String FLAVOR: " + flavor); return true; } System.err.println("canImport: Rejected Flavor: " + flavor); } // Didn't find any that match, so: return false; }
From source file:DnDDemo2.java
public boolean isDataFlavorSupported(DataFlavor flavor) { for (int i = 0; i < flavors.length; i++) { if (flavor.equals(flavors[i])) { return true; }//from www . j a va 2 s . c o m } return false; }
From source file:ImageTransferTest.java
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (flavor.equals(DataFlavor.imageFlavor)) { return theImage; } else {/*from ww w.j a v a2 s .com*/ throw new UnsupportedFlavorException(flavor); } }
From source file:Dropper.java
/** * Do the actual import./* w w w . jav a2 s. co m*/ * * @see javax.swing.TransferHandler#importData(javax.swing.JComponent, * java.awt.datatransfer.Transferable) */ public boolean importData(JComponent comp, Transferable t) { DataFlavor[] flavors = t.getTransferDataFlavors(); System.out.println("Trying to import:" + t); System.out.println("... which has " + flavors.length + " flavors."); for (int i = 0; i < flavors.length; i++) { DataFlavor flavor = flavors[i]; try { 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()); // Now do something with the file... } 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()); // Do something with the contents... return true; } catch (MalformedURLException ex) { System.err.println("Not a valid URL"); return false; } // now do something with the String. } else { System.out.println("importData rejected: " + flavor); // Don't return; try next flavor. } } catch (IOException ex) { System.err.println("IOError getting data: " + ex); } catch (UnsupportedFlavorException e) { System.err.println("Unsupported Flavor: " + e); } } // If you get here, I didn't like the flavor. Toolkit.getDefaultToolkit().beep(); return false; }
From source file:JLabelDragSource.java
public boolean isDataFlavorSupported(DataFlavor fl) { for (int i = 0; i < flavors.length; i++) { if (fl.equals(flavors[i])) { return true; }/* ww w. ja v a2 s . co m*/ } return false; }
From source file:JLabelDragSource.java
public Object getTransferData(DataFlavor fl) { if (!isDataFlavorSupported(fl)) { return null; }/*from w w w . j a v a 2 s . c om*/ if (fl.equals(DataFlavor.stringFlavor)) { // String - return the text as a String return label.getText() + " (DataFlavor.stringFlavor)"; } else if (fl.equals(jLabelFlavor)) { // The JLabel itself - just return the label. return label; } else { // Plain text - return an InputStream try { String targetText = label.getText() + " (plain text flavor)"; int length = targetText.length(); ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStreamWriter w = new OutputStreamWriter(os); w.write(targetText, 0, length); w.flush(); byte[] bytes = os.toByteArray(); w.close(); return new ByteArrayInputStream(bytes); } catch (IOException e) { return null; } } }
From source file:net.sf.jabref.external.TransferableFileLinkSelection.java
@Override public boolean isDataFlavorSupported(DataFlavor dataFlavor) { LOGGER.debug("Query: " + dataFlavor.getHumanPresentableName() + " , " + dataFlavor.getDefaultRepresentationClass() + " , " + dataFlavor.getMimeType()); return dataFlavor.equals(DataFlavor.javaFileListFlavor) || dataFlavor.equals(DataFlavor.stringFlavor); }
From source file:EditorDropTarget2.java
protected boolean dropContent(Transferable transferable, DropTargetDropEvent dtde) { if (!pane.isEditable()) { // Can't drop content on a read-only text control return false; }//from ww w . j av a 2 s . c o m try { // Check for a match with the current content type DataFlavor[] flavors = dtde.getCurrentDataFlavors(); DataFlavor selectedFlavor = null; // Look for either plain text or a String. for (int i = 0; i < flavors.length; i++) { DataFlavor flavor = flavors[i]; if (flavor.equals(DataFlavor.plainTextFlavor) || flavor.equals(DataFlavor.stringFlavor)) { selectedFlavor = flavor; break; } } if (selectedFlavor == null) { // No compatible flavor - should never happen return false; } DnDUtils.debugPrintln("Selected flavor is " + selectedFlavor.getHumanPresentableName()); // Get the transferable and then obtain the data Object data = transferable.getTransferData(selectedFlavor); DnDUtils.debugPrintln("Transfer data type is " + data.getClass().getName()); String insertData = null; if (data instanceof InputStream) { // Plain text flavor String charSet = selectedFlavor.getParameter("charset"); InputStream is = (InputStream) data; byte[] bytes = new byte[is.available()]; is.read(bytes); try { insertData = new String(bytes, charSet); } catch (UnsupportedEncodingException e) { // Use the platform default encoding insertData = new String(bytes); } } else if (data instanceof String) { // String flavor insertData = (String) data; } if (insertData != null) { int selectionStart = pane.getCaretPosition(); pane.replaceSelection(insertData); pane.select(selectionStart, selectionStart + insertData.length()); return true; } return false; } catch (Exception e) { return false; } }