Exemplo n.º 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();
 }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
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();
  }
Exemplo n.º 6
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();
  }
Exemplo n.º 8
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();
  }
  @FXML
  public void webViewDragDropped(DragEvent event) {
    Dragboard db = event.getDragboard();
    boolean dropCompleted = false;

    if (db.hasFiles()) {
      File draggedFile = db.getFiles().get(0);

      if (draggedFile.getName().toLowerCase().endsWith(".html")) {
        try {
          URL url = new URL("file", "", draggedFile.getAbsolutePath());
          loadContent(url);
          dropCompleted = true;
        } catch (MalformedURLException ex) {
        }
      }
    }

    event.setDropCompleted(dropCompleted);
  }