예제 #1
0
 private void dragConsume(DragEvent e, Consumer<DragEvent> c) {
   List<File> files = e.getDragboard().getFiles();
   if (files != null && !files.isEmpty()) {
     c.accept(e);
   }
   e.consume();
 }
  @FXML
  void dragExited(DragEvent event) {
    /* mouse moved away, remove the graphical cues */
    imageView.setEffect(null);

    event.consume();
  }
  @FXML
  void dragDone(DragEvent event) {
    /* the drag-and-drop gesture ended */

    /* if the data was successfully moved, clear it */
    if (event.getTransferMode() == TransferMode.MOVE) {}

    event.consume();
  }
예제 #4
0
  @FXML
  public void onDragOverFolder(DragEvent event) {
    Dragboard dragboard = event.getDragboard();

    if (dragboard.hasFiles()
        && dragboard.getFiles().size() == 1
        && dragboard.getFiles().get(0).isDirectory()) {
      event.acceptTransferModes(TransferMode.COPY);
    }

    event.consume();
  }
예제 #5
0
  @FXML
  public void onDragDroppedFile(DragEvent event) {
    Dragboard dragboard = event.getDragboard();

    this.targetFiles = dragboard.getFiles();
    this.targetFilesLabel.setText(this.targetFiles.size() + " 件選択されています");
    this.targetFilesLabel.setDisable(true);
    this.filterTextField.setDisable(false);
    this.filterTextField.requestFocus();

    event.setDropCompleted(true);
    event.consume();
  }
  @FXML
  void dragOver(DragEvent event) {

    /* data is dragged over the target */

    /* accept it only if it is  not dragged from the same node
     * and if it has a string data */
    if (event.getGestureSource() != imageView && event.getDragboard().hasString()) {
      /* allow for both copying and moving, whatever user chooses */
      event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
    }

    event.consume();
  }
  @FXML
  void dragEntered(DragEvent event) {

    /* the drag-and-drop gesture entered the target */

    /* show to the user that it is an actual gesture target */
    if (event.getGestureSource() != imageView && event.getDragboard().hasString()) {
      ColorAdjust colorAdjust = new ColorAdjust();
      colorAdjust.setBrightness(0.5);
      imageView.setEffect(colorAdjust);
    }

    event.consume();
  }
예제 #8
0
  @FXML
  public void onDragOverFile(DragEvent event) {
    Dragboard dragboard = event.getDragboard();

    if (dragboard.hasFiles()) {
      boolean allFile = dragboard.getFiles().stream().allMatch(File::isFile);

      if (allFile) {
        event.acceptTransferModes(TransferMode.COPY);
      }
    }

    event.consume();
  }
  @FXML
  void dragDropped(DragEvent event) {
    /* data dropped */
    /* if there is a string data on dragboard, read it and use it */
    Dragboard db = event.getDragboard();
    boolean success = false;
    if (db.hasUrl()) {
      imageView.setImage(new LocatedImage(db.getUrl()));
      success = true;
    }
    /* let the source know whether the string was successfully
     * transferred and used */
    event.setDropCompleted(success);

    event.consume();
  }
예제 #10
0
  @FXML
  public void onDragDroppedFolder(DragEvent event) {
    Dragboard dragboard = event.getDragboard();

    File folder = dragboard.getFiles().get(0);

    DestinationFolder dest = new DestinationFolder(folder);

    if (this.repository.existsSameFolder(dest)) {
      Alert alert = new Alert(AlertType.ERROR);
      alert.setTitle("エラー");
      alert.setHeaderText("既にフォルダが登録されています。");
      alert.getDialogPane().setContentText(dest.getDestPath());
      alert.show();
    } else {
      TextInputDialog dialog = new TextInputDialog();
      dialog.setTitle("フォルダ追加");
      dialog.setContentText("フォルダ名");
      dialog.setHeaderText(dest.getDestPath());
      dialog.getEditor().setText(dest.getName());

      dialog.setOnCloseRequest(
          e -> {
            TextInputDialog d = (TextInputDialog) e.getTarget();
            String result = d.getResult();

            if (result != null) {
              if (result.isEmpty()) {
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("エラー");
                alert.setHeaderText("フォルダ名に空は指定できません。");
                alert.show();
              } else {
                dest.setName(result);
                this.repository.registerFolder(dest);
                this.destinationFolders = repository.findAll();
                this.refreshDestFolderListView();
              }
            }
          });

      dialog.show();
    }

    event.setDropCompleted(true);
    event.consume();
  }