allow drag and drop in FileNamesComponent
@@ -29,6 +29,7 @@ import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.Tooltip;
+import javafx.scene.input.TransferMode;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
@@ -56,6 +57,7 @@ public class FileNamesComponent extends FlowPane {
txtFilename.setPrefColumnCount(40);
txtFilename.setPrefRowCount(6);
txtFilename.setFont(smallFont);
+ initDragDropped();
Button btnFileBrowser = new Button("Select");
btnFileBrowser.setOnAction(e -> {
@@ -173,4 +175,38 @@ public class FileNamesComponent extends FlowPane {
txtFilename.setTooltip(new Tooltip(toolTip));
}
+ private void initDragDropped() {
+ txtFilename.setOnDragOver(e -> {
+ if (e.getGestureSource() != this && e.getGestureSource() != txtFilename && e.getDragboard()
+ .hasFiles()) {
+ e.acceptTransferModes(TransferMode.COPY_OR_MOVE);
+ }
+ e.consume();
+ });
+ txtFilename.setOnDragDropped(e -> {
+ if (e.getDragboard().hasFiles()) {
+ final List<File> files = e.getDragboard().getFiles();
+ final List<String> patterns = new ArrayList<>();
+
+ StringBuilder sb = new StringBuilder(txtFilename.getText());
+ if(!sb.toString().endsWith("\n")) {
+ sb.append("\n");
+ }
+
+ filters.stream().flatMap(f -> f.getExtensions().stream())
+ .forEach(extension -> patterns.add(extension.toLowerCase().replace("*", "")));
+
+ for (File file : files) {
+ if (patterns.stream().anyMatch(filter -> file.getAbsolutePath().contains(filter))) {
+ sb.append(file.getPath()).append("\n");
+ }
+ }
+
+ txtFilename.setText(sb.toString());
+
+ e.setDropCompleted(true);
+ e.consume();
+ }
+ });
+ }
}
