Skip to content

Commit

Permalink
Merge pull request #15 from gkhays/develop
Browse files Browse the repository at this point in the history
Issue #14
  • Loading branch information
gkhays authored Nov 8, 2017
2 parents 8fa2da7 + 495554b commit acd3364
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/pushbutton/aws/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public App() {
* Initialize the contents of the frame.
*/
private void initialize() {
instanceId = SettingsManager.getProperties().getProperty("instanceId");
instanceId = SettingsManager.getDefaultProperties().getProperty("instanceId");
launcherFrame = new AWSLauncher(instanceId);
launcherFrame.setBounds(100, 100, 450, 300);
launcherFrame.setLocationRelativeTo(null);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/pushbutton/aws/gui/AWSLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

public class AWSLauncher extends JFrame implements IdChangeListener {

private static final long serialVersionUID = -5754438927656452678L;

public static final Color TXT_COLOR = Color.WHITE;
public static final String APP_NAME = "EC2 Push Button";

private static final long serialVersionUID = -5754438927656452678L;
private static final Color BG_COLOR = Color.DARK_GRAY;

private JPanel contentPane;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/pushbutton/aws/gui/SettingsGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public SettingsGui() {
setTitle("Configuration Settings");
btnOk.setToolTipText("Save property changes");
this.properties = SettingsManager.getProperties();
this.properties.putAll(SettingsManager.getDefaultProperties());
changedEntries = new HashMap<String, String>();
model = new DefaultTableModel();
model.addColumn("Property");
Expand Down Expand Up @@ -93,9 +94,6 @@ private void saveTable() {
l.instanceChanged(instanceId);
}
}
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
38 changes: 31 additions & 7 deletions src/main/java/org/pushbutton/utils/SettingsManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.pushbutton.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -11,31 +13,53 @@

public class SettingsManager {

private static URL url;
private static final String PROPERTY_FILE = "app.properties";

private static Properties properties = new Properties();

private SettingsManager() {}

static {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream in = classLoader.getResourceAsStream("app.properties");
url = classLoader.getResource("app.properties");
InputStream in = null;

try {
try {
in = new FileInputStream(PROPERTY_FILE);
} catch (FileNotFoundException e) {
File file = new File(PROPERTY_FILE);
if (!file.exists()) {
file.createNewFile();
}
in = new FileInputStream(PROPERTY_FILE);
}
properties.load(in);
} catch (IOException e) {
// TODO Auto-generated catch block
// TODO Throw up an error dialog
e.printStackTrace();
}
}

public static Properties getDefaultProperties() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream in = classLoader.getResourceAsStream(PROPERTY_FILE);
Properties defaultProps = new Properties();

try {
defaultProps.load(in);
} catch (IOException e) {
e.printStackTrace();
}

return defaultProps;
}

public static Properties getProperties() {
return properties;
}

public static void saveProperties() throws URISyntaxException, IOException {
File file = new File(url.toURI());
OutputStream out = new FileOutputStream(file);
public static void saveProperties() throws IOException {
OutputStream out = new FileOutputStream(PROPERTY_FILE);
properties.store(out, "Saved by the settings form.");
}

Expand Down

0 comments on commit acd3364

Please sign in to comment.