/*
   * 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");
    }
  }
  @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 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();
  }
  @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);
  }