Change initialize primary stage
This commit is contained in:
parent
2a4f325305
commit
fea377697f
5
pom.xml
5
pom.xml
@ -37,6 +37,11 @@
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.28.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -1,24 +1,14 @@
|
||||
package dev.mateuszkowalczyk.ffm;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.view.StageController;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception{
|
||||
URL welcomePageUrl = getClass().getClassLoader().
|
||||
getResource("welcomePage.fxml");
|
||||
|
||||
Parent welcomePage = FXMLLoader.load(welcomePageUrl);
|
||||
primaryStage.setTitle("Friend Face Matcher");
|
||||
primaryStage.setScene(new Scene(welcomePage));
|
||||
primaryStage.show();
|
||||
public void start(Stage stage) throws Exception{
|
||||
StageController.getInstance().initApp(stage);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,54 @@
|
||||
package dev.mateuszkowalczyk.ffm.utils;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class PropertiesLoader {
|
||||
public static final String CONFIG_NAME_FILE = "config.properties";
|
||||
|
||||
private static final PropertiesLoader instance = new PropertiesLoader();
|
||||
private ResourceLoader resourceLoader = ResourceLoader.getInstance();
|
||||
private Properties properties = null;
|
||||
|
||||
public PropertiesLoader () {}
|
||||
|
||||
public static PropertiesLoader getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Properties load() {
|
||||
this.properties = new Properties();
|
||||
try {
|
||||
InputStream inputStream = resourceLoader.getResourceAsStream(CONFIG_NAME_FILE);
|
||||
this.properties.load(inputStream);
|
||||
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void save(Properties prop) {
|
||||
try {
|
||||
OutputStream output = new FileOutputStream(this.resourceLoader.getPath(CONFIG_NAME_FILE));
|
||||
prop.store(output, null);
|
||||
|
||||
output.close();
|
||||
System.out.println(prop);
|
||||
} catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String get(String name) {
|
||||
if (this.properties == null) {
|
||||
this.load();
|
||||
}
|
||||
|
||||
return this.properties.getProperty(name);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package dev.mateuszkowalczyk.ffm.utils;
|
||||
|
||||
public class Property {
|
||||
public static final String PATH_TO_DIRECTORY = "pathToDirectory";
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package dev.mateuszkowalczyk.ffm.utils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class ResourceLoader {
|
||||
private static final ResourceLoader instance = new ResourceLoader();
|
||||
|
||||
private ResourceLoader(){}
|
||||
|
||||
public URL getResource(String name) {
|
||||
return getClass().getClassLoader().getResource(name);
|
||||
}
|
||||
|
||||
public InputStream getResourceAsStream(String name) {
|
||||
return getClass().getClassLoader().getResourceAsStream( name);
|
||||
}
|
||||
|
||||
public String getPath(String name) {
|
||||
return this.getResource(name).getPath();
|
||||
}
|
||||
|
||||
public static ResourceLoader getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package dev.mateuszkowalczyk.ffm.view;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.utils.Property;
|
||||
import dev.mateuszkowalczyk.ffm.utils.PropertiesLoader;
|
||||
import dev.mateuszkowalczyk.ffm.utils.ResourceLoader;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class StageController {
|
||||
private static final StageController instance = new StageController();
|
||||
private ResourceLoader resourceLoader = ResourceLoader.getInstance();
|
||||
private PropertiesLoader propertiesLoader = PropertiesLoader.getInstance();
|
||||
private Stage stage;
|
||||
|
||||
private StageController() {}
|
||||
|
||||
public static StageController getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void initApp(Stage stage) throws IOException {
|
||||
this.stage = stage;
|
||||
this.stage.setTitle("Friend Face Matcher");
|
||||
|
||||
URL sceneUrl = null;
|
||||
if (this.propertiesLoader.get(Property.PATH_TO_DIRECTORY) != null) {
|
||||
sceneUrl = this.resourceLoader.getResource("welcomePage.fxml");
|
||||
} else {
|
||||
sceneUrl = this.resourceLoader.getResource("welcomePage.fxml");
|
||||
}
|
||||
Scene scene = new Scene(FXMLLoader.load(sceneUrl));
|
||||
this.stage.setScene(scene);
|
||||
this.stage.show();
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package dev.mateuszkowalczyk.ffm.controller;
|
||||
package dev.mateuszkowalczyk.ffm.view.controller;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
|
0
src/main/resources/config.properties
Normal file
0
src/main/resources/config.properties
Normal file
@ -6,7 +6,7 @@
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dev.mateuszkowalczyk.ffm.controller.WelcomePageController">
|
||||
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dev.mateuszkowalczyk.ffm.view.controller.WelcomePageController">
|
||||
<children>
|
||||
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
|
||||
<children>
|
||||
|
Loading…
Reference in New Issue
Block a user