List of usage examples for java.awt.datatransfer Transferable isDataFlavorSupported
public boolean isDataFlavorSupported(DataFlavor flavor);
From source file:net.technicpack.launcher.ui.LauncherFrame.java
protected void pasteUpdated(Transferable transferable) { String text;/*from w w w . ja v a2 s . c o m*/ if (!transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) return; try { text = transferable.getTransferData(DataFlavor.stringFlavor).toString(); } catch (IOException ex) { Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex); return; } catch (UnsupportedFlavorException ex) { Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex); return; } try { final URL platformUrl = new URL(text); new SwingWorker<PlatformPackInfo, Void>() { @Override protected PlatformPackInfo doInBackground() throws Exception { PlatformPackInfo info = RestObject.getRestObject(PlatformPackInfo.class, platformUrl.toString()); //Don't let people jerk us around with non-platform sites- make sure this is a real pack //on the technic platform return platformApi.getPlatformPackInfo(info.getName()); } @Override public void done() { PlatformPackInfo result; try { result = get(); if (result == null) return; } catch (ExecutionException ex) { //We eat these two exceptions because they are almost certainly caused by //the pasted text not being relevant to this program return; } catch (InterruptedException ex) { return; } if (!packRepo.getInstalledPacks().containsKey(result.getName())) { packRepo.put(new InstalledPack(result.getName(), true, InstalledPack.RECOMMENDED)); } packRepo.setSelectedSlug(result.getName()); modpackSelector.forceRefresh(); LauncherFrame.this.setExtendedState(JFrame.ICONIFIED); EventQueue.invokeLater(new Runnable() { @Override public void run() { LauncherFrame.this.setExtendedState(JFrame.NORMAL); EventQueue.invokeLater(new Runnable() { @Override public void run() { LauncherFrame.this.selectTab("modpacks"); } }); } }); } }.execute(); } catch (MalformedURLException ex) { return; } }
From source file:org.freeplane.features.clipboard.mindmapmode.MClipboardController.java
private void processTransferable(final Transferable transferable, final NodeModel target, Operation operation) { if (!transferable.isDataFlavorSupported(MindMapNodesSelection.mindMapNodeObjectsFlavor)) return;//from www. ja v a 2s. c om try { @SuppressWarnings("unchecked") final List<NodeModel> clonedNodes = (List<NodeModel>) transferable .getTransferData(MindMapNodesSelection.mindMapNodeObjectsFlavor); for (NodeModel clonedNode : clonedNodes) { if (clonedNode.getParentNode() == null || !clonedNode.getMap().equals(target.getMap())) return; final MMapController mapController = (MMapController) Controller.getCurrentModeController() .getMapController(); if (!clonedNode.isRoot() && !clonedNode.subtreeContainsCloneOf(target)) { switch (operation) { case CLONE: final NodeModel clone = clonedNode.cloneTree(); mapController.addNewNode(clone, target, target.getChildCount(), target.isNewChildLeft()); break; case MOVE: mapController.moveNodeAsChild(clonedNode, target, target.isNewChildLeft(), target.isNewChildLeft() != clonedNode.isLeft()); break; } } } } catch (Exception e) { LogUtils.severe(e); } }
From source file:xtrememp.PlaylistManager.java
@Override @SuppressWarnings("unchecked") public void drop(DropTargetDropEvent ev) { DropTargetContext targetContext = ev.getDropTargetContext(); Transferable t = ev.getTransferable(); try {/*from ww w.j av a 2 s. c om*/ // Windows if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { ev.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); addFiles((List<File>) t.getTransferData(DataFlavor.javaFileListFlavor), false); targetContext.dropComplete(true); // Linux } else if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { ev.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String urls = (String) t.getTransferData(DataFlavor.stringFlavor); List<File> fileList = new ArrayList<>(); StringTokenizer st = new StringTokenizer(urls); while (st.hasMoreTokens()) { URI uri = new URI(st.nextToken()); fileList.add(new File(uri)); } addFiles(fileList, false); targetContext.dropComplete(true); } } catch (UnsupportedFlavorException | InvalidDnDOperationException | IOException | URISyntaxException ex) { logger.error(ex.getMessage(), ex); } }
From source file:org.freeplane.features.clipboard.mindmapmode.MClipboardController.java
Collection<IDataFlavorHandler> getFlavorHandlers() { final Transferable t = getClipboardContents(); final Collection<IDataFlavorHandler> handlerList = new LinkedList<IDataFlavorHandler>(); if (t == null) { return handlerList; }/* ww w . j ava 2s .c om*/ if (t.isDataFlavorSupported(MindMapNodesSelection.mindMapNodesFlavor)) { try { final String textFromClipboard = t.getTransferData(MindMapNodesSelection.mindMapNodesFlavor) .toString(); handlerList.add(new MindMapNodesFlavorHandler(textFromClipboard)); } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } if (t.isDataFlavorSupported(MindMapNodesSelection.htmlFlavor)) { try { final String textFromClipboard = t.getTransferData(MindMapNodesSelection.htmlFlavor).toString(); if (textFromClipboard.charAt(0) != 65533) { if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { handlerList.add(new StructuredHtmlFlavorHandler(textFromClipboard)); handlerList.add(new DirectHtmlFlavorHandler(textFromClipboard)); } } } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { final String plainTextFromClipboard = t.getTransferData(DataFlavor.stringFlavor).toString(); handlerList.add(new StringFlavorHandler(plainTextFromClipboard)); } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } if (t.isDataFlavorSupported(MindMapNodesSelection.fileListFlavor)) { try { final List<File> fileList = castToFileList(t.getTransferData(MindMapNodesSelection.fileListFlavor)); handlerList.add(new FileListFlavorHandler(fileList)); } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) { try { BufferedImage image = (BufferedImage) t.getTransferData(DataFlavor.imageFlavor); handlerList.add(new ImageFlavorHandler(image)); } catch (final UnsupportedFlavorException e) { } catch (final IOException e) { } } return handlerList; }
From source file:com._17od.upm.gui.AccountDialog.java
/** * This method takes in a JTextField object and then sets the text of that * text field to the contents of the system clipboard. * /*ww w .java 2 s .c o m*/ * @param textField */ public void pasteToTextField(JTextField textField) { String text = ""; Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable clipText = clipboard.getContents(null); if ((clipText != null) && clipText.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { text = (String) clipText.getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } textField.setText(text); }
From source file:com._17od.upm.gui.AccountDialog.java
/** * This method takes in a JTextArea object and then inserts the contents of * the system clipboard into that text area at the cursor position. * /*from w w w.ja v a2 s .c o m*/ * @param textArea */ public void pasteToTextArea(JTextArea textArea) { String text = ""; Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable clipText = clipboard.getContents(null); if ((clipText != null) && clipText.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { text = (String) clipText.getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } textArea.insert(text, textArea.getCaretPosition()); textArea.requestFocus(); }
From source file:com.netease.dagger.BrowserEmulator.java
/** * Paste text from clipboard content/*from ww w .j a va2s . co m*/ */ public String getClipboardContent() { pause(stepInterval); try { String text = ""; Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable data = clip.getContents(null); if (data != null) { if (data.isDataFlavorSupported(DataFlavor.stringFlavor)) { text = (String) data.getTransferData(DataFlavor.stringFlavor); } } return text; } catch (Exception e) { e.printStackTrace(); handleFailure("Failed to get clipboard content"); } logger.info("Success to get clipboard content"); return null; }
From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java
public void dragEnter(DropTargetDragEvent dtde) { try {// w w w. ja va2 s .c o m Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator iterator = fileList.iterator(); if (iterator.hasNext() && fileList.size() == 1) { String fileName = ((File) iterator.next()).getName(); if (!fileName.substring(fileName.lastIndexOf(".")).equalsIgnoreCase(".xml")) { dtde.rejectDrag(); } } else { dtde.rejectDrag(); } } else if (tr.isDataFlavorSupported(TreeTransferable.RULE_DATA_FLAVOR)) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); } else { dtde.rejectDrag(); } } catch (Exception e) { dtde.rejectDrag(); } }
From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java
public void drop(DropTargetDropEvent dtde) { try {//www .j a v a2s . c om dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator<File> iterator = fileList.iterator(); if (fileList.size() == 1) { File file = (File) iterator.next(); importFilter(parent.readFileToString(file)); } } else if (tr.isDataFlavorSupported(TreeTransferable.RULE_DATA_FLAVOR)) { Object transferData = tr.getTransferData(TreeTransferable.RULE_DATA_FLAVOR); if (transferData instanceof RuleDropData) { RuleDropData data = (RuleDropData) transferData; addNewRule(MirthTree.constructNodeDescription(data.getNode()), data.getMapping()); } } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java
public void dragEnter(DropTargetDragEvent dtde) { try {/* w w w . j ava2s . c o m*/ Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator iterator = fileList.iterator(); if (iterator.hasNext() && fileList.size() == 1) { String fileName = ((File) iterator.next()).getName(); if (!fileName.substring(fileName.lastIndexOf(".")).equalsIgnoreCase(".xml")) { dtde.rejectDrag(); } } else { dtde.rejectDrag(); } } else if (tr.isDataFlavorSupported(TreeTransferable.MAPPER_DATA_FLAVOR) || tr.isDataFlavorSupported(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR)) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); } else { dtde.rejectDrag(); } } catch (Exception e) { dtde.rejectDrag(); } }