Java Code Examples for javafx.scene.input.ClipboardContent#putString()

The following examples show how to use javafx.scene.input.ClipboardContent#putString() . 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: DisplayEditor.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Copy currently selected widgets to clipboard
 *  @return Widgets that were copied or <code>null</code>
 */
public List<Widget> copyToClipboard()
{
    if (selection_tracker.isInlineEditorActive())
        return null;

    final List<Widget> widgets = selection.getSelection();
    if (widgets.isEmpty())
        return null;

    final String xml;
    try
    {
        xml = ModelWriter.getXML(widgets);
    }
    catch (Exception ex)
    {
        logger.log(Level.WARNING, "Cannot create content for clipboard", ex);
        return null;
    }

    final ClipboardContent content = new ClipboardContent();
    content.putString(xml);
    Clipboard.getSystemClipboard().setContent(content);
    return widgets;
}
 
Example 2
Source File: RegionBaseRepresentation.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Copy PV name to clipboard when middle button clicked
 *  @param event Mouse pressed event
 */
private void hookMiddleButtonCopy(final MouseEvent event)
{
    if (event.getButton() != MouseButton.MIDDLE)
        return;

    final String pv_name = ((PVWidget)model_widget).propPVName().getValue();

    // Copy to copy/paste clipboard
    final ClipboardContent content = new ClipboardContent();
    content.putString(pv_name);
    Clipboard.getSystemClipboard().setContent(content);

    // Copy to the 'selection' buffer used by X11
    // for middle-button copy/paste
    // Note: This is AWT API!
    // JavaFX has no API, https://bugs.openjdk.java.net/browse/JDK-8088117
    if (Toolkit.getDefaultToolkit().getSystemSelection() != null)
        Toolkit.getDefaultToolkit().getSystemSelection().setContents(new StringSelection(pv_name), null);
}
 
Example 3
Source File: ItemItemController.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * 艦隊分析
 */
@FXML
void kancolleFleetanalysis() {
    try {
        List<KancolleFleetanalysisItem> list = SlotItemCollection.get().getSlotitemMap().values().stream()
                .filter(item -> item.getLocked())
                .map(KancolleFleetanalysisItem::toItem)
                .sorted(Comparator.comparing(KancolleFleetanalysisItem::getId)
                        .thenComparing(Comparator.comparing(KancolleFleetanalysisItem::getLv)))
                .collect(Collectors.toList());
        ObjectMapper mapper = new ObjectMapper();
        String input = mapper.writeValueAsString(list);

        ClipboardContent content = new ClipboardContent();
        content.putString(input);
        Clipboard.getSystemClipboard().setContent(content);
    } catch (Exception e) {
        LoggerHolder.get().error("艦隊分析のロック装備をクリップボードにコピーに失敗しました", e);
    }
}
 
Example 4
Source File: MsSpectrumPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public void handleCopySpectra(Event event) {
  StringBuilder sb = new StringBuilder();
  for (MsSpectrumDataSet dataset : datasets) {
    MsSpectrum spectrum = dataset.getSpectrum();
    String spectrumString = TxtExportAlgorithm.spectrumToString(spectrum);
    String splash = SplashCalculationAlgorithm.calculateSplash(spectrum);
    sb.append("# ");
    sb.append(dataset.getName());
    sb.append("\n");
    sb.append("# SPLASH ID: ");
    sb.append(splash);
    sb.append("\n");
    sb.append(spectrumString);
    sb.append("\n");
  }
  final Clipboard clipboard = Clipboard.getSystemClipboard();
  final ClipboardContent content = new ClipboardContent();
  content.putString(sb.toString());
  clipboard.setContent(content);
}
 
Example 5
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 6
Source File: CopyPropertiesAction.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void selectPropertiesToCopy(final Node parent, final Widget widget)
{
    final SelectWidgetPropertiesDialog dialog = new SelectWidgetPropertiesDialog(widget);
    DialogHelper.positionDialog(dialog, parent, -200, -400);
    final Optional<List<WidgetProperty<?>>> result = dialog.showAndWait();
    if (! result.isPresent())
        return;
    final List<WidgetProperty<?>> properties = result.get();
    if (properties.isEmpty())
        return;

    // Place XML for selected properties on clipboard
    try
    {
        final ByteArrayOutputStream buf = new ByteArrayOutputStream();
        final ModelWriter model_writer = new ModelWriter(buf);
        model_writer.getWriter().writeStartElement("properties");
        for (WidgetProperty<?> prop : properties)
            model_writer.writeProperty(prop);
        model_writer.getWriter().writeEndElement();
        model_writer.close();

        final String xml = buf.toString();
        final ClipboardContent content = new ClipboardContent();
        content.putString(xml);
        Clipboard.getSystemClipboard().setContent(content);
    }
    catch (Exception ex)
    {
        ExceptionDetailsErrorDialog.openError("Copy Properties", "Cannot copy properties", ex);
    }
}
 
Example 7
Source File: ScanCommandDragDrop.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
public static ClipboardContent createClipboardContent(final List<ScanCommand> commands)
{
    final ClipboardContent content = new ClipboardContent();
    try
    {
        content.putString(XMLCommandWriter.toXMLString(commands));
    }
    catch (Exception ex)
    {
        logger.log(Level.WARNING, "Cannot serialize commands", ex);
    }
    return content;
}
 
Example 8
Source File: TableUtils.java    From kafka-message-tool with MIT License 5 votes vote down vote up
private static void copySelectionToClipboard(TableView<?> table) {

        StringBuilder clipboardString = new StringBuilder();

        ObservableList<TablePosition> positionList = table.getSelectionModel().getSelectedCells();

        if (positionList.size() == 0) {
            return;
        }
        if (positionList.size() > 1) {
            Logger.error("Invalid selection: should be selected only one cell, but is " + positionList.size());
            return;
        }

        TablePosition position = positionList.get(0);
        int row = position.getRow();
        int col = position.getColumn();

        Object cell = table.getColumns().get(col).getCellData(row);
        if (cell == null) {
            return;
        }

        clipboardString.append(cell.toString());
        final ClipboardContent clipboardContent = new ClipboardContent();
        clipboardContent.putString(clipboardString.toString());
        Clipboard.getSystemClipboard().setContent(clipboardContent);
    }
 
Example 9
Source File: UIMenuItem.java    From tcMenu with Apache License 2.0 5 votes vote down vote up
public boolean handleCopy() {
    TextField focused = getFocusedTextField();
    if (focused == null) return false;
    String text = focused.getSelectedText();

    if (!StringHelper.isStringEmptyOrNull(text)) {
        Clipboard systemClipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        content.putString(text);
        systemClipboard.setContent(content);
    }
    return true;
}
 
Example 10
Source File: ShipTablePane.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 表示されている艦をクリップボードにコピーする。
 *
 * @param table テーブル
 */
public static void displayCopy(TableView<ShipItem> table) {
    ClipboardContent content = new ClipboardContent();
    content.putString(text(table.getItems()
            .stream()
            .map(ShipItem::getShip)
            .collect(Collectors.toList())));
    Clipboard.getSystemClipboard().setContent(content);
}
 
Example 11
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 12
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 13
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 14
Source File: ClickableBitcoinAddress.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@FXML
protected void copyAddress(ActionEvent event) {
    // User clicked icon or menu item.
    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.putString(addressStr.get());
    content.putHtml(String.format("<a href='%s'>%s</a>", uri(), addressStr.get()));
    clipboard.setContent(content);
}
 
Example 15
Source File: PasteboardImpl.java    From oim-fx with MIT License 5 votes vote down vote up
@Override
public void writeSelection(boolean canSmartCopyOrDelete, String text, String html) {
	ClipboardContent content = new ClipboardContent();
	content.putString(text);
	content.putHtml(html);
	clipboard.setContent(content);
}
 
Example 16
Source File: Tools.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 選択行をヘッダ付きでクリップボードにコピーします
 *
 * @param table テーブル
 */
public static void selectionCopy(TableView<?> table) {
    ClipboardContent content = new ClipboardContent();
    content.putString(selectionToString(table));
    Clipboard.getSystemClipboard()
            .setContent(content);
}
 
Example 17
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 18
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 19
Source File: PasteboardImpl.java    From oim-fx with MIT License 4 votes vote down vote up
@Override
public void writePlainText(String text) {
	ClipboardContent content = new ClipboardContent();
	content.putString(text);
	clipboard.setContent(content);
}
 
Example 20
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);
}