diff --git a/src/main/java/forge/GuiDisplay4.java b/src/main/java/forge/GuiDisplay4.java index aebf88a159a..1078c60f8ef 100644 --- a/src/main/java/forge/GuiDisplay4.java +++ b/src/main/java/forge/GuiDisplay4.java @@ -1175,7 +1175,7 @@ public class GuiDisplay4 extends JFrame implements CardContainer, Display, NewCo * @return a boolean. */ public boolean loadPrefs() { - ForgePreferences fp = OldGuiNewGame.preferences; + ForgePreferences fp = Singletons.getModel().getPreferences(); cbAIUpkeep.setSelected(fp.bAIUpkeep); cbAIDraw.setSelected(fp.bAIDraw); @@ -1201,7 +1201,7 @@ public class GuiDisplay4 extends JFrame implements CardContainer, Display, NewCo */ public boolean savePrefs() { Constant.Runtime.Mill[0] = canLoseByDecking.isSelected(); - ForgePreferences fp = OldGuiNewGame.preferences; + ForgePreferences fp = Singletons.getModel().getPreferences(); fp.bAIUpkeep = cbAIUpkeep.isSelected(); fp.bAIDraw = cbAIDraw.isSelected(); diff --git a/src/main/java/forge/Gui_NewGame.java b/src/main/java/forge/Gui_NewGame.java index 0a7e88d716a..c7a5718537f 100644 --- a/src/main/java/forge/Gui_NewGame.java +++ b/src/main/java/forge/Gui_NewGame.java @@ -2,8 +2,12 @@ package forge; /** * Contains a main delegate; this class used to be Forge's entry point. + * + * The class that used to be here is presently at + * {@link forge.view.swing.OldGuiNewGame}, which is slowly being refactored out + * of existence. */ -public class Gui_NewGame { +public final class Gui_NewGame { /** * Do not instantiate. @@ -14,12 +18,10 @@ public class Gui_NewGame { /** * This is a delegate. - * - * @deprecated use forge.view.swing.Main.main - * - * @see forge.view.swing.Main.main - * + * * @param args from the OS or command line + * + * @deprecated use {@link forge.view.swing.Main.main} */ public static void main(final String[] args) { forge.view.swing.Main.main(args); diff --git a/src/main/java/forge/model/FModel.java b/src/main/java/forge/model/FModel.java index ecfbca9b99b..050cd9ec018 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -7,6 +7,8 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import forge.properties.ForgePreferences; + //import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor; import arcane.util.MultiplexOutputStream; @@ -27,6 +29,7 @@ public class FModel { private final transient PrintStream oldSystemOut; private final transient PrintStream oldSystemErr; private BuildInfo buildInfo; + private ForgePreferences preferences; /** * Constructor. @@ -61,6 +64,12 @@ public class FModel { oldSystemErr = System.err; System.setErr(new PrintStream(new MultiplexOutputStream(System.err, logFileStream), true)); + try { + setPreferences(new ForgePreferences("forge.preferences")); + } catch (Exception exn) { + throw new RuntimeException(exn); + } + setBuildInfo(new BuildInfo()); } @@ -106,4 +115,19 @@ public class FModel { this.buildInfo = neoBuildInfo; } + /** + * @return the preferences + */ + public final ForgePreferences getPreferences() { + return preferences; + } + + /** + * @param neoPreferences the preferences to set + */ + public final void setPreferences(final ForgePreferences neoPreferences) { + this.preferences = neoPreferences; + } + + } diff --git a/src/main/java/forge/view/swing/Main.java b/src/main/java/forge/view/swing/Main.java index 885c12aa118..f7fbb01715c 100644 --- a/src/main/java/forge/view/swing/Main.java +++ b/src/main/java/forge/view/swing/Main.java @@ -50,8 +50,8 @@ public final class Main { ForgePreferences preferences = null; try { - OldGuiNewGame.preferences = new ForgePreferences("forge.preferences"); - preferences = OldGuiNewGame.preferences; + + preferences = model.getPreferences(); OldGuiNewGame.useLAFFonts.setSelected(preferences.lafFonts); // newGuiCheckBox.setSelected(preferences.newGui); @@ -77,8 +77,8 @@ public final class Main { Constant.Runtime.UpldDrft[0] = false; } - } catch (Exception e) { - Log.error("Error loading preferences"); + } catch (Exception exn) { + Log.error("Error loading preferences: " + exn); } OldGuiNewGame.loadDynamicGamedata(); diff --git a/src/main/java/forge/view/swing/OldGuiNewGame.java b/src/main/java/forge/view/swing/OldGuiNewGame.java index ec73aed9560..d414d74b6c8 100644 --- a/src/main/java/forge/view/swing/OldGuiNewGame.java +++ b/src/main/java/forge/view/swing/OldGuiNewGame.java @@ -65,6 +65,7 @@ import forge.ImageCache; import forge.MyRandom; import forge.PlayerType; import forge.SealedDeck; +import forge.Singletons; import forge.deck.Deck; import forge.deck.DeckManager; import forge.deck.generate.Generate2ColorDeck; @@ -168,9 +169,6 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. private final Action DNLD_PRICES_ACTION = new DownloadPriceAction(); private final Action BUGZ_REPORTER_ACTION = new BugzReporterAction(); - /** Constant preferences. */ - public static ForgePreferences preferences; - /** *

* Constructor for OldGuiNewGame. @@ -528,7 +526,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. devModeCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final ActionEvent e) { Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected(); - preferences.developerMode = Constant.Runtime.DevMode[0]; + Singletons.getModel().getPreferences().developerMode = Constant.Runtime.DevMode[0]; } }); @@ -540,7 +538,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. upldDrftCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final ActionEvent e) { Constant.Runtime.UpldDrft[0] = upldDrftCheckBox.isSelected(); - preferences.uploadDraftAI = Constant.Runtime.UpldDrft[0]; + Singletons.getModel().getPreferences().uploadDraftAI = Constant.Runtime.UpldDrft[0]; } }); @@ -549,7 +547,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. foilRandomCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final ActionEvent e) { Constant.Runtime.RndCFoil[0] = foilRandomCheckBox.isSelected(); - preferences.randCFoil = Constant.Runtime.RndCFoil[0]; + Singletons.getModel().getPreferences().randCFoil = Constant.Runtime.RndCFoil[0]; } }); @@ -1321,7 +1319,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. return; } // UIManager.setLookAndFeel(info[index].getClassName()); - preferences.laf = LAFMap.get(name); + Singletons.getModel().getPreferences().laf = LAFMap.get(name); UIManager.setLookAndFeel(LAFMap.get(name)); SwingUtilities.updateComponentTreeUI(c); @@ -1512,7 +1510,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. * @param index */ public static void set(final int index) { - preferences.cardSize = CardSizeType.valueOf(keys[index].toLowerCase()); + Singletons.getModel().getPreferences().cardSize = CardSizeType.valueOf(keys[index].toLowerCase()); Constant.Runtime.width[0] = widths[index]; Constant.Runtime.height[0] = heights[index]; } @@ -1522,7 +1520,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. * @param s */ public static void set(final CardSizeType s) { - preferences.cardSize = s; + Singletons.getModel().getPreferences().cardSize = s; int index = 0; for (String str : keys) { if (str.toLowerCase().equals(s.toString())) { @@ -1580,7 +1578,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. * @param index */ public static void set(final int index) { - preferences.maxStackSize = values[index]; + Singletons.getModel().getPreferences().maxStackSize = values[index]; Constant.Runtime.stackSize[0] = values[index]; } @@ -1589,7 +1587,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. * @param val */ public static void setVal(final int val) { - preferences.maxStackSize = val; + Singletons.getModel().getPreferences().maxStackSize = val; Constant.Runtime.stackSize[0] = val; } } @@ -1636,7 +1634,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. * @param index */ public static void set(final int index) { - preferences.stackOffset = StackOffsetType.valueOf(keys[index].toLowerCase()); + Singletons.getModel().getPreferences().stackOffset = StackOffsetType.valueOf(keys[index].toLowerCase()); Constant.Runtime.stackOffset[0] = offsets[index]; } @@ -1645,7 +1643,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. * @param s */ public static void set(final StackOffsetType s) { - preferences.stackOffset = s; + Singletons.getModel().getPreferences().stackOffset = s; int index = 0; for (String str : keys) { if (str.toLowerCase().equals(s.toString())) { @@ -1742,6 +1740,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants. */ public final boolean exit() { try { + ForgePreferences preferences = Singletons.getModel().getPreferences(); preferences.laf = UIManager.getLookAndFeel().getClass().getName(); preferences.lafFonts = useLAFFonts.isSelected(); // preferences.newGui = newGuiCheckBox.isSelected(); diff --git a/src/test/java/forge/model/FModelTest.java b/src/test/java/forge/model/FModelTest.java index 6d9a83302c7..ec038ba7928 100644 --- a/src/test/java/forge/model/FModelTest.java +++ b/src/test/java/forge/model/FModelTest.java @@ -7,6 +7,8 @@ import java.io.FileNotFoundException; import org.testng.annotations.Test; +import forge.properties.ForgePreferences; + /** * Tests FModel. */ @@ -55,4 +57,19 @@ public class FModelTest { model.close(); } + + /** + * Test getPreferences. + * @throws FileNotFoundException indirectly + */ + @Test + public final void test_getPreferences() throws FileNotFoundException { + final FModel model = new FModel(null); + try { + ForgePreferences prefs = model.getPreferences(); + assertNotNull(prefs, "prefs instance is not null"); + } finally { + model.close(); + } + } }