DialogBoxes

master
Oystein 2021-04-26 11:36:28 +02:00
parent 075988f327
commit 08f9b2b881
4 changed files with 72 additions and 21 deletions

View File

@ -1,16 +1,51 @@
package app.service;
import java.io.File;
import app.model.Model;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class DialogBoxes {
private DialogBoxes() {}
private static FileChooser fc = new FileChooser();
private static DirectoryChooser dc = new DirectoryChooser();
private static Alert error = new Alert(AlertType.ERROR);
public static void showErrorMessage(String errorMessage) {
Alert error = new Alert(AlertType.ERROR);
error.setContentText(errorMessage);
error.showAndWait();
}
public static File showopenFileWithDialog(Stage stage) {
fc.setTitle("Open File");
File chosenFile = fc.showOpenDialog(stage);
return chosenFile;
}
public static File showOpenFolderWithDialog(Stage stage) {
dc.setTitle("Open Project");
File dir = dc.showDialog(stage);
return dir;
}
public static File showSaveFileWithDialog(Stage stage) {
FileChooser fc = new FileChooser();
fc.setTitle("Save as");
Model
.getProjectPath()
.ifPresent(path -> fc.setInitialDirectory(path.toFile()));
File chosenLocation = fc.showSaveDialog(stage);
return chosenLocation;
}
}

View File

@ -8,8 +8,6 @@ import java.util.Optional;
import java.util.Scanner;
import app.model.Model;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class FileOperations {
@ -20,11 +18,7 @@ public class FileOperations {
// TODO: This class needs to be extensively error checked
public static File openFileWithDialog(Stage stage) throws FileNotFoundException {
FileChooser fc = new FileChooser();
fc.setTitle("Open File");
File chosenFile = fc.showOpenDialog(stage);
File chosenFile = DialogBoxes.showopenFileWithDialog(stage);
if (chosenFile == null)
throw new FileNotFoundException();
@ -34,11 +28,7 @@ public class FileOperations {
}
public static File openFolderWithDialog(Stage stage) throws FileNotFoundException {
DirectoryChooser dc = new DirectoryChooser();
dc.setTitle("Open Project");
File dir = dc.showDialog(stage);
File dir = DialogBoxes.showOpenFolderWithDialog(stage);
if (dir == null)
throw new FileNotFoundException();
@ -58,14 +48,7 @@ public class FileOperations {
}
public static boolean saveFileWithDialog(Stage stage, String content) {
FileChooser fc = new FileChooser();
fc.setTitle("Save as");
Model
.getProjectPath()
.ifPresent(path -> fc.setInitialDirectory(path.toFile()));
File chosenLocation = fc.showSaveDialog(stage);
File chosenLocation = DialogBoxes.showSaveFileWithDialog(stage);
if (chosenLocation == null)
return false;

View File

@ -0,0 +1,11 @@
package app.service;
public class DialogBoxesTest {
}

View File

@ -0,0 +1,22 @@
package app.settings;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class SettingsProviderTest {
@Test
@DisplayName("Test load settings")
public void testLoadSettings() {
}
@Test
@DisplayName("Test save settings")
public void testSaveSettings() {
}
}