- Issue 106: Refactor Gui_NewGame. Moved preferences to FModel.

* Updated former references to preferences to use FModel in forge.GuiDisplay4 and in forge.view.swing.OldGuiNewGame.
* Added simple unit test.

Bug: 106
This commit is contained in:
Braids
2011-08-13 02:38:01 +00:00
parent e6032d1825
commit 5a3f6d312c
6 changed files with 67 additions and 25 deletions

View File

@@ -1175,7 +1175,7 @@ public class GuiDisplay4 extends JFrame implements CardContainer, Display, NewCo
* @return a boolean. * @return a boolean.
*/ */
public boolean loadPrefs() { public boolean loadPrefs() {
ForgePreferences fp = OldGuiNewGame.preferences; ForgePreferences fp = Singletons.getModel().getPreferences();
cbAIUpkeep.setSelected(fp.bAIUpkeep); cbAIUpkeep.setSelected(fp.bAIUpkeep);
cbAIDraw.setSelected(fp.bAIDraw); cbAIDraw.setSelected(fp.bAIDraw);
@@ -1201,7 +1201,7 @@ public class GuiDisplay4 extends JFrame implements CardContainer, Display, NewCo
*/ */
public boolean savePrefs() { public boolean savePrefs() {
Constant.Runtime.Mill[0] = canLoseByDecking.isSelected(); Constant.Runtime.Mill[0] = canLoseByDecking.isSelected();
ForgePreferences fp = OldGuiNewGame.preferences; ForgePreferences fp = Singletons.getModel().getPreferences();
fp.bAIUpkeep = cbAIUpkeep.isSelected(); fp.bAIUpkeep = cbAIUpkeep.isSelected();
fp.bAIDraw = cbAIDraw.isSelected(); fp.bAIDraw = cbAIDraw.isSelected();

View File

@@ -2,8 +2,12 @@ package forge;
/** /**
* Contains a main delegate; this class used to be Forge's entry point. * 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. * Do not instantiate.
@@ -15,11 +19,9 @@ public class Gui_NewGame {
/** /**
* This is a delegate. * 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 * @param args from the OS or command line
*
* @deprecated use {@link forge.view.swing.Main.main}
*/ */
public static void main(final String[] args) { public static void main(final String[] args) {
forge.view.swing.Main.main(args); forge.view.swing.Main.main(args);

View File

@@ -7,6 +7,8 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import forge.properties.ForgePreferences;
//import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; //import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor; import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
import arcane.util.MultiplexOutputStream; import arcane.util.MultiplexOutputStream;
@@ -27,6 +29,7 @@ public class FModel {
private final transient PrintStream oldSystemOut; private final transient PrintStream oldSystemOut;
private final transient PrintStream oldSystemErr; private final transient PrintStream oldSystemErr;
private BuildInfo buildInfo; private BuildInfo buildInfo;
private ForgePreferences preferences;
/** /**
* Constructor. * Constructor.
@@ -61,6 +64,12 @@ public class FModel {
oldSystemErr = System.err; oldSystemErr = System.err;
System.setErr(new PrintStream(new MultiplexOutputStream(System.err, logFileStream), true)); 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()); setBuildInfo(new BuildInfo());
} }
@@ -106,4 +115,19 @@ public class FModel {
this.buildInfo = neoBuildInfo; 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;
}
} }

View File

@@ -50,8 +50,8 @@ public final class Main {
ForgePreferences preferences = null; ForgePreferences preferences = null;
try { try {
OldGuiNewGame.preferences = new ForgePreferences("forge.preferences");
preferences = OldGuiNewGame.preferences; preferences = model.getPreferences();
OldGuiNewGame.useLAFFonts.setSelected(preferences.lafFonts); OldGuiNewGame.useLAFFonts.setSelected(preferences.lafFonts);
// newGuiCheckBox.setSelected(preferences.newGui); // newGuiCheckBox.setSelected(preferences.newGui);
@@ -77,8 +77,8 @@ public final class Main {
Constant.Runtime.UpldDrft[0] = false; Constant.Runtime.UpldDrft[0] = false;
} }
} catch (Exception e) { } catch (Exception exn) {
Log.error("Error loading preferences"); Log.error("Error loading preferences: " + exn);
} }
OldGuiNewGame.loadDynamicGamedata(); OldGuiNewGame.loadDynamicGamedata();

View File

@@ -65,6 +65,7 @@ import forge.ImageCache;
import forge.MyRandom; import forge.MyRandom;
import forge.PlayerType; import forge.PlayerType;
import forge.SealedDeck; import forge.SealedDeck;
import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
import forge.deck.DeckManager; import forge.deck.DeckManager;
import forge.deck.generate.Generate2ColorDeck; 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 DNLD_PRICES_ACTION = new DownloadPriceAction();
private final Action BUGZ_REPORTER_ACTION = new BugzReporterAction(); private final Action BUGZ_REPORTER_ACTION = new BugzReporterAction();
/** Constant <code>preferences</code>. */
public static ForgePreferences preferences;
/** /**
* <p> * <p>
* Constructor for OldGuiNewGame. * Constructor for OldGuiNewGame.
@@ -528,7 +526,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
devModeCheckBox.addActionListener(new java.awt.event.ActionListener() { devModeCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected(); 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() { upldDrftCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
Constant.Runtime.UpldDrft[0] = upldDrftCheckBox.isSelected(); 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() { foilRandomCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
Constant.Runtime.RndCFoil[0] = foilRandomCheckBox.isSelected(); 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; return;
} }
// UIManager.setLookAndFeel(info[index].getClassName()); // UIManager.setLookAndFeel(info[index].getClassName());
preferences.laf = LAFMap.get(name); Singletons.getModel().getPreferences().laf = LAFMap.get(name);
UIManager.setLookAndFeel(LAFMap.get(name)); UIManager.setLookAndFeel(LAFMap.get(name));
SwingUtilities.updateComponentTreeUI(c); SwingUtilities.updateComponentTreeUI(c);
@@ -1512,7 +1510,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
* @param index * @param index
*/ */
public static void set(final int 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.width[0] = widths[index];
Constant.Runtime.height[0] = heights[index]; Constant.Runtime.height[0] = heights[index];
} }
@@ -1522,7 +1520,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
* @param s * @param s
*/ */
public static void set(final CardSizeType s) { public static void set(final CardSizeType s) {
preferences.cardSize = s; Singletons.getModel().getPreferences().cardSize = s;
int index = 0; int index = 0;
for (String str : keys) { for (String str : keys) {
if (str.toLowerCase().equals(s.toString())) { if (str.toLowerCase().equals(s.toString())) {
@@ -1580,7 +1578,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
* @param index * @param index
*/ */
public static void set(final int index) { public static void set(final int index) {
preferences.maxStackSize = values[index]; Singletons.getModel().getPreferences().maxStackSize = values[index];
Constant.Runtime.stackSize[0] = values[index]; Constant.Runtime.stackSize[0] = values[index];
} }
@@ -1589,7 +1587,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
* @param val * @param val
*/ */
public static void setVal(final int val) { public static void setVal(final int val) {
preferences.maxStackSize = val; Singletons.getModel().getPreferences().maxStackSize = val;
Constant.Runtime.stackSize[0] = val; Constant.Runtime.stackSize[0] = val;
} }
} }
@@ -1636,7 +1634,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
* @param index * @param index
*/ */
public static void set(final int 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]; Constant.Runtime.stackOffset[0] = offsets[index];
} }
@@ -1645,7 +1643,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
* @param s * @param s
*/ */
public static void set(final StackOffsetType s) { public static void set(final StackOffsetType s) {
preferences.stackOffset = s; Singletons.getModel().getPreferences().stackOffset = s;
int index = 0; int index = 0;
for (String str : keys) { for (String str : keys) {
if (str.toLowerCase().equals(s.toString())) { if (str.toLowerCase().equals(s.toString())) {
@@ -1742,6 +1740,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
*/ */
public final boolean exit() { public final boolean exit() {
try { try {
ForgePreferences preferences = Singletons.getModel().getPreferences();
preferences.laf = UIManager.getLookAndFeel().getClass().getName(); preferences.laf = UIManager.getLookAndFeel().getClass().getName();
preferences.lafFonts = useLAFFonts.isSelected(); preferences.lafFonts = useLAFFonts.isSelected();
// preferences.newGui = newGuiCheckBox.isSelected(); // preferences.newGui = newGuiCheckBox.isSelected();

View File

@@ -7,6 +7,8 @@ import java.io.FileNotFoundException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import forge.properties.ForgePreferences;
/** /**
* Tests FModel. * Tests FModel.
*/ */
@@ -55,4 +57,19 @@ public class FModelTest {
model.close(); 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();
}
}
} }