List of usage examples for java.awt.datatransfer Transferable isDataFlavorSupported
public boolean isDataFlavorSupported(DataFlavor flavor);
From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java
public void drop(DropTargetDropEvent dtde) { try {/* w ww . j a v a 2 s. com*/ Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator<File> iterator = fileList.iterator(); if (fileList.size() == 1) { File file = (File) iterator.next(); importTransformer(parent.readFileToString(file)); } } else if (tr.isDataFlavorSupported(TreeTransferable.MAPPER_DATA_FLAVOR) || tr.isDataFlavorSupported(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Object mapperTransferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR); Object messageBuilderTransferData = tr .getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR); if (mapperTransferData != null && !parent.isAcceleratorKeyPressed()) { Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR); MapperDropData data = (MapperDropData) transferData; addNewStep(data.getVariable(), data.getVariable(), data.getMapping(), MAPPER); } else if (mapperTransferData != null && parent.isAcceleratorKeyPressed()) { Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR); MapperDropData data2 = (MapperDropData) transferData; MessageBuilderDropData data = new MessageBuilderDropData(data2.getNode(), MirthTree.constructPath(data2.getNode().getParent(), "msg", "").toString(), ""); addNewStep(MirthTree.constructMessageBuilderStepName(null, data.getNode()), data.getMessageSegment(), data.getMapping(), MESSAGE_BUILDER); } else if (messageBuilderTransferData != null) { Object transferData = tr.getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR); MessageBuilderDropData data = (MessageBuilderDropData) transferData; addNewStep(MirthTree.constructMessageBuilderStepName(null, data.getNode()), data.getMessageSegment(), data.getMapping(), MESSAGE_BUILDER); } } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java
public void drop(DropTargetDropEvent evt) { logger.debug("=-> drop"); try {//from ww w .j av a2 s . com Transferable t = evt.getTransferable(); if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { logger.debug(" Accepting 'string' data flavor..."); evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String s = (String) t.getTransferData(DataFlavor.stringFlavor); evt.getDropTargetContext().dropComplete(true); logger.debug("DnD: '" + s + "'"); if (s != null) { int indexOf = s.indexOf("\n"); if (indexOf != -1) { dragAndDropReference = new DragAndDropReference(s.substring(indexOf + 1), s.substring(0, indexOf), DragAndDropReference.BROWSER_LINK); } else { dragAndDropReference = new DragAndDropReference(s, DragAndDropReference.BROWSER_LINK); } } } else { if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { logger.debug(" Accepting 'file list' data flavor..."); evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); List<Object> list = (List<Object>) t.getTransferData(DataFlavor.javaFileListFlavor); if (list != null) { Iterator<Object> iterator = list.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next instanceof File) { logger.debug(" DnD file: " + next); dragAndDropReference = new DragAndDropReference(((File) next).getAbsolutePath(), DragAndDropReference.EXPLORER_LINK); } } } } else { logger.debug("DnD rejected! "); dragAndDropReference = null; // DataFlavor[] dfs=t.getTransferDataFlavors(); // for (int i = 0; i < dfs.length; i++) { // logger.debug(" "+i+" ... "+dfs[i].getMimeType()); // logger.debug(" "+i+" ... // "+dfs[i].getDefaultRepresentationClassAsString()); // logger.debug(" "+i+" ... // "+dfs[i].getHumanPresentableName()); // } } } } catch (Exception e) { logger.debug("Drag&Drop error:", e); dragAndDropReference = null; } OutlineJPanel.getInstance().enableDisableAttachToolbarButton(); if (dragAndDropReference != null) { JOptionPane.showMessageDialog(this, "Dropped local/web resource reference stored! Use \n'clip' icon from Notebook outline toolbar to attach it.", "Drag&Drop Info", JOptionPane.INFORMATION_MESSAGE); dragAndDropReference.debug(); } logger.debug("<-= drop"); }
From source file:org.languagetool.gui.Main.java
private String getClipboardText() { // get text from clipboard or selection: Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection(); if (clipboard == null) { // on Windows clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); }//from w w w . j a va 2s . c o m String s; Transferable data = clipboard.getContents(this); try { if (data != null && data.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) { DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor(); try (Reader sr = df.getReaderForText(data)) { s = StringTools.readerToString(sr); } } else { s = ""; } } catch (Exception ex) { s = data.toString(); } return s; }
From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java
private void pdsTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pdsTableMouseReleased if (evt.isPopupTrigger()) { copyMenuItem.setEnabled(!pdsTable.getSelectionModel().isSelectionEmpty()); Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this); pasteMenuItem.setEnabled(contents.isDataFlavorSupported(DataFlavor.stringFlavor)); tablePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); }//w ww . j a v a 2 s . c o m }
From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java
private void pdsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pdsTableMousePressed if (evt.isPopupTrigger()) { copyMenuItem.setEnabled(!pdsTable.getSelectionModel().isSelectionEmpty()); Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this); pasteMenuItem.setEnabled(contents.isDataFlavorSupported(DataFlavor.stringFlavor)); tablePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); }//w w w . j a va2 s .c om }
From source file:ded.ui.DiagramController.java
/** Try to read the clipboard contents as a Diagram. Return null and * display an error if we cannot. */ private Diagram getClipboardAsDiagram() { // Let's start with the "selection" because if it is valid JSON // then it's probably what we want. String selErrorMessage = null; String selContents = null;/*from w ww .j a v a2s. c o m*/ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection(); if (clipboard == null) { // Probably we're running on something other than X Windows, // so we thankfully don't have to deal with the screwy // "selection" concept. } else { Transferable clipData = clipboard.getContents(clipboard); if (clipData == null) { selErrorMessage = "Nothing is in the \"selection\"."; } else { try { if (clipData.isDataFlavorSupported(DataFlavor.stringFlavor)) { selContents = (String) (clipData.getTransferData(DataFlavor.stringFlavor)); // Try to parse it. try { return Diagram.parseJSONString(selContents); } catch (JSONException e) { selErrorMessage = "Could not parse selection data as Diagram JSON: " + e; } } else { selErrorMessage = "The data in the selection is not a string."; } } catch (Exception e) { selErrorMessage = "Error while retrieving selection data: " + e; } } } // Now try again with the clipboard. String clipErrorMessage = null; String clipContents = null; clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); if (clipboard == null) { clipErrorMessage = "getSystemClipboard returned null?!"; } else { Transferable clipData = clipboard.getContents(clipboard); if (clipData == null) { clipErrorMessage = "Nothing is in the clipboard."; } else { try { if (clipData.isDataFlavorSupported(DataFlavor.stringFlavor)) { clipContents = (String) (clipData.getTransferData(DataFlavor.stringFlavor)); try { return Diagram.parseJSONString(clipContents); } catch (JSONException e) { clipErrorMessage = "Could not parse clipboard data as Diagram JSON: " + e; } } else { clipErrorMessage = "The data in the clipboard is not a string."; } } catch (Exception e) { clipErrorMessage = "Error while retrieving clipboard data: " + e; } } } // Both methods failed, and we have one or two error messages. // Decide what to show. if (selErrorMessage == null) { this.errorMessageBox(clipErrorMessage); } else if (selContents == null && clipContents != null) { this.errorMessageBox(clipErrorMessage); } else if (selContents != null && clipContents == null) { this.errorMessageBox(selErrorMessage); } else if (selContents.equals(clipContents)) { this.errorMessageBox(clipErrorMessage + " (The selection and clipboard contents are the same.)"); } else { this.errorMessageBox("Failed to read either the selection or the clipboard. " + selErrorMessage + " " + clipErrorMessage); } return null; }
From source file:com.pironet.tda.TDA.java
private void getLogfileFromClipboard() { Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); String text = null;/* w w w. j a v a 2 s. c o m*/ try { if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { text = (String) t.getTransferData(DataFlavor.stringFlavor); } } catch (UnsupportedFlavorException | IOException ex) { ex.printStackTrace(); } if (text != null) { if (topNodes == null) { initDumpDisplay(text); } else { addDumpStream(new ByteArrayInputStream(text.getBytes()), "Clipboard at " + new Date(System.currentTimeMillis()), false); addToLogfile(text); if (this.getRootPane() != null) { this.getRootPane().revalidate(); } displayContent(null); } if (!this.runningAsVisualVMPlugin) { getMainMenu().getFindLRThreadsToolBarButton().setEnabled(true); getMainMenu().getExpandButton().setEnabled(true); getMainMenu().getCollapseButton().setEnabled(true); } } }
From source file:com.declarativa.interprolog.gui.ListenerWindow.java
void handlePrologInputDnD(DropTargetDropEvent dtde) { //System.out.println("drop:"+dtde); try {/* w w w.j a va2s . c om*/ Transferable transferable = dtde.getTransferable(); /* DataFlavor[] flavors = transferable.getTransferDataFlavors(); for (int f=0;f<flavors.length;f++) System.out.println("Flavor:"+flavors[f]);*/ int action = dtde.getDropAction(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { if (engine.isIdle()) { dtde.acceptDrop(action); final java.util.List files = (java.util.List) transferable .getTransferData(DataFlavor.javaFileListFlavor); dtde.getDropTargetContext().dropComplete(true); boolean allPs = true; for (int f = 0; f < files.size(); f++) { String filename = ((File) files.get(f)).getName(); int dot = filename.lastIndexOf('.'); if (!filename.endsWith(".P")) { allPs = false; break; } } if (!allPs) { errorMessage("All dragged files must be Prolog source files (with a .P extension)"); } else { prologOutput.append("\nReconsulting " + ((files.size() > 1 ? files.size() + " files...\n" : files.size() + " file...\n"))); Runnable r = new Runnable() { public void run() { boolean crashed = false; Toolkit.getDefaultToolkit().sync(); for (int f = 0; f < files.size() && !crashed; f++) { File file = (File) files.get(f); if (!processDraggedFile(file)) { crashed = true; } } if (crashed) { prologOutput.append("...terminated with errors.\n"); } else { prologOutput.append("...done.\n"); } } }; SwingUtilities.invokeLater(r); } } else { dtde.rejectDrop(); errorMessage("You can not consult files while Prolog is working"); } } else { dtde.rejectDrop(); } } catch (Exception e) { throw new IPException("Problem dropping:" + e); } }
From source file:com.cohort.util.String2.java
/** * Get gets the String from the system clipboard * (or null if none).//from w w w. ja v a 2s . c om * This works in a standalone Java program, not an applet. * From Java Developers Almanac. * This won't throw an exception. */ public static String getClipboardString() { try { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable t = clipboard.getContents(null); if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) return (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Throwable th) { log(ERROR + " while getting the string from the clipboard:\n" + MustBe.throwableToString(th)); } return null; }