From: Stefan F. <ste...@us...> - 2012-04-01 11:30:35
|
LocalisedText.properties | 7 + buildRails.xml | 2 data/Properties.xml | 1 data/profiles/LIST_OF_PROFILES | 1 data/profiles/ftf.predefined | 4 data/profiles/pbem.predefined | 6 - data/profiles/root | 3 rails/common/ConfigManager.java | 13 ++ rails/common/ConfigProfile.java | 92 +++++++++++++++-- rails/game/GameManager.java | 12 +- rails/game/specific/_18EU/StockRound_18EU.java | 8 + rails/ui/swing/ConfigWindow.java | 131 +++++++++++++++++-------- rails/ui/swing/GameSetupWindow.java | 17 ++- rails/ui/swing/GameUIManager.java | 22 +++- rails/ui/swing/WindowSettings.java | 5 rails/ui/swing/elements/DockingFrame.java | 13 -- rails/util/GameFileIO.java | 5 17 files changed, 261 insertions(+), 81 deletions(-) New commits: commit c3f1f3169475d6fb04889bb75d223aab863bf432 Author: Stefan Frey <ste...@we...> Date: Sun Apr 1 13:27:50 2012 +0200 Added option to save.filename.suffix that it displays the current round. TODO: Add shortname method for rounds (to use SRx and ORy.z). diff --git a/LocalisedText.properties b/LocalisedText.properties index 1a5e29d..463e3ae 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -174,6 +174,7 @@ Config.infoText.gridPanel.tableBorders=Grid layouts are used for the Status Wind Config.infoText.map.displayCurrentRoutes=If enabled, optimal train routes are displayed for the company which is currently taking its turn. Config.infoText.map.highlightHexes=<html>If enabled, parts of the map are highlighted depending on the position of the mouse pointer:<ul><li><b>Private companies:</b> Point to the name of a private company in order to highlight the locations associated with it (e.g., its reserved hex).<ul><li>If you point to a set of private companies (in the player or company holding), the locations of all contained private companies are highlighted</ul><li><b>Minor & Public Companies:</b> Point to the name of the company in order to highlight the locations associated with it (home and destination).</ul></html> Config.infoText.or.window.dockablePanels=<html>This alters the window of the Operating Round. If enabled, allows for the following:<ul><li>Manually resize panels.<li>Manually adjust the layout of the panels within the window.<li>Detach / retach panel from / to window.</ul></html> +Config.infoText.save.filename.suffix="<html>A suffix to the filename. There are two values that create a dynamic suffix: 'NEXT_PLAYER' is replaced by the player having the next action, 'CURRENT_ROUND' by the current round name. Config.infoText.sound.backgroundMusic=The only music file type supported is mp3. Config.infoText.sound.backgroundMusic.stockRound=<html>Enter assignment of music files to phases.<ul><li>Separate the assignments by commas.<li>Each assignment has the syntax phaseName=complete file path<li>Default music is defined by omitting "phaseName=" in the assignment.</ul><strong>Examples:</strong><ul><li>Set default music: <br><code>c:\SR-default.mp3</code><li>Set phase-dependent music and a default (for trains above 6): <br><code>2=c:\SR-2.mp3,3=c:\SR-3.mp3,4=c:\SR-4.mp3,5=c:\SR-5.mp3,6=c:\SR-6.mp3,c:\SR-D.mp3</code></ul> </html> Config.infoText.sound.backgroundMusic.operatingRound=<html>Enter assignment of music files to phases.<ul><li>Separate the assignments by commas.<li>Each assignment has the syntax phaseName=complete file path<li>Default music is defined by omitting "phaseName=" in the assignment.</ul><strong>Examples:</strong><ul><li>Set default music: <br><code>c:\OR-default.mp3</code><li>Set phase-dependent music and a default (for trains above 6): <br><code>2=c:\OR-2.mp3,3=c:\OR-3.mp3,4=c:\OR-4.mp3,5=c:\OR-5.mp3,6=c:\OR-6.mp3,c:\OR-D.mp3</code></ul> </html> diff --git a/data/profiles/ftf.predefined b/data/profiles/ftf.predefined index 377a680..c784667 100644 --- a/data/profiles/ftf.predefined +++ b/data/profiles/ftf.predefined @@ -1,3 +1,4 @@ ### ftf profile ### optimized for face-to-face play +save.filename.suffix=CURRENT_ROUND save.recovery.active=yes diff --git a/data/profiles/pbem.predefined b/data/profiles/pbem.predefined index 6f96b68..2c72adf 100644 --- a/data/profiles/pbem.predefined +++ b/data/profiles/pbem.predefined @@ -1,3 +1,4 @@ ### pbem profile ### optimized for pbem play +save.filename.suffix=NEXT_PLAYER save.recovery.active=no diff --git a/data/profiles/root b/data/profiles/root index c77f040..9aef24e 100644 --- a/data/profiles/root +++ b/data/profiles/root @@ -11,7 +11,6 @@ local.player.names= save.directory= save.filename.date_time_pattern=yyyyMMdd_HHmm save.filename.date_time_zone=UTC -save.filename.suffix=NEXT_PLAYER save.filename.extension=rails ### Panel Font diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index 90d81c5..452ff61 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -56,6 +56,7 @@ public class GameUIManager implements DialogOwner { protected static final String DEFAULT_SAVE_PATTERN = "yyyyMMdd_HHmm"; public static final String DEFAULT_SAVE_EXTENSION = "rails"; protected static final String NEXT_PLAYER_SUFFIX = "NEXT_PLAYER"; + protected static final String CURRENT_ROUND_SUFFIX = "CURRENT_ROUND"; protected String saveDirectory; protected String savePattern; @@ -99,6 +100,7 @@ public class GameUIManager implements DialogOwner { private SplashWindow splashWindow = null; + public GameUIManager() { } @@ -158,10 +160,16 @@ public class GameUIManager implements DialogOwner { saveDateTimeFormat.setTimeZone(TimeZone.getTimeZone(timezone)); } saveSuffixSpec = Config.get("save.filename.suffix"); - if (Util.hasValue(saveSuffixSpec) && !saveSuffixSpec.equals(NEXT_PLAYER_SUFFIX)) { - saveSuffix = saveSuffixSpec; - } else { + if (!Util.hasValue(saveSuffixSpec) || saveSuffixSpec.equals(NEXT_PLAYER_SUFFIX)) { saveSuffix = getPlayers().get(0).getName(); + } else if (saveSuffixSpec.equals(CURRENT_ROUND_SUFFIX)) { + if (currentRound != null) { + saveSuffix = currentRound.getRoundName(); + } else { + saveSuffix = ""; + } + } else { // otherwise use specified suffix + saveSuffix = saveSuffixSpec; } log.debug("Initial save suffix: "+saveSuffix); } @@ -878,6 +886,12 @@ public class GameUIManager implements DialogOwner { String currentSuffix; if (NEXT_PLAYER_SUFFIX.equals(saveSuffixSpec)) { currentSuffix = getCurrentPlayer().getName().replaceAll("[^-\\w\\.]", "_"); + } else if (CURRENT_ROUND_SUFFIX.equals(saveSuffixSpec)) { + if (currentRound != null) { + currentSuffix = currentRound.getRoundName(); + } else { + currentSuffix = ""; + } } else { currentSuffix = saveSuffix; } commit cf66fe881924aefafe4561eb733e27affa63382d Author: Stefan Frey <ste...@we...> Date: Sun Apr 1 12:52:14 2012 +0200 Transfer existing options to children after deletion of a profile diff --git a/rails/common/ConfigProfile.java b/rails/common/ConfigProfile.java index 216735c..20eee1c 100644 --- a/rails/common/ConfigProfile.java +++ b/rails/common/ConfigProfile.java @@ -351,9 +351,13 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { if (result) { // and reassign and save children - for (ConfigProfile profile:getChildren()) { - profile.setParent(parent); - profile.store(); + for (ConfigProfile child:getChildren()) { + child.setParent(parent); + // and transfer (directly stored) properties + for (Object key:properties.keySet()) { + child.setProperty((String)key, (String)properties.get(key)); + } + child.store(); } } return result; commit 7f2a92ddd288d3416dd57c9810d808d593270776 Author: Stefan Frey <ste...@we...> Date: Sun Apr 1 12:26:08 2012 +0200 Added ftf profile (currently only using autosave) diff --git a/data/profiles/LIST_OF_PROFILES b/data/profiles/LIST_OF_PROFILES index d061833..eeeda12 100644 --- a/data/profiles/LIST_OF_PROFILES +++ b/data/profiles/LIST_OF_PROFILES @@ -2,5 +2,6 @@ ### available for user selection ### with extension .predefined pbem +ftf ORDocking prettyUI diff --git a/data/profiles/ftf.predefined b/data/profiles/ftf.predefined new file mode 100644 index 0000000..377a680 --- /dev/null +++ b/data/profiles/ftf.predefined @@ -0,0 +1,3 @@ +### ftf profile +### optimized for face-to-face play +save.recovery.active=yes diff --git a/data/profiles/pbem.predefined b/data/profiles/pbem.predefined index 122c1b7..6f96b68 100644 --- a/data/profiles/pbem.predefined +++ b/data/profiles/pbem.predefined @@ -1,2 +1,3 @@ -### Default profile currently is identical to root.profile -### so no change here +### pbem profile +### optimized for pbem play +save.recovery.active=no diff --git a/data/profiles/root b/data/profiles/root index 55ae8c1..c77f040 100644 --- a/data/profiles/root +++ b/data/profiles/root @@ -13,7 +13,6 @@ 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 ### Panel Font font.ui.scale=1 commit 123c1b62e061db62ec336e859f87d205c32d3008 Author: Stefan Frey <ste...@we...> Date: Sun Apr 1 12:23:01 2012 +0200 Bugfix for Error reported by John Galt- Mar 31 2012 fixed by Martin Brumm diff --git a/rails/game/specific/_18EU/StockRound_18EU.java b/rails/game/specific/_18EU/StockRound_18EU.java index 5387e71..c511571 100644 --- a/rails/game/specific/_18EU/StockRound_18EU.java +++ b/rails/game/specific/_18EU/StockRound_18EU.java @@ -4,6 +4,7 @@ import java.util.*; import rails.common.DisplayBuffer; import rails.common.LocalText; +import rails.common.parser.ConfigurationException; import rails.game.*; import rails.game.action.*; import rails.game.move.AddToList; @@ -393,6 +394,13 @@ public class StockRound_18EU extends StockRound { } else if (selectedHomeCity != null) { homeHex = selectedHomeCity.getHolder(); homeCityNumber = selectedHomeCity.getNumber(); + //Bugfix for Error reported by John Galt- Mar 31 2012 ; Martin Brumm + //The maphex needs to have the homes map set with the company value. + try { + homeHex.addHome(company, homeCityNumber); + } catch (ConfigurationException e) { + log.error(e.getStackTrace()); + } } company.setHomeHex(homeHex); company.setHomeCityNumber(homeCityNumber); commit 0cf54cfce27ac3860d640c36561971c6b0b919af Author: Stefan Frey <ste...@we...> Date: Fri Mar 30 19:56:22 2012 +0200 fixed autosave configuration and autosave now uses central storage diff --git a/data/Properties.xml b/data/Properties.xml index 1e5c37e..341a2fe 100644 --- a/data/Properties.xml +++ b/data/Properties.xml @@ -17,7 +17,6 @@ <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" /> </Section> <Section name="Font"> <Property name="font.ui.scale" type="PERCENT" diff --git a/data/profiles/root b/data/profiles/root index 3e08d4d..55ae8c1 100644 --- a/data/profiles/root +++ b/data/profiles/root @@ -14,7 +14,6 @@ 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 diff --git a/rails/game/GameManager.java b/rails/game/GameManager.java index 15915f0..a3cbbf7 100644 --- a/rails/game/GameManager.java +++ b/rails/game/GameManager.java @@ -19,6 +19,7 @@ import rails.game.special.SpecialPropertyI; import rails.game.special.SpecialTokenLay; import rails.game.state.*; import rails.util.GameFileIO; +import rails.util.SystemOS; import rails.util.Util; /** @@ -1113,10 +1114,13 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { protected void recoverySave() { if (Config.get("save.recovery.active", "yes").equalsIgnoreCase("no")) return; - String filePath = Config.get("save.recovery.filepath", "18xx_autosave.rails"); + // TODO: Fix those static strings defined here + File directory = SystemOS.get().getConfigurationFolder(GameFileIO.autosaveFolder, true); + String fileName = GameFileIO.autosaveFile; + // create temporary new save file File tempFile = null; - tempFile = new File(filePath + ".tmp"); + tempFile = new File(directory, fileName + ".tmp"); if (!save(tempFile, recoverySaveWarning, "RecoverySaveFailed")) { recoverySaveWarning = false; return; @@ -1128,11 +1132,11 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { try { log.debug("Created temporary recovery file, path = " + tempFile.getPath()); // check if previous save file exists - recoveryFile = new File(filePath); + recoveryFile = new File(directory, fileName); log.debug("Potential recovery filePath = " + recoveryFile.getPath()); if (recoveryFile.exists()) { log.debug("Potential recovery filePath = " + recoveryFile.getPath()); - File backupFile = new File(filePath + ".bak"); + File backupFile = new File(directory, fileName + ".bak"); //delete backup file if existing if (backupFile.exists()) backupFile.delete(); //old recovery file becomes new backup file diff --git a/rails/ui/swing/ConfigWindow.java b/rails/ui/swing/ConfigWindow.java index 180d8ef..d312d2b 100644 --- a/rails/ui/swing/ConfigWindow.java +++ b/rails/ui/swing/ConfigWindow.java @@ -441,7 +441,13 @@ class ConfigWindow extends JFrame { deleteButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { + // store active Profile for deletion (see below) + String activeProfile = cm.getActiveProfile(); if (cm.deleteActiveProfile()) { + // delete item from selection in GameSetupWindow + if (parent instanceof GameSetupWindow) { + ((GameSetupWindow) parent).configureBox.removeItem(activeProfile); + } changeProfile(cm.getActiveProfile()); } } @@ -520,6 +526,10 @@ class ConfigWindow extends JFrame { result = saveProfile(newProfile); // only change if save was possible if (result) { + // add new item to selection in GameSetupWindow + if (parent instanceof GameSetupWindow) { + ((GameSetupWindow) parent).configureBox.addItem(newProfile); + } changeProfile(newProfile); } } diff --git a/rails/ui/swing/GameSetupWindow.java b/rails/ui/swing/GameSetupWindow.java index efbefa0..b5ac85a 100644 --- a/rails/ui/swing/GameSetupWindow.java +++ b/rails/ui/swing/GameSetupWindow.java @@ -14,6 +14,8 @@ import rails.common.*; import rails.common.parser.*; import rails.game.*; import rails.sound.SoundManager; +import rails.util.GameFileIO; +import rails.util.SystemOS; import rails.util.Util; /** @@ -333,8 +335,14 @@ public class GameSetupWindow extends JDialog implements ActionListener { return; } } else if (arg0.getSource().equals(recoveryButton)) { - String filePath = Config.get("save.recovery.filepath", "18xx_autosave.rails"); - loadAndStartGame(filePath, null); + new Thread() { + @Override + public void run() { + String filePath = SystemOS.get().getConfigurationFolder(GameFileIO.autosaveFolder, true).getAbsolutePath() + + File.separator + GameFileIO.autosaveFile; + loadAndStartGame(filePath, null); + } + }.start(); } else if (arg0.getSource().equals(infoButton)) { GameInfo gameInfo = this.getSelectedGameInfo(); JOptionPane.showMessageDialog(this, diff --git a/rails/util/GameFileIO.java b/rails/util/GameFileIO.java index ec682df..16f1991 100644 --- a/rails/util/GameFileIO.java +++ b/rails/util/GameFileIO.java @@ -33,6 +33,11 @@ public class GameFileIO { // fields for data save private boolean initSave = false; + + // static data for autosave + public static final String autosaveFolder = "autosave"; + public static final String autosaveFile = "18xx_autosave.rails"; + public String getGameDataAsText() { return gameData.metaDataAsText() + gameData.gameOptionsAsText() + gameData.playerNamesAsText(); commit 052dd8bfce727baaa1116d7f5efb16ef39a871e1 Author: Stefan Frey <ste...@we...> Date: Fri Mar 30 19:20:20 2012 +0200 fixed issues with the configuration system diff --git a/LocalisedText.properties b/LocalisedText.properties index 059e471..1a5e29d 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -78,7 +78,9 @@ 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_USER_PROFILE=Active user profile = {0} +CONFIG_CLOSE_MESSAGE=<html> Closing the configuration window does not save nor applies the changed settings. <br> Use buttons 'Save' or 'SaveAs' instead.</html> +CONFIG_CLOSE_TITLE=Close Configuration +CONFIG_USER_PROFILE=Active user profile = {0}, based on = {1} 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. @@ -285,6 +287,7 @@ CorrectionModeActivate={1} activated by {0} CorrectionModeDeactivate={1} deactivated by {0} CREDITS=Credits DeclineToBid=Decline to Bid +DELETE=Delete DestinationReachedByToken={0} gains {1} by laying a token on its destination {2} DestinationReached={0} has reached its destination hex {1} DestinationsReached=Destinations reached @@ -595,6 +598,7 @@ REPORT_MOVE_FORWARD=> REPORT_PLAY_FROM_HERE=Play from here REPORT_LEAVE_TIMEWARP=Leave history REPORT_TIMEWARP_ACTIVE=<html><center><font color="red"> Game history active <br> (Other windows disabled) </font></center></html> +RESET=Reset REVENUE=Revenue RevenueBonus=Bonus(es) = {0} RevenueCalculation=support for revenue calculation diff --git a/rails/common/ConfigManager.java b/rails/common/ConfigManager.java index e328aad..61a3644 100644 --- a/rails/common/ConfigManager.java +++ b/rails/common/ConfigManager.java @@ -205,6 +205,10 @@ public class ConfigManager implements ConfigurableComponentI { return activeProfile.getName(); } + public String getActiveParent() { + return activeProfile.getParent().getName(); + } + public boolean IsActiveUserProfile() { return activeProfile.getType() == ConfigProfile.Type.USER; } @@ -272,6 +276,15 @@ public class ConfigManager implements ConfigurableComponentI { return saveProfile(applyInitMethods); } + public boolean deleteActiveProfile() { + if (activeProfile.delete()) { + activeProfile = activeProfile.getParent(); + return true; + } else { + return false; + } + } + String getRecent(String key) { // get value from active profile (this escalates) String value = recentData.getProperty(key); diff --git a/rails/common/ConfigProfile.java b/rails/common/ConfigProfile.java index c6bcb7d..216735c 100644 --- a/rails/common/ConfigProfile.java +++ b/rails/common/ConfigProfile.java @@ -2,8 +2,10 @@ package rails.common; import java.io.File; import java.io.FilenameFilter; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -151,7 +153,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { } boolean isFinal() { - if (!loaded && type == Type.USER) return true; + ensureLoad(); if (Util.hasValue(properties.getProperty(FINAL_KEY))) { return Util.parseBoolean(properties.getProperty(FINAL_KEY)); @@ -160,6 +162,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { } ConfigProfile setParent(ConfigProfile parent) { + ensureLoad(); this.parent = parent; properties.setProperty(PARENT_KEY, parent.getName()); return this; @@ -170,10 +173,12 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { } ConfigProfile getParent() { + ensureLoad(); return parent; } String getProperty(String key) { + ensureLoad(); if (this == root || properties.containsKey(key)) { return properties.getProperty(key); } else { @@ -182,6 +187,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { } void setProperty(String key, String value) { + ensureLoad(); if (!parent.getProperty(key).equals(value)) { properties.setProperty(key, value); } else { @@ -191,15 +197,14 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { void makeActive(){ - // check if is already loaded - if (!isLoaded()) { - load(); - } + ensureLoad(); // and store it to recent Config.storeRecent(CLI_AND_RECENT_OPTION, getName()); } ConfigProfile deriveUserProfile(String name) { + ensureLoad(); + ConfigProfile newProfile = new ConfigProfile(Type.USER, name); ConfigProfile reference; @@ -221,6 +226,12 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { return newProfile; } + + private void ensureLoad() { + if (loaded == false) { + load(); + } + } boolean load() { // loaded is set independent of success @@ -282,16 +293,71 @@ public final class ConfigProfile implements Comparable<ConfigProfile> { return Util.loadPropertiesFromResource(properties, filePath); } - boolean store() { - if (type != Type.USER) return false; - loaded = true; + private File getFile() { File folder = SystemOS.get().getConfigurationFolder(PROFILE_FOLDER, true); if (folder == null) { - return false; + return null; } else { - File profile = new File(folder, name + PROFILE_EXTENSION); - return Util.storeProperties(properties, profile); + return new File(folder, name + PROFILE_EXTENSION); + } + } + + /** + * stores profile + * @return true if save was successful + */ + boolean store() { + if (type != Type.USER) return false; + + File file = getFile(); + if (file != null) { + return Util.storeProperties(properties, file); + } else { + return false; + } + } + + private List<ConfigProfile> getChildren() { + List<ConfigProfile> children = new ArrayList<ConfigProfile>(); + for (ConfigProfile profile:profiles.values()) { + if (profile.getParent() == this) { + children.add(profile); + } + } + return children; + } + + /** + * delete profile (including deleting the saved file and removing from the map of profiles) + * @return true if deletion was successful + */ + boolean delete() { + // cannot delete parents + if (type != Type.USER) return false; + + // delete profile file + boolean result; + File file = getFile(); + if (file != null) { + if (file.delete()) { + profiles.remove(this.name); + result = true; + } else { + result = false; + } + } else { + result = false; } + + if (result) { + // and reassign and save children + for (ConfigProfile profile:getChildren()) { + profile.setParent(parent); + profile.store(); + } + } + return result; + } private int compare(ConfigProfile a, ConfigProfile b) { diff --git a/rails/ui/swing/ConfigWindow.java b/rails/ui/swing/ConfigWindow.java index 7d0d061..180d8ef 100644 --- a/rails/ui/swing/ConfigWindow.java +++ b/rails/ui/swing/ConfigWindow.java @@ -25,19 +25,19 @@ class ConfigWindow extends JFrame { //(e.g. specifying file names >2000px) private static final int MAX_FIELD_WIDTH = 200; + private Window parent; + private JPanel profilePanel; private JTabbedPane configPane; private JPanel buttonPanel; - private boolean fromStatusWindow; - private ConfigManager cm; - ConfigWindow(boolean fromStatusWindow) { + ConfigWindow(Window parent) { cm = ConfigManager.getInstance(); - // store for handling of close - this.fromStatusWindow = fromStatusWindow; + // store for various handling issues + this.parent = parent; // JFrame properties setTitle(LocalText.getText("CONFIG_WINDOW_TITLE")); @@ -60,6 +60,8 @@ class ConfigWindow extends JFrame { addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { + JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_CLOSE_MESSAGE"), LocalText.getText("CONFIG_CLOSE_TITLE") + , JOptionPane.INFORMATION_MESSAGE); closeConfig(false); } }); @@ -86,7 +88,7 @@ class ConfigWindow extends JFrame { String activeProfile = cm.getActiveProfile(); String profileText; if (cm.IsActiveUserProfile()) { - profileText = LocalText.getText("CONFIG_USER_PROFILE", activeProfile); + profileText = LocalText.getText("CONFIG_USER_PROFILE", activeProfile, cm.getActiveParent()); } else { profileText = LocalText.getText("CONFIG_PREDEFINED_PROFILE", activeProfile); } @@ -399,44 +401,62 @@ class ConfigWindow extends JFrame { private void setupButtonPanel() { buttonPanel.removeAll(); - // apply button + // save button for user profiles if (cm.IsActiveUserProfile()) { - JButton applyButton = new JButton(LocalText.getText("APPLY")); - applyButton.addActionListener( + JButton saveButton = new JButton(LocalText.getText("SAVE")); + saveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { ConfigWindow.this.saveConfig(); } } ); - buttonPanel.add(applyButton); + buttonPanel.add(saveButton); } // save (as) button - JButton saveButton = new JButton(LocalText.getText("SAVE_AND_APPLY")); - saveButton.addActionListener( + JButton saveAsButton = new JButton(LocalText.getText("SAVEAS")); + saveAsButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { ConfigWindow.this.saveAsConfig(); } } ); - buttonPanel.add(saveButton); + buttonPanel.add(saveAsButton); - JButton cancelButton = new JButton(LocalText.getText("CANCEL")); - cancelButton.addActionListener( + JButton resetButton = new JButton(LocalText.getText("RESET")); + resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { - ConfigWindow.this.closeConfig(true); + // reset button: revert to activeProfile + changeProfile(cm.getActiveProfile()); } } ); - buttonPanel.add(cancelButton); + buttonPanel.add(resetButton); + + if (cm.IsActiveUserProfile()) { + JButton deleteButton = new JButton(LocalText.getText("DELETE")); + deleteButton.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + if (cm.deleteActiveProfile()) { + changeProfile(cm.getActiveProfile()); + } + } + } + ); + buttonPanel.add(deleteButton); + } } private void changeProfile(String profileName) { cm.changeProfile(profileName); + if (parent instanceof GameSetupWindow) { + ((GameSetupWindow) parent).configureBox.setSelectedItem(profileName); + } repaintLater(); } @@ -449,48 +469,73 @@ class ConfigWindow extends JFrame { }); } - private boolean saveConfig() { - if (cm.saveProfile(fromStatusWindow)) { + private boolean saveProfile(String newProfile) { + + // check for parent if initMethods have to be called + boolean initMethods; + if (parent instanceof StatusWindow) { + initMethods = true; + } else { + initMethods = false; + } + + // save depending (either as newProfile or as existing) + boolean result; + if (newProfile == null) { + result = cm.saveProfile(initMethods); + } else { + result = cm.saveNewProfile(newProfile, initMethods); + } + + if (result) { JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_SAVE_CONFIRM_MESSAGE", cm.getActiveProfile()), - LocalText.getText("CONFIG_SAVE_TITLE"), JOptionPane.INFORMATION_MESSAGE); - return true; + LocalText.getText("CONFIG_SAVE_TITLE"), JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_SAVE_ERROR_MESSAGE", cm.getActiveProfile()), LocalText.getText("CONFIG_SAVE_TITLE"), JOptionPane.ERROR_MESSAGE); - return false; } + + return result; + } + + private boolean saveConfig() { + return saveProfile(null); } private boolean saveAsConfig() { - // get Names + // get all profile Names List<String> allProfileNames = cm.getProfiles(); + + // select profile name 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)); + } while (newProfile != null && allProfileNames.contains(newProfile)); - boolean result = false; - if (newProfile != null) { - if (cm.saveNewProfile(newProfile, fromStatusWindow)) { - JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_SAVE_CONFIRM_MESSAGE", cm.getActiveProfile()), - LocalText.getText("CONFIG_SAVE_TITLE"), JOptionPane.INFORMATION_MESSAGE); - } else { - JOptionPane.showMessageDialog(ConfigWindow.this, LocalText.getText("CONFIG_SAVE_ERROR_MESSAGE", cm.getActiveProfile()), - LocalText.getText("CONFIG_SAVE_TITLE"), JOptionPane.ERROR_MESSAGE); - result = false; + boolean result; + if (newProfile == null || newProfile.equals("")) { + result = false; + } else { + result = saveProfile(newProfile); + // only change if save was possible + if (result) { + changeProfile(newProfile); } - changeProfile(newProfile); - } + } return result; } private void closeConfig(boolean cancel) { - if (cancel) cm.changeProfile(cm.getActiveProfile()); + if (cancel) { + cm.changeProfile(cm.getActiveProfile()); + init(false); + } this.setVisible(false); - if (fromStatusWindow) { + + if (parent instanceof StatusWindow) { StatusWindow.uncheckMenuItemBox(StatusWindow.CONFIG_CMD); - } + } } } diff --git a/rails/ui/swing/GameSetupWindow.java b/rails/ui/swing/GameSetupWindow.java index d948ff4..efbefa0 100644 --- a/rails/ui/swing/GameSetupWindow.java +++ b/rails/ui/swing/GameSetupWindow.java @@ -112,6 +112,9 @@ public class GameSetupWindow extends JDialog implements ActionListener { configureBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { cm.changeProfile((String)configureBox.getSelectedItem()); + if (configWindow != null) { + configWindow.init(false); + } } } ); @@ -266,7 +269,7 @@ public class GameSetupWindow extends JDialog implements ActionListener { } else if (arg0.getSource().equals(configureButton)) { // start configureWindow if (configWindow == null) { - configWindow = new ConfigWindow(false); + configWindow = new ConfigWindow(this); configWindow.init(true); configWindow.setVisible(true); } else { diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index a43f683..90d81c5 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -238,7 +238,7 @@ public class GameUIManager implements DialogOwner { // define configWindow splashWindow.notifyOfStep(SplashWindow.STEP_CONFIG_WINDOW); - configWindow = new ConfigWindow(true); + configWindow = new ConfigWindow(statusWindow); configWindow.init(true); // notify sound manager of game initialization commit 46e605bfbb7560be0184b66ddf68a83b3463e13c Author: Stefan Frey <ste...@we...> Date: Fri Mar 30 14:42:07 2012 +0200 uses system configuration folders for windowSettings and DockingLayout diff --git a/rails/ui/swing/WindowSettings.java b/rails/ui/swing/WindowSettings.java index d6ed816..03d0409 100644 --- a/rails/ui/swing/WindowSettings.java +++ b/rails/ui/swing/WindowSettings.java @@ -9,6 +9,7 @@ import javax.swing.JFrame; import org.apache.log4j.Logger; import rails.common.Config; +import rails.util.SystemOS; public class WindowSettings { @@ -18,13 +19,13 @@ public class WindowSettings { private boolean defaultUsed = false; private static final String settingsfilename = "settings_xxxx.rails_ini"; + private static final String settingsFolder = "windowSettings"; protected static Logger log = Logger.getLogger(WindowSettings.class.getPackage().getName()); public WindowSettings (String gameName) { - String directory = System.getProperty("settings.directory"); - if (directory == null) directory = Config.get("save.directory"); + File directory = SystemOS.get().getConfigurationFolder(settingsFolder, true); defaultpath = directory + File.separator + settingsfilename; filepath = defaultpath.replace("xxxx", gameName); } diff --git a/rails/ui/swing/elements/DockingFrame.java b/rails/ui/swing/elements/DockingFrame.java index 7ec0f2b..59d7858 100644 --- a/rails/ui/swing/elements/DockingFrame.java +++ b/rails/ui/swing/elements/DockingFrame.java @@ -19,6 +19,7 @@ import javax.swing.SwingUtilities; import rails.common.Config; import rails.common.LocalText; import rails.ui.swing.SplashWindow; +import rails.util.SystemOS; import bibliothek.gui.DockController; import bibliothek.gui.DockStation; @@ -217,17 +218,7 @@ public abstract class DockingFrame extends JFrame { * get layout directory (and ensure that it is available) */ private File getLayoutDirectory() { - try { - File layoutDirectory = new File(Config.get("save.directory"),layoutDirectoryName); - if (!layoutDirectory.isDirectory()) { - layoutDirectory.mkdirs(); - } - return layoutDirectory; - } - catch (Exception e) { - //return no valid file if anything goes wrong - return null; - } + return SystemOS.get().getConfigurationFolder(layoutDirectoryName, true); } private File getLayoutFile() { commit 5a2c5196bd5c6f65aeb48baac96569a3c45190ec Author: Stefan Frey <ste...@we...> Date: Fri Mar 30 14:18:13 2012 +0200 fixed typo in manifest definition diff --git a/buildRails.xml b/buildRails.xml index a2decc3..158fc15 100644 --- a/buildRails.xml +++ b/buildRails.xml @@ -137,7 +137,7 @@ ./lib/batik-1.7/lib/batik-anim.jar ./lib/df_1.1.0/dockingFramesCommon.jar ./lib/df_1.1.0/dockingFramesCore.jar - -/lib/commons-io-2.1/commons-io-2.1.jar"/> + ./lib/commons-io-2.1/commons-io-2.1.jar"/> </manifest> </jar> <delete dir="jar"/> |