little clean up in the code
This commit is contained in:
parent
461738d25e
commit
a692141db6
@ -1,5 +1,6 @@
|
||||
package application;
|
||||
|
||||
import application.client.view.ResourceLoader;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
@ -1,4 +1,4 @@
|
||||
package application;
|
||||
package application.client.view.mainPage;
|
||||
|
||||
import application.client.Connector;
|
||||
import application.client.exception.CannotConnectException;
|
@ -7,7 +7,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="application.MainPageController">
|
||||
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.client.view.mainPage.MainPageController">
|
||||
<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