|
From: <ev...@us...> - 2010-12-30 10:12:48
|
Revision: 1469
http://rails.svn.sourceforge.net/rails/?rev=1469&view=rev
Author: evos
Date: 2010-12-30 10:12:42 +0000 (Thu, 30 Dec 2010)
Log Message:
-----------
Added system property to define windows settings directories.
Added ability to create a default settings file.
Modified Paths:
--------------
trunk/18xx/rails/ui/swing/StockChart.java
trunk/18xx/rails/ui/swing/WindowSettings.java
Modified: trunk/18xx/rails/ui/swing/StockChart.java
===================================================================
--- trunk/18xx/rails/ui/swing/StockChart.java 2010-12-25 21:34:13 UTC (rev 1468)
+++ trunk/18xx/rails/ui/swing/StockChart.java 2010-12-30 10:12:42 UTC (rev 1469)
@@ -57,7 +57,8 @@
WindowSettings ws = gameUIManager.getWindowSettings();
Rectangle bounds = ws.getBounds(this);
if (bounds.x != -1 && bounds.y != -1) setLocation(bounds.getLocation());
- if (bounds.width != -1 && bounds.height != -1) setSize(bounds.getSize());
+ if (bounds.width != -1 && bounds.height != -1
+ && !ws.isDefaultUsed()) setSize(bounds.getSize());
ws.set(frame);
}
Modified: trunk/18xx/rails/ui/swing/WindowSettings.java
===================================================================
--- trunk/18xx/rails/ui/swing/WindowSettings.java 2010-12-25 21:34:13 UTC (rev 1468)
+++ trunk/18xx/rails/ui/swing/WindowSettings.java 2010-12-30 10:12:42 UTC (rev 1469)
@@ -14,6 +14,8 @@
private Map<String, Rectangle> settings = new HashMap<String, Rectangle>();
private String filepath;
+ private String defaultpath;
+ private boolean defaultUsed = false;
private static final String settingsfilename = "settings_xxxx.rails_ini";
@@ -21,8 +23,10 @@
Logger.getLogger(WindowSettings.class.getPackage().getName());
public WindowSettings (String gameName) {
- String directory = Config.get("save.directory");
- filepath = directory + File.separator + settingsfilename.replace("xxxx", gameName);
+ String directory = System.getProperty("settings.directory");
+ if (directory == null) directory = Config.get("save.directory");
+ defaultpath = directory + File.separator + settingsfilename;
+ filepath = defaultpath.replace("xxxx", gameName);
}
private Rectangle rectangle (String windowName) {
@@ -40,11 +44,26 @@
return rectangle (w.getClass().getSimpleName());
}
+ public boolean isDefaultUsed() {
+ return defaultUsed;
+ }
+
public void load () {
+ FileReader file;
+ try {
+ file = new FileReader (filepath);
+ } catch (FileNotFoundException e1) {
+ try {
+ file = new FileReader (defaultpath);
+ } catch (FileNotFoundException e2) {
+ return;
+ }
+ defaultUsed = true;
+ }
BufferedReader in;
try {
- in = new BufferedReader (new FileReader (filepath));
+ in = new BufferedReader (file);
String line;
String[] fields;
int v;
@@ -62,9 +81,6 @@
}
}
in.close();
- } catch (FileNotFoundException e) {
- // No problem
- return;
} catch (Exception e) {
log.error ("Error while loading "+filepath, e);
}
@@ -103,7 +119,7 @@
}
out.close();
} catch (Exception e) {
-
+ log.error ("Exception while saving window settings", e);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|