|
From: <ste...@us...> - 2010-07-16 20:37:39
|
Revision: 1338
http://rails.svn.sourceforge.net/rails/?rev=1338&view=rev
Author: stefanfrey
Date: 2010-07-16 20:37:33 +0000 (Fri, 16 Jul 2010)
Log Message:
-----------
Started configuration window/item implementation
Modified Paths:
--------------
trunk/18xx/rails/test/GameTest.java
trunk/18xx/rails/ui/swing/StatusWindow.java
trunk/18xx/rails/util/Config.java
trunk/18xx/rails/util/ListAndFixSavedFiles.java
trunk/18xx/rails/util/RunGame.java
trunk/18xx/test/TestGameBuilder.java
Added Paths:
-----------
trunk/18xx/default.profiles
trunk/18xx/log4j.properties
trunk/18xx/rails/ui/swing/ConfigWindow.java
trunk/18xx/rails/util/ConfigItem.java
trunk/18xx/user.profiles
Added: trunk/18xx/default.profiles
===================================================================
--- trunk/18xx/default.profiles (rev 0)
+++ trunk/18xx/default.profiles 2010-07-16 20:37:33 UTC (rev 1338)
@@ -0,0 +1,2 @@
+default=my.properties
+test=test/test.properties
Added: trunk/18xx/log4j.properties
===================================================================
--- trunk/18xx/log4j.properties (rev 0)
+++ trunk/18xx/log4j.properties 2010-07-16 20:37:33 UTC (rev 1338)
@@ -0,0 +1,23 @@
+####################### Log4J properties ##############################
+# For information on how to customise log4j logging, see for instance
+# http://www.vipan.com/htdocs/log4jhelp.html
+# It's a bit outdated: Category is now named Logger,
+# and Priority is now named Level.
+# But it's the best intro I know on how to configure Appenders. (EV)
+#######################################################################
+# Set root logger level to DEBUG and use appender F(file)
+#log4j.debug=true
+log4j.rootLogger=DEBUG, F
+log4j.logger.rails.algorithms=INFO
+
+# Define the Log file appender
+log4j.appender.F=org.apache.log4j.FileAppender
+
+# Log file properties
+log4j.appender.F.File=18xx.log
+log4j.appender.F.append=false
+
+# Log file layout
+log4j.appender.F.layout=org.apache.log4j.PatternLayout
+log4j.appender.F.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n
+################## End of Log4J properties #############################
Modified: trunk/18xx/rails/test/GameTest.java
===================================================================
--- trunk/18xx/rails/test/GameTest.java 2010-07-11 16:44:29 UTC (rev 1337)
+++ trunk/18xx/rails/test/GameTest.java 2010-07-16 20:37:33 UTC (rev 1338)
@@ -2,35 +2,14 @@
import rails.ui.swing.GameSetupWindow;
import rails.util.Config;
-import rails.util.Util;
public class GameTest {
- /** The default properties file name */
- private static String DEFAULT_CONFIG_FILE = "my.properties";
public static void main(String[] args) {
- /*
- * Check if the property file has been set on the command line. The way
- * to do this is adding an option to the java command: -Dconfigfile=<property-filename>
- */
- String myConfigFile = System.getProperty("configfile");
- System.out.println("Cmdline configfile setting = " + myConfigFile);
-
- /* If not, use the default configuration file name */
- if (!Util.hasValue(myConfigFile)) {
- myConfigFile = DEFAULT_CONFIG_FILE;
- }
-
- /*
- * Set the system property that tells log4j to use this file. (Note:
- * this MUST be done before updating Config)
- */
- System.setProperty("log4j.configuration", myConfigFile);
- /* Tell the properties loader to read this file. */
- Config.setConfigFile(myConfigFile);
- System.out.println("Configuration file = " + myConfigFile);
-
+ // intialize configuration
+ Config.setConfigSelection();
+
int nargs = 0;
if (args != null && args.length > 0) {
for (String arg : args) {
Added: trunk/18xx/rails/ui/swing/ConfigWindow.java
===================================================================
--- trunk/18xx/rails/ui/swing/ConfigWindow.java (rev 0)
+++ trunk/18xx/rails/ui/swing/ConfigWindow.java 2010-07-16 20:37:33 UTC (rev 1338)
@@ -0,0 +1,144 @@
+package rails.ui.swing;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Map;
+import java.util.List;
+
+import javax.swing.JButton;
+import javax.swing.JColorChooser;
+import javax.swing.JComponent;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+
+import rails.util.Config;
+import rails.util.ConfigItem;
+import rails.util.LocalText;
+
+class ConfigWindow extends JFrame {
+ private static final long serialVersionUID = 1L;
+
+ private JTabbedPane pane;
+
+ ConfigWindow() {
+ // JFrame properties
+ setTitle(LocalText.getText("ConfigWindowTitle"));
+// setSize(400,300);
+
+ // add profile panel
+ add(setupProfilePanel(), "North");
+
+ // configSetup pane
+ setupConfigPane();
+ add(pane, "Center");
+
+ // buttons
+ JPanel buttonPanel = new JPanel();
+
+ JButton saveButton = new JButton(LocalText.getText("Save"));
+ saveButton.addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ ConfigWindow.this.saveConfig();
+ }
+ }
+ );
+ buttonPanel.add(saveButton);
+
+ JButton cancelButton = new JButton(LocalText.getText("Cancel"));
+ cancelButton.addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ ConfigWindow.this.cancelConfig();
+ }
+ }
+ );
+ buttonPanel.add(cancelButton);
+
+ add(buttonPanel, "South");
+
+ this.pack();
+ }
+
+
+ private JComponent setupProfilePanel() {
+ JComponent panel = new JPanel();
+ panel.setLayout(new GridLayout(0,4));
+
+ // default profile
+
+
+ return panel;
+ }
+
+ private void setupConfigPane() {
+ // create pane
+ pane = new JTabbedPane();
+
+ Map<String, List<ConfigItem>> configPanels = Config.getConfigPanels();
+
+ for (String panelName:configPanels.keySet()) {
+ JPanel newPanel = new JPanel();
+ newPanel.setLayout(new GridLayout(0,3));
+ for (ConfigItem item:configPanels.get(panelName)) {
+ defineElement(newPanel, item);
+ }
+ pane.addTab(panelName, newPanel);
+ }
+ }
+
+ private void defineElement(JPanel panel, ConfigItem item) {
+
+ panel.add(new JLabel(LocalText.getText("Config." + item.name)));
+
+ final String configValue = Config.get(item.name);
+ switch (item.type) {
+ case COLOR: {
+ final JLabel label = new JLabel(configValue);
+ Color selectedColor;
+ try {
+ selectedColor = Color.decode(configValue);
+ } catch (NumberFormatException e) {
+ selectedColor = Color.WHITE;
+ }
+ label.setOpaque(true);
+ label.setBackground(selectedColor);
+ panel.add(label);
+ JButton button = new JButton("Color");
+ final Color oldColor = selectedColor;
+ button.addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ Color selectedColor=JColorChooser.showDialog(ConfigWindow.this, "", oldColor);
+ label.setText(Integer.toHexString(selectedColor.getRGB()).substring(2));
+ label.setBackground(selectedColor);
+ }
+ }
+ );
+ panel.add(button);
+ break;
+ }
+ case STRING:
+ default: {
+ JFormattedTextField textField = new JFormattedTextField();
+ textField.setValue(configValue);
+ panel.add(textField);
+ }
+ }
+ }
+
+ private void saveConfig() {
+ this.dispose();
+ }
+
+ private void cancelConfig() {
+ this.dispose();
+ }
+
+}
Modified: trunk/18xx/rails/ui/swing/StatusWindow.java
===================================================================
--- trunk/18xx/rails/ui/swing/StatusWindow.java 2010-07-11 16:44:29 UTC (rev 1337)
+++ trunk/18xx/rails/ui/swing/StatusWindow.java 2010-07-16 20:37:33 UTC (rev 1338)
@@ -3,6 +3,8 @@
import java.awt.BorderLayout;
import java.awt.Color;
+//import java.awt.GraphicsConfiguration;
+//import java.awt.Rectangle;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Collections;
@@ -48,6 +50,8 @@
protected static final String REPORT_CMD = "Report";
+ protected static final String CONFIG_CMD = "Config";
+
protected static final String BUY_CMD = "Buy";
protected static final String SELL_CMD = "Sell";
@@ -80,13 +84,21 @@
private JMenuItem menuItem;
- private ActionMenuItem saveItem, exportItem;
+ private ActionMenuItem saveItem;
+// private ActionMenuItem exportItem;
private ActionMenuItem undoItem, forcedUndoItem, redoItem, redoItem2;
protected static Logger log =
Logger.getLogger(StatusWindow.class.getPackage().getName());
+// GraphicsConfiguration graphicsConfiguration;
+
+// public StatusWindow(GraphicsConfiguration gc) {
+// super(gc);
+// this.graphicsConfiguration = gc;
+// }
+
public void initMenu() {
menuBar = new JMenuBar();
fileMenu = new JMenu(LocalText.getText("FILE"));
@@ -163,6 +175,13 @@
menuItem.setMnemonic(KeyEvent.VK_R);
menuItem.addActionListener(this);
optMenu.add(menuItem);
+
+ menuItem = new JCheckBoxMenuItem(LocalText.getText("CONFIG"));
+ menuItem.setName(CONFIG_CMD);
+ menuItem.setActionCommand(CONFIG_CMD);
+ menuItem.setMnemonic(KeyEvent.VK_C);
+ menuItem.addActionListener(this);
+ optMenu.add(menuItem);
menuBar.add(optMenu);
@@ -257,8 +276,10 @@
autopassButton.addActionListener(this);
setSize(800, 300);
- setLocation(25, 450);
+// Rectangle bounds = graphicsConfiguration.getBounds();
+// setLocation(bounds.x+ 25, bounds.y + 450);
+
buttonPanel.setBorder(BorderFactory.createEtchedBorder());
buttonPanel.setOpaque(false);
@@ -583,6 +604,10 @@
gameUIManager.stockChart.setVisible(((JMenuItem) actor.getSource()).isSelected());
} else if (command.equals(MAP_CMD)) {
gameUIManager.orWindow.setVisible(((JMenuItem) actor.getSource()).isSelected());
+ } else if (command.equals(CONFIG_CMD)) {
+ JFrame configWindow = new ConfigWindow();
+ configWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ configWindow.setVisible(true);
} else if (executedAction == null) {
;
} else if (executedAction instanceof GameAction) {
Modified: trunk/18xx/rails/util/Config.java
===================================================================
--- trunk/18xx/rails/util/Config.java 2010-07-11 16:44:29 UTC (rev 1337)
+++ trunk/18xx/rails/util/Config.java 2010-07-16 20:37:33 UTC (rev 1338)
@@ -1,11 +1,21 @@
/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/util/Config.java,v 1.13 2010/06/24 21:48:08 stefanfrey Exp $*/
package rails.util;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.apache.log4j.Logger;
+import rails.game.ConfigurationException;
import rails.game.GameManager;
/**
@@ -18,28 +28,102 @@
*/
public final class Config {
- /** Default property file name. */
- /* It will be reset from GameTest. */
- private static String myConfigFile = "my.properties";
- //private static String gamesConfigFile = "games.properties";
+ protected static Logger log =
+ Logger.getLogger(Config.class.getPackage().getName());
- /** One Properties object for all properties */
- private static Properties prop = new Properties();
- private static boolean loaded = false;
+
+ /**
+ * Defines possible types (Java classes used as types in ConfigItem below
+ */
+ public static enum ConfigType {
+ INTEGER, FLOAT, STRING, BOOLEAN, DIRECTORY, COLOR;
+ }
- protected static Logger log =
- Logger.getLogger(Config.class.getPackage().getName());
+ /** 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 PANEL_TAG = "Panel";
+ private static final String ITEM_TAG = "Property";
+ /** Log 4j configuration */
+ private static final String LOG4J_CONFIG_FILE = "log4j.properties";
+
+
+ /** Rails profile configurations */
+ private static String defaultProfilesFile = "default.profiles";
+ private static Properties defaultProfiles = new Properties();
+ private static String userProfilesFile = "user.profiles";
+ private static Properties userProfiles = new Properties();
+ private static boolean profilesLoaded = false;
+ private static final String TEST_PROFILE_SELECTION = "test";
+ private static final String DEFAULT_PROFILE_SELECTION = "default";
+ private static final String DEFAULT_PROFILE_PROPERTY = "default.profile";
+ private static final String STANDARD_PROFILE_PROPERTY = "standard.profile";
+
+ /** selected profile */
+ private static String selectedProfile;
+ private static boolean legacyConfigFile;
+ private static boolean standardProfile;
+
+ /** properties storage. */
+ private static Properties defaultProperties = new Properties();
+ private static Properties userProperties = new Properties();
+ private static boolean propertiesLoaded = false;
+
+ /** Map that holds the panel, which contains config items */
+ private static Map<String, List<ConfigItem>> configPanels = null;
+
/**
- * Hidden contructor, the class is never instantiated.
+ * Hidden constructor, the class is never instantiated, everything is static
*/
private Config() {}
- public static void setConfigFile(String myConfigFile) {
- Config.myConfigFile = myConfigFile;
- load();
+ /**
+ * Reads the config.xml file that defines all config items
+ */
+ public static void readConfigSetupXML() {
+ List<String> directories = new ArrayList<String>();
+ directories.add(CONFIG_XML_DIR);
+ try {
+ // Find the <Config> tag
+ Tag configTag =
+ Tag.findTopTagInFile(CONFIG_XML_FILE, directories, CONFIG_TAG);
+ log.debug("Opened config xml, filename = " + CONFIG_XML_FILE);
+
+ configPanels = new LinkedHashMap<String, List<ConfigItem>>();
+ // find panels
+ List<Tag> panelTags = configTag.getChildren(PANEL_TAG);
+ if (panelTags != null) {
+ for (Tag panelTag:panelTags) {
+ // find name attribute
+ String panelName = panelTag.getAttributeAsString("name");
+ if (!Util.hasValue(panelName)) continue;
+
+ // find items
+ List<Tag> itemTags = panelTag.getChildren(ITEM_TAG);
+ if (itemTags == null || itemTags.size() == 0) continue;
+ List<ConfigItem> panelItems = new ArrayList<ConfigItem>();
+ for (Tag itemTag:itemTags) {
+ panelItems.add(new ConfigItem(itemTag));
+ }
+ configPanels.put(panelName, panelItems);
+ }
+ }
+
+ } catch (ConfigurationException e) {
+ log.error("Configuration error in setup of ");
+ }
}
-
+
+ public static Map<String, List<ConfigItem>> getConfigPanels() {
+ if (configPanels == null) {
+ readConfigSetupXML();
+ }
+ log.debug("Configuration setup = " + configPanels);
+ return configPanels;
+ }
+
/**
* First tries to return {key}.{gameName}, if undefined returns {key}
*/
@@ -59,55 +143,238 @@
}
public static String get(String key) {
-
- if (prop.isEmpty() || !loaded) {
- load();
+ return get(key, "");
+ }
+
+ public static String get(String key, String defaultValue) {
+ if (defaultProperties.isEmpty() || !propertiesLoaded) {
+ initialLoad();
}
- if (prop.containsKey(key)) return prop.getProperty(key).trim();
+ if (userProperties.containsKey(key)) return userProperties.getProperty(key).trim();
+ if (defaultProperties.containsKey(key)) return defaultProperties.getProperty(key).trim();
- return "";
+ return defaultValue;
}
- public static String get(String key, String defaultValue) {
- if (prop.isEmpty() || !loaded) {
- load();
+// /**
+// * store user config file
+// */
+// public static boolean saveUserConfig() {
+// }
+//
+// /**
+// * @return if user location is defined
+// */
+// public static boolean hasUserLocation() {
+// return userConfigFile != null;
+// }
+
+
+ private static boolean storePropertyFile(Properties properties, String filepath) {
+ File outFile = new File(filepath);
+ boolean result = true;
+ try {
+ properties.store(new FileOutputStream(outFile), "Automatically generated, do not edit");
+ } catch (IOException e) {
+ result = false;
}
- if (prop.containsKey(key)) return prop.getProperty(key).trim();
+ return result;
+ }
+
+ /**
+ * save active Profile
+ */
+ public static boolean saveActiveProfile(String filepath) {
+ return storePropertyFile(userProperties, filepath);
+ }
+
+ /**
+ * change active Profile
+ */
+ public static boolean setActiveProfile(String profileName) {
+ boolean result = loadPropertyProfile(profileName);
+ if (result) selectedProfile = profileName;
+ return result;
+ }
+
+ /**
+ * returns name of (active) default profile
+ */
+ public static String getDefaultProfileName() {
+ String defaultProfileName = null;
+ if (isUserProfileActive()) {
+ defaultProfileName = userProfiles.getProperty(DEFAULT_PROFILE_PROPERTY);
+ if (defaultProfileName == null) {
+// return
+ }
+ }
+ return defaultProfileName;
+ }
+
+ /**
+ * returns name of active profile
+ */
+ public static String getActiveProfileName() {
+ return selectedProfile;
+ }
+
+ /**
+ * sets filename for an active profile (and store list of profiles)
+ */
+ public static boolean setActiveFilepath(String filepath) {
+ userProfiles.setProperty(selectedProfile, filepath);
+ return storePropertyFile(userProfiles, userProfilesFile);
+ }
+
+ /**
+ * returns filename of active profile, (null if undefined or default profile)
+ */
+ public static String getActiveFilepath() {
+ return userProfiles.getProperty(selectedProfile);
+ }
+
+ /**
+ * returns true if active profile is a user profile
+ */
+ public static boolean isUserProfileActive() {
+ return userProfiles.getProperty(selectedProfile) != null;
+ }
+
+ /**
+ * activates settings used for testing
+ */
+ public static void setConfigTest() {
+ /*
+ * Set the system property that tells log4j to use this file. (Note:
+ * this MUST be done before updating Config)
+ */
+ System.setProperty("log4j.configuration", LOG4J_CONFIG_FILE);
+ legacyConfigFile = false;
+ selectedProfile = TEST_PROFILE_SELECTION;
+ initialLoad();
+ }
- return defaultValue;
+
+ /**
+ * activates configuration settings based on default settings
+ */
+ public static void setConfigSelection() {
+ /*
+ * Set the system property that tells log4j to use this file. (Note:
+ * this MUST be done before updating Config)
+ */
+ System.setProperty("log4j.configuration", LOG4J_CONFIG_FILE);
+
+ /*
+ * Check if the profile has been set from the command line
+ * to do this is adding an option to the java command: -Dprofile=<profile-name>
+ */
+ String configSelection = System.getProperty("profile");
+ System.out.println("Cmdline profile selection = " + configSelection);
+
+ legacyConfigFile = false;
+ if (configSelection == null) {
+ /*
+ * Check if the property file has been set on the command line. The way
+ * to do this is adding an option to the java command: -Dconfigfile=<property-filename>
+ *
+ * This is for legacy reasons only
+ */
+ configSelection = System.getProperty("configfile");
+
+ if (configSelection != null) {
+ System.out.println("Cmdline configfile selection (legacy!) = " + configSelection);
+ legacyConfigFile = true;
+ }
+ }
+
+ /* if nothing has selected so far, choose standardProfile */
+ standardProfile = false;
+ if (!Util.hasValue(configSelection)) {
+ standardProfile = true;
+ }
+
+ selectedProfile = configSelection;
+ initialLoad();
}
+
- private static void load() {
+ private static void initialLoad() {
+ if (legacyConfigFile) {
+ if (!propertiesLoaded) {
+ loadPropertyFile(defaultProperties, selectedProfile, true, false);
+ propertiesLoaded = true;
+ setSaveDirDefaults();
+ }
+ return;
+ }
- if (prop.isEmpty() || !loaded) {
- /* List the property files to read here */
- load(myConfigFile, false);
- //load(gamesConfigFile, false);
- setDefaults();
- loaded = true;
+ if (!profilesLoaded) {
+ loadPropertyFile(defaultProfiles, defaultProfilesFile, true, false);
+ loadPropertyFile(userProfiles, userProfilesFile, false, false);
+ profilesLoaded = true;
}
+
+ if (standardProfile) {
+ selectedProfile = userProfiles.getProperty(STANDARD_PROFILE_PROPERTY);
+ if (selectedProfile == null) {
+ selectedProfile = defaultProfiles.getProperty(STANDARD_PROFILE_PROPERTY);
+ }
+ if (selectedProfile == null) {
+ selectedProfile = DEFAULT_PROFILE_SELECTION;
+ }
+ }
+
+ /* Tell the properties loader to read this file. */
+ log.info("Selected profile = " + selectedProfile);
+
+ if (!propertiesLoaded) {
+ propertiesLoaded = loadPropertyProfile(selectedProfile);
+ }
}
+
+ private static boolean loadPropertyProfile(String profileName) {
+
+ /* first check if it is a default profile */
+ String defaultConfigFile = defaultProfiles.getProperty(profileName);
+ if (defaultConfigFile == null) {
+ String userConfigFile = userProfiles.getProperty(profileName);
+ if (userConfigFile == null) return false;
+ loadPropertyFile(userProperties, userConfigFile, false, false);
+ defaultConfigFile = userProperties.getProperty(DEFAULT_PROFILE_PROPERTY);
+ if (defaultConfigFile == null) {
+ defaultConfigFile = defaultProfiles.getProperty(DEFAULT_PROFILE_SELECTION);
+ }
+ }
+ loadPropertyFile(defaultProperties, defaultConfigFile, true, false);
+ setSaveDirDefaults();
+ return true;
+ }
/**
* This method loads a property file.
*
* @param filename - file key name as a String.
+ * @param resource - if TRUE, loaded from jar (via classloader), otherwise from filesystem
* @param required - if TRUE, an exception will be logged if the file does
* not exist.
*/
- private static void load(String filename, boolean required) {
-
+ private static void loadPropertyFile(Properties properties, String filename, boolean resource, boolean required) {
+
try {
log.info("Loading properties from file " + filename);
- prop.load(Config.class.getClassLoader().getResourceAsStream(
- filename));
-
+ InputStream inFile;
+ if (resource) {
+ inFile = Config.class.getClassLoader().getResourceAsStream(filename);
+ } else {
+ inFile = new FileInputStream(filename);
+ }
+ properties.load(inFile);
} catch (FileNotFoundException FNFE) {
if (required) {
System.err.println("File not found: " + filename);
}
-
} catch (Exception e) {
System.err.println(e + " whilst loading properties file "
+ filename);
@@ -115,10 +382,10 @@
}
}
- private static void setDefaults() {
- if (!Util.hasValue(prop.getProperty("save.directory"))) {
+ private static void setSaveDirDefaults() {
+ if (!Util.hasValue(defaultProperties.getProperty("save.directory"))) {
log.debug("Setting save directory to "+System.getProperty("user.dir"));
- prop.put("save.directory", System.getProperty("user.dir"));
+ defaultProperties.put("save.directory", System.getProperty("user.dir"));
}
}
}
Added: trunk/18xx/rails/util/ConfigItem.java
===================================================================
--- trunk/18xx/rails/util/ConfigItem.java (rev 0)
+++ trunk/18xx/rails/util/ConfigItem.java 2010-07-16 20:37:33 UTC (rev 1338)
@@ -0,0 +1,63 @@
+package rails.util;
+
+import java.util.Arrays;
+import java.util.List;
+import rails.game.ConfigurationException;
+import rails.util.Config.ConfigType;
+
+/**
+ * Defines an item used for the configuration of rails
+ * T represents the value type
+ */
+
+public class ConfigItem {
+ public final String name;
+ public final ConfigType type;
+ public final List<String> allowedValues;
+ public final String formatMask;
+ public final String helpText;
+
+ 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");
+ }
+ String type = tag.getAttributeAsString("type");
+ if (Util.hasValue(type)) {
+ this.type = ConfigType.valueOf(type);
+ } else {
+ throw new ConfigurationException("Missing or invalid type for configuration item");
+ }
+ // optional: list of allowed values
+ String valueString = tag.getAttributeAsString("values");
+ if (Util.hasValue(valueString)) {
+ allowedValues = Arrays.asList(valueString.split(","));
+ } else {
+ allowedValues = null;
+ }
+ // optional: formatMask
+ formatMask = tag.getAttributeAsString("formatMask");
+
+ // optional: helpText
+ helpText = tag.getAttributeAsString("formatMask");
+ }
+
+ public String toString() {
+ StringBuffer s = new StringBuffer();
+ s.append("Configuration Item: name = " + name + ", type = " + type);
+ if (allowedValues != null) {
+ s.append(", allowedValues = " + allowedValues);
+ }
+ if (formatMask != null) {
+ s.append(", formatMask = " + formatMask);
+ }
+ if (helpText != null) {
+ s.append(", helpText = " + helpText);
+ }
+ return s.toString();
+ }
+
+}
Modified: trunk/18xx/rails/util/ListAndFixSavedFiles.java
===================================================================
--- trunk/18xx/rails/util/ListAndFixSavedFiles.java 2010-07-11 16:44:29 UTC (rev 1337)
+++ trunk/18xx/rails/util/ListAndFixSavedFiles.java 2010-07-16 20:37:33 UTC (rev 1338)
@@ -39,32 +39,15 @@
private String filepath;
protected static Logger log;
-
/**
* @param args
*/
public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- String myConfigFile = System.getProperty("configfile");
- System.out.println("Cmdline configfile setting = " + myConfigFile);
-
- /* If not, use the default configuration file name */
- if (!Util.hasValue(myConfigFile)) {
- myConfigFile = "my.properties";
- }
-
- /*
- * Set the system property that tells log4j to use this file. (Note:
- * this MUST be done before updating Config)
- */
- System.setProperty("log4j.configuration", myConfigFile);
- log = Logger.getLogger(ListAndFixSavedFiles.class.getPackage().getName());
-
- /* Tell the properties loader to read this file. */
- Config.setConfigFile(myConfigFile);
- System.out.println("Configuration file = " + myConfigFile);
+
+ // intialize configuration
+ Config.setConfigSelection();
+
saveDirectory = Config.get("save.directory");
System.out.println("Save directory = " + saveDirectory);
Modified: trunk/18xx/rails/util/RunGame.java
===================================================================
--- trunk/18xx/rails/util/RunGame.java 2010-07-11 16:44:29 UTC (rev 1337)
+++ trunk/18xx/rails/util/RunGame.java 2010-07-16 20:37:33 UTC (rev 1338)
@@ -7,32 +7,12 @@
import rails.ui.swing.GameUIManager;
public class RunGame {
- /** The default properties file name */
- private static String DEFAULT_CONFIG_FILE = "my.properties";
public static void main(String[] args) {
- /*
- * Check if the property file has been set on the command line. The way
- * to do this is adding an option to the java command: -Dconfigfile=<property-filename>
- */
- String myConfigFile = System.getProperty("configfile");
- System.out.println("Cmdline configfile setting = " + myConfigFile);
-
- /* If not, use the default configuration file name */
- if (!Util.hasValue(myConfigFile)) {
- myConfigFile = DEFAULT_CONFIG_FILE;
- }
-
- /*
- * Set the system property that tells log4j to use this file. (Note:
- * this MUST be done before updating Config)
- */
- System.setProperty("log4j.configuration", myConfigFile);
- /* Tell the properties loader to read this file. */
- Config.setConfigFile(myConfigFile);
- System.out.println("Configuration file = " + myConfigFile);
-
+ // intialize configuration
+ Config.setConfigSelection();
+
int nargs = 0;
if (args != null && args.length > 0) {
nargs = args.length;
Modified: trunk/18xx/test/TestGameBuilder.java
===================================================================
--- trunk/18xx/test/TestGameBuilder.java 2010-07-11 16:44:29 UTC (rev 1337)
+++ trunk/18xx/test/TestGameBuilder.java 2010-07-16 20:37:33 UTC (rev 1338)
@@ -23,7 +23,6 @@
public final class TestGameBuilder extends TestCase {
- private static String configFile = "test/test.properties";
private static char extensionSeparator = '.';
private static int maxRecursionLevel = 5;
@@ -147,14 +146,8 @@
public static Test suite() {
- // Activate logger
- System.setProperty("log4j.configuration", configFile);
+ Config.setConfigTest();
- /* Tell the properties loader to read this file. */
- Config.setConfigFile(configFile);
- System.out.println("Configuration file = " + configFile);
-
-
// Main test directory
File testDir = new File(Config.get("save.directory"));
@@ -177,13 +170,8 @@
*/
public static void main(String[] args) {
- // Activate logger
- System.setProperty("log4j.configuration", configFile);
+ Config.setConfigTest();
- /* Tell the properties loader to read this file. */
- Config.setConfigFile(configFile);
- System.out.println("Configuration file = " + configFile);
-
// Main test directory
String rootPath = Config.get("save.directory");
Added: trunk/18xx/user.profiles
===================================================================
--- trunk/18xx/user.profiles (rev 0)
+++ trunk/18xx/user.profiles 2010-07-16 20:37:33 UTC (rev 1338)
@@ -0,0 +1,2 @@
+standard.profile=sfy
+sfy=sfy.my.properties
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|