Java Code Examples for javafx.scene.input.Clipboard#getContent()

The following examples show how to use javafx.scene.input.Clipboard#getContent() . 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: TreeNode.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Fill the items actions for this node.
 *
 * @param nodeTree the node tree
 * @param items    the items
 */
@FxThread
public void fillContextMenu(@NotNull final NodeTree<?> nodeTree, @NotNull final ObservableList<MenuItem> items) {

    if (canEditName()) {
        items.add(new RenameNodeAction(nodeTree, this));
    }

    if (canCopy()) {
        items.add(new CopyNodeAction(nodeTree, this));
    }

    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final Object content = clipboard.getContent(DATA_FORMAT);
    if (!(content instanceof Long)) {
        return;
    }

    final Long objectId = (Long) content;
    final TreeItem<?> treeItem = UiUtils.findItem(nodeTree.getTreeView(), objectId);
    final TreeNode<?> treeNode = treeItem == null ? null : (TreeNode<?>) treeItem.getValue();

    if (treeNode != null && canAccept(treeNode, true)) {
        items.add(new PasteNodeAction(nodeTree, this, treeNode));
    }
}
 
Example 2
Source File: OpenLabelerController.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
private ObjectModel fromClipboard() {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    if (clipboard.getContentTypes().contains(DATA_FORMAT_JAXB)) {
        try {
            String content = (String)clipboard.getContent(DATA_FORMAT_JAXB);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            return (ObjectModel) unmarshaller.unmarshal(new StringReader(content));
        }
        catch (Exception ex) {
            LOG.log(Level.SEVERE, "Unable to get content from clipboard", ex);
        }
    }
    return null;
}
 
Example 3
Source File: ClipboardActions.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Inserts the content from the clipboard into this text-editing area,
 * replacing the current selection. If there is no selection, the content
 * from the clipboard is inserted at the current caret position.
 */
default void paste() {
    Clipboard clipboard = Clipboard.getSystemClipboard();

    if(getStyleCodecs().isPresent()) {
        Tuple2<Codec<PS>, Codec<StyledSegment<SEG, S>>> codecs = getStyleCodecs().get();
        Codec<StyledDocument<PS, SEG, S>> codec = ReadOnlyStyledDocument.codec(codecs._1, codecs._2, getSegOps());
        DataFormat format = dataFormat(codec.getName());
        if(clipboard.hasContent(format)) {
            byte[] bytes = (byte[]) clipboard.getContent(format);
            ByteArrayInputStream is = new ByteArrayInputStream(bytes);
            DataInputStream dis = new DataInputStream(is);
            StyledDocument<PS, SEG, S> doc = null;
            try {
                doc = codec.decode(dis);
            } catch (IOException e) {
                System.err.println("Codec error: Failed to decode '" + codec.getName() + "':");
                e.printStackTrace();
            }
            if(doc != null) {
                replaceSelection(doc);
                return;
            }
        }
    }

    if (clipboard.hasString()) {
        String text = clipboard.getString();
        if (text != null) {
            replaceSelection(text);
        }
    }
}
 
Example 4
Source File: WebViewContextMenuTest.java    From oim-fx with MIT License 4 votes vote down vote up
public void paste() {
	final Clipboard clipboard = Clipboard.getSystemClipboard();
	String content = (String) clipboard.getContent(DataFormat.PLAIN_TEXT);
	webView.getEngine().executeScript(String.format("editor.replaceSelection(\"%s\");", content));
}