Java Code Examples for java.awt.Toolkit#getSystemClipboard()

The following examples show how to use java.awt.Toolkit#getSystemClipboard() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatchingObjectNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    File f = FileUtil.toFile(
            matchingObject.getFileObject());
    if (f != null) {
        String path = f.getPath();
        Clipboard clipboard = Lookup.getDefault().lookup(
                ExClipboard.class);
        if (clipboard == null) {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            if (toolkit != null) {
                clipboard = toolkit.getSystemClipboard();
            }
        }
        if (clipboard != null) {
            StringSelection strSel = new StringSelection(path);
            clipboard.setContents(strSel, null);
        }
    }
}
 
Example 2
Source File: MClipboardPrinter.java    From javamelody with Apache License 2.0 6 votes vote down vote up
/**
 * Copie la sélection d'une table dans le presse-papiers (au format html pour Excel par exemple).
 *
 * @param table
 *           MBasicTable
 */
protected void copySelectionToClipboard(final MBasicTable table) {
	if (table.getSelectionModel().isSelectionEmpty()) {
		return;
	}

	final Toolkit toolkit = table.getToolkit();
	final Clipboard clipboard = toolkit.getSystemClipboard();
	final ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(2048);
	try {
		writeHtml(table, byteArrayOut, true);
		final String charset = System.getProperty("file.encoding");
		final StringSelection contents = new StringSelection(byteArrayOut.toString(charset));
		clipboard.setContents(contents, contents);
	} catch (final IOException e) {
		MSwingUtilities.showException(e);
	}
}
 
Example 3
Source File: Permissions.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 4
Source File: Utils.java    From Scripts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves text from the system clipboard.
 *
 * @return the text contents of the clipboard or an empty string if no text
 *         could be retrieved
 */
public static String getClipboardText() {
	String text = "";
	try {
		final Toolkit toolkit = Toolkit.getDefaultToolkit();
		final Clipboard clipboard = toolkit.getSystemClipboard();
		text = (String) clipboard.getData(DataFlavor.stringFlavor);
	} catch (final Exception e) {
		// if (IJ.debugMode) IJ.handleException(e);
	}
	return text;
}
 
Example 5
Source File: CopyCellRenderer.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * @param value Value to copy.
 */
public void copyCell(String value) {
  Toolkit toolkit = Toolkit.getDefaultToolkit();
  Clipboard clipboard = toolkit.getSystemClipboard();
  StringSelection strSel = new StringSelection(value);
  clipboard.setContents(strSel, null);
}
 
Example 6
Source File: Permissions.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 7
Source File: Permissions.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 8
Source File: CopyHandler.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
private static void toClipboard(final String text, int retries) {
	if (text == null) {
		return;
	}
	if (text.length() == 0) {
		return;
	}
	Toolkit toolkit = Toolkit.getDefaultToolkit();
	StringSelection selection = new StringSelection(text);
	Clipboard clipboard = toolkit.getSystemClipboard();
	try {
		clipboard.setContents(selection, null);
	} catch (IllegalStateException ex) {
		if (retries < 3) { //Retry 3 times
			retries++;
			LOG.info("Retrying copy to clipboard (" + retries + " of 3)" );
			try {
				Thread.sleep(100);
			} catch (InterruptedException ex1) {
				//No problem
			}
			toClipboard(text, retries);
		} else {
			LOG.error(ex.getMessage(), ex);
		}
	}
}
 
Example 9
Source File: Permissions.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 10
Source File: Permissions.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 11
Source File: Permissions.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 12
Source File: Permissions.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 13
Source File: Permissions.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 14
Source File: Permissions.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 15
Source File: Permissions.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 16
Source File: Permissions.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 17
Source File: Permissions.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 18
Source File: Permissions.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 19
Source File: Action.java    From PengueeBot with GNU General Public License v3.0 4 votes vote down vote up
private Clipboard getSystemClipboard() {
	Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
	Clipboard systemClipboard = defaultToolkit.getSystemClipboard();
	return systemClipboard;
}
 
Example 20
Source File: MapRuleMenu.java    From xtunnel with GNU General Public License v2.0 4 votes vote down vote up
void copyToClipBoard(String text){
	Toolkit toolkit = Toolkit.getDefaultToolkit();
	Clipboard clipboard = toolkit.getSystemClipboard();
	StringSelection stringSel = new StringSelection(text);
	clipboard.setContents(stringSel, null);
}