List of usage examples for java.awt.datatransfer ClipboardOwner ClipboardOwner
ClipboardOwner
From source file:cz.babi.desktop.remoteme.common.Controller.java
/** * Init clipboard./*from w ww . j a v a 2 s .c om*/ */ public void initClipboard() { clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboardOwner = new ClipboardOwner() { @Override public void lostOwnership(Clipboard clipboard, Transferable contents) { if (Common.DEBUG) LOGGER.debug("[lostOwnership]"); } }; }
From source file:corelyzer.util.StringUtility.java
public static void setClipboard(final String aString) { StringSelection stringSelection = new StringSelection(aString); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, new ClipboardOwner() { public void lostOwnership(final Clipboard clipboard, final Transferable transferable) { // do nothing }//from w ww.ja v a 2 s. c o m }); }
From source file:TransferableScribblePane.java
/** Copy the selected line to the clipboard */ public void copy() { if (selectedLine == null) return; // Only works if a line is selected // Get the system Clipboard object. Clipboard c = this.getToolkit().getSystemClipboard(); // Wrap the selected line in a TransferablePolyLine object // and pass it to the clipboard, with an object to receive notification // when some other application takes ownership of the clipboard c.setContents(new TransferablePolyLine((PolyLine) selectedLine.clone()), new ClipboardOwner() { public void lostOwnership(Clipboard c, Transferable t) { // This method is called when something else // is copied to the clipboard. We could use it // to deselect the selected line, if we wanted. }/*from ww w . j a v a 2 s .c o m*/ }); }
From source file:org.mwc.cmap.xyplot.views.XYPlotView.java
protected void bitmapToClipBoard(JComponent component) { Point size = _plotControl.getSize(); final BufferedImage img = new BufferedImage(size.x, size.y, BufferedImage.TYPE_INT_ARGB); Graphics g = img.getGraphics(); g.setColor(component.getForeground()); g.setFont(component.getFont());//from w w w.j a v a2 s .c om component.setSize(size.x, size.y); component.paint(g); Transferable t = new Transferable() { public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { DataFlavor.imageFlavor }; } public boolean isDataFlavorSupported(DataFlavor flavor) { if (flavor == DataFlavor.imageFlavor) return true; return false; } public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (isDataFlavorSupported(flavor)) { return img; } return null; } }; ClipboardOwner co = new ClipboardOwner() { public void lostOwnership(java.awt.datatransfer.Clipboard clipboard, Transferable contents) { } }; java.awt.datatransfer.Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.setContents(t, co); }
From source file:com.chtr.tmoauto.webui.CommonFunctions.java
@Override public void typeUsingRobot(String locator, String value) { WebElement we = findElement(locator); // try to click otherwise ignore if it fails try {//from www. j ava 2s . c o m we.click(); } catch (Exception e) { } ClipboardOwner clipboardOwner = new ClipboardOwner() { @Override public void lostOwnership(Clipboard clipboard, Transferable contents) { } }; Robot robot; try { robot = new Robot(); try { we.sendKeys(value); } catch (Exception e) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection stringSelection = new StringSelection(value); clipboard.setContents(stringSelection, clipboardOwner); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); } } catch (AWTException e1) { e1.printStackTrace(); } }
From source file:org.jetbrains.jet.grammar.GrammarGenerator.java
private static void copyToClipboard(StringBuilder result) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(result.toString()), new ClipboardOwner() { @Override//from w w w .j a v a 2 s . co m public void lostOwnership(Clipboard clipboard, Transferable contents) { } }); }