Changed user preference storage to Java Preferences API
This commit is contained in:
Fabian Becker 2012-04-27 11:32:52 +00:00
parent b6c265a08c
commit 7778c46fd1
2 changed files with 15 additions and 21 deletions

View File

@ -833,13 +833,13 @@ public class EvAClient implements RemoteStateListener, Serializable {
JOptionPane.showMessageDialog(evaFrame.getContentPane(), "No modules available on " + comAdapter.getHostName(), EvAInfo.infoTitle, 1);
} else {
String lastModule = null;
try {
FileInputStream inputStream = new FileInputStream("lastmodule.ser");
lastModule = Serializer.loadString(inputStream);
inputStream.close();
} catch (Exception ex) {
LOGGER.log(Level.WARNING, "Could not load last loaded module.", ex);
}
java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userRoot();
lastModule = prefs.get("lastModule", null);
} catch (SecurityException ex) {
LOGGER.log(Level.WARNING, "Can't write user preference.", ex);
}
if (lastModule == null) {
lastModule = ModuleNameList[0];
@ -858,15 +858,12 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (selectedModule == null) {
System.err.println("not loading any module");
} else {
} else {
try {
FileOutputStream outStream = new FileOutputStream("lastmodule.ser");
Serializer.storeString(outStream, selectedModule);
outStream.close();
} catch (FileNotFoundException ex) {
LOGGER.log(Level.WARNING, "Could not store selected module.", ex);
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Could not close file stream.", ex);
java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userRoot();
prefs.put("lastModule", selectedModule);
} catch (SecurityException ex) {
LOGGER.log(Level.WARNING, "Can't write user preference.", ex);
}
loadSpecificModule(selectedModule, goParams);

View File

@ -316,13 +316,10 @@ public class ComAdapter {
public void setHostName(final String newHost) {
hostName = newHost;
try {
FileOutputStream fileStream = new FileOutputStream("hostname.ser");
Serializer.storeString(fileStream, hostName);
fileStream.close();
} catch (FileNotFoundException ex) {
LOGGER.log(Level.WARNING, "Could not write hostname to file.", ex);
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Error writing hostname to file.", ex);
java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userRoot();
prefs.put("hostname", hostName);
} catch (SecurityException ex) {
LOGGER.log(Level.WARNING, "Can't write user preference.", ex);
}
}