@FXML
  protected void handleCopyAction(ActionEvent event) {

    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(generatedTextField.getText());
    clipboard.setContent(content);
  }
Пример #2
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;
 }
 private void addDragHandlers(Node node) {
   node.setOnDragDetected(
       event -> {
         currentlyDraggingNode = node;
         Dragboard dragboard = getToolBar().startDragAndDrop(TransferMode.MOVE);
         ClipboardContent cc = new ClipboardContent();
         cc.putString(""); // Empty string on the clipboard since we need to transfer something
         dragboard.setContent(cc);
       });
 }
  /**
   * 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);
  }
  @FXML
  void dragDetected(MouseEvent event) {
    /* drag was detected, start drag-and-drop gesture*/

    /* allow any transfer mode */
    Dragboard db = imageView.startDragAndDrop(TransferMode.ANY);

    /* put a string on dragboard */
    ClipboardContent content = new ClipboardContent();
    content.putImage(imageView.getImage());
    db.setContent(content);

    event.consume();
  }
Пример #6
0
  public TargetView() {
    setId("targetview");
    setCellFactory(
        e -> {
          return new PageItemListCell();
        });

    getSelectionModel()
        .selectedIndexProperty()
        .addListener(
            (a, b, c) -> {
              ToolbarEvent ev =
                  new ToolbarEvent(
                      this, c.intValue() != -1 ? ToolbarEvent.ENABLE : ToolbarEvent.DISABLE);

              getScene().lookup("#targettoolbar").fireEvent(ev);
            });

    getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    setOnDragDetected(
        de -> {
          Dragboard dragBoard = startDragAndDrop(TransferMode.COPY_OR_MOVE);

          ClipboardContent content = new ClipboardContent();
          ObservableList<PageItem> pi = getSelectionModel().getSelectedItems();
          content.put(PAGE_ITEM_FORMAT, new PageItems(pi));
          // getItems().removeAll(pi);
          dragBoard.setContent(content);
          getSelectionModel().clearSelection();
        });

    setOnDragOver(
        dragEvent -> {
          dragEvent.acceptTransferModes(TransferMode.COPY_OR_MOVE);
        });

    setOnDragDropped(
        dragEvent -> {
          PageItems item = (PageItems) dragEvent.getDragboard().getContent(PAGE_ITEM_FORMAT);

          EventTarget target = dragEvent.getTarget();

          Node p = null;
          if (target instanceof Node) {
            p = (Node) target;
          }

          while (!(p instanceof PageItemListCell) && p != null) {
            p = p.getParent();
          }
          int index = -1;

          if (dragEvent.getTransferMode() == TransferMode.MOVE) {
            getItems().removeAll(item);
          } else {
            ArrayList<PageItem> itemsx = new ArrayList<>(getItems());
            itemsx.addAll(item);
            // copy should change name #1
            item.forEach(
                e -> {
                  e.countUp(itemsx);
                });
          }

          if (p instanceof PageItemListCell) {
            index = getItems().indexOf(((PageItemListCell) p).getItem());
          }
          if (index != -1) {
            getItems().addAll(index, item);
          } else {
            getItems().addAll(item);
          }

          dragEvent.setDropCompleted(true);
        });

    addEventHandler(
        ToolbarEvent.ROTATE,
        e -> {
          System.out.println("R event");
        });
    addEventHandler(
        ToolbarEvent.SAVE,
        e -> {
          System.out.println("SAVE!!");
        });
  }
  @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();
  }
Пример #8
0
  /**
   * Highlights a row if a matching query is found within that row. If there is no matching query,
   * the row's style is set to null (default).
   */
  @Override
  void setFactory() {
    setRowFactory(
        tr -> {
          TableRow<T> row =
              new TableRow<T>() {
                @Override
                protected void updateItem(T item, boolean empty) {
                  super.updateItem(item, empty);

                  if (item != null) {
                    if (matchingItems.contains(item)) {
                      setStyle(
                          "-fx-background-color: "
                              + SearchableControl.highlightColourString
                              + "; ");
                    } else {
                      setStyle(null);
                    }
                  }
                }
              };

          row.setOnDragDetected(
              event -> {
                if (!row.isEmpty()) {
                  Integer index = row.getIndex();
                  Dragboard db = row.startDragAndDrop(TransferMode.MOVE);
                  db.setDragView(row.snapshot(null, null));
                  ClipboardContent cc = new ClipboardContent();
                  cc.put(DataFormat.PLAIN_TEXT, index);
                  db.setContent(cc);
                  event.consume();
                }
              });

          row.setOnDragOver(
              event -> {
                Dragboard db = event.getDragboard();
                if (db.hasContent(DataFormat.PLAIN_TEXT)) {
                  if (row.getIndex() != (Integer) db.getContent(DataFormat.PLAIN_TEXT)) {
                    event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                    event.consume();
                  }
                }
              });

          row.setOnDragDropped(
              event -> {
                Dragboard db = event.getDragboard();
                if (db.hasContent(DataFormat.PLAIN_TEXT)) {
                  int draggedIndex = (Integer) db.getContent(DataFormat.PLAIN_TEXT);
                  T draggedItem = table.getItems().remove(draggedIndex);

                  int dropIndex;

                  if (row.isEmpty()) {
                    dropIndex = table.getItems().size();
                  } else {
                    dropIndex = row.getIndex();
                  }

                  table.getItems().add(dropIndex, draggedItem);

                  event.setDropCompleted(true);
                  table.getSelectionModel().select(dropIndex);
                  event.consume();
                }
              });

          return row;
        });
  }