Merge branch 'feature/client_navigation' into feature/client_printExport
This commit is contained in:
commit
2339d70499
5 changed files with 79 additions and 41 deletions
|
|
@ -5,14 +5,11 @@ import java.util.List;
|
|||
|
||||
public class Config {
|
||||
|
||||
/*
|
||||
Sets parameters for what the config file needs with a config
|
||||
Object that will be used in the ConfigService object
|
||||
*/
|
||||
|
||||
private String language = "en";
|
||||
private String serverUrl = "http://localhost:8080";
|
||||
|
||||
private List<String> favourites = new ArrayList<>();
|
||||
private List<Long> favourites = new ArrayList<>();
|
||||
private List<String> shoppingList = new ArrayList<>();
|
||||
|
||||
public Config(){}
|
||||
|
|
@ -25,7 +22,7 @@ public class Config {
|
|||
return shoppingList;
|
||||
}
|
||||
|
||||
public List<String> getFavourites() {
|
||||
public List<Long> getFavourites() {
|
||||
return favourites;
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +38,7 @@ public class Config {
|
|||
this.serverUrl = serverUrl;
|
||||
}
|
||||
|
||||
public void setFavourites(List<String> favourites) {
|
||||
public void setFavourites(List<Long> favourites) {
|
||||
this.favourites = favourites;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package client.utils;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.exc.StreamReadException;
|
||||
import com.fasterxml.jackson.databind.DatabindException;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -31,21 +30,18 @@ public class ConfigService {
|
|||
*/
|
||||
private void load(){
|
||||
File file = configPath.toFile(); //reads the config file as file
|
||||
if(file.exists()){
|
||||
try{
|
||||
config = mapper.readValue(file, Config.class); //uses Jackson to map the file to the config attribute
|
||||
if (!file.exists()) { //if file doesn't exist then it creates a config object
|
||||
config = new Config();
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (StreamReadException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (DatabindException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
else{
|
||||
config = new Config(); // if file doesn't exist, it creates one
|
||||
try{
|
||||
config = mapper.readValue(file, Config.class); //uses Jackson to map the file to the config attribute
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Path getConfigPath() {
|
||||
|
|
|
|||
|
|
@ -9,17 +9,32 @@ public class Navigation {
|
|||
private final MyFXML myFXML;
|
||||
private Pane screen;
|
||||
|
||||
/**
|
||||
* Constructs a Navigation Object that uses a fxml object and Pane that will allow to switch UI screens
|
||||
* @param x - a MyFXML Object
|
||||
* @param y - a Pane Object
|
||||
*/
|
||||
public Navigation(MyFXML x, Pane y){
|
||||
this.myFXML = x;
|
||||
this.screen = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* The show function takes in an FxmlPath and changes the current pane to the value given by the path
|
||||
* using the load function of the myFXML object
|
||||
* @param fxmlpath - FXML path provided to show the next pane
|
||||
*/
|
||||
public void show(String fxmlpath){
|
||||
var result = myFXML.load(Object.class, fxmlpath);
|
||||
Parent UIRoot = result.getValue();
|
||||
screen.getChildren().setAll(UIRoot);
|
||||
|
||||
|
||||
try{
|
||||
var result = myFXML.load(Object.class, fxmlpath); //stores the result of the load method in result
|
||||
Parent uiRoot = result.getValue();
|
||||
screen.getChildren().setAll(uiRoot);
|
||||
}
|
||||
catch(Exception e) { //catches any failures thrown by the load method
|
||||
System.err.println("Failed to load FXML file: " + fxmlpath);
|
||||
throw new IllegalArgumentException("Cannot load FXML file: " + fxmlpath, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue