diff --git a/src/main/java/forge/model/FModel.java b/src/main/java/forge/model/FModel.java index c1e2294c641..384cf78124b 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -28,6 +28,7 @@ import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor; import arcane.util.MultiplexOutputStream; import forge.Constant; import forge.HttpUtil; +import forge.ImageCache; import forge.properties.ForgePreferences; import forge.properties.ForgeProps; import forge.properties.NewConstants; @@ -64,13 +65,7 @@ public class FModel { * if we could not find or write to the log file. */ public FModel(final BraidsProgressMonitor theMonitor) throws FileNotFoundException { - /* - * To be implemented later. -Braids BraidsProgressMonitor monitor; if - * (theMonitor == null) { monitor = new - * BaseProgressMonitor(NUM_INIT_PHASES, 1); } else { monitor = - * theMonitor; } - */ - + // Fire up log file final File logFile = new File("forge.log"); final boolean deleteSucceeded = logFile.delete(); @@ -85,18 +80,25 @@ public class FModel { this.oldSystemErr = System.err; System.setErr(new PrintStream(new MultiplexOutputStream(System.err, this.logFileStream), true)); + // Instantiate preferences try { this.setPreferences(new ForgePreferences("forge.preferences")); } catch (final Exception exn) { - throw new RuntimeException(exn); // NOPMD by Braids on 8/13/11 8:21 - // PM + // NOPMD by Braids on 8/13/11 8:21 PM + // Log.error("Error loading preferences: " + exn); + throw new RuntimeException(exn); } + // TODO these should be set along with others all at the same time, not here Constant.Runtime.MILL[0] = this.preferences.isMillingLossCondition(); Constant.Runtime.DEV_MODE[0] = this.preferences.isDeveloperMode(); Constant.Runtime.UPLOAD_DRAFT[0] = this.preferences.isUploadDraftAI(); Constant.Runtime.RANDOM_FOIL[0] = this.preferences.isRandCFoil(); + ImageCache.setScaleLargerThanOriginal(preferences.isScaleLargerThanOriginal()); + ///////// + // Instantiate pinger + // TODO is this in the right place? final HttpUtil pinger = new HttpUtil(); String url = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/draftAI/ping.php"; if (pinger.getURL(url).equals("pong")) { diff --git a/src/main/java/forge/view/FView.java b/src/main/java/forge/view/FView.java index a0bf0cd138b..abe000cc055 100644 --- a/src/main/java/forge/view/FView.java +++ b/src/main/java/forge/view/FView.java @@ -17,24 +17,18 @@ */ package forge.view; -import javax.swing.JFrame; import javax.swing.SwingUtilities; import net.slightlymagic.braids.util.UtilFunctions; import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor; -import com.esotericsoftware.minlog.Log; - import forge.AllZone; import forge.ComputerAIGeneral; import forge.ComputerAIInput; import forge.Constant; -import forge.ImageCache; import forge.control.ControlAllUI; import forge.error.ErrorViewer; import forge.game.GameType; -import forge.model.FModel; -import forge.properties.ForgePreferences; import forge.view.home.SplashFrame; import forge.view.toolbox.CardFaceSymbols; import forge.view.toolbox.FSkin; @@ -58,29 +52,20 @@ public class FView { this.skin = skin0; // We must use invokeAndWait here to fulfill the constructor's - // contract. - - UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() { // NOPMD - // by - // Braids - // on - // 8/18/11 - // 11:37 - // PM - @Override - public void run() { - FView.this.splashFrame = new SplashFrame(skin); - } - }); - - SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on - // 8/18/11 11:37 PM - @Override - public void run() { - FView.this.splashFrame.setVisible(true); - } - }); - + // contract. NOPMD by Braids on 8/18/11 11:37 PM + UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() { + @Override + public void run() { + FView.this.splashFrame = new SplashFrame(skin); + } + }); + // NOPMD by Braids on 8/18/11 11:37 PM + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + FView.this.splashFrame.setVisible(true); + } + }); } /** @@ -113,22 +98,8 @@ public class FView { /** * Tell the view that the model has been bootstrapped, and its data is ready * for initial display. - * - * @param model - * the model that has finished bootstrapping */ - public final void setModel(final FModel model) { - try { - - final ForgePreferences preferences = model.getPreferences(); - - // FindBugs doesn't like the next line. - ImageCache.setScaleLargerThanOriginal(preferences.isScaleLargerThanOriginal()); - - } catch (final Exception exn) { - Log.error("Error loading preferences: " + exn); - } - + public final void initialize() { // For the following two blocks, check if user has cancelled // SplashFrame. // Note: Error thrown sometimes because log file cannot be accessed @@ -138,35 +109,33 @@ public class FView { if (!this.splashFrame.getSplashHasBeenClosed()) { try { - CardFaceSymbols.loadImages(); + // NOPMD by Braids on 8/7/11 1:07 + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral())); + skin.loadFontAndImages(); - Constant.Runtime.setGameType(GameType.Constructed); - SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids - // on 8/7/11 1:07 - // PM: this isn't a - // web app - @Override - public void run() { - AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral())); + CardFaceSymbols.loadImages(); - // Enable only one of the following two lines. - // The second - // is useful for debugging. + Constant.Runtime.setGameType(GameType.Constructed); - FView.this.splashFrame.dispose(); - // splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + GuiTopLevel g = new GuiTopLevel(); + AllZone.setDisplay(g); + g.getController().changeState(ControlAllUI.HOME_SCREEN); + g.pack(); + g.setVisible(true); - FView.this.splashFrame = null; - skin.loadFontAndImages(); - GuiTopLevel g = new GuiTopLevel(); - g.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - AllZone.setDisplay(g); - g.getController().changeState(ControlAllUI.HOME_SCREEN); - } - }); + FView.this.splashFrame.dispose(); + // Enable only one of the following two lines. + // The second is useful for debugging. + FView.this.splashFrame = null; + // FView.this.splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + } + }); } catch (final Exception ex) { ErrorViewer.showError(ex); } - } // End if(splashHasBeenClosed) + } // End if(splashHasBeenClosed) */ } // End FView() } diff --git a/src/main/java/forge/view/GuiTopLevel.java b/src/main/java/forge/view/GuiTopLevel.java index 25df10e4eb6..d62f407309d 100644 --- a/src/main/java/forge/view/GuiTopLevel.java +++ b/src/main/java/forge/view/GuiTopLevel.java @@ -65,10 +65,9 @@ public class GuiTopLevel extends JFrame implements Display, CardContainer { this.lpnContent.setOpaque(true); this.setContentPane(this.lpnContent); this.addOverlay(); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/images/symbols-13/favicon.png")); - this.setTitle("Forge"); - - this.setVisible(true); + this.setTitle("Forge: " + Singletons.getModel().getBuildInfo().getVersion()); // Init controller this.control = new ControlAllUI(this); diff --git a/src/main/java/forge/view/Main.java b/src/main/java/forge/view/Main.java index b38b28cd523..730628e803a 100644 --- a/src/main/java/forge/view/Main.java +++ b/src/main/java/forge/view/Main.java @@ -50,10 +50,10 @@ public final class Main { ExceptionHandler.registerErrorHandling(); try { final FModel model = new FModel(null); - Singletons.setModel(model); - - final FSkin skin = new FSkin(Singletons.getModel().getPreferences().getSkin()); + final FSkin skin = new FSkin(model.getPreferences().getSkin()); final FView view = new FView(skin); + + Singletons.setModel(model); Singletons.setView(view); // Need this soon after card factory is loaded @@ -63,11 +63,9 @@ public final class Main { // game. // It is only here to maintain semantic equality with the current // code base. - model.resetGameState(); - view.setModel(model); - + view.initialize(); } catch (final Throwable exn) { ErrorViewer.showError(exn); } diff --git a/src/main/java/forge/view/home/SplashFrame.java b/src/main/java/forge/view/home/SplashFrame.java index fa0f1811e61..08e79276d6e 100644 --- a/src/main/java/forge/view/home/SplashFrame.java +++ b/src/main/java/forge/view/home/SplashFrame.java @@ -20,6 +20,7 @@ package forge.view.home; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; +import java.awt.Toolkit; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; @@ -94,6 +95,8 @@ public class SplashFrame extends JFrame { this.setLocationRelativeTo(null); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/images/symbols-13/favicon.png")); + this.setTitle("Loading Forge..."); // Insert JPanel to hold content above background final JPanel contentPane = new JPanel();