Search in sources :

Example 1 with Clipboard

use of javafx.scene.input.Clipboard in project trex-stateless-gui by cisco-system-traffic-generator.

the class ConsoleLogView method copyToClipboard.

/**
     * Copy console log to clipboard
     */
public void copyToClipboard() {
    // select all text
    logsContent.selectAll();
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(logsContent.getText());
    clipboard.setContent(content);
}
Also used : ClipboardContent(javafx.scene.input.ClipboardContent) Clipboard(javafx.scene.input.Clipboard)

Example 2 with Clipboard

use of javafx.scene.input.Clipboard in project Gargoyle by callakrsos.

the class FxTableViewUtil method installPasteClipboard.

public static <K> void installPasteClipboard(TableView<K> tb, Class<K> clazz, Field targetField) {
    tb.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        if (e.isControlDown() && e.getCode() == KeyCode.V) {
            Clipboard clip = Clipboard.getSystemClipboard();
            ObservableList<TableColumn<K, ?>> columns = tb.getColumns();
            if (columns.isEmpty())
                return;
            Object value = null;
            if (clip.hasFiles()) {
                value = clip.getFiles();
            } else if (clip.hasHtml()) {
                value = clip.getHtml();
            } else if (clip.hasImage()) {
                value = clip.getImage();
            } else if (clip.hasRtf()) {
                value = clip.getRtf();
            } else if (clip.hasString()) {
                value = clip.getString();
            } else if (clip.hasUrl()) {
                value = clip.getUrl();
            }
            if (value == null)
                return;
            try {
                K newInstance = clazz.newInstance();
                Field field = clazz.getField(targetField.getName());
                if (field != null) {
                    if (!field.isAccessible())
                        field.setAccessible(true);
                    field.set(newInstance, value);
                }
                tb.getItems().add(newInstance);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });
}
Also used : Field(java.lang.reflect.Field) Clipboard(javafx.scene.input.Clipboard) TableColumn(javafx.scene.control.TableColumn)

Example 3 with Clipboard

use of javafx.scene.input.Clipboard in project tokentool by RPTools.

the class TokenTool_Controller method editPasteImageMenu_onAction.

@FXML
void editPasteImageMenu_onAction(ActionEvent event) {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    Image originalImage = portraitImageView.getImage();
    // So lets just check for File first...
    if (clipboard.hasFiles()) {
        clipboard.getFiles().forEach(file -> {
            try {
                Image cbImage = new Image(file.toURI().toURL().toExternalForm());
                if (cbImage != null)
                    updatePortrait(cbImage);
                updateFileNameTextField(FilenameUtils.getBaseName(file.toURI().toURL().toExternalForm()));
            } catch (Exception e) {
                log.error("Could not load image " + file);
                e.printStackTrace();
            }
        });
    } else if (clipboard.hasImage()) {
        try {
            Image cbImage = clipboard.getImage();
            if (cbImage != null)
                updatePortrait(cbImage);
        } catch (IllegalArgumentException e) {
            log.info(e);
            updatePortrait(originalImage);
        }
    } else if (clipboard.hasUrl()) {
        try {
            Image cbImage = new Image(clipboard.getUrl());
            if (cbImage != null)
                updatePortrait(cbImage);
            updateFileNameTextField(FileSaveUtil.searchURL(clipboard.getUrl()));
        } catch (IllegalArgumentException e) {
            log.info(e);
        }
    } else if (clipboard.hasString()) {
        try {
            Image cbImage = new Image(clipboard.getString());
            if (cbImage != null)
                updatePortrait(cbImage);
            updateFileNameTextField(FileSaveUtil.searchURL(clipboard.getString()));
        } catch (IllegalArgumentException e) {
            log.info(e);
        }
    }
}
Also used : Clipboard(javafx.scene.input.Clipboard) Image(javafx.scene.image.Image) IOException(java.io.IOException) FXML(javafx.fxml.FXML)

Example 4 with Clipboard

use of javafx.scene.input.Clipboard in project uPMT by coco35700.

the class MomentExpVBox method copyMoment.

/* */
public void copyMoment() {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
}
Also used : ClipboardContent(javafx.scene.input.ClipboardContent) Clipboard(javafx.scene.input.Clipboard)

Example 5 with Clipboard

use of javafx.scene.input.Clipboard in project certmgr by hdecarne.

the class CertExportController method exportToClipboard.

void exportToClipboard(CertWriter format, CertObjectStore exportObjects, boolean encryptExport) throws IOException {
    StringWriter text = new StringWriter();
    try (IOResource<Writer> out = new IOResource<>(text, CertExportI18N.formatSTR_TEXT_CLIPBOARD())) {
        if (encryptExport) {
            format.writeEncryptedString(out, exportObjects, PasswordDialog.enterNewPassword(this));
        } else {
            format.writeString(out, exportObjects);
        }
    }
    String textData = text.toString();
    if (Platform.IS_WINDOWS) {
        // JavaFX on Windows doubles Windows "\r\n" line breaks
        // We replace them Unix line breaks "\n" as a workaround.
        textData = textData.replace("\r\n", "\n");
    }
    String clipboardData = textData;
    PlatformHelper.runLater(() -> {
        Clipboard clipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        content.putString(clipboardData);
        clipboard.setContent(content);
    });
}
Also used : IOResource(de.carne.certmgr.certs.io.IOResource) StringWriter(java.io.StringWriter) ClipboardContent(javafx.scene.input.ClipboardContent) Clipboard(javafx.scene.input.Clipboard) Writer(java.io.Writer) CertWriter(de.carne.certmgr.certs.spi.CertWriter) StringWriter(java.io.StringWriter)

Aggregations

Clipboard (javafx.scene.input.Clipboard)22 ClipboardContent (javafx.scene.input.ClipboardContent)17 FXML (javafx.fxml.FXML)10 IOException (java.io.IOException)5 File (java.io.File)3 StringWriter (java.io.StringWriter)3 UserCertStore (de.carne.certmgr.certs.UserCertStore)2 UserCertStoreEntry (de.carne.certmgr.certs.UserCertStoreEntry)2 Images (de.carne.certmgr.jfx.resources.Images)2 UserCertStoreTreeTableViewHelper (de.carne.certmgr.jfx.util.UserCertStoreTreeTableViewHelper)2 PathPreference (de.carne.certmgr.util.PathPreference)2 Nullable (de.carne.check.Nullable)2 PlatformHelper (de.carne.jfx.application.PlatformHelper)2 Alerts (de.carne.jfx.scene.control.Alerts)2 StageController (de.carne.jfx.stage.StageController)2 Lazy (de.carne.util.Lazy)2 Path (java.nio.file.Path)2 List (java.util.List)2 Preferences (java.util.prefs.Preferences)2 Collectors (java.util.stream.Collectors)2