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

The following examples show how to use javafx.scene.input.Clipboard#setContent() . 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: UIMenuItem.java    From tcMenu with Apache License 2.0 6 votes vote down vote up
public boolean handleCut() {
    Clipboard systemClipboard = Clipboard.getSystemClipboard();

    TextField focused = getFocusedTextField();
    if (focused == null) return false;
    String text = focused.getSelectedText();

    ClipboardContent content = new ClipboardContent();
    content.putString(text);
    systemClipboard.setContent(content);

    IndexRange range = focused.getSelection();
    String origText = focused.getText();
    String firstPart = origText.substring(0, range.getStart());
    String lastPart = origText.substring(range.getEnd());
    focused.setText(firstPart + lastPart);

    focused.positionCaret(range.getStart());
    return true;
}
 
Example 2
Source File: ExceptionController.java    From BetonQuest-Editor with GNU General Public License v3.0 5 votes vote down vote up
@FXML private void copy() {
	try {
		Clipboard clipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        String string = stackTrace.getText();
		// add 4 spaces before each line so when pasted on GitHub it's formatted as code
        content.putString("    " + string.replace("\n", "\n    ").trim());
        clipboard.setContent(content);
	} catch (Exception e) {
		ExceptionController.display(e);
	}
}
 
Example 3
Source File: EditorFrame.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Copies the current image to the clipboard.
 */
public void copyToClipboard() 
{
	DiagramTab frame = getSelectedDiagramTab();
	final Image image = ImageCreator.createImage(frame.getDiagram());
	final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putImage(image);
    clipboard.setContent(content);
	Alert alert = new Alert(AlertType.INFORMATION, RESOURCES.getString("dialog.to_clipboard.message"), ButtonType.OK);
	alert.initOwner(aMainStage);
	alert.setHeaderText(RESOURCES.getString("dialog.to_clipboard.title"));
	alert.showAndWait();
}
 
Example 4
Source File: JFreeChartUtils.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static void exportToClipboard(ChartViewer chartNode) {
  final Clipboard clipboard = Clipboard.getSystemClipboard();
  final ClipboardContent content = new ClipboardContent();
  final int width = (int) chartNode.getWidth();
  final int height = (int) chartNode.getHeight();
  WritableImage img = new WritableImage(width, height);
  SnapshotParameters params = new SnapshotParameters();
  chartNode.snapshot(params, img);
  content.putImage(img);
  clipboard.setContent(content);
}
 
Example 5
Source File: LogsView.java    From trex-stateless-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Copy logs to clipboard
 */
public void copyToClipboard() {
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(sb.toString());
    clipboard.setContent(content);
}
 
Example 6
Source File: UIUtils.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copy text to clipboard
 */
public static void copyToClipBoard(String text) {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.putString(text);
    clipboard.setContent(content);
}
 
Example 7
Source File: CopyNodeAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final TreeNode<?> node = getNode();

    final ClipboardContent content = new ClipboardContent();
    content.put(DATA_FORMAT, node.getObjectId());

    final Clipboard clipboard = Clipboard.getSystemClipboard();
    clipboard.setContent(content);
}
 
Example 8
Source File: TerminalView.java    From TerminalFX with MIT License 5 votes vote down vote up
@WebkitCall(from = "hterm")
public void copy(String text) {
	final Clipboard clipboard = Clipboard.getSystemClipboard();
	final ClipboardContent clipboardContent = new ClipboardContent();
	clipboardContent.putString(text);
	clipboard.setContent(clipboardContent);
}
 
Example 9
Source File: MsSpectrumPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void handleCopySplash(Event event) {
  StringBuilder sb = new StringBuilder();
  for (MsSpectrumDataSet dataset : datasets) {
    MsSpectrum spectrum = dataset.getSpectrum();
    String splash = SplashCalculationAlgorithm.calculateSplash(spectrum);
    sb.append(dataset.getName());
    sb.append(" SPLASH ID: ");
    sb.append(splash);
    sb.append("\n");
  }
  final Clipboard clipboard = Clipboard.getSystemClipboard();
  final ClipboardContent content = new ClipboardContent();
  content.putString(sb.toString());
  clipboard.setContent(content);
}
 
Example 10
Source File: TraceContextMenu.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
private void copyToClipboard(StringBuilder sbuilder) {
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();

    content.putString(sbuilder.toString());
    clipboard.setContent(content);
}
 
Example 11
Source File: Utilities.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void copyToClipboard(String content) {
    try {
        if (content != null && content.length() > 0) {
            Clipboard clipboard = Clipboard.getSystemClipboard();
            ClipboardContent clipboardContent = new ClipboardContent();
            clipboardContent.putString(content);
            clipboard.setContent(clipboardContent);
        }
    } catch (Throwable e) {
        log.error("copyToClipboard failed " + e.getMessage());
        e.printStackTrace();
    }
}
 
Example 12
Source File: CodeGenLoggingController.java    From tcMenu with Apache License 2.0 5 votes vote down vote up
/**
 * A shortcut button to get the contents of the logger window into the clipboard.
 * @param actionEvent ignored
 */
public void onCopyToClipboard(ActionEvent actionEvent) {
    Clipboard systemClipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.putString(loggingArea.getText());
    systemClipboard.setContent(content);
}
 
Example 13
Source File: WebViewContextMenuTest.java    From oim-fx with MIT License 5 votes vote down vote up
public void copy() {
	String selectedText = (String) webView.getEngine().executeScript("editor.getSelection();");
	final Clipboard clipboard = Clipboard.getSystemClipboard();
	final ClipboardContent content = new ClipboardContent();
	content.putString(selectedText);
	clipboard.setContent(content);
}
 
Example 14
Source File: WebViewContextMenuTest.java    From oim-fx with MIT License 5 votes vote down vote up
public void cut() {
	String selectedText = (String) webView.getEngine().executeScript("editor.getSelection();");
	webView.getEngine().executeScript("editor.replaceSelection(\"\");");
	final Clipboard clipboard = Clipboard.getSystemClipboard();
	final ClipboardContent content = new ClipboardContent();
	content.putString(selectedText);
	clipboard.setContent(content);

}
 
Example 15
Source File: Screenshot.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
/**
 * Save screenshot to clipbaord
 */
public void screenshotToClipboard() {
    Image image = getScreenshot();
    Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putImage(image);
    clipboard.setContent(content);
    LOGGER.atInfo().log("Copied screenshot to clipboard");
}
 
Example 16
Source File: TableViewUtilities.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Copy the given text to the system clipboard.
 *
 * @param text the text to copy.
 */
public static void copyToClipboard(final String text) {
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(text);
    clipboard.setContent(content);
}
 
Example 17
Source File: ClipboardUtilities.java    From constellation with Apache License 2.0 5 votes vote down vote up
public static void copyToClipboard(final String text) {
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(text);
    clipboard.setContent(content);

    PluginExecution.withPlugin(new SimplePlugin("Copy To Clipboard") {
        @Override
        protected void execute(PluginGraphs graphs, PluginInteraction interaction, PluginParameters parameters) throws InterruptedException, PluginException {
            ConstellationLoggerHelper.copyPropertyBuilder(this, text.length(), ConstellationLoggerHelper.SUCCESS);
        }
    }).interactively(true).executeLater(null);
}
 
Example 18
Source File: FileUtils.java    From Notebook with Apache License 2.0 4 votes vote down vote up
public static void toClipboard(String message) {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent clipboardContent = new ClipboardContent();
    clipboardContent.putString(message);
    clipboard.setContent(clipboardContent);
}
 
Example 19
Source File: SampleController.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
private void putIntoClipboard(String t){
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(t);
    clipboard.setContent(content);
}
 
Example 20
Source File: TermTreeView.java    From erlyberly with GNU General Public License v3.0 4 votes vote down vote up
private void copyToClipboard(StringBuilder sbuilder) {
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(sbuilder.toString());
    clipboard.setContent(content);
}