@FXML
  protected void handleCopyAction(ActionEvent event) {

    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(generatedTextField.getText());
    clipboard.setContent(content);
  }
  /**
   * Copy to clipboard
   *
   * @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);
  }
 @Test
 public void clickCopy() throws Exception {
   FXTestUtils.invokeAndWait(
       () -> {
         Clipboard.getSystemClipboard().clear();
         assertTrue(isBlank(Clipboard.getSystemClipboard().getString()));
       },
       2);
   click("#copyEnvDetails");
   FXTestUtils.invokeAndWait(
       () -> assertTrue(Clipboard.getSystemClipboard().getString().contains("PDFsam")), 1);
 }
  /*
   * Called either when the user clicks the 'paste' button, or when they drop
   * files onto the scene overlay. Supports animating multiple files, or just
   * accepting one file.
   */
  private void checkBoard(Clipboard board, DragEvent de) {
    // clean up from any previous runs
    clear();

    if (board == null) {
      System.out.println("HelloImageClipboard: sorry - null Clipboard");
    }

    if (board.hasImage()) {
      if (de != null) de.acceptTransferModes(TransferMode.ANY);
      imageView.setImage(board.getImage());
      if (de != null) de.setDropCompleted(true);
      System.out.println("HelloImageClipboard: single image");
    } else {
      if (de != null) de.setDropCompleted(false);
      System.out.println("HelloImageClipboard: sorry - no images on the Clipboard");
    }
  }
示例#5
0
 /**
  * Copies the selected text to clipboard.
  *
  * @return True if performed successfully.
  */
 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;
 }
示例#6
0
 /** Paste text from clipboard after the cursor. */
 public void doPaste() {
   getEditor().insert(Clipboard.getSystemClipboard().getString());
 }
  @Override
  public void start(Stage stage) {
    // stage.initStyle(StageStyle.UNDECORATED);
    stage.setTitle("Hello Image Clipboard");
    Scene scene = new Scene(new Group(), 1024, 768);
    scene.setFill(Color.LIGHTGREEN);

    Rectangle overlay = new Rectangle();
    overlay.setWidth(800);
    overlay.setHeight(600);
    overlay.setFill(Color.TRANSPARENT);
    EventHandler<DragEvent> drop = de -> checkBoard(de.getDragboard(), de);

    EventHandler<DragEvent> enter =
        de -> {
          if (de != null && de.getDragboard() != null && de.getDragboard().hasImage()) {
            de.acceptTransferModes(TransferMode.ANY);
          }
        };

    EventHandler<DragEvent> dragged =
        de -> {
          if (de != null && de.getDragboard() != null && de.getDragboard().hasImage()) {
            de.acceptTransferModes(TransferMode.ANY);
          }
        };

    overlay.setOnDragDropped(drop);
    overlay.setOnDragEntered(enter);
    overlay.setOnDragOver(dragged);

    clearBtn = new Button("Clear");
    clearBtn.setTranslateX(50);
    clearBtn.setTranslateY(30);

    copyBtn = new Button("Copy");
    copyBtn.setTranslateX(125);
    copyBtn.setTranslateY(30);

    pasteBtn = new Button("Paste");
    pasteBtn.setTranslateX(200);
    pasteBtn.setTranslateY(30);

    clearBtn.setOnAction(e -> clear());
    copyBtn.setOnAction(
        e -> {
          ClipboardContent content = new ClipboardContent();
          content.putImage(imageView.getImage());
          Clipboard.getSystemClipboard().setContent(content);
        });
    pasteBtn.setOnAction(e -> checkBoard(Clipboard.getSystemClipboard(), null));

    Group root = (Group) scene.getRoot();
    root.getChildren().add(overlay);
    root.getChildren().add(imageView);
    root.getChildren().add(clearBtn);
    root.getChildren().add(copyBtn);
    root.getChildren().add(pasteBtn);

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