|
From: <ste...@us...> - 2010-08-01 11:46:32
|
Revision: 1364
http://rails.svn.sourceforge.net/rails/?rev=1364&view=rev
Author: stefanfrey
Date: 2010-08-01 11:46:26 +0000 (Sun, 01 Aug 2010)
Log Message:
-----------
Updated and improved configuration settings
Modified Paths:
--------------
trunk/18xx/LocalisedText.properties
trunk/18xx/data/Properties.xml
trunk/18xx/rails/ui/swing/ConfigWindow.java
trunk/18xx/rails/ui/swing/StartRoundWindow.java
trunk/18xx/rails/util/Config.java
trunk/18xx/rails/util/LocalText.java
Added Paths:
-----------
trunk/18xx/rails/ui/swing/elements/RailsIcon.java
Property Changed:
----------------
trunk/18xx/
Property changes on: trunk/18xx
___________________________________________________________________
Modified: svn:ignore
- *.bat
*.txt
.cvsignore
.classpath
.externalToolBuilders
18xx.zip
deploy.xml
.project
zip.xml
NewUIstuff.zip
COMP.WPS
rails.jar
rails.jardesc
Rails-1.0.1.jar
my_my.properties
log
rails-1.0.1.jar
rails*.zip
rails-*.jar
tools
rails-?.*.*
jar/*
classes/*
18xx_autosave.rails
18xx_autosave.rails.tmp
+ *.bat
*.txt
.cvsignore
.classpath
.externalToolBuilders
18xx.zip
deploy.xml
.project
zip.xml
NewUIstuff.zip
COMP.WPS
rails.jar
rails.jardesc
Rails-1.0.1.jar
my_my.properties
log
rails-1.0.1.jar
rails*.zip
rails-*.jar
tools
rails-?.*.*
jar/*
classes/*
18xx_autosave.rails
18xx_autosave.rails.tmp
user.profiles
Modified: trunk/18xx/LocalisedText.properties
===================================================================
--- trunk/18xx/LocalisedText.properties 2010-07-30 20:59:08 UTC (rev 1363)
+++ trunk/18xx/LocalisedText.properties 2010-08-01 11:46:26 UTC (rev 1364)
@@ -67,18 +67,19 @@
COMPANY=Company
COMPANY_DETAILS=Company details
CONFIG=Configuration
-CONFIG_APPLY_MESSAGE=Current changes (will be) applied
+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_PROFILE=Active profile = {0} (based on = {1})
CONFIG_DEFAULT_TITLE=Default profile
CONFIG_DEFAULT_MESSAGE=Select a template for settings
+CONFIG_INFO_TITLE=Info text for {0}
CONFIG_NEW_MESSAGE=Select a name of the new profile
CONFIG_NEW_TITLE=Create profile
CONFIG_SELECT_PROFILE=Select profile ->
CONFIG_SETTINGS=Profile settings
CONFIG_SAVE_MESSAGE=Active profile {0} was saved
CONFIG_SAVE_TITLE=Save confirmation
-CONFIG_WINDOW_TITLE=Rails Configuration
+CONFIG_WINDOW_TITLE=Rails Configuration
CORRECT_CASH=Cash Correction
CORRECT_MAP=Map Correction
CURRENT=Current
@@ -149,6 +150,19 @@
ComponentInitAs=Component {0} is initialized as class {1}
ComponentManagerNotReconfigured=Cannot reconfigure the ComponentManager.
ComponentManagerNotYetConfigured=ComponentManager has not yet been configured.
+Config.infoText.locale=<html>te_ST shows local text keys. <br> Requires restart.</html>
+Config.infoText.default_players=Enter player names separated by commas.
+Config.label.default_game=Default game
+Config.label.default_players=Default players
+Config.label.local.player.name=Local player (for pbem)
+Config.label.locale=Language Setting
+Config.toolTip.local.player.name=Player name used as suffix for game save
+Config.section.Format=Format/Colors
+Config.section.General=General
+Config.section.Log=Log
+Config.section.Map=Map
+Config.section.Save=Save
+Config.section.UI=Windows/Fonts
ConfirmToken=Press Lay Token to confirm token, click another city hex, or press the No Token button.
connected=connected
CorrectCashAddMoney=CORRECTION: {0} receives {1} from the bank
Modified: trunk/18xx/data/Properties.xml
===================================================================
--- trunk/18xx/data/Properties.xml 2010-07-30 20:59:08 UTC (rev 1363)
+++ trunk/18xx/data/Properties.xml 2010-08-01 11:46:26 UTC (rev 1364)
@@ -2,7 +2,7 @@
<!-- Supported properties Defines rails configuration options, but do not
stores the actual values -->
<Properties>
- <Panel name="General">
+ <Section name="General">
<Property name="locale" type="LIST" values="en_US,te_ST"
initClass="rails.util.LocalText" initMethod="setLocale"
initParameter="yes" />
@@ -10,28 +10,28 @@
<Property name="default_players" type="STRING" />
<Property name="local.player.name" type="STRING" />
- </Panel>
- <Panel name="Save">
+ </Section>
+ <Section name="Save">
<Property name="save.directory" type="DIRECTORY" />
<Property name="save.filename.date_time_pattern" type="STRING" />
<Property name="save.filename.suffix" type="STRING" />
<Property name="save.filename.extension" type="STRING" />
<Property name="save.recovery.active" type="BOOLEAN" />
<Property name="save.recovery.filepath" type="FILE" />
- </Panel>
- <Panel name="UI">
+ </Section>
+ <Section name="UI">
<Property name="report.window.open" type="BOOLEAN" />
<Property name="report.window.editable" type="BOOLEAN" />
<Property name="stockchart.window.open" type="BOOLEAN" />
<Property name="font.ui.scale" type="PERCENT" />
<Property name="font.ui.name" type="FONT" />
<Property name="font.ui.style" type="LIST" values="plain,bold" />
- </Panel>
- <Panel name="Map">
+ </Section>
+ <Section name="Map">
<Property name="map.autoscroll" type="BOOLEAN" />
<Property name="map.zoomstep" type="INTEGER" />
- </Panel>
- <Panel name="Format">
+ </Section>
+ <Section name="Format">
<Property name="money_format" type="STRING" />
<Property name="or.number_format" type="LIST" values="simple,composite" />
<Property name="route.colour.1" type="COLOR"
@@ -42,10 +42,10 @@
initClass="rails.ui.swing.hexmap.HexMap" initMethod="setRouteColours" />
<Property name="route.colour.4" type="COLOR"
initClass="rails.ui.swing.hexmap.HexMap" initMethod="setRouteColours" />
- </Panel>
- <Panel name="Log">
+ </Section>
+ <Section name="Log">
<Property name="report.directory" type="DIRECTORY" />
<Property name="report.filename.date_time_pattern" type="STRING" />
<Property name="report.filename.extension" type="STRING" />
- </Panel>
+ </Section>
</Properties>
\ No newline at end of file
Modified: trunk/18xx/rails/ui/swing/ConfigWindow.java
===================================================================
--- trunk/18xx/rails/ui/swing/ConfigWindow.java 2010-07-30 20:59:08 UTC (rev 1363)
+++ trunk/18xx/rails/ui/swing/ConfigWindow.java 2010-08-01 11:46:26 UTC (rev 1364)
@@ -14,8 +14,12 @@
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.Map;
import java.util.List;
@@ -28,6 +32,7 @@
import javax.swing.filechooser.FileFilter;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
+import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
@@ -42,6 +47,7 @@
import javax.swing.border.Border;
import rails.game.ConfigurationException;
+import rails.ui.swing.elements.RailsIcon;
import rails.util.Config;
import rails.util.ConfigItem;
import rails.util.LocalText;
@@ -151,10 +157,10 @@
Border titled = BorderFactory.createTitledBorder(etched, LocalText.getText("CONFIG_SETTINGS"));
configPane.setBorder(titled);
- Map<String, List<ConfigItem>> configPanels = Config.getConfigPanels();
+ Map<String, List<ConfigItem>> configSections = Config.getConfigSections();
int maxElements = Config.getMaxElementsInPanels();
- for (String panelName:configPanels.keySet()) {
+ for (String sectionName:configSections.keySet()) {
JPanel newPanel = new JPanel();
newPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
@@ -164,18 +170,18 @@
gbc.weighty = 0.8;
gbc.insets = new Insets(5,5,5,5);
gbc.anchor = GridBagConstraints.WEST;
- for (ConfigItem item:configPanels.get(panelName)) {
+ for (ConfigItem item:configSections.get(sectionName)) {
gbc.gridx = 0;
gbc.gridy++;
defineElement(newPanel, item, gbc);
}
// fill up to maxElements
gbc.gridx = 0;
- for (gbc.gridy++; gbc.gridy < maxElements; gbc.gridy++) {
+ while (++gbc.gridy < maxElements) {
JLabel emptyLabel = new JLabel("");
newPanel.add(emptyLabel, gbc);
}
- configPane.addTab(LocalText.getText("Config.panel." + panelName), newPanel);
+ configPane.addTab(LocalText.getText("Config.section." + sectionName), newPanel);
}
}
@@ -192,13 +198,17 @@
private void defineElement(JPanel panel, final ConfigItem item, GridBagConstraints gbc) {
- // standard components
+ // current value (based on current changes and properties)
String configValue = item.getCurrentValue();
-// final String toolTip = item.toolTip;
- // item label
- JLabel label = new JLabel(LocalText.getText("Config." + item.name));
-// label.setToolTipText(toolTip);
+ // item label, toolTip and infoText
+ final String itemLabel = LocalText.getText("Config.label." + item.name);
+ final String toolTip = LocalText.getTextWithDefault("Config.toolTip." + item.name, null);
+ final String infoText = LocalText.getTextWithDefault("Config.infoText." + item.name, null);
+
+ // define label
+ JLabel label = new JLabel(itemLabel);
+ label.setToolTipText(toolTip);
gbc.fill = GridBagConstraints.NONE;
addToGridBag(panel, label, gbc);
@@ -277,7 +287,7 @@
}
final JComboBox comboBox = new JComboBox(allowedValues);
comboBox.setSelectedItem(configValue);
-// comboBox.setToolTipText(toolTip));
+ comboBox.setToolTipText(toolTip);
comboBox.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent arg0) {
// do nothing
@@ -295,19 +305,20 @@
case FILE:
final JLabel dirLabel = new JLabel(configValue);
dirLabel.setHorizontalAlignment(SwingConstants.CENTER);
-// dirLabel.setToolTipText(toolTip);
+ dirLabel.setToolTipText(toolTip);
gbc.fill = GridBagConstraints.HORIZONTAL;
addToGridBag(panel, dirLabel, gbc);
JButton dirButton = new JButton("Choose...");
dirButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
- JFileChooser fc = new JFileChooser(dirLabel.getText());
+ JFileChooser fc = new JFileChooser();
if (item.type == ConfigItem.ConfigType.DIRECTORY) {
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
} else {
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
+ fc.setSelectedFile(new File(dirLabel.getText()));
int state = fc.showOpenDialog(ConfigWindow.this);
if ( state == JFileChooser.APPROVE_OPTION ){
File file = fc.getSelectedFile();
@@ -336,7 +347,7 @@
} else {
colorLabel.setForeground(Color.BLACK);
}
-// colorLabel.setToolTipText(toolTip);
+ colorLabel.setToolTipText(toolTip);
gbc.fill = GridBagConstraints.HORIZONTAL;
addToGridBag(panel, colorLabel, gbc);
JButton colorButton = new JButton("Choose...");
@@ -378,6 +389,43 @@
addEmptyLabel(panel, gbc);
break;
}
+ // add info icon for infoText
+ if (infoText != null) {
+ JLabel infoIcon = new JLabel(RailsIcon.INFO.icon);
+ infoIcon.addMouseListener(new MouseListener() {
+ public void mousePressed(MouseEvent e) {
+ final JDialog dialog = new JDialog(ConfigWindow.this, false);
+ final JOptionPane optionPane = new JOptionPane();
+ optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
+ optionPane.setMessage(infoText);
+ optionPane.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY,
+ new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent e) {
+ dialog.dispose();
+ }
+ }
+ );
+ dialog.setTitle(LocalText.getText("CONFIG_INFO_TITLE", itemLabel));
+ dialog.getContentPane().add(optionPane);
+ dialog.pack();
+ dialog.setVisible(true);
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ }
+ public void mouseReleased(MouseEvent e) {
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+ });
+ gbc.fill = GridBagConstraints.NONE;
+ addToGridBag(panel, infoIcon, gbc);
+ addEmptyLabel(panel, gbc);
+ }
}
private void setupButtonPanel() {
Modified: trunk/18xx/rails/ui/swing/StartRoundWindow.java
===================================================================
--- trunk/18xx/rails/ui/swing/StartRoundWindow.java 2010-07-30 20:59:08 UTC (rev 1363)
+++ trunk/18xx/rails/ui/swing/StartRoundWindow.java 2010-08-01 11:46:26 UTC (rev 1364)
@@ -702,15 +702,7 @@
}
private ImageIcon createInfoIcon() {
-
- String path = "/rails/ui/images/Inform.gif";
- java.net.URL imgURL = getClass().getResource(path);
- if (imgURL != null) {
- return new ImageIcon(imgURL, "Info");
- } else {
- System.err.println("Couldn't find file: " + path);
- return null;
- }
+ return RailsIcon.INFO.icon;
}
public void keyPressed(KeyEvent e) {
Added: trunk/18xx/rails/ui/swing/elements/RailsIcon.java
===================================================================
--- trunk/18xx/rails/ui/swing/elements/RailsIcon.java (rev 0)
+++ trunk/18xx/rails/ui/swing/elements/RailsIcon.java 2010-08-01 11:46:26 UTC (rev 1364)
@@ -0,0 +1,30 @@
+package rails.ui.swing.elements;
+
+import javax.swing.ImageIcon;
+
+/**
+ * Enumeration that provides a specific ImageIcon
+ * Simply use RailsIcon.{IconName}.create
+ * @author freystef
+ */
+
+public enum RailsIcon {
+
+ // in parentheses the image file
+ INFO ("Inform.gif");
+
+ private final static String IMAGE_PATH = "/rails/ui/images/";
+ public final ImageIcon icon;
+
+ private RailsIcon(String fileName) {
+ String path = IMAGE_PATH + fileName;
+ java.net.URL imgURL = getClass().getResource(path);
+ if (imgURL != null) {
+ icon = new ImageIcon(imgURL, "Info");
+ } else {
+ System.err.println("Couldn't find file: " + path);
+ icon = null;
+ }
+ }
+
+}
Property changes on: trunk/18xx/rails/ui/swing/elements/RailsIcon.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/18xx/rails/util/Config.java
===================================================================
--- trunk/18xx/rails/util/Config.java 2010-07-30 20:59:08 UTC (rev 1363)
+++ trunk/18xx/rails/util/Config.java 2010-08-01 11:46:26 UTC (rev 1364)
@@ -39,7 +39,7 @@
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 SECTION_TAG = "Section";
private static final String ITEM_TAG = "Property";
/** Log 4j configuration */
@@ -67,7 +67,7 @@
private static boolean propertiesLoaded = false;
/** Map that holds the panel, which contains config items */
- private static Map<String, List<ConfigItem>> configPanels = null;
+ private static Map<String, List<ConfigItem>> configSections = null;
/**
* Hidden constructor, the class is never instantiated, everything is static
@@ -81,28 +81,30 @@
List<String> directories = new ArrayList<String>();
directories.add(CONFIG_XML_DIR);
try {
- // Find the <Config> tag
+ // 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);
- configPanels = new LinkedHashMap<String, List<ConfigItem>>();
- // find panels
- List<Tag> panelTags = configTag.getChildren(PANEL_TAG);
- if (panelTags != null) {
- for (Tag panelTag:panelTags) {
+ // define sections
+ configSections = new LinkedHashMap<String, List<ConfigItem>>();
+
+ // find sections
+ List<Tag> sectionTags = configTag.getChildren(SECTION_TAG);
+ if (sectionTags != null) {
+ for (Tag sectionTag:sectionTags) {
// find name attribute
- String panelName = panelTag.getAttributeAsString("name");
- if (!Util.hasValue(panelName)) continue;
+ String sectionName = sectionTag.getAttributeAsString("name");
+ if (!Util.hasValue(sectionName)) continue;
// find items
- List<Tag> itemTags = panelTag.getChildren(ITEM_TAG);
+ List<Tag> itemTags = sectionTag.getChildren(ITEM_TAG);
if (itemTags == null || itemTags.size() == 0) continue;
- List<ConfigItem> panelItems = new ArrayList<ConfigItem>();
+ List<ConfigItem> sectionItems = new ArrayList<ConfigItem>();
for (Tag itemTag:itemTags) {
- panelItems.add(new ConfigItem(itemTag));
+ sectionItems.add(new ConfigItem(itemTag));
}
- configPanels.put(panelName, panelItems);
+ configSections.put(sectionName, sectionItems);
}
}
@@ -111,20 +113,20 @@
}
}
- public static Map<String, List<ConfigItem>> getConfigPanels() {
- if (configPanels == null) {
+ public static Map<String, List<ConfigItem>> getConfigSections() {
+ if (configSections == null) {
readConfigSetupXML();
}
- log.debug("Configuration setup = " + configPanels);
- return configPanels;
+ log.debug("Configuration setup = " + configSections);
+ return configSections;
}
public static int getMaxElementsInPanels() {
int maxElements = 0;
- for (List<ConfigItem> panel:configPanels.values()) {
+ for (List<ConfigItem> panel:configSections.values()) {
maxElements = Math.max(maxElements, panel.size());
}
- log.debug("maxelements" + maxElements);
+ log.debug("Configuration sections with maximum elements of " + maxElements);
return maxElements;
}
@@ -132,7 +134,7 @@
* updates the profile according to the changes in configitems
*/
public static void updateProfile() {
- for (List<ConfigItem> items:configPanels.values()) {
+ for (List<ConfigItem> items:configSections.values()) {
for (ConfigItem item:items) {
if (!item.hasNewValue()) continue;
if (item.getNewValue().equals(defaultProperties.get(item.name))) {
@@ -151,7 +153,7 @@
* reverts all changes in configitems
*/
public static void revertProfile() {
- for (List<ConfigItem> items:configPanels.values()) {
+ for (List<ConfigItem> items:configSections.values()) {
for (ConfigItem item:items) {
item.setNewValue(null);
}
Modified: trunk/18xx/rails/util/LocalText.java
===================================================================
--- trunk/18xx/rails/util/LocalText.java 2010-07-30 20:59:08 UTC (rev 1363)
+++ trunk/18xx/rails/util/LocalText.java 2010-08-01 11:46:26 UTC (rev 1364)
@@ -29,10 +29,20 @@
}
public static String getText(String key, Object parameter) {
- return getText(key, new Object[] { parameter });
+ return getText(key, new Object[] { parameter });
}
+
+ public static String getText(String key, Object... parameters) {
+ /* If the text is not found, return the key in brackets */
+ return getTextExecute(key, "<" + key + ">", true, parameters);
+ }
+
+ public static String getTextWithDefault(String key, String defaultText) {
+ return getTextExecute(key, defaultText, false, (Object[]) null);
+ }
- public static String getText(String key, Object... parameters) {
+ // actual procedure to retrieve the local text
+ private static String getTextExecute(String key, String defaultText, boolean errorOnMissing, Object... parameters) {
String result = "";
if (key == null || key.length() == 0) return "";
@@ -95,11 +105,12 @@
try {
result = localisedText.getString(key);
} catch (Exception e) {
- System.out.println("Missing text for key " + key + " in locale "
+ if (errorOnMissing) {
+ System.out.println("Missing text for key " + key + " in locale "
+ locale.getDisplayName() + " (" + localeCode
+ ")");
- /* If the text is not found, return the key in brackets */
- return "<" + key + ">";
+ }
+ return defaultText;
}
if (parameters != null) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|