From 3dd01f4b0ddf5038f6e1ab98faf1ea57194d333b Mon Sep 17 00:00:00 2001 From: Doublestrike Date: Tue, 30 Aug 2011 15:50:10 +0000 Subject: [PATCH] Updated splash frame close functionality to also cancel preloading and gui creation process if user has closed splash frame. --- .../forge/view/swing/ApplicationView.java | 50 +++++++++++-------- .../java/forge/view/swing/SplashFrame.java | 21 +++++++- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/main/java/forge/view/swing/ApplicationView.java b/src/main/java/forge/view/swing/ApplicationView.java index 9c104834f3e..629b2747e2f 100644 --- a/src/main/java/forge/view/swing/ApplicationView.java +++ b/src/main/java/forge/view/swing/ApplicationView.java @@ -117,27 +117,35 @@ public class ApplicationView implements FView { } }); - AllZone.getCardFactory(); // forces preloading of all cards - try { - Constant.Runtime.GameType[0] = Constant.GameType.Constructed; - SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/7/11 1:07 PM: this isn't a web app - public void run() { - AllZone.setComputer(new ComputerAI_Input(new ComputerAI_General())); - - // Enable only one of the following two lines. The second - // is useful for debugging. - - splashFrame.dispose(); - //splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - - splashFrame = null; - new OldGuiNewGame(); - } - }); - } catch (Exception ex) { - ErrorViewer.showError(ex); + // For the following two blocks, check if user has cancelled SplashFrame. + // Note: Error thrown sometimes because log file cannot be accessed + if(!splashFrame.getSplashHasBeenClosed()) { + AllZone.getCardFactory(); // forces preloading of all cards } + + if(!splashFrame.getSplashHasBeenClosed()) { + System.out.println("splashFrame still running"); + try { + Constant.Runtime.GameType[0] = Constant.GameType.Constructed; + SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/7/11 1:07 PM: this isn't a web app + public void run() { + AllZone.setComputer(new ComputerAI_Input(new ComputerAI_General())); + + // Enable only one of the following two lines. The second + // is useful for debugging. + + splashFrame.dispose(); + //splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + + splashFrame = null; + new OldGuiNewGame(); + } + }); + } catch (Exception ex) { + ErrorViewer.showError(ex); + } + } // End if(splashHasBeenClosed) - } + } // End ApplicationView() } diff --git a/src/main/java/forge/view/swing/SplashFrame.java b/src/main/java/forge/view/swing/SplashFrame.java index 90229e460e0..26561ec0331 100644 --- a/src/main/java/forge/view/swing/SplashFrame.java +++ b/src/main/java/forge/view/swing/SplashFrame.java @@ -42,6 +42,8 @@ public class SplashFrame extends JFrame { private SplashProgressModel monitorModel = null; private SplashProgressComponent monitorView = null; + + private boolean SplashHasBeenClosed = false; /** *

Create the frame; this must be called from an event @@ -102,6 +104,7 @@ public class SplashFrame extends JFrame { @Override public void actionPerformed(ActionEvent ae) { + setSplashHasBeenClosed(true); dispose(); } }); @@ -155,10 +158,26 @@ public class SplashFrame extends JFrame { /** * Getter for progress monitor model. - * @return the BaseProgressMonitor model used in the splash frame. + * @return the BraidsProgressMonitor model used in the splash frame. */ public final BraidsProgressMonitor getMonitorModel() { return monitorModel; } + + /** + * Returns state of splash frame, to determine if GUI should continue loading. + * @return SplashHasBeenClosed boolean. + */ + public final boolean getSplashHasBeenClosed() { + return SplashHasBeenClosed; + } + + /** + * Sets state of splash frame, to determine if GUI should continue loading. + * @param SplashHasBeenClosed boolean. + */ + public final void setSplashHasBeenClosed(boolean neoState) { + SplashHasBeenClosed = neoState; + } }