List of usage examples for java.awt.datatransfer DataFlavor getMimeType
public String getMimeType()
From source file:org.fseek.simon.swing.filetree.dnd.FileTransferHandler.java
@Override public boolean canImport(TransferSupport support) { DataFlavor[] dataFlavors = support.getDataFlavors(); for (DataFlavor f : supportedFlavors) { String suppMime = f.getMimeType(); for (DataFlavor dataFlavor : dataFlavors) { if (dataFlavor == null) continue; ;// w w w . j a v a2 s .co m if (dataFlavor.getMimeType().equals(suppMime)) { return this.hasFile.canImport(support); } } } return false; }
From source file:org.fseek.simon.swing.filetree.dnd.FileTransferHandler.java
public boolean importData(TransferSupport support, int action) { Transferable transferable = support.getTransferable(); DataFlavor[] dataFlavors = support.getDataFlavors(); File[] transferData = null;//from w ww . ja va 2 s . co m //check if we support one of the data flavors for (DataFlavor dataFlavor : dataFlavors) { String mimeType = dataFlavor.getMimeType(); if (mimeType.equals(urlFlavor.getMimeType())) { transferData = getFromURL(transferable); } else if (mimeType.equals(DataFlavor.javaFileListFlavor.getMimeType())) { transferData = getFile(transferable); } else if (mimeType.equals(uriList.getMimeType())) { transferData = getFromFileString(transferable); } if (transferData != null) { return hasFile.importFile(transferData, action, support.getDropLocation()); } } if (transferData == null) { Logger.getLogger(FileTransferHandler.class.getName()).log(Level.INFO, "Unsupported flavor: {0}", dataFlavors[0].getMimeType()); } return false; }
From source file:pl.otros.logview.gui.actions.read.DragAndDropFilesHandler.java
private boolean isURL(TransferSupport support) { DataFlavor[] dataFlavors = support.getDataFlavors(); boolean isUrl = false; for (DataFlavor dataFlavor : dataFlavors) { if (dataFlavor.getMimeType().equals(APPLICATION_X_JAVA_URL_DATA_FLAVOR)) { isUrl = true;/*from w ww . j av a2 s .c o m*/ break; } } LOGGER.info("Data transfer is list of file: " + isUrl); return isUrl; }
From source file:pl.otros.logview.gui.actions.read.DragAndDropFilesHandler.java
private boolean isUriList(TransferSupport support) { DataFlavor[] dataFlavors = support.getDataFlavors(); boolean isUriList = false; for (DataFlavor dataFlavor : dataFlavors) { if (dataFlavor.getMimeType().equals(TEXT_URI_LIST)) { isUriList = true;/*from w w w . j a v a 2s.c om*/ break; } } LOGGER.info("Data transfer is URI list: " + isUriList); return isUriList; }
From source file:tk.tomby.tedit.core.Workspace.java
/** * Creates a new WorkSpace object./* w ww .ja v a 2 s . c o m*/ */ public Workspace() { super(); setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); MessageManager.addMessageListener(MessageManager.BUFFER_GROUP_NAME, new IMessageListener<BufferMessage>() { public void receiveMessage(BufferMessage message) { Workspace.this.receiveMessage(message); } }); MessageManager.addMessageListener(MessageManager.PREFERENCE_GROUP_NAME, new IMessageListener<PreferenceMessage>() { public void receiveMessage(PreferenceMessage message) { Workspace.this.receiveMessage(message); } }); bufferPane = new JTabbedPane(); bufferPane.setMinimumSize(new Dimension(600, 400)); bufferPane.setPreferredSize(new Dimension(800, 600)); bufferPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); bottomPort = createDockingPort(0, 80); rightPort = createDockingPort(80, 0); leftPort = createDockingPort(80, 0); splitPaneRight = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, bufferPane, rightPort); splitPaneLeft = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPort, splitPaneRight); splitPaneBottom = createSplitPane(JSplitPane.VERTICAL_SPLIT, splitPaneLeft, bottomPort); bufferPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { MessageManager .sendMessage(new WorkspaceMessage(evt.getSource(), bufferPane.getSelectedComponent())); } }); bufferPane.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { splitPaneLeft.setDividerLocation(0.0d); splitPaneBottom.setDividerLocation(1.0d); splitPaneRight.setDividerLocation(1.0d); } } }); DropTarget dropTarget = new DropTarget(bufferPane, new DropTargetAdapter() { public void drop(DropTargetDropEvent dtde) { if (log.isDebugEnabled()) { log.debug("drop start"); } try { if (log.isDebugEnabled()) { log.debug(dtde.getSource()); } Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (int i = 0; i < flavors.length; i++) { DataFlavor flavor = flavors[i]; if (log.isDebugEnabled()) { log.debug("mime-type:" + flavor.getMimeType()); } if (flavor.isMimeTypeEqual("text/plain")) { final Object obj = tr.getTransferData(flavor); if (log.isDebugEnabled()) { log.debug(obj); } if (obj instanceof String) { TaskManager.execute(new Runnable() { public void run() { BufferFactory factory = new BufferFactory(); IBuffer buffer = factory.createBuffer(); buffer.open((String) obj); addBuffer(buffer); } }); } dtde.dropComplete(true); return; } } } catch (UnsupportedFlavorException e) { log.warn(e.getMessage(), e); } catch (IOException e) { log.warn(e.getMessage(), e); } dtde.rejectDrop(); if (log.isDebugEnabled()) { log.debug("drop end"); } } }); bufferPane.setDropTarget(dropTarget); this.add(BorderLayout.CENTER, splitPaneBottom); }
From source file:zsk.JFCMainClient.java
/** * processing event of dropping a HTTP URL, YT-Video Image or plain text (URL) onto the frame * /*from w w w.ja v a 2s . 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); }