Example usage for javafx.scene.input ClipboardContent ClipboardContent

List of usage examples for javafx.scene.input ClipboardContent ClipboardContent

Introduction

In this page you can find the example usage for javafx.scene.input ClipboardContent ClipboardContent.

Prototype

ClipboardContent

Source Link

Usage

From source file:io.github.mzmine.util.jfreechart.JFreeChartUtils.java

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);// w  w  w .j ava 2 s .  co  m
    content.putImage(img);
    clipboard.setContent(content);
}

From source file:com.cdd.bao.editor.endpoint.BrowseEndpoint.java

public void actionCopy() {
    Branch branch = currentBranchValue();
    if (branch == null || branch.assay == null)
        return;// w  ww .j a va  2s  .c  om

    JSONObject json = ClipboardSchema.composeAssay(branch.assay);

    String serial = null;
    try {
        serial = json.toString(2);
    } catch (JSONException ex) {
        return;
    }

    ClipboardContent content = new ClipboardContent();
    content.putString(serial);
    if (!Clipboard.getSystemClipboard().setContent(content)) {
        Util.informWarning("Clipboard Copy", "Unable to copy to the clipboard.");
        return;
    }

}

From source file:io.bitsquare.common.util.Utilities.java

public static void copyToClipboard(String content) {
    try {//from  ww w.ja  v  a2s . c o m
        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();
    }
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Menu Sample");
    Scene scene = new Scene(new VBox(), 400, 350);
    scene.setFill(Color.OLDLACE);

    name.setFont(new Font("Verdana Bold", 22));
    binName.setFont(new Font("Arial Italic", 10));
    pic.setFitHeight(150);/*from  w  ww  . j a  v  a  2 s .c  o m*/
    pic.setPreserveRatio(true);
    description.setWrapText(true);
    description.setTextAlignment(TextAlignment.JUSTIFY);

    shuffle();

    MenuBar menuBar = new MenuBar();

    // --- Graphical elements
    final VBox vbox = new VBox();
    vbox.setAlignment(Pos.CENTER);
    vbox.setSpacing(10);
    vbox.setPadding(new Insets(0, 10, 0, 10));
    vbox.getChildren().addAll(name, binName, pic, description);

    // --- Menu File
    Menu menuFile = new Menu("File");
    MenuItem add = new MenuItem("Shuffle", new ImageView(new Image("src/menusample/new.png")));
    add.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            shuffle();
            vbox.setVisible(true);
        }
    });

    MenuItem clear = new MenuItem("Clear");
    clear.setAccelerator(KeyCombination.keyCombination("Ctrl+X"));
    clear.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            vbox.setVisible(false);
        }
    });

    MenuItem exit = new MenuItem("Exit");
    exit.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            System.exit(0);
        }
    });

    menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit);

    // --- Menu Edit
    Menu menuEdit = new Menu("Edit");
    Menu menuEffect = new Menu("Picture Effect");

    final ToggleGroup groupEffect = new ToggleGroup();
    for (Entry effect : effects) {
        RadioMenuItem itemEffect = new RadioMenuItem((String) effect.getKey());
        itemEffect.setUserData(effect.getValue());
        itemEffect.setToggleGroup(groupEffect);
        menuEffect.getItems().add(itemEffect);
    }

    final MenuItem noEffects = new MenuItem("No Effects");
    noEffects.setDisable(true);
    noEffects.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            pic.setEffect(null);
            groupEffect.getSelectedToggle().setSelected(false);
            noEffects.setDisable(true);
        }
    });

    groupEffect.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue ov, Toggle old_toggle, Toggle new_toggle) {
            if (groupEffect.getSelectedToggle() != null) {
                Effect effect = (Effect) groupEffect.getSelectedToggle().getUserData();
                pic.setEffect(effect);
                noEffects.setDisable(false);
            } else {
                noEffects.setDisable(true);
            }
        }
    });

    menuEdit.getItems().addAll(menuEffect, noEffects);

    // --- Menu View
    Menu menuView = new Menu("View");
    CheckMenuItem titleView = createMenuItem("Title", name);
    CheckMenuItem binNameView = createMenuItem("Binomial name", binName);
    CheckMenuItem picView = createMenuItem("Picture", pic);
    CheckMenuItem descriptionView = createMenuItem("Decsription", description);

    menuView.getItems().addAll(titleView, binNameView, picView, descriptionView);
    menuBar.getMenus().addAll(menuFile, menuEdit, menuView);

    // --- Context Menu
    final ContextMenu cm = new ContextMenu();
    MenuItem cmItem1 = new MenuItem("Copy Image");
    cmItem1.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
            Clipboard clipboard = Clipboard.getSystemClipboard();
            ClipboardContent content = new ClipboardContent();
            content.putImage(pic.getImage());
            clipboard.setContent(content);
        }
    });

    cm.getItems().add(cmItem1);
    pic.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (e.getButton() == MouseButton.SECONDARY)
                cm.show(pic, e.getScreenX(), e.getScreenY());
        }
    });

    ((VBox) scene.getRoot()).getChildren().addAll(menuBar, vbox);

    stage.setScene(scene);
    stage.show();
}

From source file:org.sandsoft.acefx.AceEditor.java

/**
 * Copies the selected text to clipboard.
 *
 * @return True if performed successfully.
 *//*  ww w  .ja  v  a  2  s  .  co m*/
public boolean doCopy() {
    String copy = mEditor.getCopyText();
    if (copy != null && !copy.isEmpty()) {
        ClipboardContent content = new ClipboardContent();
        content.putString(copy);
        Clipboard.getSystemClipboard().setContent(content);
        return true;
    }
    return false;
}

From source file:com.chart.SwingChart.java

/**
 * Copy to clipboard/*from  w  ww  .j a  v a 2  s.co m*/
 * @param node JavaFX Node to copy
 */
public final void copyClipboard(final Node node) {

    WritableImage captura = node.snapshot(new SnapshotParameters(), null);

    ImageView iv = new ImageView(captura);

    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.put(DataFormat.IMAGE, captura);
    clipboard.setContent(content);

}

From source file:com.joliciel.talismane.terminology.viewer.TerminologyViewerController.java

@FXML
protected void tblTerms_OnKeyPressed(KeyEvent keyEvent) {
    if (keyEvent.isControlDown()) {
        //          LOG.debug("keyEvent.getCharacter(): " + keyEvent.getCharacter());
        //          LOG.debug("keyEvent.getCode().getName(): " + keyEvent.getCode().getName());
        if (keyEvent.getCode().getName().equals("C")) {
            final Clipboard clipboard = Clipboard.getSystemClipboard();
            final ClipboardContent content = new ClipboardContent();
            Term term = tblTerms.getSelectionModel().getSelectedItem();
            content.putString(term.getText());
            clipboard.setContent(content);
        }//www.  jav  a  2  s. c  om
    } else if (keyEvent.getCode().getName().equalsIgnoreCase("M")) {
        this.markTerm();
    } else if (keyEvent.getCode().getName().equalsIgnoreCase("E")) {
        this.doExpansions();
    } else if (keyEvent.getCode().getName().equalsIgnoreCase("B")) {
        this.doBack();
    } else if (keyEvent.getCode().getName().equalsIgnoreCase("F")) {
        this.doForward();
    }
}

From source file:com.joliciel.talismane.terminology.viewer.TerminologyViewerController.java

@FXML
protected void tblContexts_OnKeyPressed(KeyEvent keyEvent) {
    if (keyEvent.isControlDown()) {
        if (keyEvent.getCode().getName().equals("C")) {
            final Clipboard clipboard = Clipboard.getSystemClipboard();
            final ClipboardContent content = new ClipboardContent();
            Context context = tblContexts.getSelectionModel().getSelectedItem();
            content.putString(context.getTextSegment());
            clipboard.setContent(content);
        }/*from   ww  w  .ja v  a 2  s .c  o m*/
    }
}

From source file:net.rptools.tokentool.controller.TokenTool_Controller.java

@FXML
void editCopyImageMenu_onAction(ActionEvent event) {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();

    // for paste as file, e.g. in Windows Explorer
    try {/*from w  w w .ja  v a  2s  .c  o  m*/
        File tempTokenFile = fileSaveUtil.getTempFileName(false, useFileNumberingCheckbox.isSelected(),
                fileNameTextField.getText(), fileNameSuffixTextField);

        writeTokenImage(tempTokenFile);
        content.putFiles(java.util.Collections.singletonList(tempTokenFile));
        tempTokenFile.deleteOnExit();
    } catch (Exception e) {
        log.error(e);
    }

    // for paste as image, e.g. in GIMP
    content.putImage(tokenImageView.getImage());

    // Finally, put contents on clip board
    clipboard.setContent(content);
}

From source file:com.rockhoppertech.symchords.fx.SymChordsController.java

protected void setupDragonDrop() {
    Image image = new Image(getClass().getResourceAsStream("/images/rocky-32-trans.png"));
    dragImageView = new ImageView(image);
    dragImageView.setFitHeight(32);//w ww . j a v a  2  s. c o  m
    dragImageView.setFitWidth(32);

    grandStaff.setOnDragDetected(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent me) {

            if (!root.getChildren().contains(dragImageView)) {
                root.getChildren().add(dragImageView);
            }

            // dragImageView.setOpacity(0.5);
            dragImageView.toFront();
            dragImageView.setMouseTransparent(true);
            dragImageView.setVisible(true);
            dragImageView.relocate((int) (me.getSceneX() - dragImageView.getBoundsInLocal().getWidth() / 2),
                    (int) (me.getSceneY() - dragImageView.getBoundsInLocal().getHeight() / 2));

            Dragboard db = grandStaff.startDragAndDrop(TransferMode.ANY);

            // TODO remove the custom image nonsense in javafx 8
            // javafx 8
            // db.setDragView(dragImageView);

            ClipboardContent content = new ClipboardContent();
            // MIDITrack track = grandStaff.getMIDITrack();
            MIDITrack track = model.getMIDITrack();
            content.put(midiTrackDataFormat, track);
            db.setContent(content);
            me.consume();
        }
    });

    grandStaff.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent e) {
            dragImageView.setVisible(false);
            e.consume();
        }
    });

    // Parent root = grandStaff.getScene().getRoot();
    // stage.getScene().getRoot();

    if (root != null) {
        root.setOnDragOver(new EventHandler<DragEvent>() {
            public void handle(DragEvent e) {
                Point2D localPoint = grandStaff.getScene().getRoot()
                        .sceneToLocal(new Point2D(e.getSceneX(), e.getSceneY()));
                dragImageView.relocate(
                        (int) (localPoint.getX() - dragImageView.getBoundsInLocal().getWidth() / 2),
                        (int) (localPoint.getY() - dragImageView.getBoundsInLocal().getHeight() / 2));
                e.consume();
            }
        });
    }

    trackList.setOnDragOver(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /*
             * data is dragged over the target; accept it only if it is not
             * dragged from the same node and if it has MIDITrack data
             */
            if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) {
                logger.debug("drag over");
                /* allow for both copying and moving, whatever user chooses */
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
            }

            // Don't consume the event. Let the layers below process the
            // DragOver event as well so that the
            // translucent container image will follow the cursor.
            // event.consume();
        }
    });

    trackList.setOnDragEntered(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture entered the target */
            /* show to the user that it is an actual gesture target */
            logger.debug("drag entered");
            if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) {
                DropShadow dropShadow = new DropShadow();
                dropShadow.setRadius(5.0);
                dropShadow.setOffsetX(3.0);
                dropShadow.setOffsetY(3.0);
                dropShadow.setColor(Color.color(0.4, 0.5, 0.5));
                trackList.setEffect(dropShadow);
            }
            event.consume();
        }
    });

    trackList.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            trackList.setEffect(null);
            event.consume();
        }
    });

    trackList.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {

            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasContent(midiTrackDataFormat)) {
                MIDITrack track = (MIDITrack) db.getContent(midiTrackDataFormat);
                trackList.getItems().add(track);
                success = true;

            }
            /*
             * let the source know whether the data was successfully
             * transferred and used
             */
            event.setDropCompleted(success);
            event.consume();
        }
    });

    logger.debug("jvm mime {}", DataFlavor.javaJVMLocalObjectMimeType);
}