Java Code Examples for java.awt.datatransfer.Clipboard#setContents()

The following examples show how to use java.awt.datatransfer.Clipboard#setContents() . 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: DebugCommand.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] params)
{
	EntityPlayerMP player;
	try {
		player = getCommandSenderAsPlayer(sender);
	} catch (PlayerNotFoundException e) {
		return;
	}
	WorldServer world = server.worldServerForDimension(player.getEntityWorld().provider.getDimension());

	if(params.length == 1 && params[0].equalsIgnoreCase("report"))
	{
		int xM =player.getPosition().getX() >> 12;
		int zM =player.getPosition().getZ() >> 12;
		String out = "World Seed: [" + world.getSeed() + "] | IslandMap: [" +xM + "," + zM + "] | PlayerPos: [" + player.getPosition().toString() + "]";
		StringSelection selection = new StringSelection(out);
		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		if(clipboard != null)
			clipboard.setContents(selection, selection);

	}
}
 
Example 2
Source File: MultipleLogEntryMenu.java    From LoggerPlusPlus with GNU Affero General Public License v3.0 6 votes vote down vote up
private void copySelected(List<LogEntry> items, Scope scope, boolean onlyUnique){
    Clipboard clipboard = getToolkit().getSystemClipboard();
    Collection<String> values;
    if(onlyUnique) values = new LinkedHashSet<String>();
    else values = new LinkedList<>();
    for (LogEntry item : items) {
        switch (scope){
            case URL: values.add(String.valueOf(item.url)); break;
            case PATH: values.add(item.url.getPath()); break;
            case DOMAIN: values.add(item.hostname); break;
        }
    }

    String result = values.stream().collect(Collectors.joining("\n"));
    clipboard.setContents(new StringSelection(result), null);
}
 
Example 3
Source File: PasteAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent ev) {
    try {
        Transferable trans = t.paste();
        Clipboard clipboard = getClipboard();

        if (trans != null) {
            ClipboardOwner owner = (trans instanceof ClipboardOwner) ? (ClipboardOwner) trans
                                                                     : new StringSelection(""); // NOI18N
            clipboard.setContents(trans, owner);
        }
    } catch (UserCancelException exc) {
        // ignore - user just pressed cancel in some dialog....
    } catch (IOException e) {
        Exceptions.printStackTrace(e);
    } finally {
        EventQueue.invokeLater(this);
    }
}
 
Example 4
Source File: CodeEditorHandlerThread.java    From collect-earth with MIT License 5 votes vote down vote up
private void sendThroughClipboard(WebElement textArea, String contents) {
	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	StringSelection clipboardtext = new StringSelection(contents);
	clipboard.setContents(clipboardtext, null);
	Keys controlChar = Keys.CONTROL;
	if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
		controlChar = Keys.COMMAND;
	}
	textArea.sendKeys(Keys.chord(controlChar, "a"));
	textArea.sendKeys(Keys.chord(controlChar, "v"));
}
 
Example 5
Source File: MainActivity.java    From Raccoon with Apache License 2.0 5 votes vote down vote up
private void doExport() {
	List<String> lst = archive.list();
	StringBuilder sb = new StringBuilder();
	for (String s : lst) {
		sb.append("market://details?id="); //$NON-NLS-1$
		sb.append(s);
		sb.append("\n"); //$NON-NLS-1$
	}
	StringSelection stringSelection = new StringSelection(sb.toString());
	Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
	clpbrd.setContents(stringSelection, null);
	searchView.doMessage(Messages.getString("MainActivity.38")); //$NON-NLS-1$
}
 
Example 6
Source File: ClientGlobals.java    From gepard with MIT License 5 votes vote down vote up
public static void copyTextToClipboard(String text) {
	Clipboard systemClipboard =
		Toolkit.getDefaultToolkit().getSystemClipboard();
	// create transferrable text object and set clipboard text
	Transferable transferableText =	new StringSelection(text);
	systemClipboard.setContents(transferableText,null);
}
 
Example 7
Source File: EditableTextDelegate.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void copyToClipboard() {
	Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
	int start = Math.min(insertPos, insertPos + numSelected);
	int end = Math.max(insertPos, insertPos + numSelected);
	StringBuilder sb = new StringBuilder(text);
	String copiedText = sb.substring(start, end);
	clpbrd.setContents(new StringSelection(copiedText), null);
}
 
Example 8
Source File: ProductSceneViewTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    Selection selection = getLookup().lookup(Selection.class);
    if (selection != null && !selection.isEmpty()) {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        // todo - when we copy, we actually don't clone the SimpleFeature. Then, if we paste, two figures refer
        // to the same SimpleFeature.
        Transferable transferable = getView().getFigureEditor().getFigureSelection().createTransferable(true);
        clipboard.setContents(transferable, selection);
        //JOptionPane.showMessage(WindowManager.getDefault().getMainWindow(), "Copy: " + transferable);
    }
}
 
Example 9
Source File: InstancesListControllerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void copyIdToClipboard() {
    Instance instance = instancesListController.getSelectedInstance();
    if (instance == null) return;
    
    Clipboard clipboard = Lookup.getDefault().lookup(Clipboard.class);

    clipboard.setContents(new StringSelection("0x" + Long.toHexString(instance.getInstanceId())), null);  // NOI18N
}
 
Example 10
Source File: DViewPem.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
private void copyPressed() {
	String policy = jtaPem.getText();

	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	StringSelection copy = new StringSelection(policy);
	clipboard.setContents(copy, copy);
}
 
Example 11
Source File: Editor.java    From i18n-editor with MIT License 5 votes vote down vote up
public void copySelectedTranslationKey() {
	TranslationTreeNode node = translationTree.getSelectionNode();
	if (node != null && !node.isRoot()) {
		String key = node.getKey();
		StringSelection selection = new StringSelection(key);
		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		clipboard.setContents(selection, selection);
	}
}
 
Example 12
Source File: MediaUtils.java    From aurous-app with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @author Andrew
 *
 *         switches the album cover
 */
public static void copyMediaURL(final JTable target) {
	final int row = target.getSelectedRow();

	final String link = (String) target.getValueAt(row, 7);
	final StringSelection stringSelection = new StringSelection(link);
	final Clipboard clpbrd = Toolkit.getDefaultToolkit()
			.getSystemClipboard();
	clpbrd.setContents(stringSelection, null);
}
 
Example 13
Source File: RobotInput.java    From knife with MIT License 5 votes vote down vote up
public final String getSelectedString(){
		try {
			Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();//获取剪切板
			Transferable origin = clip.getContents(null);//备份之前剪切板的内容

			String selectedString = (String)clip.getData(DataFlavor.stringFlavor);
			System.out.println("复制之前剪切板中的内容:"+selectedString);
			
			inputWithCtrl(KeyEvent.VK_C);
			final String result = (String)clip.getData(DataFlavor.stringFlavor);
			//selectedString = (String)clip.getData(DataFlavor.stringFlavor);
			System.out.println("复制之后剪切板中的内容:"+result);

			clip.setContents(origin, null);//恢复之前剪切板的内容

			selectedString = (String)clip.getData(DataFlavor.stringFlavor);
			System.out.println("恢复之后剪切板中的内容:"+selectedString);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
//		复制之前剪切板中的内容:printStackTrace
//		复制之后剪切板中的内容:null
//		恢复之后剪切板中的内容:printStackTrace
//		printStackTrace//最后的值随着剪切板的恢复而改变了,应该是引用传递的原因。所有需要将复制后的值设置为final。
	}
 
Example 14
Source File: GuiUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static void copyToClipboard( String text ) {
    StringSelection selection = new StringSelection(text);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(selection, selection);
}
 
Example 15
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
public void copyLocationToClipBoard(Vec3d pos) {
	String data = String.format("(%.3f, %.3f, %.3f)", pos.x, pos.y, pos.z);
	StringSelection stringSelection = new StringSelection(data);
	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	clipboard.setContents( stringSelection, null );
}
 
Example 16
Source File: WatchProjects.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void cleanWellKnownStaticFields() throws Exception {
        Object o;

//        resetJTreeUIs(Frame.getFrames());

        tryCloseNavigator();

        StringSelection ss = new StringSelection("");
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, ss);
//      Toolkit.getDefaultToolkit().getSystemSelection().setContents(ss, ss);
//      fix for Issue 146901
        Clipboard clipBoard = Toolkit.getDefaultToolkit().getSystemSelection();
        if (clipBoard != null) {
            clipBoard.setContents(ss, ss);
        }
        Clipboard cc = Lookup.getDefault().lookup(Clipboard.class);
        Assert.assertNotNull("There is a clipboard in lookup", cc);
        cc.setContents(ss, ss);

        for (Frame f : Frame.getFrames()) {
            clearInstanceField( f, "java.awt.Container", "dispatcher" );
        }

// XXX: uncommented because of the csl.api & related changes
        JFrame empty = new JFrame("Clear");
        empty.getContentPane().setLayout(new FlowLayout());
        empty.getContentPane().add(new JEditorPane());
        empty.pack();
        empty.setVisible(true);
        empty.requestFocusInWindow();
// --------------------------------------------------------


        clearField("sun.awt.im.InputContext", "previousInputMethod");
        clearField("sun.awt.im.InputContext", "inputMethodWindowContext");
        clearField("sun.awt.im.CompositionAreaHandler", "compositionAreaOwner");
//        clearField("sun.awt.AppContext", "mainAppContext");
//        clearField("org.netbeans.modules.beans.BeanPanel", "INSTANCE");
        clearField("java.awt.KeyboardFocusManager", "focusedWindow");
        clearField("java.awt.KeyboardFocusManager", "activeWindow");
        clearField("java.awt.KeyboardFocusManager", "focusOwner");
        clearField("java.awt.KeyboardFocusManager", "permanentFocusOwner");
        clearField("java.awt.KeyboardFocusManager", "newFocusOwner");
        clearField("java.awt.KeyboardFocusManager", "currentFocusCycleRoot");
//        clearField("org.netbeans.jemmy.EventTool", "listenerSet");
        clearField("sun.awt.X11.XKeyboardFocusManagerPeer", "currentFocusOwner");
        clearField("sun.awt.X11.XKeyboardFocusManagerPeer", "currentFocusedWindow");
//        clearField("org.netbeans.modules.java.navigation.CaretListeningFactory", "INSATNCE");
//        clearField("org.netbeans.modules.editor.hints.HintsUI", "INSTANCE");
//        clearField("org.netbeans.modules.websvc.core.ProjectWebServiceView", "views");
//        clearField("org.netbeans.api.java.source.support.OpenedEditors", "DEFAULT");
//        clearField("org.netbeans.spi.palette.PaletteSwitch", "theInstance");
//        clearField("org.netbeans.core.NbMainExplorer$MainTab", "lastActivated");
//        clearField("org.netbeans.core.NbMainExplorer$MainTab", "DEFAULT");
/*
        o = getFieldValue("org.netbeans.api.java.source.JavaSource", "toRemove");
        if (o instanceof Collection) {
            Collection c = (Collection) o;
            c.clear();
        }
        o = getFieldValue("org.netbeans.api.java.source.JavaSource", "requests");
        if (o instanceof Collection) {
            Collection c = (Collection) o;
            c.clear();
        }
*/
        clearField("sun.awt.im.InputContext", "previousInputMethod");
        clearField("sun.awt.im.InputContext", "inputMethodWindowContext");
    }
 
Example 17
Source File: EditorTexto.java    From brModelo with GNU General Public License v3.0 4 votes vote down vote up
private void btnCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCopyActionPerformed
    StringSelection vai = new StringSelection(TextArea.getText());
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(vai, this);
}
 
Example 18
Source File: ALTaskManagerPanel.java    From moa with GNU General Public License v3.0 3 votes vote down vote up
public void copyClipBoardConfiguration() {

        StringSelection selection = new StringSelection(this.taskDescField.getText().trim());
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(selection, selection);

    }
 
Example 19
Source File: MultiLabelTaskManagerPanel.java    From moa with GNU General Public License v3.0 3 votes vote down vote up
public void copyClipBoardConfiguration() {

        StringSelection selection = new StringSelection(this.taskDescField.getText().trim());
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(selection, selection);

    }
 
Example 20
Source File: ClipboardHandler.java    From PolyGlot with MIT License 2 votes vote down vote up
/**
 * Place a String on the clipboard, and make this class the owner of the
 * Clipboard's contents.
 *
 * @param aString
 */
public void setClipboardContents(String aString) {
    StringSelection stringSelection = new StringSelection(aString);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, this);
}