Skip to content

Commit

Permalink
Removed instant 'sorting' from model to speed up process.
Browse files Browse the repository at this point in the history
Added new skin based on CSS.
Added custom (self made) PNG icons for files.
Replaced progress indicator with progress bar.
Added buffer to reduce number of runnables performing updates on central
observable list of files.
  • Loading branch information
Oliver-Loeffler committed Mar 11, 2018
1 parent 0027e3c commit b278c79
Show file tree
Hide file tree
Showing 61 changed files with 698 additions and 202 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ It turned out that with slow network connections the experience is great when us
* The choose directory button provides a menu, where default locations (or a history of locations) can be provided. **(tbd.)**
* File types can be selected from filters **(tbd.)**

![default locations](pages/DefaultLocationsExample.png) ![default locations](pages/PathFilterExample.png)

![default locations](pages/DefaultLocationsExample.png) ![path filter](pages/PathFilterExample.png) ![search option](pages/SortingMenuExample.png)

**Ideas**
* A nice build script.
Expand Down Expand Up @@ -119,8 +118,4 @@ final class FileUpdateService extends javafx.concurrent.Service<Void> {
return new FindFilesTask(rootFolder.getValue(), pathsToUpdate);
}
}
```

The FindFilesTask so far only lists files matching the Predicate<Path> `Files::isRegularFile`.

![Swing version with Filter](pages/Windows81_Swing_Dialog_ProcessRunning.png)
```
1 change: 1 addition & 0 deletions TestData/fiveFiles/HorrbibleSpreadSheet.xls
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestFile1.txt
1 change: 1 addition & 0 deletions TestData/fiveFiles/JustNumbers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestFile1.txt
1 change: 1 addition & 0 deletions TestData/fiveFiles/NewerDocument.docx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestFile1.txt
1 change: 1 addition & 0 deletions TestData/fiveFiles/OldDocument.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestFile1.txt
1 change: 1 addition & 0 deletions TestData/fiveFiles/SupposedToBeXtensible.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestFile1.txt
1 change: 1 addition & 0 deletions TestData/fiveFiles/XtremeHorrbibleSpreadSheet.xlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestFile1.txt
Binary file modified pages/DefaultLocationsExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pages/PathFilterExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/SortingMenuExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/Windows81_JavaFX_Stage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pages/Windows81_Swing_Dialog_Filtered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions src/main/java/net/raumzeitfalle/fx/DemoJavaFxStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ public class DemoJavaFxStage extends Application {
@Override
public void start(Stage primaryStage) throws Exception {

PathFilter exe = PathFilter.create(".exe", p->p.getFileName().toString().toLowerCase().endsWith(".exe"));
PathFilter xml = PathFilter.create(".xml", p->p.getFileName().toString().toLowerCase().endsWith(".xml"));
PathFilter txt = PathFilter.create(".txt", p->p.getFileName().toString().toLowerCase().endsWith(".txt"));
PathFilter exe = PathFilter.create(".exe", p->p.getName().toString().toLowerCase().endsWith(".exe"));
PathFilter xml = PathFilter.create(".xml", p->p.getName().toString().toLowerCase().endsWith(".xml"));
PathFilter txt = PathFilter.create(".txt", p->p.getName().toString().toLowerCase().endsWith(".txt"));

PathFilter xlsx = PathFilter.create(".xls or .xlsx", p-> p.getFileName().toString().toLowerCase().endsWith(".xls")
|| p.getFileName().toString().toLowerCase().endsWith(".xlsx"));
PathFilter xlsx = PathFilter.create(".xls or .xlsx", p-> p.getName().toString().toLowerCase().endsWith(".xls")
|| p.getName().toString().toLowerCase().endsWith(".xlsx"));

PathFilter na0 = PathFilter.forFileExtension(".na0 (LMS binary files)", "n[a-z]\\d");

Path remote = Paths.get("\\\\SEDNA\\Temp\\TEST");
Path local = Paths.get("C:\\Users\\Oliver\\Downloads");
FXFileChooserStage fc = FXFileChooserStage.create(local,xml, xlsx, na0, txt, exe);

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/raumzeitfalle/fx/DemoJavaSwingIntegration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.raumzeitfalle.fx;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
Expand All @@ -20,21 +21,20 @@ private static void initAndShowGui() {

JButton showDialog = new JButton("Show JavaFX Stage as Dialog in Swing: SwingFileChooser.class");

PathFilter xml = PathFilter.create(".xml", p->p.getFileName().toString().toLowerCase().endsWith(".xml"));
PathFilter txt = PathFilter.create(".txt", p->p.getFileName().toString().toLowerCase().endsWith(".txt"));
PathFilter xml = PathFilter.create(".xml", p->p.getName().toString().toLowerCase().endsWith(".xml"));
PathFilter txt = PathFilter.create(".txt", p->p.getName().toString().toLowerCase().endsWith(".txt"));

PathFilter xlsx = PathFilter.create(".xls or .xlsx", p-> p.getFileName().toString().toLowerCase().endsWith(".xls")
|| p.getFileName().toString().toLowerCase().endsWith(".xlsx"));
PathFilter xlsx = PathFilter.create(".xls or .xlsx", p-> p.getName().toString().toLowerCase().endsWith(".xls")
|| p.getName().toString().toLowerCase().endsWith(".xlsx"));

PathFilter na0 = PathFilter.forFileExtension(".na0 (LMS binary files)", "n[a-z]\\d");

SwingFileChooser fileChooser = SwingFileChooser.create(xml, xlsx, na0, txt);

SwingFileChooser fileChooser = SwingFileChooser.create(xml, xlsx, txt);
showDialog.addActionListener(l -> {
int option = fileChooser.showOpenDialog(frame);
System.out.println(option);

if (option == SwingFileChooser.APPROVE_OPTION) {
System.out.println(fileChooser.getSelectedFile().toString());
System.out.println(fileChooser.getSelectedFile());
}

});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.raumzeitfalle.fx.filechooser;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.Optional;

import javafx.beans.property.ObjectProperty;
import javafx.stage.DirectoryChooser;
import javafx.stage.Window;

public class FXDirectoryChooser implements PathSupplier {

public static FXDirectoryChooser createIn(ObjectProperty<Path> startLocation, Window owner) {

Path location = startLocation.get();

if (null == location) {
location = Paths.get("");
}

return new FXDirectoryChooser(location, owner);
}

public static FXDirectoryChooser createIn(Path startLocation, Window owner) {
Objects.requireNonNull(startLocation,"startLocation for file search must not be null.");
return new FXDirectoryChooser(startLocation, owner);
}

private final DirectoryChooser dc;

private final Window owner;

private FXDirectoryChooser(Path startLocation, Window owner) {
this.dc = new DirectoryChooser();
this.dc.setInitialDirectory(startLocation.toFile());
this.owner = owner;
}

@Override
public Optional<Path> get() {
File selection = this.dc.showDialog(owner);

if (null != selection)
return Optional.of(selection.toPath());

return Optional.empty();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.raumzeitfalle.fx.filechooser;

import java.io.File;
import java.net.URL;
import java.nio.file.Path;
import java.util.ResourceBundle;
Expand All @@ -14,15 +15,12 @@
import javafx.scene.control.ListView;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.SplitMenuButton;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;

import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.scene.shape.SVGPath;

final class FileChooserController implements Initializable {

Expand All @@ -46,15 +44,16 @@ final class FileChooserController implements Initializable {

@FXML
private Label allPathsCount;



@FXML
private ProgressIndicator progress;
private ProgressBar progressBar;

@FXML
private TextField fileNameFilter;

@FXML
private ListView<Path> listOfFiles;
private ListView<File> listOfFiles;

@FXML
private TextField selectedFile;
Expand All @@ -65,6 +64,15 @@ final class FileChooserController implements Initializable {
@FXML
private Button stopButton;

@FXML
private MenuButton sortMenu;

@FXML
private MenuItem buttonSortAz;

@FXML
private MenuItem buttonSortZa;

@FXML
private Button okButton;

Expand All @@ -76,37 +84,38 @@ final class FileChooserController implements Initializable {

private final FileChooserModel model;

private final DirectoryChooser dirChooser;

private final HideableWindow stage;

private final UsePattern usagePattern;

private final PathSupplier pathSupplier;

public static FileChooserController withDialog(final FileChooserModel fileChooserModel, final Dialog<Path> dialogWindow) {
return new FileChooserController(fileChooserModel, ()->dialogWindow.close(), UsePattern.DIALOG);
public static FileChooserController withDialog(final FileChooserModel fileChooserModel, final PathSupplier pathSupplier, final Dialog<Path> dialogWindow) {
return new FileChooserController(fileChooserModel, pathSupplier, ()->dialogWindow.close(), UsePattern.DIALOG);
}

public static FileChooserController withStage(final FileChooserModel fileChooserModel, final HideableWindow window) {
return new FileChooserController(fileChooserModel, ()->window.hide(), UsePattern.NORMAL_STAGE);
public static FileChooserController withStage(final FileChooserModel fileChooserModel, final PathSupplier pathSupplier, final HideableWindow window) {
return new FileChooserController(fileChooserModel, pathSupplier, ()->window.hide(), UsePattern.NORMAL_STAGE);
}


private FileChooserController(final FileChooserModel fileChooserModel, final HideableWindow window, UsePattern useCase) {
private FileChooserController(final FileChooserModel fileChooserModel, final PathSupplier pathSupplier, final HideableWindow window, UsePattern useCase) {
this.model = fileChooserModel;
this.dirChooser = new DirectoryChooser();
this.stage = window;
this.usagePattern = useCase;
this.pathSupplier = pathSupplier;
}

@Override
public void initialize(URL location, ResourceBundle resources) {
this.listOfFiles.setItems(this.model.getSortedPaths());
this.listOfFiles.setItems(this.model.getFilteredPaths()); // .getSortedPaths() => consider sorting in a table model

fileNameFilter.textProperty().addListener( l -> {
this.listOfFiles.getSelectionModel().clearSelection();
this.model.updateFilterCriterion(fileNameFilter.getText());
});


listOfFiles.setCellFactory(c -> new FilesListCell());
listOfFiles.getSelectionModel().selectedItemProperty().addListener(l -> {
model.setSelectedFile(selectedItem());
Expand All @@ -129,35 +138,55 @@ public void initialize(URL location, ResourceBundle resources) {

});

// TODO: Ensure the proper owner window is passed into dirChooser
chooser.setOnAction(e -> {
Platform.runLater(()->{
fileChooserForm.setDisable(true);

// TODO: make dirChooser exchangeable and assign owner outside the controller.
model.updateFilesIn(dirChooser.showDialog(null));
pathSupplier.get().ifPresent(model::updateFilesIn);
fileChooserForm.setDisable(false);
});
});

refreshButton.setOnAction(e -> model.refreshFiles());
stopButton.setOnAction(e -> model.getFileUpdateService().cancel());
buttonSortAz.setOnAction(e -> {
Invoke.later(()->{
model.sort((a,b)->a.getName().compareTo(b.getName()));
SVGPath svgPath = new SVGPath();
svgPath.getStyleClass().add("tool-bar-icon");
svgPath.setContent(((SVGPath)buttonSortAz.getGraphic()).getContent());
sortMenu.setGraphic(svgPath);
});
});

buttonSortZa.setOnAction(e -> {
Invoke.later(()->{
model.sort((a,b)->b.getName().compareTo(a.getName()));


SVGPath svgPath = new SVGPath();
svgPath.getStyleClass().add("tool-bar-icon");
svgPath.setContent(((SVGPath)buttonSortZa.getGraphic()).getContent());
sortMenu.setGraphic(svgPath);
sortMenu.getGraphic().getStyleClass().add("tool-bar-icon");
});

});

ReadOnlyBooleanProperty updateIsRunning = model.getFileUpdateService().runningProperty();

/*
* TODO: replace progress indicator by progress bar which is updated in intervals only
* OR use indicator for small sets and bar for large data sets
*/
progress.visibleProperty().bind(updateIsRunning);
progressBar.progressProperty().bind(model.getFileUpdateService().progressProperty());

//counterPane.visibleProperty().bind(updateIsRunning);
counterPane.setVisible(false);
counterPane.setVisible(true);
stopButton.visibleProperty().bind(updateIsRunning);

// TODO: update counts after refresh
//filteredPathsCount.textProperty().bind(model.filteredPathsSizeProperty().asString());
//allPathsCount.textProperty().bind(model.allPathsSizeProperty().asString());
filteredPathsCount.textProperty().bind(model.filteredPathsSizeProperty().asString());
allPathsCount.textProperty().bind(model.allPathsSizeProperty().asString());

okButton.setOnAction(e -> {
this.stage.hide();
Expand Down Expand Up @@ -187,7 +216,7 @@ public void initialize(URL location, ResourceBundle resources) {
}
}

private Path selectedItem() {
private File selectedItem() {
return listOfFiles.getSelectionModel().selectedItemProperty().getValue();
}

Expand Down
Loading

0 comments on commit b278c79

Please sign in to comment.