From: Frederick W. <fre...@us...> - 2012-02-17 17:32:42
|
LocalisedText.properties | 17 + data/Properties.xml | 1 data/profiles/default.profile | 2 data/profiles/root.profile | 1 images/icon/green_station.png |binary images/icon/green_track.png |binary images/icon/grey_station.png |binary images/icon/grey_track.png |binary images/icon/russet_station.png |binary images/icon/russet_track.png |binary images/icon/yellow_station.png |binary images/icon/yellow_track.png |binary rails/game/GameManager.java | 13 - rails/ui/swing/AbstractReportWindow.java | 9 rails/ui/swing/ConfigWindow.java | 11 rails/ui/swing/GameSetupWindow.java | 63 +++-- rails/ui/swing/GameUIManager.java | 99 +++++++- rails/ui/swing/ORWindow.java | 48 ++-- rails/ui/swing/SplashWindow.java | 356 ++++++++++++++++++++++++++++++ rails/ui/swing/StartRoundWindow.java | 10 rails/ui/swing/StatusWindow.java | 10 rails/ui/swing/StockChart.java | 10 rails/ui/swing/elements/DockingFrame.java | 6 rails/util/RunGame.java | 19 - 24 files changed, 582 insertions(+), 93 deletions(-) New commits: commit 0dd7547b2f850ea7e6e5b5c7ccf01c846ab5898c Author: Frederick Weld <fre...@gm...> Date: Fri Feb 17 18:30:28 2012 +0100 Added splash screen option to the root profile Default is on. Prior behavior cannot be restored anyway as the option only triggers whether the splash screen appears (and not whether window popup is occurs prematurely). diff --git a/data/profiles/root.profile b/data/profiles/root.profile index a553e4c..3e08d4d 100644 --- a/data/profiles/root.profile +++ b/data/profiles/root.profile @@ -34,6 +34,7 @@ or.window.dockablePanels=no report.window.type=dynamic report.window.open=yes report.window.editable=no +splash.window.open=yes stockchart.window.open=yes ### Panel Format commit 2d3fd85bfff93e46f42125bdc6fafd13bfd11e6c Author: Frederick Weld <fre...@gm...> Date: Fri Feb 17 17:55:22 2012 +0100 Visualized game initializing progress (splash) by tile upgrades Reused http://rails.sourceforge.net/ icons for this purpose. diff --git a/images/icon/green_station.png b/images/icon/green_station.png new file mode 100644 index 0000000..993e4f0 Binary files /dev/null and b/images/icon/green_station.png differ diff --git a/images/icon/green_track.png b/images/icon/green_track.png new file mode 100644 index 0000000..3d79ec5 Binary files /dev/null and b/images/icon/green_track.png differ diff --git a/images/icon/grey_station.png b/images/icon/grey_station.png new file mode 100644 index 0000000..9597307 Binary files /dev/null and b/images/icon/grey_station.png differ diff --git a/images/icon/grey_track.png b/images/icon/grey_track.png new file mode 100644 index 0000000..6c498f3 Binary files /dev/null and b/images/icon/grey_track.png differ diff --git a/images/icon/russet_station.png b/images/icon/russet_station.png new file mode 100644 index 0000000..625bcea Binary files /dev/null and b/images/icon/russet_station.png differ diff --git a/images/icon/russet_track.png b/images/icon/russet_track.png new file mode 100644 index 0000000..acddde2 Binary files /dev/null and b/images/icon/russet_track.png differ diff --git a/images/icon/yellow_station.png b/images/icon/yellow_station.png new file mode 100644 index 0000000..0bc7f8c Binary files /dev/null and b/images/icon/yellow_station.png differ diff --git a/images/icon/yellow_track.png b/images/icon/yellow_track.png new file mode 100644 index 0000000..1034612 Binary files /dev/null and b/images/icon/yellow_track.png differ diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index 618e677..8104a6d 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Set; import javax.swing.BoxLayout; +import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; @@ -38,33 +39,33 @@ public class SplashWindow { /** * in millisecs */ - private static long PROGRESS_UPDATE_INTERVAL = 200; + private final static long PROGRESS_UPDATE_INTERVAL = 200; - private static String DUMMY_STEP_BEFORE_START = "-1"; - private static String DUMMY_STEP_START = "0"; - private static String DUMMY_STEP_END = "inf"; + private final static String DUMMY_STEP_BEFORE_START = "-1"; + private final static String DUMMY_STEP_START = "0"; + private final static String DUMMY_STEP_END = "inf"; - public static String STEP_LOAD_GAME = "Splash.step.loadGame"; - public static String STEP_INIT_UI = "Splash.step.initUI"; - public static String STEP_STOCK_CHART = "Splash.step.stockChart"; - public static String STEP_REPORT_WINDOW = "Splash.step.reportWindow"; - public static String STEP_OR_INIT_DOCKING_FRAME = "Splash.step.or.initDockingFrame"; - public static String STEP_OR_INIT_PANELS = "Splash.step.or.initPanels"; - public static String STEP_OR_INIT_TILES = "Splash.step.or.initTiles"; - public static String STEP_OR_APPLY_DOCKING_FRAME = "Splash.step.or.applyDockingFrame"; - public static String STEP_STATUS_WINDOW = "Splash.step.statusWindow"; - public static String STEP_INIT_NEW_GAME = "Splash.step.initNewGame"; - public static String STEP_CONFIG_WINDOW = "Splash.step.configWindow"; - public static String STEP_INIT_SOUND = "Splash.step.initSound"; - public static String STEP_INIT_LOADED_GAME = "Splash.step.initLoadedGame"; - public static String STEP_FINALIZE = "Splash.step.finalize"; + public final static String STEP_LOAD_GAME = "Splash.step.loadGame"; + public final static String STEP_INIT_UI = "Splash.step.initUI"; + public final static String STEP_STOCK_CHART = "Splash.step.stockChart"; + public final static String STEP_REPORT_WINDOW = "Splash.step.reportWindow"; + public final static String STEP_OR_INIT_DOCKING_FRAME = "Splash.step.or.initDockingFrame"; + public final static String STEP_OR_INIT_PANELS = "Splash.step.or.initPanels"; + public final static String STEP_OR_INIT_TILES = "Splash.step.or.initTiles"; + public final static String STEP_OR_APPLY_DOCKING_FRAME = "Splash.step.or.applyDockingFrame"; + public final static String STEP_STATUS_WINDOW = "Splash.step.statusWindow"; + public final static String STEP_INIT_NEW_GAME = "Splash.step.initNewGame"; + public final static String STEP_CONFIG_WINDOW = "Splash.step.configWindow"; + public final static String STEP_INIT_SOUND = "Splash.step.initSound"; + public final static String STEP_INIT_LOADED_GAME = "Splash.step.initLoadedGame"; + public final static String STEP_FINALIZE = "Splash.step.finalize"; - private static List<String> STEP_GROUP_LOAD = Arrays.asList(new String[] { + private final static List<String> STEP_GROUP_LOAD = Arrays.asList(new String[] { STEP_LOAD_GAME, STEP_INIT_LOADED_GAME }); - private static List<String> STEP_GROUP_DOCKING_LAYOUT = Arrays.asList(new String[] { + private final static List<String> STEP_GROUP_DOCKING_LAYOUT = Arrays.asList(new String[] { STEP_OR_INIT_DOCKING_FRAME, STEP_OR_INIT_TILES, STEP_OR_APPLY_DOCKING_FRAME, @@ -78,7 +79,7 @@ public class SplashWindow { this.labelConfigKey = labelConfigKey; } } - private static StepDuration[] stepDuration = { + private final static StepDuration[] stepDuration = { new StepDuration ( 0, DUMMY_STEP_BEFORE_START), // used to facilitate array border handling new StepDuration ( 0, DUMMY_STEP_START), // used to facilitate array border handling new StepDuration ( 6000, STEP_LOAD_GAME ), @@ -97,15 +98,22 @@ public class SplashWindow { new StepDuration ( 1000, STEP_FINALIZE), new StepDuration ( 0, DUMMY_STEP_END), // used to facilitate array border handling }; - + private long totalDuration = 0; private long[] cumulativeDuration = null; private Set<JFrame> framesRegisteredAsVisible = new HashSet<JFrame>(); private List<JFrame> framesRegisteredToFront = new ArrayList<JFrame>(); - private static Dimension iconSize = new Dimension(90,78); - + private final static String iconPath = "/images/icon/"; + + private final static String[][] icons = new String[][] { + { "yellow_track.png" , "yellow_station.png" }, + { "green_track.png" , "green_station.png" }, + { "russet_track.png" , "russet_station.png" }, + { "grey_track.png" , "grey_station.png" } + }; + private JWindow myWin = null; private JLabel leftIcon = null; private JLabel rightIcon = null; @@ -114,7 +122,8 @@ public class SplashWindow { private ProgressVisualizer progressVisualizer = null; - private int currentStep = 1; //the start step + private int currentStep = 0; + private int currentIconIndex = 0; public SplashWindow(boolean isLoad, String initDetailsText) { //quit directly when no visualization required @@ -139,16 +148,19 @@ public class SplashWindow { myWin = new JWindow(); leftIcon = new JLabel(); - leftIcon.setPreferredSize(iconSize); + setIcon(leftIcon,icons[currentIconIndex][0]); + leftIcon.setBorder(new CompoundBorder(new EmptyBorder(5,5,5,5),new EtchedBorder())); rightIcon = new JLabel(); - rightIcon.setPreferredSize(iconSize); + setIcon(rightIcon,icons[currentIconIndex][1]); + rightIcon.setBorder(new CompoundBorder(new EmptyBorder(5,5,5,5),new EtchedBorder())); progressBar = new JProgressBar(0,(int)totalDuration); progressBar.setStringPainted(true); progressBar.setMinimum(0); - stepLabel = new JLabel(); + stepLabel = new JLabel(" "); // needed in order to allocate vertical space stepLabel.setAlignmentX(Component.CENTER_ALIGNMENT); + stepLabel.setBorder(new EmptyBorder(5,5,5,5)); //set up static elements @@ -160,7 +172,7 @@ public class SplashWindow { String commandTextKey = isLoad ? "Splash.command.loadGame" : "Splash.command.newGame"; JLabel commandLabel = new JLabel( LocalText.getText(commandTextKey,initDetailsText)); - commandLabel.setFont(commandLabel.getFont().deriveFont(Font.ITALIC)); + commandLabel.setFont(commandLabel.getFont().deriveFont(Font.BOLD)); commandLabel.setAlignmentX(Component.CENTER_ALIGNMENT); //plug elements together and set up layout @@ -169,12 +181,14 @@ public class SplashWindow { railsCommandPanel.setLayout(new BoxLayout(railsCommandPanel, BoxLayout.Y_AXIS)); railsCommandPanel.add(railsLabel); railsCommandPanel.add(commandLabel); + railsCommandPanel.setBorder(new EmptyBorder(3,3,3,3)); JPanel idPanel = new JPanel(); idPanel.setLayout(new BoxLayout(idPanel, BoxLayout.X_AXIS)); idPanel.add(leftIcon); idPanel.add(railsCommandPanel); idPanel.add(rightIcon); + idPanel.setBorder(new EmptyBorder(3,3,3,3)); JComponent contentPane = (JComponent)myWin.getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); @@ -201,7 +215,7 @@ public class SplashWindow { } catch (Exception e) {} progressVisualizer = new ProgressVisualizer(); - progressVisualizer.setCurrentStep(currentStep); + notifyOfStep(DUMMY_STEP_START); progressVisualizer.start(); } @@ -218,10 +232,10 @@ public class SplashWindow { } /** - * @param elapsedDuration Refers to a duration normalized based on the expected durations + * @param elapsedTime Refers to a duration normalized based on the expected durations * of the process steps. */ - synchronized private void visualizeProgress(long elapsedDuration, int currentStep) { + synchronized private void visualizeProgress(long elapsedTime, int currentStep) { //update current step (including description) if (currentStep != this.currentStep) { this.currentStep = currentStep; @@ -232,13 +246,32 @@ public class SplashWindow { } } + //update icon + int newIconIndex = (int)(icons.length * elapsedTime / totalDuration); + newIconIndex = Math.max( Math.min(icons.length-1 , newIconIndex) , 0); + if (newIconIndex != currentIconIndex) { + currentIconIndex = newIconIndex; + setIcon(leftIcon,icons[newIconIndex][0]); + setIcon(rightIcon,icons[newIconIndex][1]); + } + //show progress - progressBar.setValue((int)elapsedDuration); + progressBar.setValue((int)elapsedTime); //ensure visibility of window myWin.toFront(); } + private void setIcon(JLabel iconLabel, String iconFileName) { + String path = iconPath + iconFileName; + java.net.URL imgURL = getClass().getResource(path); + if (imgURL != null) { + iconLabel.setIcon(new ImageIcon(imgURL)); + } else { + System.err.println("Couldn't find file: " + path); + } + } + /** * Remembers that this frame is to be put to visible at the end of the splash process */ commit 682539e88405e444c60fc0bc8649ed43c7c40dbd Author: Frederick Weld <fre...@gm...> Date: Fri Feb 17 17:25:17 2012 +0100 Added texts for game init steps (displayed in progress bar) diff --git a/LocalisedText.properties b/LocalisedText.properties index d5f8f37..ac4899b 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -642,6 +642,20 @@ SoldOutNoRaise={0} is sold out, but price stays at {1}({2}) SPECIAL=Special Splash.command.loadGame=Loading Game: {0} Splash.command.newGame=Starting New Game: {0} +Splash.step.loadGame=Replaying game... +Splash.step.initUI=Initializing user interface... +Splash.step.stockChart=Building stock chart... +Splash.step.reportWindow=Building report window... +Splash.step.or.initDockingFrame=Initializing docking framework for flexible panels... +Splash.step.or.initPanels=Building operating round window... +Splash.step.or.initTiles=Initializing tiles... +Splash.step.or.applyDockingFrame=Applying docking framework to operating round window... +Splash.step.statusWindow=Building status window... +Splash.step.initNewGame=Initializing new game... +Splash.step.configWindow=Building configuration window... +Splash.step.initSound=Initializing sound... +Splash.step.initLoadedGame=Initializing loaded game... +Splash.step.finalize=Finalizing... SPLIT=Split SRHelpText=Stock round help text goes here. START_COMPANY={0} starts {1} at {2}. diff --git a/rails/ui/swing/ORWindow.java b/rails/ui/swing/ORWindow.java index 68f2ce5..89d037f 100644 --- a/rails/ui/swing/ORWindow.java +++ b/rails/ui/swing/ORWindow.java @@ -191,10 +191,6 @@ public class ORWindow extends DockingFrame implements ActionPerformer { if (isDockingFrameworkEnabled()) { initLayout(); - - //trigger early painting in order to parallelize OR window setup - //with other setup activities - repaint(); } } }); diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index 0d6ebdb..618e677 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -88,7 +88,7 @@ public class SplashWindow { new StepDuration ( 2600, STEP_OR_INIT_DOCKING_FRAME ), new StepDuration ( 1650, STEP_OR_INIT_PANELS ), new StepDuration ( 5000, STEP_OR_INIT_TILES ), - new StepDuration ( 1000, STEP_OR_APPLY_DOCKING_FRAME ), + new StepDuration ( 3000, STEP_OR_APPLY_DOCKING_FRAME ), new StepDuration ( 400, STEP_STATUS_WINDOW ), new StepDuration ( 300, STEP_INIT_NEW_GAME ), new StepDuration ( 1200, STEP_CONFIG_WINDOW ), @@ -214,6 +214,7 @@ public class SplashWindow { progressVisualizer.setCurrentStep(i); } } + } /** @@ -226,29 +227,19 @@ public class SplashWindow { this.currentStep = currentStep; //only display step description for non-dummy steps if (stepDuration[currentStep].expectedDurationInMillis > 0) { - stepLabel.setText(stepDuration[currentStep].labelConfigKey); - enforeGUIUpdate(stepLabel); + stepLabel.setText(LocalText.getText( + stepDuration[currentStep].labelConfigKey)); } } //show progress progressBar.setValue((int)elapsedDuration); - enforeGUIUpdate(progressBar); //ensure visibility of window myWin.toFront(); } /** - * ensure that progress is updated even if EDT is very busy - * CAUTION: paintImmediately is called outside of EDT - * works but not guideline-conform - */ - private void enforeGUIUpdate(JComponent c) { - c.paintImmediately(c.getBounds()); - } - - /** * Remembers that this frame is to be put to visible at the end of the splash process */ public void registerFrameForDeferredVisibility(JFrame frame,boolean setToVisible) { commit 116db12ebbaceffb1e5f112bfb3bd9c55a2d96d2 Author: Frederick Weld <fre...@gm...> Date: Fri Feb 17 17:13:01 2012 +0100 Added splash screen label for init operation New label indicates "Starting New Game: xyz" or "Loading Game: xyz". diff --git a/LocalisedText.properties b/LocalisedText.properties index ee7f6f5..d5f8f37 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -640,6 +640,8 @@ SharesPutInTreasury=The remaining {0}% shares of {1} are put in its treasury SoldOut={0} is sold out, price rises from {1}({2}) to {3}({4}) SoldOutNoRaise={0} is sold out, but price stays at {1}({2}) SPECIAL=Special +Splash.command.loadGame=Loading Game: {0} +Splash.command.newGame=Starting New Game: {0} SPLIT=Split SRHelpText=Stock round help text goes here. START_COMPANY={0} starts {1} at {2}. diff --git a/rails/ui/swing/GameSetupWindow.java b/rails/ui/swing/GameSetupWindow.java index 6a633a9..4d7e73d 100644 --- a/rails/ui/swing/GameSetupWindow.java +++ b/rails/ui/swing/GameSetupWindow.java @@ -228,7 +228,7 @@ public class GameSetupWindow extends JDialog implements ActionListener { */ private void loadAndStartGame(String filePath, String saveDirectory) { prepareGameUIInit(); - SplashWindow splashWindow = new SplashWindow(true); + SplashWindow splashWindow = new SplashWindow(true,filePath); splashWindow.notifyOfStep(SplashWindow.STEP_LOAD_GAME); if ((game = Game.load(filePath)) == null) { JOptionPane.showMessageDialog(this, @@ -500,7 +500,12 @@ public class GameSetupWindow extends JDialog implements ActionListener { } } - game = new Game(this.getSelectedGameInfo().getName(), playerNames, selectedOptions); + String gameName = getSelectedGameInfo().getName(); + + SplashWindow splashWindow = new SplashWindow(false,gameName); + + game = new Game(gameName, playerNames, selectedOptions); + if (!game.setup()) { JOptionPane.showMessageDialog(this, DisplayBuffer.get(), "", JOptionPane.ERROR_MESSAGE); @@ -517,7 +522,6 @@ public class GameSetupWindow extends JDialog implements ActionListener { System.exit(-1); } prepareGameUIInit(); - SplashWindow splashWindow = new SplashWindow(false); startGameUIManager (game, false, splashWindow); gameUIManager.gameUIInit(true); // true indicates new game completeGameUIInit(splashWindow); diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index 1e1201e..0d6ebdb 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -2,6 +2,7 @@ package rails.ui.swing; import java.awt.Component; import java.awt.Dimension; +import java.awt.Font; import java.awt.Toolkit; import java.util.ArrayList; import java.util.Arrays; @@ -21,6 +22,7 @@ import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; +import rails.common.LocalText; import rails.common.parser.Config; import rails.game.Game; @@ -114,7 +116,7 @@ public class SplashWindow { private int currentStep = 1; //the start step - public SplashWindow(boolean isLoad) { + public SplashWindow(boolean isLoad, String initDetailsText) { //quit directly when no visualization required //all visualization related attributes remain null then if ("no".equals(Config.get("splash.window.open"))) return; @@ -155,7 +157,10 @@ public class SplashWindow { (float)2.0 * railsLabel.getFont().getSize())); railsLabel.setAlignmentX(Component.CENTER_ALIGNMENT); - JLabel commandLabel = new JLabel("Setting up new game / loading game"); + String commandTextKey = isLoad ? "Splash.command.loadGame" : "Splash.command.newGame"; + JLabel commandLabel = new JLabel( + LocalText.getText(commandTextKey,initDetailsText)); + commandLabel.setFont(commandLabel.getFont().deriveFont(Font.ITALIC)); commandLabel.setAlignmentX(Component.CENTER_ALIGNMENT); //plug elements together and set up layout diff --git a/rails/util/RunGame.java b/rails/util/RunGame.java index 8206c25..3c08442 100644 --- a/rails/util/RunGame.java +++ b/rails/util/RunGame.java @@ -49,11 +49,12 @@ public class RunGame { static void loadGame (String[] args) { - SplashWindow splashWindow = new SplashWindow(true); - splashWindow.notifyOfStep(SplashWindow.STEP_LOAD_GAME); - Game game = null; String filepath = args[0]; + + SplashWindow splashWindow = new SplashWindow(true,filepath); + splashWindow.notifyOfStep(SplashWindow.STEP_LOAD_GAME); + System.out.println("Starting game from saved file "+filepath); if ((game = Game.load(filepath)) == null) { System.err.println("Loading file "+filepath+" was unsuccessful"); commit b28efc90ce9a591119f83d6613d16df57990917a Author: Frederick Weld <fre...@gm...> Date: Fri Feb 17 16:27:15 2012 +0100 Laid out splash screen (incl. rails version, progress bar) diff --git a/LocalisedText.properties b/LocalisedText.properties index 9c1ccd7..ee7f6f5 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -213,7 +213,7 @@ Config.label.route.colour.1=Route color for first train Config.label.route.colour.2=Route color for second train Config.label.route.colour.3=Route color for third train Config.label.route.colour.4=Route color for fourth train -Config.label.splash.window.open=Splash window open +Config.label.splash.window.open=Display splash screen Config.label.sound.backgroundMusic=Background Music Config.label.sound.backgroundMusic.endOfGameRound=End of Game Config.label.sound.backgroundMusic.gameSetup=Initial Game Setup diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index edb8cad..1e1201e 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -1,18 +1,28 @@ package rails.ui.swing; -import java.awt.Rectangle; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Toolkit; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.swing.BoxLayout; +import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; import javax.swing.JWindow; import javax.swing.SwingUtilities; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; import rails.common.parser.Config; +import rails.game.Game; /** * Splash window shown during setup of game UI components and game loading. @@ -32,20 +42,20 @@ public class SplashWindow { private static String DUMMY_STEP_START = "0"; private static String DUMMY_STEP_END = "inf"; - public static String STEP_LOAD_GAME = "1"; - public static String STEP_INIT_UI = "2"; - public static String STEP_STOCK_CHART = "3"; - public static String STEP_REPORT_WINDOW = "4"; - public static String STEP_OR_INIT_DOCKING_FRAME = "5A"; - public static String STEP_OR_INIT_PANELS = "5B"; - public static String STEP_OR_INIT_TILES = "5C"; - public static String STEP_OR_APPLY_DOCKING_FRAME = "5D"; - public static String STEP_STATUS_WINDOW = "6"; - public static String STEP_INIT_NEW_GAME = "7"; - public static String STEP_CONFIG_WINDOW = "8"; - public static String STEP_INIT_SOUND = "9"; - public static String STEP_INIT_LOADED_GAME = "10"; - public static String STEP_FINALIZE = "11"; + public static String STEP_LOAD_GAME = "Splash.step.loadGame"; + public static String STEP_INIT_UI = "Splash.step.initUI"; + public static String STEP_STOCK_CHART = "Splash.step.stockChart"; + public static String STEP_REPORT_WINDOW = "Splash.step.reportWindow"; + public static String STEP_OR_INIT_DOCKING_FRAME = "Splash.step.or.initDockingFrame"; + public static String STEP_OR_INIT_PANELS = "Splash.step.or.initPanels"; + public static String STEP_OR_INIT_TILES = "Splash.step.or.initTiles"; + public static String STEP_OR_APPLY_DOCKING_FRAME = "Splash.step.or.applyDockingFrame"; + public static String STEP_STATUS_WINDOW = "Splash.step.statusWindow"; + public static String STEP_INIT_NEW_GAME = "Splash.step.initNewGame"; + public static String STEP_CONFIG_WINDOW = "Splash.step.configWindow"; + public static String STEP_INIT_SOUND = "Splash.step.initSound"; + public static String STEP_INIT_LOADED_GAME = "Splash.step.initLoadedGame"; + public static String STEP_FINALIZE = "Splash.step.finalize"; private static List<String> STEP_GROUP_LOAD = Arrays.asList(new String[] { STEP_LOAD_GAME, @@ -92,11 +102,15 @@ public class SplashWindow { private Set<JFrame> framesRegisteredAsVisible = new HashSet<JFrame>(); private List<JFrame> framesRegisteredToFront = new ArrayList<JFrame>(); + private static Dimension iconSize = new Dimension(90,78); + private JWindow myWin = null; - private ProgressVisualizer progressVisualizer = null; + private JLabel leftIcon = null; + private JLabel rightIcon = null; + private JProgressBar progressBar = null; + private JLabel stepLabel = null; - //TODO remove temp label - private JLabel tempL = null; + private ProgressVisualizer progressVisualizer = null; private int currentStep = 1; //the start step @@ -104,17 +118,7 @@ public class SplashWindow { //quit directly when no visualization required //all visualization related attributes remain null then if ("no".equals(Config.get("splash.window.open"))) return; - - myWin = new JWindow(); - myWin.setBounds(new Rectangle(200,200,400,200)); - - //TODO remove temp - tempL = new JLabel(""); - myWin.getContentPane().add(tempL); - tempL.setVisible(true); - //TODO set up frame (incl. title, icons, bar, status text) - myWin.setVisible(true); - + //calculate estimated duration for the respective steps cumulativeDuration = new long[stepDuration.length]; boolean isDockingLayout = "yes".equals(Config.get("or.window.dockablePanels")); @@ -128,6 +132,69 @@ public class SplashWindow { cumulativeDuration[i] = totalDuration; } + //set up dynamic elements + + myWin = new JWindow(); + + leftIcon = new JLabel(); + leftIcon.setPreferredSize(iconSize); + rightIcon = new JLabel(); + rightIcon.setPreferredSize(iconSize); + + progressBar = new JProgressBar(0,(int)totalDuration); + progressBar.setStringPainted(true); + progressBar.setMinimum(0); + + stepLabel = new JLabel(); + stepLabel.setAlignmentX(Component.CENTER_ALIGNMENT); + + //set up static elements + + JLabel railsLabel = new JLabel("Rails " + Game.getFullVersion()); + railsLabel.setFont(railsLabel.getFont().deriveFont( + (float)2.0 * railsLabel.getFont().getSize())); + railsLabel.setAlignmentX(Component.CENTER_ALIGNMENT); + + JLabel commandLabel = new JLabel("Setting up new game / loading game"); + commandLabel.setAlignmentX(Component.CENTER_ALIGNMENT); + + //plug elements together and set up layout + + JPanel railsCommandPanel = new JPanel(); + railsCommandPanel.setLayout(new BoxLayout(railsCommandPanel, BoxLayout.Y_AXIS)); + railsCommandPanel.add(railsLabel); + railsCommandPanel.add(commandLabel); + + JPanel idPanel = new JPanel(); + idPanel.setLayout(new BoxLayout(idPanel, BoxLayout.X_AXIS)); + idPanel.add(leftIcon); + idPanel.add(railsCommandPanel); + idPanel.add(rightIcon); + + JComponent contentPane = (JComponent)myWin.getContentPane(); + contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); + contentPane.add(idPanel); + contentPane.add(progressBar); + contentPane.add(stepLabel); + contentPane.setBorder(new CompoundBorder(new EtchedBorder(),new EmptyBorder(5,5,5,5))); + + //perform layout within the EDT + //blocking call as further initialization requires the layout to be frozen + try { + SwingUtilities.invokeAndWait(new Thread() { + @Override + public void run() { + myWin.pack(); + Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); + myWin.setLocation( + (dim.width - myWin.getSize().width) / 2, + (dim.height - myWin.getSize().height) / 2 + ); + myWin.setVisible(true); + } + }); + } catch (Exception e) {} + progressVisualizer = new ProgressVisualizer(); progressVisualizer.setCurrentStep(currentStep); progressVisualizer.start(); @@ -154,24 +221,29 @@ public class SplashWindow { this.currentStep = currentStep; //only display step description for non-dummy steps if (stepDuration[currentStep].expectedDurationInMillis > 0) { - //TODO + stepLabel.setText(stepDuration[currentStep].labelConfigKey); + enforeGUIUpdate(stepLabel); } } //show progress - double percentage = 100.0 * elapsedDuration / totalDuration; - tempL.setText("<html>" + percentage + "<br>" + stepDuration[currentStep].labelConfigKey + "</html>"); + progressBar.setValue((int)elapsedDuration); + enforeGUIUpdate(progressBar); - //ensure that progress is updated even if EDT is very busy - //CAUTION: paintImmediately is called outside of EDT - // works but not guideline-conform - tempL.paintImmediately(tempL.getBounds()); - //ensure visibility of window myWin.toFront(); } /** + * ensure that progress is updated even if EDT is very busy + * CAUTION: paintImmediately is called outside of EDT + * works but not guideline-conform + */ + private void enforeGUIUpdate(JComponent c) { + c.paintImmediately(c.getBounds()); + } + + /** * Remembers that this frame is to be put to visible at the end of the splash process */ public void registerFrameForDeferredVisibility(JFrame frame,boolean setToVisible) { commit 1aa89dfdc7568950f5f6b0b8833c0e12e25e1eee Author: Frederick Weld <fre...@gm...> Date: Fri Feb 17 06:19:19 2012 +0100 Added option to display splash screen (default yes) Even if splash screen is not to be displayed, the init logic (deferring setVisible/toFront, parallelization EDT and non-EDT) is applied. diff --git a/LocalisedText.properties b/LocalisedText.properties index 087534b..9c1ccd7 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -213,6 +213,7 @@ Config.label.route.colour.1=Route color for first train Config.label.route.colour.2=Route color for second train Config.label.route.colour.3=Route color for third train Config.label.route.colour.4=Route color for fourth train +Config.label.splash.window.open=Splash window open Config.label.sound.backgroundMusic=Background Music Config.label.sound.backgroundMusic.endOfGameRound=End of Game Config.label.sound.backgroundMusic.gameSetup=Initial Game Setup diff --git a/data/Properties.xml b/data/Properties.xml index 9399a9f..1e5c37e 100644 --- a/data/Properties.xml +++ b/data/Properties.xml @@ -41,6 +41,7 @@ <Property name="report.window.editable" type="BOOLEAN" /> <Property name="stockchart.window.open" type="BOOLEAN" /> <Property name="or.window.dockablePanels" type="BOOLEAN" /> + <Property name="splash.window.open" type="BOOLEAN" /> </Section> <Section name="Format"> <Property name="money_format" type="STRING" /> diff --git a/data/profiles/default.profile b/data/profiles/default.profile index 03d7a58..122c1b7 100644 --- a/data/profiles/default.profile +++ b/data/profiles/default.profile @@ -1,2 +1,2 @@ ### Default profile currently is identical to root.profile -### so no change here \ No newline at end of file +### so no change here diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index 68fddda..edb8cad 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -87,20 +87,24 @@ public class SplashWindow { }; private long totalDuration = 0; - private long[] cumulativeDuration; + private long[] cumulativeDuration = null; private Set<JFrame> framesRegisteredAsVisible = new HashSet<JFrame>(); private List<JFrame> framesRegisteredToFront = new ArrayList<JFrame>(); - private JWindow myWin; - private ProgressVisualizer progressVisualizer; + private JWindow myWin = null; + private ProgressVisualizer progressVisualizer = null; //TODO remove temp label - private JLabel tempL; + private JLabel tempL = null; private int currentStep = 1; //the start step public SplashWindow(boolean isLoad) { + //quit directly when no visualization required + //all visualization related attributes remain null then + if ("no".equals(Config.get("splash.window.open"))) return; + myWin = new JWindow(); myWin.setBounds(new Rectangle(200,200,400,200)); @@ -130,6 +134,9 @@ public class SplashWindow { } public void notifyOfStep(String stepLabelConfigKey) { + //ignore if no visualization requested + if (myWin == null) return; + for (int i = 0 ; i < stepDuration.length ; i++) { if (stepDuration[i].labelConfigKey.equals(stepLabelConfigKey)) { progressVisualizer.setCurrentStep(i); @@ -208,10 +215,11 @@ public class SplashWindow { }); } catch (Exception e) {} - progressVisualizer.interrupt(); - - myWin.dispose(); - + //clean up visualization only if it was requested + if (myWin != null) { + progressVisualizer.interrupt(); + myWin.dispose(); + } } private class ProgressVisualizer extends Thread { commit 2f2e71b6e7de9340e5c9e64388b1f10a097f5e41 Author: Frederick Weld <fre...@gm...> Date: Thu Feb 16 19:59:37 2012 +0100 Added context dependent progress calculation (new/load, conv/docking) Init time largely depend on whether - new game is started or old game is loaded (latter lasts longer) - conventional layout or docking layout is used (latter is longer) Now, the splash window's heuristic takes into account this context information for better display of the progress. diff --git a/rails/ui/swing/GameSetupWindow.java b/rails/ui/swing/GameSetupWindow.java index c7ebea1..6a633a9 100644 --- a/rails/ui/swing/GameSetupWindow.java +++ b/rails/ui/swing/GameSetupWindow.java @@ -228,7 +228,7 @@ public class GameSetupWindow extends JDialog implements ActionListener { */ private void loadAndStartGame(String filePath, String saveDirectory) { prepareGameUIInit(); - SplashWindow splashWindow = new SplashWindow(); + SplashWindow splashWindow = new SplashWindow(true); splashWindow.notifyOfStep(SplashWindow.STEP_LOAD_GAME); if ((game = Game.load(filePath)) == null) { JOptionPane.showMessageDialog(this, @@ -517,7 +517,7 @@ public class GameSetupWindow extends JDialog implements ActionListener { System.exit(-1); } prepareGameUIInit(); - SplashWindow splashWindow = new SplashWindow(); + SplashWindow splashWindow = new SplashWindow(false); startGameUIManager (game, false, splashWindow); gameUIManager.gameUIInit(true); // true indicates new game completeGameUIInit(splashWindow); diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index 0f030a1..68fddda 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -2,6 +2,7 @@ package rails.ui.swing; import java.awt.Rectangle; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -11,6 +12,8 @@ import javax.swing.JLabel; import javax.swing.JWindow; import javax.swing.SwingUtilities; +import rails.common.parser.Config; + /** * Splash window shown during setup of game UI components and game loading. * Provides for a progress bar, status bar, and ensures that frames only become visible @@ -43,6 +46,17 @@ public class SplashWindow { public static String STEP_INIT_SOUND = "9"; public static String STEP_INIT_LOADED_GAME = "10"; public static String STEP_FINALIZE = "11"; + + private static List<String> STEP_GROUP_LOAD = Arrays.asList(new String[] { + STEP_LOAD_GAME, + STEP_INIT_LOADED_GAME + }); + + private static List<String> STEP_GROUP_DOCKING_LAYOUT = Arrays.asList(new String[] { + STEP_OR_INIT_DOCKING_FRAME, + STEP_OR_INIT_TILES, + STEP_OR_APPLY_DOCKING_FRAME, + }); private static class StepDuration { long expectedDurationInMillis; @@ -62,7 +76,7 @@ public class SplashWindow { new StepDuration ( 2600, STEP_OR_INIT_DOCKING_FRAME ), new StepDuration ( 1650, STEP_OR_INIT_PANELS ), new StepDuration ( 5000, STEP_OR_INIT_TILES ), - new StepDuration ( 3000, STEP_OR_APPLY_DOCKING_FRAME ), + new StepDuration ( 1000, STEP_OR_APPLY_DOCKING_FRAME ), new StepDuration ( 400, STEP_STATUS_WINDOW ), new StepDuration ( 300, STEP_INIT_NEW_GAME ), new StepDuration ( 1200, STEP_CONFIG_WINDOW ), @@ -86,20 +100,27 @@ public class SplashWindow { private int currentStep = 1; //the start step - public SplashWindow() { + public SplashWindow(boolean isLoad) { myWin = new JWindow(); myWin.setBounds(new Rectangle(200,200,400,200)); //TODO remove temp - tempL = new JLabel("sghsghsghsfghws"); + tempL = new JLabel(""); myWin.getContentPane().add(tempL); tempL.setVisible(true); //TODO set up frame (incl. title, icons, bar, status text) myWin.setVisible(true); + //calculate estimated duration for the respective steps cumulativeDuration = new long[stepDuration.length]; + boolean isDockingLayout = "yes".equals(Config.get("or.window.dockablePanels")); for (int i = 0 ; i < stepDuration.length ; i++) { - totalDuration += stepDuration[i].expectedDurationInMillis; + //only consider step if relevant for this setup + if ( (isLoad || !STEP_GROUP_LOAD.contains(stepDuration[i].labelConfigKey)) + && + (isDockingLayout || !STEP_GROUP_DOCKING_LAYOUT.contains(stepDuration[i].labelConfigKey)) ) { + totalDuration += stepDuration[i].expectedDurationInMillis; + } cumulativeDuration[i] = totalDuration; } diff --git a/rails/util/RunGame.java b/rails/util/RunGame.java index 461035a..8206c25 100644 --- a/rails/util/RunGame.java +++ b/rails/util/RunGame.java @@ -49,7 +49,7 @@ public class RunGame { static void loadGame (String[] args) { - SplashWindow splashWindow = new SplashWindow(); + SplashWindow splashWindow = new SplashWindow(true); splashWindow.notifyOfStep(SplashWindow.STEP_LOAD_GAME); Game game = null; commit 88c68529a44f51f2a17bb7c9932b6b2eeff2f112 Author: Frederick Weld <fre...@gm...> Date: Thu Feb 16 16:55:11 2012 +0100 Ensured that progress is visualized even if EDT is busy diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index b8ba47d..0f030a1 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -23,7 +23,7 @@ public class SplashWindow { /** * in millisecs */ - private static long PROGRESS_UPDATE_INTERVAL = 100; + private static long PROGRESS_UPDATE_INTERVAL = 200; private static String DUMMY_STEP_BEFORE_START = "-1"; private static String DUMMY_STEP_START = "0"; @@ -133,6 +133,11 @@ public class SplashWindow { //show progress double percentage = 100.0 * elapsedDuration / totalDuration; tempL.setText("<html>" + percentage + "<br>" + stepDuration[currentStep].labelConfigKey + "</html>"); + + //ensure that progress is updated even if EDT is very busy + //CAUTION: paintImmediately is called outside of EDT + // works but not guideline-conform + tempL.paintImmediately(tempL.getBounds()); //ensure visibility of window myWin.toFront(); commit e75ec0326113597cb78ca5836c3017b47537ceb5 Author: Frederick Weld <fre...@gm...> Date: Thu Feb 16 16:41:33 2012 +0100 Added support for setting frames in correct front-to-back order after init diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index 809dcf4..7e59194 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -475,7 +475,7 @@ public class GameUIManager implements DialogOwner { setMeVisible(stockChart,stockChartVisibilityHint); previousStockChartVisibilityHint = stockChartVisibilityHint; } - if (hint.getVisibility()) stockChart.toFront(); + if (hint.getVisibility()) setMeToFront(stockChart); break; case STATUS: boolean statusWindowVisibilityHint = hint.getVisibility(); @@ -483,7 +483,7 @@ public class GameUIManager implements DialogOwner { setMeVisible(statusWindow,statusWindowVisibilityHint); previousStatusWindowVisibilityHint = statusWindowVisibilityHint; } - if (statusWindowVisibilityHint) statusWindow.toFront(); + if (statusWindowVisibilityHint) setMeToFront(statusWindow); break; case MAP: boolean orWindowVisibilityHint = hint.getVisibility(); @@ -491,7 +491,7 @@ public class GameUIManager implements DialogOwner { setMeVisible(orWindow,orWindowVisibilityHint); previousORWindowVisibilityHint = orWindowVisibilityHint; } - if (orWindowVisibilityHint) orWindow.toFront(); + if (orWindowVisibilityHint) setMeToFront(orWindow); break; case START_ROUND: // Handled elsewhere @@ -511,7 +511,7 @@ public class GameUIManager implements DialogOwner { log.debug("Entering Start Round UI type"); activeWindow = startRoundWindow; setMeVisible(startRoundWindow,true); - startRoundWindow.toFront(); + setMeToFront(startRoundWindow); } else if (uiHints.getActivePanel() == GuiDef.Panel.STATUS || correctionOverride) { @@ -519,14 +519,14 @@ public class GameUIManager implements DialogOwner { activeWindow = statusWindow; stockChart.setVisible(true); setMeVisible(statusWindow,true); - statusWindow.toFront(); + setMeToFront(statusWindow); } else if (uiHints.getActivePanel() == GuiDef.Panel.MAP && !correctionOverride) { log.debug("Entering Operating Round UI type "); activeWindow = orWindow; setMeVisible(orWindow,true); - orWindow.toFront(); + setMeToFront(orWindow); } @@ -1146,6 +1146,19 @@ public class GameUIManager implements DialogOwner { } /** + * Only set frame directly to front if the splash phase is already over. + * Otherwise, the splash framework remembers this toFront request and + * postpones the toFront to the point in time where the splash is completed. + */ + public void setMeToFront(JFrame frame) { + if (splashWindow == null) { + frame.toFront(); + } else { + splashWindow.registerFrameForDeferredToFront(frame); + } + } + + /** * called when the splash process is completed * (and visibility changes are not to be deferred any more) */ diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index 8a279ce..b8ba47d 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -1,7 +1,9 @@ package rails.ui.swing; import java.awt.Rectangle; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.swing.JFrame; @@ -40,6 +42,7 @@ public class SplashWindow { public static String STEP_CONFIG_WINDOW = "8"; public static String STEP_INIT_SOUND = "9"; public static String STEP_INIT_LOADED_GAME = "10"; + public static String STEP_FINALIZE = "11"; private static class StepDuration { long expectedDurationInMillis; @@ -59,12 +62,13 @@ public class SplashWindow { new StepDuration ( 2600, STEP_OR_INIT_DOCKING_FRAME ), new StepDuration ( 1650, STEP_OR_INIT_PANELS ), new StepDuration ( 5000, STEP_OR_INIT_TILES ), - new StepDuration ( 2000, STEP_OR_APPLY_DOCKING_FRAME ), + new StepDuration ( 3000, STEP_OR_APPLY_DOCKING_FRAME ), new StepDuration ( 400, STEP_STATUS_WINDOW ), new StepDuration ( 300, STEP_INIT_NEW_GAME ), new StepDuration ( 1200, STEP_CONFIG_WINDOW ), new StepDuration ( 200, STEP_INIT_SOUND ), new StepDuration ( 1000, STEP_INIT_LOADED_GAME ), + new StepDuration ( 1000, STEP_FINALIZE), new StepDuration ( 0, DUMMY_STEP_END), // used to facilitate array border handling }; @@ -72,6 +76,7 @@ public class SplashWindow { private long[] cumulativeDuration; private Set<JFrame> framesRegisteredAsVisible = new HashSet<JFrame>(); + private List<JFrame> framesRegisteredToFront = new ArrayList<JFrame>(); private JWindow myWin; private ProgressVisualizer progressVisualizer; @@ -119,7 +124,8 @@ public class SplashWindow { //update current step (including description) if (currentStep != this.currentStep) { this.currentStep = currentStep; - if (currentStep != 0 && currentStep != stepDuration.length - 1) { + //only display step description for non-dummy steps + if (stepDuration[currentStep].expectedDurationInMillis > 0) { //TODO } } @@ -143,19 +149,38 @@ public class SplashWindow { } } + /** + * Remembers that this frame is to be put to front at the end of the splash process + * Handles the list of to front requests in order to + * - apply all requests in a FIFO manner + * - ensure that each frame is only sent to the front once (at the latest registered time) + */ + public void registerFrameForDeferredToFront(JFrame frame) { + framesRegisteredToFront.remove(frame); + framesRegisteredToFront.add(frame); + } + public void finalizeGameInit() { - progressVisualizer.setCurrentStep(stepDuration.length - 1); + notifyOfStep(STEP_FINALIZE); - //finally restore visibility of registered frames + //finally restore visibility / toFront of registered frames //only after EDT is ready (as window built-up could still be pending) - SwingUtilities.invokeLater(new Thread() { - @Override - public void run() { - for (JFrame frame : framesRegisteredAsVisible) { - frame.setVisible(true); + //block any frame disposal to the point in time when this is through + try { + SwingUtilities.invokeAndWait(new Thread() { + @Override + public void run() { + //visibility + for (JFrame frame : framesRegisteredAsVisible) { + frame.setVisible(true); + } + //to front + for (JFrame frame : framesRegisteredToFront) { + frame.toFront(); + } } - } - }); + }); + } catch (Exception e) {} progressVisualizer.interrupt(); @@ -164,24 +189,24 @@ public class SplashWindow { } private class ProgressVisualizer extends Thread { - private long elapsedDuration = 0; + private long elapsedTime = 0; private int currentStep = 0; @Override public void run() { try { while (!isInterrupted()) { - visualizeProgress(elapsedDuration, currentStep); + visualizeProgress(elapsedTime, currentStep); sleep(PROGRESS_UPDATE_INTERVAL); //adjusted elapsed duration synchronized (this) { - elapsedDuration += PROGRESS_UPDATE_INTERVAL; + elapsedTime += PROGRESS_UPDATE_INTERVAL; //elapsed duration must remain within the bounds of the estimated cumulative duration //between the end of last step and the end of the current step - elapsedDuration = Math.max ( + elapsedTime = Math.max ( cumulativeDuration[currentStep-1], - Math.min( elapsedDuration, cumulativeDuration[currentStep] ) + Math.min( elapsedTime, cumulativeDuration[currentStep] ) ); } } @@ -190,6 +215,7 @@ public class SplashWindow { synchronized private void setCurrentStep(int currentStep) { this.currentStep = currentStep; + //System.out.println("Time: "+elapsedTime + " (Step: "+stepDuration[currentStep].labelConfigKey+")"); } } } \ No newline at end of file commit c71458876f4beb07d49543bbf6fdc74bae3c8ae8 Author: Frederick Weld <fre...@gm...> Date: Thu Feb 16 16:16:10 2012 +0100 Removed multi-instance GameManager concept / set GameManager to singleton diff --git a/rails/game/GameManager.java b/rails/game/GameManager.java index c147924..15915f0 100644 --- a/rails/game/GameManager.java +++ b/rails/game/GameManager.java @@ -136,6 +136,12 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { new EnumMap<GuiDef.Parm, Boolean>(GuiDef.Parm.class); /** + * Update: + * NDC concept has been replaced by the origin singleton one. + * Target design to be decided when distributed rails is being conceived + * and developed. + * + * Former design: * Map of GameManager instances. * Currently there can be only one instance, but in a possible * future multi-game server there may be several instances @@ -237,8 +243,8 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { public GameManager() { gmName = GM_NAME; gmKey = GM_KEY; - NDC.clear(); - NDC.push (GM_KEY); + //NDC.clear(); + //NDC.push (GM_KEY); gameManagerMap.put(GM_KEY, this); displayBuffer = new DisplayBuffer(); reportBuffer = new ReportBuffer(); @@ -633,7 +639,8 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { * @return instance of GameManager */ public static GameManagerI getInstance () { - return gameManagerMap.get(NDC.peek()); +// return gameManagerMap.get(NDC.peek()); + return gameManagerMap.get(GM_KEY); } /* (non-Javadoc) commit 33e8c3cf880ee791cfd1c941eef6be64395394a4 Author: Frederick Weld <fre...@gm...> Date: Thu Feb 16 16:11:36 2012 +0100 Removed game init by default from EDT / put pack explicitly into EDT diff --git a/rails/ui/swing/ConfigWindow.java b/rails/ui/swing/ConfigWindow.java index db03e10..e5fb185 100644 --- a/rails/ui/swing/ConfigWindow.java +++ b/rails/ui/swing/ConfigWindow.java @@ -8,6 +8,7 @@ import java.awt.GraphicsEnvironment; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; @@ -43,6 +44,7 @@ import javax.swing.JSpinner; import javax.swing.JTabbedPane; import javax.swing.SpinnerNumberModel; import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.WindowConstants; import javax.swing.border.Border; @@ -105,8 +107,13 @@ class ConfigWindow extends JFrame { setupProfilePanel(); setupConfigPane(); setupButtonPanel(); - this.pack(); - setSize(600,400); + + SwingUtilities.invokeLater(new Thread() { + public void run() { + ConfigWindow.this.pack(); + ConfigWindow.this.setSize(600,400); + } + }); } private void setupProfilePanel() { diff --git a/rails/ui/swing/ORWindow.java b/rails/ui/swing/ORWindow.java index c67a23f..68f2ce5 100644 --- a/rails/ui/swing/ORWindow.java +++ b/rails/ui/swing/ORWindow.java @@ -189,7 +189,13 @@ public class ORWindow extends DockingFrame implements ActionPerformer { if (bounds.width != -1 && bounds.height != -1) setSize(bounds.getSize()); ws.set(frame); - if (isDockingFrameworkEnabled()) initLayout(); + if (isDockingFrameworkEnabled()) { + initLayout(); + + //trigger early painting in order to parallelize OR window setup + //with other setup activities + repaint(); + } } }); diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index 406af02..8a279ce 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -104,7 +104,6 @@ public class SplashWindow { } public void notifyOfStep(String stepLabelConfigKey) { - myWin.toFront(); for (int i = 0 ; i < stepDuration.length ; i++) { if (stepDuration[i].labelConfigKey.equals(stepLabelConfigKey)) { progressVisualizer.setCurrentStep(i); @@ -128,6 +127,9 @@ public class SplashWindow { //show progress double percentage = 100.0 * elapsedDuration / totalDuration; tempL.setText("<html>" + percentage + "<br>" + stepDuration[currentStep].labelConfigKey + "</html>"); + + //ensure visibility of window + myWin.toFront(); } /** diff --git a/rails/util/RunGame.java b/rails/util/RunGame.java index 55e6fb5..461035a 100644 --- a/rails/util/RunGame.java +++ b/rails/util/RunGame.java @@ -39,14 +39,7 @@ public class RunGame { static void loadGameOnEventQueue(final String[] args) { try { - java.awt.EventQueue.invokeAndWait( - new Runnable() - { - public void run() { - loadGame(args); - } - } - ); + loadGame(args); } catch (Exception e) { System.err.println("Cannot load game: "+e.getMessage()); e.printStackTrace(System.err); commit 8d63d4c97bf2847f79af079da18eb34e3a841656 Author: Frederick Weld <fre...@gm...> Date: Thu Feb 16 16:00:06 2012 +0100 Added continuous visualization of init progress Before, progress was updated upon the completion of a init step. Now, progress is updated continuously based on a heuristic that gets the expected duration of the init steps as an input parameter. diff --git a/rails/ui/swing/SplashWindow.java b/rails/ui/swing/SplashWindow.java index 439fba1..406af02 100644 --- a/rails/ui/swing/SplashWindow.java +++ b/rails/ui/swing/SplashWindow.java @@ -1,6 +1,3 @@ -/** - * - */ package rails.ui.swing; import java.awt.Rectangle; @@ -21,6 +18,15 @@ import javax.swing.SwingUtilities; */ public class SplashWindow { + /** + * in millisecs + */ + private static long PROGRESS_UPDATE_INTERVAL = 100; + + private static String DUMMY_STEP_BEFORE_START = "-1"; + private static String DUMMY_STEP_START = "0"; + private static String DUMMY_STEP_END = "inf"; + public static String STEP_LOAD_GAME = "1"; public static String STEP_INIT_UI = "2"; public static String STEP_STOCK_CHART = "3"; @@ -36,15 +42,16 @@ public class SplashWindow { public static String STEP_INIT_LOADED_GAME = "10"; private static class StepDuration { - int expectedDurationInMillis; + long expectedDurationInMillis; String labelConfigKey; - StepDuration(int expDurationInMillis,String labelConfigKey) { - this.expectedDurationInMillis = expDurationInMillis; + StepDuration(int expectedDurationInMillis,String labelConfigKey) { + this.expectedDurationInMillis = expectedDurationInMillis; this.labelConfigKey = labelConfigKey; } } private static StepDuration[] stepDuration = { - new StepDuration ( 0, "Start"), // used to facilitate array border handling + new StepDuration ( 0, DUMMY_STEP_BEFORE_START), // used to facilitate array border handling + new StepDuration ( 0, DUMMY_STEP_START), // used to facilitate array border handling new StepDuration ( 6000, STEP_LOAD_GAME ), new StepDuration ( 500, STEP_INIT_UI ), new StepDuration ( 230, STEP_STOCK_CHART ), @@ -58,19 +65,22 @@ public class SplashWindow { new StepDuration ( 1200, STEP_CONFIG_WINDOW ), new StepDuration ( 200, STEP_INIT_SOUND ), new StepDuration ( 1000, STEP_INIT_LOADED_GAME ), - ... [truncated message content] |