-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update scan-folder-to-add-files function: set pop-up window with indi…
…cator showing how many files did we scan and how many files would be added. Minor color corrections on light theme for whoever use it Fix TF progress-bar (can't recall when I broke it..)
- Loading branch information
1 parent
619a2b1
commit d8ea426
Showing
11 changed files
with
247 additions
and
32 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
src/main/java/nsusbloader/Controllers/FilesDropHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
Copyright 2019-2020 Dmitry Isaenko | ||
This file is part of NS-USBloader. | ||
NS-USBloader is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
NS-USBloader is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package nsusbloader.Controllers; | ||
|
||
import javafx.geometry.Insets; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.ProgressBar; | ||
import javafx.scene.control.ProgressIndicator; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.Pane; | ||
import javafx.scene.layout.Priority; | ||
import javafx.scene.layout.VBox; | ||
import javafx.stage.Stage; | ||
import nsusbloader.AppPreferences; | ||
import nsusbloader.MediatorControl; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.ResourceBundle; | ||
|
||
public class FilesDropHandle { | ||
|
||
public FilesDropHandle(List<File> files, String filesRegex, String foldersRegex){ | ||
|
||
// | ||
// TODO: ADD GRAPHICS BEFORE RELEASE ! | ||
// | ||
|
||
FilesDropHandleTask filesDropHandleTask = new FilesDropHandleTask(files, filesRegex, foldersRegex); | ||
|
||
ResourceBundle resourceBundle = MediatorControl.getInstance().getResourceBundle(); | ||
Button cancelButton = new Button(resourceBundle.getString("btn_Cancel")); | ||
|
||
ProgressIndicator progressIndicator = new ProgressIndicator(); | ||
progressIndicator.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS); | ||
|
||
Label downloadStatusLabel = new Label(); | ||
downloadStatusLabel.setWrapText(true); | ||
downloadStatusLabel.textProperty().bind(filesDropHandleTask.messageProperty()); | ||
|
||
Pane fillerPane1 = new Pane(); | ||
Pane fillerPane2 = new Pane(); | ||
|
||
VBox parentVBox = new VBox(); | ||
parentVBox.setAlignment(Pos.TOP_CENTER); | ||
parentVBox.setFillWidth(true); | ||
parentVBox.setSpacing(5.0); | ||
parentVBox.setPadding(new Insets(5.0)); | ||
parentVBox.setFillWidth(true); | ||
parentVBox.getChildren().addAll( | ||
downloadStatusLabel, | ||
fillerPane1, | ||
progressIndicator, | ||
fillerPane2, | ||
cancelButton | ||
); // TODO:FIX | ||
|
||
VBox.setVgrow(fillerPane1, Priority.ALWAYS); | ||
VBox.setVgrow(fillerPane2, Priority.ALWAYS); | ||
|
||
Stage stage = new Stage(); | ||
stage.setTitle(resourceBundle.getString("windowTitleAddingFiles")); | ||
stage.getIcons().addAll( | ||
new Image("/res/dwnload_ico32x32.png"), //TODO: REDRAW | ||
new Image("/res/dwnload_ico48x48.png"), | ||
new Image("/res/dwnload_ico64x64.png"), | ||
new Image("/res/dwnload_ico128x128.png") | ||
); | ||
stage.setMinWidth(300); | ||
stage.setMinHeight(175); | ||
stage.setAlwaysOnTop(true); | ||
Scene mainScene = new Scene(parentVBox, 310, 185); | ||
|
||
mainScene.getStylesheets().add(AppPreferences.getInstance().getTheme()); | ||
|
||
stage.setOnHidden(windowEvent -> filesDropHandleTask.cancel(true ) ); | ||
|
||
stage.setScene(mainScene); | ||
stage.show(); | ||
stage.toFront(); | ||
|
||
filesDropHandleTask.setOnSucceeded(event -> { | ||
cancelButton.setText(resourceBundle.getString("btn_Close")); | ||
|
||
List<File> allFiles = filesDropHandleTask.getValue(); | ||
|
||
if (! allFiles.isEmpty()) { | ||
MediatorControl.getInstance().getGamesController().tableFilesListController.setFiles(allFiles); | ||
} | ||
stage.close(); | ||
}); | ||
|
||
new Thread(filesDropHandleTask).start(); | ||
|
||
cancelButton.setOnAction(actionEvent -> { | ||
filesDropHandleTask.cancel(true); | ||
stage.close(); | ||
}); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/java/nsusbloader/Controllers/FilesDropHandleTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright 2019-2020 Dmitry Isaenko | ||
This file is part of NS-USBloader. | ||
NS-USBloader is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
NS-USBloader is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package nsusbloader.Controllers; | ||
|
||
import javafx.concurrent.Task; | ||
import nsusbloader.MediatorControl; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FilesDropHandleTask extends Task<List<File>> { | ||
private final String filesRegex; | ||
private final String foldersRegex; | ||
|
||
private final List<File> filesDropped; | ||
private final List<File> allFiles; | ||
|
||
private String messageTemplate; | ||
private long filesScanned = 0; | ||
private long filesAdded = 0; | ||
|
||
FilesDropHandleTask(List<File> files, | ||
String filesRegex, | ||
String foldersRegex) { | ||
this.filesDropped = files; | ||
this.filesRegex = filesRegex; | ||
this.foldersRegex = foldersRegex; | ||
this.allFiles = new ArrayList<>(); | ||
this.messageTemplate = MediatorControl.getInstance().getResourceBundle().getString("windowBodyFilesScanned"); | ||
} | ||
|
||
@Override | ||
protected List<File> call() { | ||
if (filesDropped == null || filesDropped.size() == 0) | ||
return allFiles; | ||
|
||
for (File file : filesDropped){ | ||
if (isCancelled()) | ||
return new ArrayList<>(); | ||
collectFiles(file); | ||
updateMessage(String.format(messageTemplate, filesScanned++, filesAdded)); | ||
} | ||
|
||
return allFiles; | ||
} | ||
|
||
private void collectFiles(File startFolder) { | ||
if (startFolder == null) | ||
return; | ||
|
||
final String startFolderNameInLowercase = startFolder.getName().toLowerCase(); | ||
|
||
if (startFolder.isFile()) { | ||
if (startFolderNameInLowercase.matches(filesRegex)) { | ||
allFiles.add(startFolder); | ||
filesAdded++; | ||
} | ||
return; | ||
} | ||
|
||
if (startFolderNameInLowercase.matches(foldersRegex)) { | ||
allFiles.add(startFolder); | ||
filesAdded++; | ||
return; | ||
} | ||
|
||
File[] files = startFolder.listFiles(); | ||
if (files == null) | ||
return; | ||
|
||
for (File file : files) { | ||
if (isCancelled()) | ||
return; | ||
collectFiles(file); | ||
updateMessage(String.format(messageTemplate, filesScanned++, filesAdded)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.