List of usage examples for java.awt.datatransfer DataFlavor isFlavorTextType
public boolean isFlavorTextType()
From source file:Main.java
public static void main(String[] args) { DataFlavor df = DataFlavor.stringFlavor; System.out.println(df.isFlavorTextType()); }
From source file:zsk.JFCMainClient.java
/** * processing event of dropping a HTTP URL, YT-Video Image or plain text (URL) onto the frame * //w w w .j ava 2 s . c o m * seems not to work with M$-IE (8,9) - what a pity! */ public void drop(DropTargetDropEvent dtde) { Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); DataFlavor fl = null; String str = ""; debugoutput("DataFlavors found: ".concat(Integer.toString(flavors.length))); for (int i = 0; i < flavors.length; i++) { fl = flavors[i]; if (fl.isFlavorTextType() /* || fl.isMimeTypeEqual("text/html") || fl.isMimeTypeEqual("application/x-java-url") || fl.isMimeTypeEqual("text/uri-list")*/) { try { dtde.acceptDrop(dtde.getDropAction()); } catch (Throwable t) { } try { if (tr.getTransferData(fl) instanceof InputStreamReader) { debugoutput("Text-InputStream"); BufferedReader textreader = new BufferedReader((Reader) tr.getTransferData(fl)); String sline = ""; try { while (sline != null) { sline = textreader.readLine(); if (sline != null) str += sline; } } catch (Exception e) { } finally { textreader.close(); } str = str.replaceAll("<[^>]*>", ""); // remove HTML tags, especially a hrefs - ignore HTML characters like ß (which are no tags) } else if (tr.getTransferData(fl) instanceof InputStream) { debugoutput("Byte-InputStream"); InputStream input = new BufferedInputStream((InputStream) tr.getTransferData(fl)); int idata = input.read(); String sresult = ""; while (idata != -1) { if (idata != 0) sresult += new Character((char) idata).toString(); idata = input.read(); } // while debugoutput("sresult: ".concat(sresult)); } else { str = tr.getTransferData(fl).toString(); } } catch (IOException ioe) { } catch (UnsupportedFlavorException ufe) { } debugoutput("drop event text: ".concat(str).concat(" (").concat(fl.getMimeType()).concat(") ")); // insert text into textfield - almost the same as user drops text/url into this field // except special characaters -> from http://de.wikipedia.org/wiki/GNU-Projekt (GNU is not Unix)(„GNU is not Unix“) // two drops from same source .. one time in textfield and elsewhere - maybe we change that later?! if (str.matches(szYTREGEX.concat("(.*)"))) { synchronized (JFCMainClient.frame.textinputfield) { JFCMainClient.frame.textinputfield .setText(str.concat(JFCMainClient.frame.textinputfield.getText())); } debugoutput("breaking for-loop with str: ".concat(str)); break; } } else { String sv = "drop event unknown type: ".concat(fl.getHumanPresentableName()); //output(sv); debugoutput(sv); } } // for dtde.dropComplete(true); }