mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
- Issue 106: Continue refactoring code from Gui_NewGame to other classes.
* Moved most of forge.view.swing.Main.main's code into forge.model.FModel and forge.view.swing.ApplicationView. * Tested and seems to work OK. * Reduced Checkstyle, FindBugs, and PMD output in all changed files.
This commit is contained in:
@@ -7,6 +7,8 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.HttpUtil;
|
||||
import forge.properties.ForgePreferences;
|
||||
|
||||
//import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
|
||||
@@ -67,7 +69,19 @@ public class FModel {
|
||||
try {
|
||||
setPreferences(new ForgePreferences("forge.preferences"));
|
||||
} catch (Exception exn) {
|
||||
throw new RuntimeException(exn);
|
||||
throw new RuntimeException(exn); // NOPMD by Braids on 8/13/11 8:21 PM
|
||||
}
|
||||
|
||||
Constant.Runtime.Mill[0] = preferences.millingLossCondition;
|
||||
Constant.Runtime.DevMode[0] = preferences.developerMode;
|
||||
Constant.Runtime.UpldDrft[0] = preferences.uploadDraftAI;
|
||||
Constant.Runtime.RndCFoil[0] = preferences.randCFoil;
|
||||
|
||||
final HttpUtil pinger = new HttpUtil();
|
||||
if (pinger.getURL("http://cardforge.org/draftAI/ping.php").equals("pong")) {
|
||||
Constant.Runtime.NetConn[0] = true;
|
||||
} else {
|
||||
Constant.Runtime.UpldDrft[0] = false;
|
||||
}
|
||||
|
||||
setBuildInfo(new BuildInfo());
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
package forge.view;
|
||||
|
||||
import forge.model.FModel;
|
||||
|
||||
/**
|
||||
* Generic view (as in model-view-controller) interface for Forge.
|
||||
*/
|
||||
public interface 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
|
||||
*/
|
||||
void setModel(FModel model);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
package forge.view.swing;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.ComputerAI_General;
|
||||
import forge.ComputerAI_Input;
|
||||
import forge.Constant;
|
||||
import forge.ImageCache;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.view.FView;
|
||||
import forge.view.swing.OldGuiNewGame.CardSizesAction;
|
||||
import forge.view.swing.OldGuiNewGame.CardStackAction;
|
||||
import forge.view.swing.OldGuiNewGame.CardStackOffsetAction;
|
||||
|
||||
/**
|
||||
* The main view for Forge: a java swing application.
|
||||
@@ -10,6 +26,65 @@ public class ApplicationView implements FView {
|
||||
* Constructor.
|
||||
*/
|
||||
public ApplicationView() { // NOPMD by Braids on 8/7/11 1:14 PM: Damnation if it's here; Damnation if it's not.
|
||||
// blank for now.
|
||||
// TODO: insert splash window here
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.view.FView#setModel(forge.model.FModel)
|
||||
*/
|
||||
@Override
|
||||
public final void setModel(final FModel model) {
|
||||
try {
|
||||
|
||||
final ForgePreferences preferences = model.getPreferences();
|
||||
|
||||
OldGuiNewGame.useLAFFonts.setSelected(preferences.lafFonts);
|
||||
// newGuiCheckBox.setSelected(preferences.newGui);
|
||||
OldGuiNewGame.smoothLandCheckBox.setSelected(preferences.stackAiLand);
|
||||
OldGuiNewGame.devModeCheckBox.setSelected(preferences.developerMode);
|
||||
OldGuiNewGame.cardOverlay.setSelected(preferences.cardOverlay);
|
||||
ImageCache.scaleLargerThanOriginal = preferences.scaleLargerThanOriginal;
|
||||
OldGuiNewGame.cardScale.setSelected(preferences.scaleLargerThanOriginal);
|
||||
CardStackOffsetAction.set(preferences.stackOffset);
|
||||
CardStackAction.setVal(preferences.maxStackSize);
|
||||
CardSizesAction.set(preferences.cardSize);
|
||||
OldGuiNewGame.upldDrftCheckBox.setSelected(preferences.uploadDraftAI);
|
||||
OldGuiNewGame.foilRandomCheckBox.setSelected(preferences.randCFoil);
|
||||
|
||||
} catch (Exception exn) {
|
||||
Log.error("Error loading preferences: " + exn);
|
||||
}
|
||||
|
||||
OldGuiNewGame.loadDynamicGamedata();
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/7/11 1:07 PM: this isn't a web app
|
||||
public void run() {
|
||||
final ForgePreferences finalPreferences = model.getPreferences();
|
||||
|
||||
try {
|
||||
if ("".equals(finalPreferences.laf)) {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} else {
|
||||
UIManager.setLookAndFeel(finalPreferences.laf);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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()));
|
||||
new OldGuiNewGame();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,10 @@
|
||||
package forge.view.swing;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.ComputerAI_General;
|
||||
import forge.ComputerAI_Input;
|
||||
import forge.Constant;
|
||||
import forge.HttpUtil;
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.error.ExceptionHandler;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.view.FView;
|
||||
import forge.view.swing.OldGuiNewGame.CardSizesAction;
|
||||
import forge.view.swing.OldGuiNewGame.CardStackAction;
|
||||
import forge.view.swing.OldGuiNewGame.CardStackOffsetAction;
|
||||
|
||||
/**
|
||||
* Main class for Forge's swing application view.
|
||||
@@ -42,74 +27,12 @@ public final class Main {
|
||||
public static void main(final String[] args) {
|
||||
ExceptionHandler.registerErrorHandling();
|
||||
try {
|
||||
final FModel model = new FModel(null);
|
||||
Singletons.setModel(model);
|
||||
final FView view = new ApplicationView();
|
||||
Singletons.setView(view);
|
||||
final FModel model = new FModel(null);
|
||||
Singletons.setModel(model);
|
||||
|
||||
ForgePreferences preferences = null;
|
||||
|
||||
try {
|
||||
|
||||
preferences = model.getPreferences();
|
||||
|
||||
OldGuiNewGame.useLAFFonts.setSelected(preferences.lafFonts);
|
||||
// newGuiCheckBox.setSelected(preferences.newGui);
|
||||
OldGuiNewGame.smoothLandCheckBox.setSelected(preferences.stackAiLand);
|
||||
Constant.Runtime.Mill[0] = preferences.millingLossCondition;
|
||||
Constant.Runtime.DevMode[0] = preferences.developerMode;
|
||||
OldGuiNewGame.devModeCheckBox.setSelected(preferences.developerMode);
|
||||
OldGuiNewGame.cardOverlay.setSelected(preferences.cardOverlay);
|
||||
ImageCache.scaleLargerThanOriginal = preferences.scaleLargerThanOriginal;
|
||||
OldGuiNewGame.cardScale.setSelected(preferences.scaleLargerThanOriginal);
|
||||
CardStackOffsetAction.set(preferences.stackOffset);
|
||||
CardStackAction.setVal(preferences.maxStackSize);
|
||||
CardSizesAction.set(preferences.cardSize);
|
||||
Constant.Runtime.UpldDrft[0] = preferences.uploadDraftAI;
|
||||
OldGuiNewGame.upldDrftCheckBox.setSelected(preferences.uploadDraftAI);
|
||||
Constant.Runtime.RndCFoil[0] = preferences.randCFoil;
|
||||
OldGuiNewGame.foilRandomCheckBox.setSelected(preferences.randCFoil);
|
||||
|
||||
final HttpUtil pinger = new HttpUtil();
|
||||
if (pinger.getURL("http://cardforge.org/draftAI/ping.php").equals("pong")) {
|
||||
Constant.Runtime.NetConn[0] = true;
|
||||
} else {
|
||||
Constant.Runtime.UpldDrft[0] = false;
|
||||
}
|
||||
|
||||
} catch (Exception exn) {
|
||||
Log.error("Error loading preferences: " + exn);
|
||||
}
|
||||
|
||||
OldGuiNewGame.loadDynamicGamedata();
|
||||
|
||||
final ForgePreferences finalPreferences = preferences;
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/7/11 1:07 PM: this isn't a web app
|
||||
public void run() {
|
||||
try {
|
||||
if ("".equals(finalPreferences.laf)) {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} else {
|
||||
UIManager.setLookAndFeel(finalPreferences.laf);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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()));
|
||||
new OldGuiNewGame();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
view.setModel(model);
|
||||
|
||||
}
|
||||
catch (Throwable exn) { // NOPMD by Braids on 8/7/11 1:07 PM: must catch all throwables here.
|
||||
|
||||
Reference in New Issue
Block a user