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

View File

@ -316,13 +316,10 @@ public class ComAdapter {
public void setHostName(final String newHost) { public void setHostName(final String newHost) {
hostName = newHost; hostName = newHost;
try { try {
FileOutputStream fileStream = new FileOutputStream("hostname.ser"); java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userRoot();
Serializer.storeString(fileStream, hostName); prefs.put("hostname", hostName);
fileStream.close(); } catch (SecurityException ex) {
} catch (FileNotFoundException ex) { LOGGER.log(Level.WARNING, "Can't write user preference.", 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);
} }
} }