Add choosing directory

This commit is contained in:
Mateusz Kowalczyk 2020-01-05 15:32:01 +01:00
parent fea377697f
commit 49c7465f07
5 changed files with 62 additions and 4 deletions

View File

@ -0,0 +1,17 @@
package dev.mateuszkowalczyk.ffm.app;
import dev.mateuszkowalczyk.ffm.data.Chooser;
import dev.mateuszkowalczyk.ffm.utils.PropertiesLoader;
import dev.mateuszkowalczyk.ffm.utils.Property;
import java.util.Properties;
public class WorkspaceService {
private PropertiesLoader propertiesLoader = new PropertiesLoader();
public void setupWorkspace() {
Chooser chooser = new Chooser();
String path = chooser.chooseDirectory();
this.propertiesLoader.set(Property.PATH_TO_DIRECTORY, path);
}
}

View File

@ -0,0 +1,20 @@
package dev.mateuszkowalczyk.ffm.data;
import dev.mateuszkowalczyk.ffm.view.StageController;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import java.io.File;
public class Chooser {
private StageController stageController = StageController.getInstance();
public String chooseDirectory() {
DirectoryChooser directoryChooser = new DirectoryChooser();
Stage stage = this.stageController.getStage();
File selectedDirectory = directoryChooser.showDialog(stage);
return selectedDirectory.getAbsolutePath();
}
}

View File

@ -32,6 +32,10 @@ public class PropertiesLoader {
return this.properties;
}
public void save() {
this.save(this.properties);
}
public void save(Properties prop) {
try {
OutputStream output = new FileOutputStream(this.resourceLoader.getPath(CONFIG_NAME_FILE));
@ -51,4 +55,14 @@ public class PropertiesLoader {
return this.properties.getProperty(name);
}
public void set(String name, String value) {
if (this.properties == null) {
this.load();
}
this.properties.setProperty(name, value);
this.save();
}
}

View File

@ -1,7 +1,7 @@
package dev.mateuszkowalczyk.ffm.view;
import dev.mateuszkowalczyk.ffm.utils.Property;
import dev.mateuszkowalczyk.ffm.utils.PropertiesLoader;
import dev.mateuszkowalczyk.ffm.utils.Property;
import dev.mateuszkowalczyk.ffm.utils.ResourceLoader;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
@ -16,17 +16,22 @@ public class StageController {
private PropertiesLoader propertiesLoader = PropertiesLoader.getInstance();
private Stage stage;
private StageController() {}
private StageController() {
}
public static StageController getInstance() {
return instance;
}
public Stage getStage() {
return stage;
}
public void initApp(Stage stage) throws IOException {
this.stage = stage;
this.stage.setTitle("Friend Face Matcher");
URL sceneUrl = null;
URL sceneUrl;
if (this.propertiesLoader.get(Property.PATH_TO_DIRECTORY) != null) {
sceneUrl = this.resourceLoader.getResource("welcomePage.fxml");
} else {

View File

@ -1,5 +1,6 @@
package dev.mateuszkowalczyk.ffm.view.controller;
import dev.mateuszkowalczyk.ffm.app.WorkspaceService;
import javafx.fxml.FXML;
public class WelcomePageController {
@ -9,6 +10,7 @@ public class WelcomePageController {
@FXML
public void startNewApp(){
System.out.println("Button work");;
var workspaceService = new WorkspaceService();
workspaceService.setupWorkspace();
}
}