List of usage examples for java.awt.datatransfer Clipboard setContents
public synchronized void setContents(Transferable contents, ClipboardOwner owner)
From source file:com.jk.util.JKStringUtil.java
/** * Copy to clipboard.// w w w . j a v a2 s .c om * * @param text * the text */ public static void copyToClipboard(String text) { final StringSelection stringSelection = new StringSelection(text); final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, stringSelection); }
From source file:org.syncany.gui.util.DesktopUtil.java
/** * Copies the given text to the user clipboard. *//*from ww w . jav a2 s .co m*/ public static void copyToClipboard(String copyText) { StringSelection applicationLinkStringSelection = new StringSelection(copyText); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(applicationLinkStringSelection, applicationLinkStringSelection); }
From source file:UploadUtils.ImgurUpload.java
/** * Copy image link to user's clipboard.// w w w .ja v a 2 s .co m * This method could be called in onImageLink(String link) to copy the link to the user's clipboard. * @param imgurl the string to copy to the clipboard */ public static void copyToClipBoard(String imgurl) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection selection = new StringSelection(imgurl); clipboard.setContents(selection, null); }
From source file:org.broad.igv.util.StringUtils.java
/** * Copy a text string to the clipboard// w w w . j a va2s .com * * @param text */ public static void copyTextToClipboard(String text) { StringSelection stringSelection = new StringSelection(text); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); }
From source file:UploadUtils.PomfUpload.java
/** * Copy image link to user's clipboard.// w w w . j a v a 2 s . c om * This method could be called in onImageLink(String link) to copy the link to the user's clipboard. * @param link the string to copy to the clipboard */ public static void copyToClipBoard(String link) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection selection = new StringSelection(link); clipboard.setContents(selection, null); }
From source file:org.kontalk.view.Utils.java
static WebMenuItem createCopyMenuItem(final String copyText, String toolTipText) { WebMenuItem item = new WebMenuItem(Tr.tr("Copy")); if (!toolTipText.isEmpty()) item.setToolTipText(toolTipText); item.addActionListener(new ActionListener() { @Override/* ww w . j a v a 2 s . co m*/ public void actionPerformed(ActionEvent event) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); clip.setContents(new StringSelection(copyText), null); } }); return item; }
From source file:net.sf.translate64.util.TranslateUtils.java
public static void setClipboardText(String text) { // create a new clipboard instance Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // set the contents clipboard.setContents(new StringSelection(text), null); }
From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java
public static void copySpec(RuntimeBean runtime) { AppSpecBean spec = makeMRU(runtime, null); JSONObject jspec = ToJSONLogic.toJSON(spec); StringSelection ss = new StringSelection(jspec.toJSONString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(ss, mClipOwner); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.actions.CopyChartAction.java
/** * Copies the current chart to the system clipboard. *///from w ww .j av a 2 s.c o m public static synchronized void copyChart(final JFreeChartPlotEngine engine) { Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Insets insets = engine.getChartPanel().getInsets(); int w = engine.getChartPanel().getWidth() - insets.left - insets.right; int h = engine.getChartPanel().getHeight() - insets.top - insets.bottom; ChartTransferable selection = new ChartTransferable(engine.getChartPanel().getChart(), w, h); systemClipboard.setContents(selection, null); }
From source file:com.qawaa.gui.EventWebScanGUI.java
/** * ??/*from w w w . j av a 2s . co m*/ */ private static void setConsoleRight() { consoleRight = new JPopupMenu(); consoleRight.setBorderPainted(true); consoleRight.setPopupSize(new Dimension(105, 135)); JMenuItem clear = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.clear", null, Locale.CHINA), KeyEvent.VK_L); JMenuItem copy = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.copy", null, Locale.CHINA), KeyEvent.VK_C); JMenuItem cut = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.cut", null, Locale.CHINA), KeyEvent.VK_X); JMenuItem font = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.font", null, Locale.CHINA), KeyEvent.VK_F); JMenuItem choose = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.choose", null, Locale.CHINA), KeyEvent.VK_O); JMenuItem saveas = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.saveas", null, Locale.CHINA), KeyEvent.VK_S); consoleRight.add(clear); consoleRight.add(copy); consoleRight.add(cut); consoleRight.add(font); consoleRight.add(choose); consoleRight.add(saveas); clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { consolePane.setText(""); jConsole.clear(); } }); copy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(consolePane.getText()); clip.setContents(tText, null); } } }); cut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(consolePane.getText()); clip.setContents(tText, null); } consolePane.setText(""); jConsole.clear(); } }); saveas.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); int option = fileChooser.showSaveDialog(null); if (option == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { if (file.exists() == false) { file.createNewFile(); } FileWriter writer = new FileWriter(file); char[] arry = consolePane.getText().toCharArray(); writer.write(arry); writer.flush(); writer.close(); LOG.info(CONTEXT.getMessage("gobal.right.menu.saveas.success", null, Locale.CHINA)); } catch (IOException ioe) { } } } }); }