Add choosing directory
This commit is contained in:
parent
fea377697f
commit
49c7465f07
@ -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);
|
||||||
|
}
|
||||||
|
}
|
20
src/main/java/dev/mateuszkowalczyk/ffm/data/Chooser.java
Normal file
20
src/main/java/dev/mateuszkowalczyk/ffm/data/Chooser.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,10 @@ public class PropertiesLoader {
|
|||||||
return this.properties;
|
return this.properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
this.save(this.properties);
|
||||||
|
}
|
||||||
|
|
||||||
public void save(Properties prop) {
|
public void save(Properties prop) {
|
||||||
try {
|
try {
|
||||||
OutputStream output = new FileOutputStream(this.resourceLoader.getPath(CONFIG_NAME_FILE));
|
OutputStream output = new FileOutputStream(this.resourceLoader.getPath(CONFIG_NAME_FILE));
|
||||||
@ -51,4 +55,14 @@ public class PropertiesLoader {
|
|||||||
|
|
||||||
return this.properties.getProperty(name);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package dev.mateuszkowalczyk.ffm.view;
|
package dev.mateuszkowalczyk.ffm.view;
|
||||||
|
|
||||||
import dev.mateuszkowalczyk.ffm.utils.Property;
|
|
||||||
import dev.mateuszkowalczyk.ffm.utils.PropertiesLoader;
|
import dev.mateuszkowalczyk.ffm.utils.PropertiesLoader;
|
||||||
|
import dev.mateuszkowalczyk.ffm.utils.Property;
|
||||||
import dev.mateuszkowalczyk.ffm.utils.ResourceLoader;
|
import dev.mateuszkowalczyk.ffm.utils.ResourceLoader;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
@ -16,17 +16,22 @@ public class StageController {
|
|||||||
private PropertiesLoader propertiesLoader = PropertiesLoader.getInstance();
|
private PropertiesLoader propertiesLoader = PropertiesLoader.getInstance();
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
|
|
||||||
private StageController() {}
|
private StageController() {
|
||||||
|
}
|
||||||
|
|
||||||
public static StageController getInstance() {
|
public static StageController getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stage getStage() {
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
public void initApp(Stage stage) throws IOException {
|
public void initApp(Stage stage) throws IOException {
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
this.stage.setTitle("Friend Face Matcher");
|
this.stage.setTitle("Friend Face Matcher");
|
||||||
|
|
||||||
URL sceneUrl = null;
|
URL sceneUrl;
|
||||||
if (this.propertiesLoader.get(Property.PATH_TO_DIRECTORY) != null) {
|
if (this.propertiesLoader.get(Property.PATH_TO_DIRECTORY) != null) {
|
||||||
sceneUrl = this.resourceLoader.getResource("welcomePage.fxml");
|
sceneUrl = this.resourceLoader.getResource("welcomePage.fxml");
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.mateuszkowalczyk.ffm.view.controller;
|
package dev.mateuszkowalczyk.ffm.view.controller;
|
||||||
|
|
||||||
|
import dev.mateuszkowalczyk.ffm.app.WorkspaceService;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
|
||||||
public class WelcomePageController {
|
public class WelcomePageController {
|
||||||
@ -9,6 +10,7 @@ public class WelcomePageController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void startNewApp(){
|
public void startNewApp(){
|
||||||
System.out.println("Button work");;
|
var workspaceService = new WorkspaceService();
|
||||||
|
workspaceService.setupWorkspace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user