diff --git a/src/application/Main.java b/src/application/Main.java index 8844289..653a639 100644 --- a/src/application/Main.java +++ b/src/application/Main.java @@ -1,5 +1,6 @@ package application; +import application.client.view.ResourceLoader; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; diff --git a/src/application/PropertiesLoader.java b/src/application/PropertiesLoader.java index d230bc9..2923445 100644 --- a/src/application/PropertiesLoader.java +++ b/src/application/PropertiesLoader.java @@ -1,6 +1,8 @@ package application; +import application.client.view.ResourceLoader; + import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -8,8 +10,11 @@ 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 () {} @@ -18,23 +23,21 @@ public class PropertiesLoader { } public Properties load() { - Properties properties = new Properties(); - + this.properties = new Properties(); try { - InputStream inputStream = resourceLoader.getResourceAsStream("config.properties"); - properties.load(inputStream); + InputStream inputStream = resourceLoader.getResourceAsStream(CONFIG_NAME_FILE); + this.properties.load(inputStream); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } - - return properties; + return this.properties; } public void save(Properties prop) { try { - OutputStream output = new FileOutputStream(this.resourceLoader.getPath("config.properties")); + OutputStream output = new FileOutputStream(this.resourceLoader.getPath(CONFIG_NAME_FILE)); prop.store(output, null); output.close(); @@ -43,4 +46,12 @@ public class PropertiesLoader { e.printStackTrace(); } } + + public String get(String name) { + if (this.properties == null) { + this.load(); + } + + return this.properties.getProperty(name); + } } diff --git a/src/application/ResourceLoader.java b/src/application/client/view/ResourceLoader.java similarity index 69% rename from src/application/ResourceLoader.java rename to src/application/client/view/ResourceLoader.java index a08cd38..41b1503 100644 --- a/src/application/ResourceLoader.java +++ b/src/application/client/view/ResourceLoader.java @@ -1,18 +1,19 @@ -package application; +package application.client.view; import java.io.InputStream; import java.net.URL; public class ResourceLoader { private static final ResourceLoader instance = new ResourceLoader(); + public static final String RESOURCE_FOLDER = "resource/"; String name; public URL getResource(String name) { - return getClass().getClassLoader().getResource("resource/" + name); + return getClass().getClassLoader().getResource(RESOURCE_FOLDER + name); } public InputStream getResourceAsStream(String name) { - return getClass().getClassLoader().getResourceAsStream("resource/" + name); + return getClass().getClassLoader().getResourceAsStream(RESOURCE_FOLDER + name); } public String getPath(String name) { diff --git a/src/application/MainPageController.java b/src/application/client/view/mainPage/MainPageController.java similarity index 94% rename from src/application/MainPageController.java rename to src/application/client/view/mainPage/MainPageController.java index 093056b..3273185 100644 --- a/src/application/MainPageController.java +++ b/src/application/client/view/mainPage/MainPageController.java @@ -1,4 +1,4 @@ -package application; +package application.client.view.mainPage; import application.client.Connector; import application.client.exception.CannotConnectException; diff --git a/src/resource/mainPage.fxml b/src/resource/mainPage.fxml index 310f671..fba4b42 100644 --- a/src/resource/mainPage.fxml +++ b/src/resource/mainPage.fxml @@ -7,7 +7,7 @@ - +