|
From: <ste...@us...> - 2010-08-22 15:30:48
|
Revision: 1399
http://rails.svn.sourceforge.net/rails/?rev=1399&view=rev
Author: stefanfrey
Date: 2010-08-22 15:30:41 +0000 (Sun, 22 Aug 2010)
Log Message:
-----------
A simplification of the config window before the upcoming release
Modified Paths:
--------------
trunk/18xx/LocalisedText.properties
trunk/18xx/rails/ui/swing/ConfigWindow.java
trunk/18xx/rails/ui/swing/GameSetupWindow.java
trunk/18xx/rails/ui/swing/GameUIManager.java
trunk/18xx/rails/util/Config.java
Modified: trunk/18xx/LocalisedText.properties
===================================================================
--- trunk/18xx/LocalisedText.properties 2010-08-21 19:36:46 UTC (rev 1398)
+++ trunk/18xx/LocalisedText.properties 2010-08-22 15:30:41 UTC (rev 1399)
@@ -71,16 +71,21 @@
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_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
CONFIG_NEW_MESSAGE=Select a name of the new profile
CONFIG_NEW_TITLE=Create profile
+CONFIG_PROFILE_ERROR_MESSAGE=An error occurred during save of the profile list in the current working directory.\nCould not store the name and filepath of the new profile.
CONFIG_SELECT_PROFILE=Select profile ->
CONFIG_SETTINGS=Profile settings
-CONFIG_SAVE_MESSAGE=Active profile {0} was saved
-CONFIG_SAVE_TITLE=Save confirmation
+CONFIG_SAVE_ERROR_MESSAGE=An error occurred during save of active profile {0}.\nProfile was not saved.
+CONFIG_SAVE_CONFIRM_MESSAGE=Active profile {0} was saved.
+CONFIG_SAVE_TITLE=Save of profile
CONFIG_WINDOW_TITLE=Rails Configuration
CORRECT_CASH=Cash Correction
CORRECT_MAP=Map Correction
@@ -296,6 +301,7 @@
HIDE_OPTIONS=Hide Options
HoldMoneyInEscrow=The price of {0} is paid to the Bank, which now holds {1} in escrow for {2}
HOW_MANY_SHARES=How many shares?
+IMPORT=Import
INFO=Game Notes
Info=Info
Insert=Insert
@@ -507,6 +513,7 @@
RustsTrains=Rusts {0}-trains
SaleNotAllowed=Selling shares of company {0} is not allowed
SAVE=Save
+SAVE_AND_APPLY=Save/Apply
SAVEAS=Save As ...
SaveFailed=Save failed, reason: {0}
Select=Select
Modified: trunk/18xx/rails/ui/swing/ConfigWindow.java
===================================================================
--- trunk/18xx/rails/ui/swing/ConfigWindow.java 2010-08-21 19:36:46 UTC (rev 1398)
+++ trunk/18xx/rails/ui/swing/ConfigWindow.java 2010-08-22 15:30:41 UTC (rev 1399)
@@ -6,7 +6,6 @@
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
-import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -57,16 +56,21 @@
private static final long serialVersionUID = 1L;
private static final String CONFIG_EXTENSION = ".rails_config";
- private static final String CONFIG_DESCRIPTION = "Rails configuration files ( *.rails_config )";
+ private static final String LEGACY_EXTENSION = ".properties";
+ private static final String CONFIG_DESCRIPTION = "Rails configuration files ( *.rails_config, *.properties)";
private JPanel profilePanel;
private JTabbedPane configPane;
private JPanel buttonPanel;
- ConfigWindow() {
- // JFrame properties
+ private boolean fromStatusWindow;
+
+ ConfigWindow(boolean fromStatusWindow) {
+ // store for handling of close
+ this.fromStatusWindow = fromStatusWindow;
+
+ // JFrame properties
setTitle(LocalText.getText("CONFIG_WINDOW_TITLE"));
-// setSize(400,300);
// add profile panel
profilePanel = new JPanel();
@@ -80,12 +84,13 @@
buttonPanel = new JPanel();
add(buttonPanel, "South");
+
// hide on close and inform
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
- closeConfig();
+ closeConfig(false);
}
});
}
@@ -95,13 +100,12 @@
setupConfigPane();
setupButtonPanel();
this.pack();
+ setSize(600,400);
}
private void setupProfilePanel() {
profilePanel.removeAll();
-
- profilePanel.setLayout(new GridLayout(0,4));
-
+
String activeProfile = Config.getActiveProfileName();
String defaultProfile = Config.getDefaultProfileName();
Border etched = BorderFactory.createEtchedBorder();
@@ -134,16 +138,27 @@
buttonPanel.add(newButton);
// button to load a new profile
- JButton loadButton = new JButton(LocalText.getText("LOAD"));
- loadButton.addActionListener(
+ JButton importButton = new JButton(LocalText.getText("IMPORT"));
+ importButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
- loadProfile();
+ importProfile();
}
}
);
- buttonPanel.add(loadButton);
+ buttonPanel.add(importButton);
+ // saveas button
+// JButton saveAsButton = new JButton(LocalText.getText("SAVEAS"));
+// saveAsButton.addActionListener(
+// new ActionListener() {
+// public void actionPerformed(ActionEvent arg0) {
+// ConfigWindow.this.saveAsConfig();
+// }
+// }
+// );
+// buttonPanel.add(saveAsButton);
+
profilePanel.add(buttonPanel);
}
@@ -322,8 +337,8 @@
int state = fc.showOpenDialog(ConfigWindow.this);
if ( state == JFileChooser.APPROVE_OPTION ){
File file = fc.getSelectedFile();
- dirLabel.setText(file.getAbsolutePath());
- item.setNewValue(file.getAbsolutePath());
+ dirLabel.setText(file.getPath());
+ item.setNewValue(file.getPath());
}
}
}
@@ -430,47 +445,43 @@
private void setupButtonPanel() {
buttonPanel.removeAll();
+
+ String activeFilePath = Config.getActiveFilepath();
+ Border etched = BorderFactory.createEtchedBorder();
+ Border titled = BorderFactory.createTitledBorder(etched, LocalText.getText("CONFIG_CURRENT_PATH", activeFilePath));
+ buttonPanel.setBorder(titled);
- // saveas button
- JButton saveAsButton = new JButton(LocalText.getText("SAVEAS"));
- saveAsButton.addActionListener(
+ // save button
+ JButton saveButton = new JButton(LocalText.getText("SAVE_AND_APPLY"));
+ saveButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
- ConfigWindow.this.saveAsConfig();
- }
- }
- );
- buttonPanel.add(saveAsButton);
-
- // save button
- if (Config.isFilePathDefined()) {
- JButton saveButton = new JButton(LocalText.getText("SAVE"));
- saveButton.addActionListener(
- new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
+ if (Config.isFilePathDefined()) {
ConfigWindow.this.saveConfig();
+ } else {
+ ConfigWindow.this.saveAsConfig();
}
}
- );
- buttonPanel.add(saveButton);
- }
-
- JButton applyButton = new JButton(LocalText.getText("APPLY"));
- applyButton.addActionListener(
- new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- ConfigWindow.this.applyConfig();
- }
}
);
- buttonPanel.add(applyButton);
+ buttonPanel.add(saveButton);
+
+// JButton applyButton = new JButton(LocalText.getText("APPLY"));
+// applyButton.addActionListener(
+// new ActionListener() {
+// public void actionPerformed(ActionEvent arg0) {
+// ConfigWindow.this.applyConfig();
+// }
+// }
+// );
+// buttonPanel.add(applyButton);
JButton cancelButton = new JButton(LocalText.getText("CANCEL"));
cancelButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
- ConfigWindow.this.closeConfig();
+ ConfigWindow.this.closeConfig(true);
}
}
);
@@ -479,8 +490,13 @@
}
private void newProfile() {
- String newProfile = JOptionPane.showInputDialog(ConfigWindow.this, LocalText.getText("CONFIG_NEW_MESSAGE"),
+ List<String> allProfileNames = Config.getAllProfiles();
+ String newProfile = null;
+ do {
+ newProfile = JOptionPane.showInputDialog(ConfigWindow.this, LocalText.getText("CONFIG_NEW_MESSAGE"),
LocalText.getText("CONFIG_NEW_TITLE"), JOptionPane.QUESTION_MESSAGE);
+ } while (allProfileNames.contains(newProfile));
+
if (Util.hasValue(newProfile)) {
String defaultProfile = (String)JOptionPane.showInputDialog(ConfigWindow.this, LocalText.getText("CONFIG_DEFAULT_MESSAGE"),
LocalText.getText("CONFIG_DEFAULT_TITLE"), JOptionPane.QUESTION_MESSAGE, null,
@@ -497,7 +513,7 @@
});
}
- private void loadProfile() {
+ private void importProfile() {
String directory = Config.get("save.directory");
JFileChooser fc = new JFileChooser(directory);
@@ -505,7 +521,9 @@
new FileFilter() {
public boolean accept( File f ){
return f.isDirectory() ||
- f.getName().toLowerCase().endsWith( ".rails_config" );
+ f.getName().toLowerCase().endsWith( CONFIG_EXTENSION) ||
+ f.getName().toLowerCase().endsWith( LEGACY_EXTENSION)
+ ;
}
public String getDescription() {
return CONFIG_DESCRIPTION;
@@ -516,8 +534,11 @@
if ( state == JFileChooser.APPROVE_OPTION )
{
File file = fc.getSelectedFile();
- if (Config.loadProfileFromFile(file)) {
+ if (Config.importProfileFromFile(file)) {
changeProfile(Config.getActiveProfileName());
+ } else {
+ JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_LOAD_ERROR_MESSAGE", Config.getActiveProfileName()),
+ LocalText.getText("CONFIG_LOAD_TITLE"), JOptionPane.ERROR_MESSAGE);
}
}
}
@@ -532,11 +553,17 @@
});
}
- private void saveConfig() {
- Config.updateProfile(); // transfer the configitem to the active profile
- Config.saveActiveProfile();
- JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_SAVE_MESSAGE", Config.getActiveProfileName()),
+ private boolean saveConfig() {
+ Config.updateProfile(fromStatusWindow); // transfer the configitem to the active profile
+ if (Config.saveActiveProfile()) {
+ JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_SAVE_CONFIRM_MESSAGE", Config.getActiveProfileName()),
LocalText.getText("CONFIG_SAVE_TITLE"), JOptionPane.INFORMATION_MESSAGE);
+ return true;
+ } else {
+ JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_SAVE_ERROR_MESSAGE", Config.getActiveProfileName()),
+ LocalText.getText("CONFIG_SAVE_TITLE"), JOptionPane.ERROR_MESSAGE);
+ return false;
+ }
}
private void saveAsConfig() {
@@ -561,11 +588,14 @@
}
);
int state = fc.showSaveDialog(this);
- if ( state == JFileChooser.APPROVE_OPTION )
- {
+ if ( state == JFileChooser.APPROVE_OPTION ) {
File file = fc.getSelectedFile();
- Config.setActiveFilepath(file.getPath());
+ if (!Config.setActiveFilepath(file.getPath())) {
+ JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_PROFILE_ERROR_MESSAGE", Config.getActiveProfileName()),
+ LocalText.getText("CONFIG_SAVE_TITLE"), JOptionPane.ERROR_MESSAGE);
+ }
saveConfig();
+ // update panel for file path
EventQueue.invokeLater(new Runnable() {
public void run() {
setupButtonPanel();
@@ -576,16 +606,18 @@
}
}
- private void applyConfig() {
- Config.updateProfile(); // transfer the configitem to the active profile
- JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_APPLY_MESSAGE"),
- LocalText.getText("CONFIG_APPLY_TITLE"), JOptionPane.INFORMATION_MESSAGE);
- }
+// private void applyConfig() {
+// Config.updateProfile(fromStatusWindow); // transfer the configitem to the active profile
+// JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_APPLY_MESSAGE"),
+// LocalText.getText("CONFIG_APPLY_TITLE"), JOptionPane.INFORMATION_MESSAGE);
+// }
- private void closeConfig() {
- Config.revertProfile();
- StatusWindow.uncheckMenuItemBox(StatusWindow.CONFIG_CMD);
+ private void closeConfig(boolean cancel) {
+ if (cancel) Config.revertProfile();
this.setVisible(false);
+ if (fromStatusWindow) {
+ StatusWindow.uncheckMenuItemBox(StatusWindow.CONFIG_CMD);
+ }
}
}
Modified: trunk/18xx/rails/ui/swing/GameSetupWindow.java
===================================================================
--- trunk/18xx/rails/ui/swing/GameSetupWindow.java 2010-08-21 19:36:46 UTC (rev 1398)
+++ trunk/18xx/rails/ui/swing/GameSetupWindow.java 2010-08-22 15:30:41 UTC (rev 1399)
@@ -25,8 +25,8 @@
private static final long serialVersionUID = 1L;
GridBagConstraints gc;
JPanel gameListPane, playersPane, buttonPane, optionsPane;
- JButton newButton, loadButton, recoveryButton, quitButton, optionButton, infoButton;
- JButton creditsButton, randomizeButton;
+ JButton newButton, loadButton, recoveryButton, quitButton, optionButton, infoButton,
+ creditsButton, randomizeButton, configureButton;
JComboBox gameNameBox = new JComboBox();
JComboBox[] playerBoxes = new JComboBox[Player.MAX_PLAYERS];
JTextField[] playerNameFields = new JTextField[Player.MAX_PLAYERS];
@@ -40,6 +40,8 @@
String gameName;
Game game;
+ private ConfigWindow configWindow;
+
// Used by the player selection combo box.
static final int NONE_PLAYER = 0;
static final int HUMAN_PLAYER = 1;
@@ -71,6 +73,7 @@
optionButton = new JButton(LocalText.getText("OPTIONS"));
infoButton = new JButton(LocalText.getText("INFO"));
creditsButton = new JButton(LocalText.getText("CREDITS"));
+ configureButton= new JButton(LocalText.getText("CONFIG"));
newButton.setMnemonic(KeyEvent.VK_N);
loadButton.setMnemonic(KeyEvent.VK_L);
@@ -78,7 +81,8 @@
quitButton.setMnemonic(KeyEvent.VK_Q);
optionButton.setMnemonic(KeyEvent.VK_O);
infoButton.setMnemonic(KeyEvent.VK_G);
- creditsButton.setMnemonic(KeyEvent.VK_C);
+ creditsButton.setMnemonic(KeyEvent.VK_E);
+ configureButton.setMnemonic(KeyEvent.VK_C);
this.getContentPane().setLayout(new GridBagLayout());
this.setTitle("Rails: New Game");
@@ -87,9 +91,9 @@
populateGameList(GamesInfo.getGameNames(), gameNameBox);
gameListPane.add(new JLabel("Available Games:"));
- gameListPane.add(new JLabel("")); // empty slot
gameListPane.add(gameNameBox);
gameListPane.add(optionButton);
+ gameListPane.add(configureButton); // empty slot
gameListPane.setLayout(new GridLayout(2, 2));
gameListPane.setBorder(BorderFactory.createLoweredBevelBorder());
@@ -101,12 +105,13 @@
infoButton.addActionListener(this);
creditsButton.addActionListener(this);
gameNameBox.addActionListener(this);
+ configureButton.addActionListener(this);
buttonPane.add(newButton);
buttonPane.add(loadButton);
- if (!Config.get("save.recovery.active", "yes").equalsIgnoreCase("no")) {
- buttonPane.add(recoveryButton);
- }
+ recoveryButton.setEnabled(Config.get("save.recovery.active", "no").equalsIgnoreCase("yes"));
+ buttonPane.add(recoveryButton);
+
buttonPane.add(infoButton);
buttonPane.add(quitButton);
buttonPane.add(creditsButton);
@@ -212,14 +217,30 @@
}
gameUIManager.startLoadedGame();
setVisible(false);
+ killConfigWindow();
}
+ private void killConfigWindow() {
+ if (configWindow == null) return;
+ configWindow.dispose();
+ configWindow = null;
+ }
+
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource().equals(newButton)) {
startNewGame();
} else if (arg0.getSource().equals(optionButton)) {
toggleOptions();
this.pack();
+ } else if (arg0.getSource().equals(configureButton)) {
+ // start configureWindow
+ if (configWindow == null) {
+ configWindow = new ConfigWindow(false);
+ configWindow.init();
+ configWindow.setVisible(true);
+ } else {
+ configWindow.setVisible(true);
+ }
} else if (arg0.getSource().equals(loadButton)) {
String saveDirectory = Config.get("save.directory");
JFileChooser jfc = new JFileChooser();
@@ -421,6 +442,7 @@
this.setVisible(false); // XXX: At some point we should destroy this
// XXX: object rather than just making it invisible
+ killConfigWindow();
}
private void startGameUIManager(Game game) {
Modified: trunk/18xx/rails/ui/swing/GameUIManager.java
===================================================================
--- trunk/18xx/rails/ui/swing/GameUIManager.java 2010-08-21 19:36:46 UTC (rev 1398)
+++ trunk/18xx/rails/ui/swing/GameUIManager.java 2010-08-22 15:30:41 UTC (rev 1399)
@@ -184,7 +184,7 @@
reportWindow.scrollDown();
// define configWindow
- configWindow = new ConfigWindow();
+ configWindow = new ConfigWindow(true);
configWindow.init();
}
Modified: trunk/18xx/rails/util/Config.java
===================================================================
--- trunk/18xx/rails/util/Config.java 2010-08-21 19:36:46 UTC (rev 1398)
+++ trunk/18xx/rails/util/Config.java 2010-08-22 15:30:41 UTC (rev 1399)
@@ -133,7 +133,7 @@
/**
* updates the profile according to the changes in configitems
*/
- public static void updateProfile() {
+ public static void updateProfile(boolean applyInitMethods) {
for (List<ConfigItem> items:configSections.values()) {
for (ConfigItem item:items) {
if (!item.hasNewValue()) continue;
@@ -142,7 +142,7 @@
continue;
}
userProperties.setProperty(item.name, item.getNewValue());
- item.callInitMethod();
+ if (applyInitMethods) item.callInitMethod();
log.debug("Changed property name = " + item.name + " to value = " + item.getNewValue());
item.setNewValue(null);
}
@@ -224,6 +224,7 @@
// add to list of user profiles
userProfiles.setProperty(profileName, "");
+
// define and load default profile
String defaultConfigFile = defaultProfiles.getProperty(defaultProfile);
userProperties.setProperty(PROFILENAME_PROPERTY, profileName);
@@ -268,6 +269,22 @@
}
/**
+ * get all (visible default + user) profiles
+ */
+ public static List<String> getAllProfiles() {
+ List<String> profiles = getDefaultProfiles(true);
+ profiles.addAll(getUserProfiles());
+ return profiles;
+ }
+
+ /**
+ * checks if profile is default profile
+ */
+ public static boolean isDefaultProfile(String profileName) {
+ return !(defaultProfiles.get(profileName) == null);
+ }
+
+ /**
* returns name of (active) default profile
*/
public static String getDefaultProfileName() {
@@ -290,6 +307,7 @@
/**
* sets filename for an active profile (and store list of profiles)
+ * @return false if list of profiles cannot be stored
*/
public static boolean setActiveFilepath(String filepath) {
userProfiles.setProperty(selectedProfile, filepath);
@@ -423,15 +441,15 @@
* loads an external user profile
* defined by the filepath
*/
- public static boolean loadProfileFromFile(File file) {
- String filepath = file.getAbsolutePath();
+ public static boolean importProfileFromFile(File file) {
+ String filepath = file.getPath();
if (loadPropertyFile(userProperties, filepath, false)) {
String profile = userProperties.getProperty(PROFILENAME_PROPERTY);
if (!Util.hasValue(profile)) {
profile = STANDARD_PROFILE_SELECTION;
}
selectedProfile = profile;
- setActiveFilepath(filepath);
+// setActiveFilepath(filepath); // do not set filepath on import
loadDefaultProfile();
setSaveDirDefaults();
return true;
@@ -509,9 +527,8 @@
}
properties.load(inFile);
} catch (Exception e) {
- System.err.println(e + " whilst loading properties file "
+ log.error(e + " whilst loading properties file "
+ filepath);
-// e.printStackTrace(System.err);
result = false;
}
return result;
@@ -531,6 +548,8 @@
properties.store(new FileOutputStream(outFile), "Automatically generated, do not edit");
log.info("Storing properties to file " + filepath);
} catch (IOException e) {
+ log.error(e + " whilst storing properties file "
+ + filepath);
result = false;
}
return result;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|