.classpath | 3
LocalisedText.properties | 6
build.xml | 72 +-
data/profiles/LIST_OF_PROFILES | 6
data/profiles/ORDocking.predefined | 5
data/profiles/ORDocking.profile | 3
data/profiles/default.profile | 2
data/profiles/default.profiles | 7
data/profiles/pbem.predefined | 2
data/profiles/prettyUI.predefined | 11
data/profiles/prettyUI.profile | 9
data/profiles/root | 63 +
data/profiles/root.profile | 63 -
data/profiles/test | 15
data/profiles/test.profile | 15
lib/commons-io-2.1/commons-io-2.1.jar |binary
rails/common/ConfigItem.java | 180 +++++
rails/common/ConfigManager.java | 259 ++++++++
rails/common/ConfigProfile.java | 303 +++++++++
rails/common/LocalText.java | 1
rails/common/MoneyFormatter.java | 1
rails/common/parser/Config.java | 606 -------------------
rails/common/parser/ConfigItem.java | 151 ----
rails/game/Bank.java | 2
rails/game/MapManager.java | 1
rails/game/ReportBuffer.java | 2
rails/sound/SoundConfig.java | 2
rails/ui/swing/AbstractReportWindow.java | 2
rails/ui/swing/ConfigWindow.java | 306 ++-------
rails/ui/swing/GameSetupWindow.java | 21
rails/ui/swing/GameUIManager.java | 3
rails/ui/swing/GridPanel.java | 2
rails/ui/swing/ImageLoader.java | 2
rails/ui/swing/ORPanel.java | 2
rails/ui/swing/ORUIManager.java | 2
rails/ui/swing/ORWindow.java | 2
rails/ui/swing/ReportWindow.java | 2
rails/ui/swing/Scale.java | 2
rails/ui/swing/SplashWindow.java | 2
rails/ui/swing/StatusWindow.java | 17
rails/ui/swing/WindowSettings.java | 2
rails/ui/swing/elements/DockingFrame.java | 2
rails/ui/swing/elements/RailsIconButton.java | 2
rails/ui/swing/hexmap/HexHighlightMouseListener.java | 2
rails/ui/swing/hexmap/HexMap.java | 2
rails/ui/swing/hexmap/HexMapImage.java | 2
rails/util/RunGame.java | 4
rails/util/SystemOS.java | 94 ++
test/TestGame.java | 2
test/TestGameBuilder.java | 7
tools/ListAndFixSavedFiles.java | 5
51 files changed, 1126 insertions(+), 1153 deletions(-)
New commits:
commit 83e4a63c76f277e11ff75bf86f0dcb84d673c215
Author: Stefan Frey <ste...@we...>
Date: Mon Feb 20 12:19:28 2012 +0100
New configuration system based on a profile tree.
Added ConfigManager and ConfigProfile classes
Refactored Config and ConfigWindow, Config is only a proxy to ConfigManager
Added SystemOS class for os related functions
Added common-io library for additional file i/o functions
diff --git a/.classpath b/.classpath
index 4dd2569..a1de363 100644
--- a/.classpath
+++ b/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry excluding="lib/JLayer1.0.1/|lib/df_1.1.0/|lib/batik-1.7/|lib/batik-1.7/|lib/batik-1.7/lib/|lib/batik-1.7/lib/|lib/jgraph5/|lib/jgraph5/|lib/jgrapht-0.7.3/|lib/jgrapht-0.7.3/|lib/junit-4.8.2|lib/log4j-1.2/|lib/log4j-1.2/" kind="src" path=""/>
+ <classpathentry excluding="lib/JLayer1.0.1/|lib/batik-1.7/|lib/batik-1.7/|lib/batik-1.7/lib/|lib/batik-1.7/lib/|lib/commons-io-2.1/|lib/df_1.1.0/|lib/jgraph5/|lib/jgraph5/|lib/jgrapht-0.7.3/|lib/jgrapht-0.7.3/|lib/junit-4.8.2|lib/log4j-1.2/|lib/log4j-1.2/" kind="src" path=""/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/log4j-1.2/log4j-1.2.14.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jgrapht-0.7.3/jgrapht-jdk1.5.jar"/>
@@ -29,5 +29,6 @@
<classpathentry kind="lib" path="lib/batik-1.7/lib/batik-codec.jar"/>
<classpathentry kind="lib" path="lib/df_1.1.0/dockingFramesCommon.jar"/>
<classpathentry kind="lib" path="lib/df_1.1.0/dockingFramesCore.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/commons-io-2.1/commons-io-2.1.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
diff --git a/LocalisedText.properties b/LocalisedText.properties
index ce07410..059e471 100644
--- a/LocalisedText.properties
+++ b/LocalisedText.properties
@@ -78,10 +78,8 @@ COMPANY_DETAILS=Company details
CONFIG=Configuration
CONFIG_APPLY_MESSAGE=<html>Current changes (will be) applied.<br>Be aware that some changes to be active require <br> UI redraws or a restart of Rails.</html>
CONFIG_APPLY_TITLE=Apply confirmation
-CONFIG_CURRENT_PATH=Active filepath = {0}
-CONFIG_CURRENT_PROFILE=Active profile = {0} (based on = {1})
-CONFIG_DEFAULT_TITLE=Default profile
-CONFIG_DEFAULT_MESSAGE=Select a template for settings
+CONFIG_USER_PROFILE=Active user profile = {0}
+CONFIG_PREDEFINED_PROFILE=Active predefined profile = {0}
CONFIG_INFO_TITLE=Info text for {0}
CONFIF_LOAD_ERROR_MESSAGE=An error occurred during load of the file {0}.\nProfile was not loaded.
CONFIG_LOAD_TITLE=Load of profile
diff --git a/build.xml b/build.xml
index c098278..e832108 100644
--- a/build.xml
+++ b/build.xml
@@ -6,6 +6,7 @@
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="Rails">
<property environment="env"/>
+ <property name="ECLIPSE_HOME" value="../../../installed/eclipse"/>
<property name="junit.output.dir" value="junit"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.5"/>
@@ -17,9 +18,6 @@
<pathelement location="lib/jgrapht-0.7.3/jgrapht-jdk1.5.jar"/>
<pathelement location="lib/jgraph5/jgraph.jar"/>
<pathelement location="lib/junit-4.8.2/junit.jar"/>
- <pathelement location="lib/JLayer1.0.1/jl1.0.1.jar"/>
- <pathelement location="lib/df_1.1.0/dockingFramesCommon.jar"/>
- <pathelement location="lib/df_1.1.0/dockingFramesCore.jar"/>
<pathelement location="lib/batik-1.7/lib/batik-transcoder.jar"/>
<pathelement location="lib/batik-1.7/lib/batik-dom.jar"/>
<pathelement location="lib/batik-1.7/lib/batik-swing.jar"/>
@@ -36,23 +34,50 @@
<pathelement location="lib/batik-1.7/lib/batik-svg-dom.jar"/>
<pathelement location="lib/batik-1.7/lib/batik-xml.jar"/>
<pathelement location="lib/batik-1.7/lib/js.jar"/>
+ <pathelement location="lib/JLayer1.0.1/jl1.0.1.jar"/>
<pathelement location="lib/batik-1.7/lib/xerces_2_5_0.jar"/>
<pathelement location="lib/batik-1.7/lib/xml-apis-ext.jar"/>
<pathelement location="lib/batik-1.7/lib/batik-anim.jar"/>
<pathelement location="lib/batik-1.7/lib/batik-codec.jar"/>
+ <pathelement location="lib/df_1.1.0/dockingFramesCommon.jar"/>
+ <pathelement location="lib/df_1.1.0/dockingFramesCore.jar"/>
+ <pathelement location="lib/commons-io-2.1/commons-io-2.1.jar"/>
</path>
<target name="init">
<mkdir dir="classes"/>
<copy includeemptydirs="false" todir="classes">
<fileset dir=".">
- <exclude name="**/*.launch"/>
+ <exclude name="**/*.ucls"/>
+ <exclude name="**/*.uad"/>
+ <exclude name="**/*.ucd"/>
+ <exclude name="**/*.uld"/>
+ <exclude name="**/*.upd"/>
+ <exclude name="**/*.udd"/>
+ <exclude name="**/*.uod"/>
+ <exclude name="**/*.usd"/>
+ <exclude name="**/*.utd"/>
+ <exclude name="**/*.uud"/>
+ <exclude name="**/*.odd"/>
+ <exclude name="**/*.ead"/>
+ <exclude name="**/*.ecd"/>
+ <exclude name="**/*.eld"/>
+ <exclude name="**/*.epd"/>
+ <exclude name="**/*.edd"/>
+ <exclude name="**/*.eod"/>
+ <exclude name="**/*.esd"/>
+ <exclude name="**/*.etd"/>
+ <exclude name="**/*.eud"/>
+ <exclude name="**/*.urd"/>
+ <exclude name="**/*.uml"/>
+ <exclude name="**/*.ecore"/>
<exclude name="**/*.java"/>
+ <exclude name="lib/JLayer1.0.1/"/>
<exclude name="lib/batik-1.7/"/>
<exclude name="lib/batik-1.7/"/>
<exclude name="lib/batik-1.7/lib/"/>
<exclude name="lib/batik-1.7/lib/"/>
- <exclude name="lib/JLayer1.0.1"/>
- <exclude name="lib/df_1.1.0"/>
+ <exclude name="lib/commons-io-2.1/"/>
+ <exclude name="lib/df_1.1.0/"/>
<exclude name="lib/jgraph5/"/>
<exclude name="lib/jgraph5/"/>
<exclude name="lib/jgrapht-0.7.3/"/>
@@ -71,14 +96,15 @@
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
- <javac debug="true" debuglevel="${debuglevel}" destdir="classes" includeantruntime="false" source="${source}" target="${target}">
+ <javac debug="true" debuglevel="${debuglevel}" destdir="classes" source="${source}" target="${target}">
<src path="."/>
+ <exclude name="lib/JLayer1.0.1/"/>
<exclude name="lib/batik-1.7/"/>
<exclude name="lib/batik-1.7/"/>
<exclude name="lib/batik-1.7/lib/"/>
<exclude name="lib/batik-1.7/lib/"/>
- <exclude name="lib/JLayer1.0.1"/>
- <exclude name="lib/df_1.1.0"/>
+ <exclude name="lib/commons-io-2.1/"/>
+ <exclude name="lib/df_1.1.0/"/>
<exclude name="lib/jgraph5/"/>
<exclude name="lib/jgraph5/"/>
<exclude name="lib/jgrapht-0.7.3/"/>
@@ -103,14 +129,31 @@
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
+ <target name="Check Save File (ListAndFixSavedFiles)">
+ <java classname="tools.ListAndFixSavedFiles" failonerror="true" fork="yes">
+ <classpath refid="Rails.classpath"/>
+ </java>
+ </target>
<target name="Start Rails (RunGame)">
<java classname="rails.util.RunGame" failonerror="true" fork="yes">
- <jvmarg line="-DRevenueCalculation=suggest -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"/>
+ <jvmarg line="-DRevenueCalculation=suggest -Dawt.useSystemAAFontSettings=on"/>
<classpath refid="Rails.classpath"/>
</java>
</target>
- <target name="Check Save File (ListAndFixSavedFiles)">
- <java classname="tools.ListAndFixSavedFiles" failonerror="true" fork="yes">
+ <target name="Start Rails (RunGame) (Profiled)">
+ <java classname="rails.util.RunGame" failonerror="true" fork="yes">
+ <jvmarg line="-DRevenueCalculation=suggest -Dawt.useSystemAAFontSettings=on"/>
+ <classpath refid="Rails.classpath"/>
+ </java>
+ </target>
+ <target name="Delete and Update Test Game Reports (TestGameBuilder)">
+ <java classname="test.TestGameBuilder" failonerror="true" fork="yes">
+ <classpath refid="Rails.classpath"/>
+ </java>
+ </target>
+ <target name="Start Rails (RunGame) Nimbus LAF">
+ <java classname="rails.util.RunGame" failonerror="true" fork="yes">
+ <jvmarg line="-DRevenueCalculation=suggest -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"/>
<classpath refid="Rails.classpath"/>
</java>
</target>
@@ -122,11 +165,6 @@
<classpath refid="Rails.classpath"/>
</junit>
</target>
- <target name="Delete and Update Test Game Reports (TestGameBuilder)">
- <java classname="test.TestGameBuilder" failonerror="true" fork="yes">
- <classpath refid="Rails.classpath"/>
- </java>
- </target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
diff --git a/data/profiles/LIST_OF_PROFILES b/data/profiles/LIST_OF_PROFILES
new file mode 100644
index 0000000..d061833
--- /dev/null
+++ b/data/profiles/LIST_OF_PROFILES
@@ -0,0 +1,6 @@
+### List of predefined profiles
+### available for user selection
+### with extension .predefined
+pbem
+ORDocking
+prettyUI
diff --git a/data/profiles/ORDocking.predefined b/data/profiles/ORDocking.predefined
new file mode 100644
index 0000000..aa4985d
--- /dev/null
+++ b/data/profiles/ORDocking.predefined
@@ -0,0 +1,5 @@
+### ORDocking profile
+### activates the docking framework
+or.window.dockablePanels=yes
+### cannot be derived
+profile.final=yes
diff --git a/data/profiles/ORDocking.profile b/data/profiles/ORDocking.profile
deleted file mode 100644
index e5f8d80..0000000
--- a/data/profiles/ORDocking.profile
+++ /dev/null
@@ -1,3 +0,0 @@
-### ORDocking profile
-### activates the docking framework
-or.window.dockablePanels=yes
diff --git a/data/profiles/default.profile b/data/profiles/default.profile
deleted file mode 100644
index 122c1b7..0000000
--- a/data/profiles/default.profile
+++ /dev/null
@@ -1,2 +0,0 @@
-### Default profile currently is identical to root.profile
-### so no change here
diff --git a/data/profiles/default.profiles b/data/profiles/default.profiles
deleted file mode 100644
index 9cedd38..0000000
--- a/data/profiles/default.profiles
+++ /dev/null
@@ -1,7 +0,0 @@
-### This is the list of (predefined) profiles and their file locations
-### A dot (".") before the profilename prevents displaying those to the user selection
-.root=data/profiles/root.profile
-.test=data/profiles/test.profile
-default=data/profiles/default.profile
-prettyUI=data/profiles/prettyUI.profile
-ORDocking=data/profiles/ORDocking.profile
diff --git a/data/profiles/pbem.predefined b/data/profiles/pbem.predefined
new file mode 100644
index 0000000..122c1b7
--- /dev/null
+++ b/data/profiles/pbem.predefined
@@ -0,0 +1,2 @@
+### Default profile currently is identical to root.profile
+### so no change here
diff --git a/data/profiles/prettyUI.predefined b/data/profiles/prettyUI.predefined
new file mode 100644
index 0000000..f2e51b3
--- /dev/null
+++ b/data/profiles/prettyUI.predefined
@@ -0,0 +1,11 @@
+### prettyUI profile
+### activates the new UI options of Frederick
+button.iconPosition=left
+button.iconText=text and icon
+button.iconSize=small
+gridPanel.tableBorders=enabled
+map.image.display=yes
+map.displayCurrentRoutes=yes
+map.highlightHexes=yes
+### cannot be derived
+profile.final=yes
diff --git a/data/profiles/prettyUI.profile b/data/profiles/prettyUI.profile
deleted file mode 100644
index a537864..0000000
--- a/data/profiles/prettyUI.profile
+++ /dev/null
@@ -1,9 +0,0 @@
-### prettyUI profile
-### activates the new UI options of Frederick
-button.iconPosition=left
-button.iconText=text and icon
-button.iconSize=small
-gridPanel.tableBorders=enabled
-map.image.display=yes
-map.displayCurrentRoutes=yes
-map.highlightHexes=yes
diff --git a/data/profiles/root b/data/profiles/root
new file mode 100644
index 0000000..3e08d4d
--- /dev/null
+++ b/data/profiles/root
@@ -0,0 +1,63 @@
+### Root profile defines the settings used for all (predefined) default profiles
+### All others define only deviations
+
+### Panel General
+locale=en_US
+default_game=1830
+default_players=
+local.player.names=
+
+### Panel Save
+save.directory=
+save.filename.date_time_pattern=yyyyMMdd_HHmm
+save.filename.date_time_zone=UTC
+save.filename.suffix=NEXT_PLAYER
+save.filename.extension=rails
+save.recovery.active=no
+save.recovery.filepath=18xx_autosave.rails
+
+### Panel Font
+font.ui.scale=1
+font.ui.name=
+font.ui.style=bold
+
+### Panel Map
+map.autoscroll=yes
+map.defaultZoomFitOption=none
+map.displayCurrentRoutes=no
+map.highlightHexes=no
+map.image.display=no
+map.zoomstep=10
+
+### Panel Windows
+or.window.dockablePanels=no
+report.window.type=dynamic
+report.window.open=yes
+report.window.editable=no
+splash.window.open=yes
+stockchart.window.open=yes
+
+### Panel Format
+money_format=
+or.number_format=composite
+
+### Panel Appearance
+button.iconText=only text
+button.iconSize=small
+button.iconPosition=left
+gridPanel.tableBorder=disabled
+route.colour.1=00ffff
+route.colour.2=ffc0cb
+route.colour.3=ffa500
+route.colour.4=808080
+
+### Panel Log
+#report.directory=log
+#report.filename.date_time_pattern=yyyyMMdd
+#report.filename.extension=log
+
+### Panel Music
+sound.backgroundMusic=disabled
+
+### Panel SFX
+sound.sfx=disabled
diff --git a/data/profiles/root.profile b/data/profiles/root.profile
deleted file mode 100644
index 3e08d4d..0000000
--- a/data/profiles/root.profile
+++ /dev/null
@@ -1,63 +0,0 @@
-### Root profile defines the settings used for all (predefined) default profiles
-### All others define only deviations
-
-### Panel General
-locale=en_US
-default_game=1830
-default_players=
-local.player.names=
-
-### Panel Save
-save.directory=
-save.filename.date_time_pattern=yyyyMMdd_HHmm
-save.filename.date_time_zone=UTC
-save.filename.suffix=NEXT_PLAYER
-save.filename.extension=rails
-save.recovery.active=no
-save.recovery.filepath=18xx_autosave.rails
-
-### Panel Font
-font.ui.scale=1
-font.ui.name=
-font.ui.style=bold
-
-### Panel Map
-map.autoscroll=yes
-map.defaultZoomFitOption=none
-map.displayCurrentRoutes=no
-map.highlightHexes=no
-map.image.display=no
-map.zoomstep=10
-
-### Panel Windows
-or.window.dockablePanels=no
-report.window.type=dynamic
-report.window.open=yes
-report.window.editable=no
-splash.window.open=yes
-stockchart.window.open=yes
-
-### Panel Format
-money_format=
-or.number_format=composite
-
-### Panel Appearance
-button.iconText=only text
-button.iconSize=small
-button.iconPosition=left
-gridPanel.tableBorder=disabled
-route.colour.1=00ffff
-route.colour.2=ffc0cb
-route.colour.3=ffa500
-route.colour.4=808080
-
-### Panel Log
-#report.directory=log
-#report.filename.date_time_pattern=yyyyMMdd
-#report.filename.extension=log
-
-### Panel Music
-sound.backgroundMusic=disabled
-
-### Panel SFX
-sound.sfx=disabled
diff --git a/data/profiles/test b/data/profiles/test
new file mode 100644
index 0000000..897ee6d
--- /dev/null
+++ b/data/profiles/test
@@ -0,0 +1,15 @@
+####################### Test preferences ################################
+#
+# Those are the settings used for automated testing
+#
+########################################################################
+locale=te_ST
+
+# An overriding format can be specified here, but then applies to all games.
+# The @ character must be present and is replaced by the amount.
+# Example: �@ to specify a pound sign prefix: �100.
+money_format=@
+
+save.directory=test/data
+report.filename.extension=report
+failed.filename.extension=failed
diff --git a/data/profiles/test.profile b/data/profiles/test.profile
deleted file mode 100644
index 897ee6d..0000000
--- a/data/profiles/test.profile
+++ /dev/null
@@ -1,15 +0,0 @@
-####################### Test preferences ################################
-#
-# Those are the settings used for automated testing
-#
-########################################################################
-locale=te_ST
-
-# An overriding format can be specified here, but then applies to all games.
-# The @ character must be present and is replaced by the amount.
-# Example: �@ to specify a pound sign prefix: �100.
-money_format=@
-
-save.directory=test/data
-report.filename.extension=report
-failed.filename.extension=failed
diff --git a/lib/commons-io-2.1/commons-io-2.1.jar b/lib/commons-io-2.1/commons-io-2.1.jar
new file mode 100644
index 0000000..b5c7d69
Binary files /dev/null and b/lib/commons-io-2.1/commons-io-2.1.jar differ
diff --git a/rails/common/ConfigItem.java b/rails/common/ConfigItem.java
new file mode 100644
index 0000000..382d9a9
--- /dev/null
+++ b/rails/common/ConfigItem.java
@@ -0,0 +1,180 @@
+package rails.common;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import rails.common.parser.ConfigurationException;
+import rails.common.parser.Tag;
+import rails.util.Util;
+
+/**
+ * Defines an item used for the configuration of rails
+ * T represents the value type
+ */
+
+public final class ConfigItem {
+
+ protected static Logger log =
+ Logger.getLogger(ConfigItem.class.getPackage().getName());
+
+ /**
+ * Defines possible types (Java classes used as types in ConfigItem below
+ */
+ public static enum ConfigType {
+ BOOLEAN, INTEGER, PERCENT, STRING, LIST, FONT, DIRECTORY, FILE, COLOR;
+ }
+
+ // static attributes
+ public final String name;
+ public final ConfigType type;
+ public final List<String> allowedValues;
+ public final String formatMask;
+
+ // method call attributes
+ private final String initClass;
+ private final String initMethod;
+ private final boolean alwaysCallInit;
+ private final boolean initParameter;
+
+ // dynamic attributes
+ private String newValue;
+ private String currentValue;
+
+ ConfigItem(Tag tag) throws ConfigurationException {
+ // check name and type (required)
+ String name = tag.getAttributeAsString("name");
+ if (Util.hasValue(name)) {
+ this.name = name;
+ } else {
+ throw new ConfigurationException("Missing name for configuration item");
+ }
+ // optional: list of allowed values
+ String valueString = tag.getAttributeAsString("values");
+ if (Util.hasValue(valueString)) {
+ allowedValues = Arrays.asList(valueString.split(","));
+ this.type = ConfigType.LIST;
+ } else {
+ allowedValues = null;
+ String type = tag.getAttributeAsString("type");
+ if (Util.hasValue(type)) {
+ try {
+ this.type = ConfigType.valueOf(type.toUpperCase());
+ } catch (Exception e) {
+ throw new ConfigurationException("Missing or invalid type for configuration item, exception = " + e);
+ }
+ } else {
+ throw new ConfigurationException("Missing or invalid type for configuration item");
+ }
+ if (this.type == ConfigType.LIST) {
+ throw new ConfigurationException("No values defined for LIST config item");
+ }
+ }
+
+ // optional: formatMask
+ formatMask = tag.getAttributeAsString("formatMask");
+
+ // optional: init method attributes
+ initClass = tag.getAttributeAsString("initClass");
+ initMethod = tag.getAttributeAsString("initMethod");
+ alwaysCallInit = tag.getAttributeAsBoolean("alwaysCallInit",false);
+ initParameter = tag.getAttributeAsBoolean("initParameter", false);
+
+ // intialize values
+ currentValue = null;
+ newValue = null;
+ }
+
+
+ public boolean hasChanged() {
+ if (newValue == null) return false;
+ return !getCurrentValue().equals(newValue);
+ }
+
+ public String getValue() {
+ if (hasChanged()) {
+ return getNewValue();
+ } else {
+ return getCurrentValue();
+ }
+ }
+
+ public String getCurrentValue() {
+ if (currentValue == null) return "";
+ return currentValue;
+ }
+
+ public void setCurrentValue(String value) {
+ currentValue = value;
+ newValue = null;
+ }
+
+ @Deprecated
+ public boolean hasNewValue() {
+ return (newValue != null);
+ }
+
+ public String getNewValue() {
+ if (newValue == null) return "";
+ return newValue;
+ }
+
+ public void setNewValue(String value) {
+ if (value == null || value.equals("") || value.equals(currentValue)) {
+ newValue = null;
+ } else {
+ newValue = value;
+ }
+ log.debug("ConfigItem " + name + " set to new value " + newValue);
+ }
+
+ public void resetValue() {
+ if (hasChanged()) {
+ currentValue = newValue;
+ newValue = null;
+ }
+ }
+
+ /**
+ * @param applyInitMethod Specifies whether init should be called. Can be overruled
+ * by an additional tag alwaysCallInit
+ */
+ void callInitMethod(boolean applyInitMethod) {
+ if (!applyInitMethod && !alwaysCallInit) return;
+ if (initClass == null || initMethod == null) return;
+
+ // call without parameter
+ try {
+ Class<?> clazz = Class.forName(initClass);
+
+ if (initParameter) {
+ clazz.getMethod(initMethod, String.class).invoke(null, newValue);
+
+ } else {
+ clazz.getMethod(initMethod).invoke(null);
+ }
+ } catch (Exception e) {
+ log.error("Config profile: cannot call initMethod, Exception = " + e.toString());
+ }
+ }
+
+
+ public String toString() {
+ StringBuffer s = new StringBuffer();
+ s.append("Configuration Item: name = " + name + ", type = " + type);
+ s.append(", current value = " + getCurrentValue()) ;
+ s.append(", new value = " + getNewValue());
+ if (allowedValues != null) {
+ s.append(", allowedValues = " + allowedValues);
+ }
+ if (formatMask != null) {
+ s.append(", formatMask = " + formatMask);
+ }
+
+ return s.toString();
+ }
+
+
+
+}
diff --git a/rails/common/ConfigManager.java b/rails/common/ConfigManager.java
new file mode 100644
index 0000000..c2420c9
--- /dev/null
+++ b/rails/common/ConfigManager.java
@@ -0,0 +1,259 @@
+package rails.common;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import rails.common.ConfigManager;
+import rails.common.parser.ConfigurableComponentI;
+import rails.common.parser.ConfigurationException;
+import rails.common.parser.Tag;
+import rails.game.Game;
+import rails.game.GameManagerI;
+import rails.util.Util;
+
+/**
+ * ConfigManager is a utility class that collects all functions
+ * used to define and control configuration options
+ *
+ * It is a rewrite of the previouslsy used static class Config
+ */
+
+public class ConfigManager implements ConfigurableComponentI {
+
+ protected static Logger log;
+
+ // STATIC CONSTANTS
+
+ // Log4j command line option, compare log4j documentation
+ private static final String LOG4J_CLI_OPTION = "log4j.configuration";
+ // Default Log4j configuration-file
+ private static final String LOG4J_CONFIG_FILE = "log4j.properties";
+
+ // XML setup
+ private static final String CONFIG_XML_DIR = "data";
+ private static final String CONFIG_XML_FILE = "Properties.xml";
+ private static final String CONFIG_TAG = "Properties";
+ private static final String SECTION_TAG = "Section";
+ private static final String ITEM_TAG = "Property";
+
+ // singleton configuration for ConfigManager
+ private static final ConfigManager instance = new ConfigManager();
+
+ // INSTANCE DATA
+
+ // configuration items: replace with Multimap in Rails 2.0
+ private final Map<String, List<ConfigItem>> configSections = new HashMap<String, List<ConfigItem>>();
+
+ // profile storage
+ private ConfigProfile activeProfile;
+
+ /**
+ * Initial configuration immediately after startup:
+ * Setting of log4j and start logger
+ * @param test if true configurations are setup for integration tests, false for productive use
+ */
+ private static void startlog4j() {
+
+ // log4j settings
+ String log4jSelection = System.getProperty(LOG4J_CLI_OPTION);
+ if (!Util.hasValue(log4jSelection)) {
+ log4jSelection = LOG4J_CONFIG_FILE;
+ }
+ // Sets those settings
+ System.setProperty("log4j.configuration", log4jSelection);
+ System.out.println("log4j.configuration = " + log4jSelection);
+
+ // Activate logger
+ log = Logger.getLogger(ConfigManager.class.getPackage().getName());
+ log.debug("Activate log4j logging using configuration file = " + log4jSelection);
+
+ }
+
+ public static void initConfiguration(boolean test) {
+ startlog4j();
+
+ try {
+ List<String> directories = new ArrayList<String>();
+ directories.add(CONFIG_XML_DIR);
+ // Find the config tag inside the the config xml file
+ Tag configTag =
+ Tag.findTopTagInFile(CONFIG_XML_FILE, directories, CONFIG_TAG);
+ log.debug("Opened config xml, filename = " + CONFIG_XML_FILE);
+ instance.configureFromXML(configTag);
+ } catch (ConfigurationException e) {
+ log.error("Configuration error in setup of " + CONFIG_XML_FILE + ", exception = " + e);
+ }
+
+ if (test) {
+ instance.initTest();
+ } else {
+ instance.init();
+ }
+ }
+
+
+ /**
+ * @return singleton instance of ConfigManager
+ */
+ pu...
[truncated message content] |