Moved the "forge.view.swing" package into "forge.view".

This commit is contained in:
Doublestrike
2012-01-17 10:47:10 +00:00
parent f7dc3eac58
commit 00766363f9
7 changed files with 326 additions and 378 deletions

4
.gitattributes vendored
View File

@@ -11065,6 +11065,7 @@ src/main/java/forge/quest/gui/package-info.java svneol=native#text/plain
src/main/java/forge/quest/package-info.java svneol=native#text/plain
src/main/java/forge/view/FView.java svneol=native#text/plain
src/main/java/forge/view/GuiTopLevel.java -text
src/main/java/forge/view/Main.java -text
src/main/java/forge/view/editor/EditorTopLevel.java -text
src/main/java/forge/view/editor/package-info.java svneol=native#text/plain
src/main/java/forge/view/home/HomeTopLevel.java -text
@@ -11092,9 +11093,6 @@ src/main/java/forge/view/match/ViewTopLevel.java -text
src/main/java/forge/view/match/ViewWinLose.java -text
src/main/java/forge/view/match/package-info.java svneol=native#text/plain
src/main/java/forge/view/package-info.java svneol=native#text/plain
src/main/java/forge/view/swing/ApplicationView.java svneol=native#text/plain
src/main/java/forge/view/swing/Main.java svneol=native#text/plain
src/main/java/forge/view/swing/package-info.java svneol=native#text/plain
src/main/java/forge/view/toolbox/CardFaceSymbols.java svneol=native#text/plain
src/main/java/forge/view/toolbox/CardViewer.java -text
src/main/java/forge/view/toolbox/DeckLister.java -text

View File

@@ -246,7 +246,7 @@
</descriptorRefs>
<archive>
<manifest>
<mainClass>forge.view.swing.Main</mainClass>
<mainClass>forge.view.Main</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
@@ -842,7 +842,7 @@
<errTitle>forge</errTitle>
<icon>${configSourceDirectory}/forge.ico</icon>
<classPath>
<mainClass>forge.view.swing.Main</mainClass>
<mainClass>forge.view.Main</mainClass>
<addDependencies>false</addDependencies>
<preCp>anything</preCp>
</classPath>
@@ -1012,7 +1012,7 @@
<mkdir dir="${project.build.directory}/res/cardsfolder" />
<zip destfile="${project.build.directory}/res/cardsfolder/cardsfolder.zip" basedir="${basedir}/res/cardsfolder" level="1" />
<taskdef name="jarbundler" classpathref="maven.runtime.classpath" classname="net.sourceforge.jarbundler.JarBundler" />
<jarbundler dir="${project.build.directory}/${project.build.finalName}-osx" name="${project.name}" version="${project.version}" mainclass="forge.view.swing.Main" icon="${basedir}/${configSourceDirectory}/Forge.icns" jvmversion="1.6+" vmoptions="-Xmx1024m" shortname="${project.name}" workingdirectory="$APP_PACKAGE/Contents/Resources/Java" jar="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar">
<jarbundler dir="${project.build.directory}/${project.build.finalName}-osx" name="${project.name}" version="${project.version}" mainclass="forge.view.Main" icon="${basedir}/${configSourceDirectory}/Forge.icns" jvmversion="1.6+" vmoptions="-Xmx1024m" shortname="${project.name}" workingdirectory="$APP_PACKAGE/Contents/Resources/Java" jar="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar">
<javafileset dir="${basedir}">
<include name="*.properties" />
<include name="res/**" />

View File

@@ -17,13 +17,86 @@
*/
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;
/**
* Generic view (as in model-view-controller) interface for Forge.
* The main view for Forge: a java swing application. All view class instances
* should be accessible from here.
*/
public interface FView {
public class FView {
private transient SplashFrame splashFrame;
/**
* The splashFrame field is guaranteed to exist when this constructor exits.
*
* @param skin
* the skin
*/
public FView(final FSkin skin) {
// 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);
}
});
}
/**
* Get the progress monitor for loading all cards at once.
*
* @return a progress monitor having only one phase; may be null
*/
public final BraidsProgressMonitor getCardLoadingProgressMonitor() {
BraidsProgressMonitor result;
if (this.splashFrame == null) {
result = null;
} else {
result = this.splashFrame.getMonitorModel();
}
return result;
}
/**
* Tell the view that the model has been bootstrapped, and its data is ready
@@ -32,12 +105,57 @@ public interface FView {
* @param model
* the model that has finished bootstrapping
*/
void setModel(FModel model);
public final void setModel(final FModel model) {
try {
/**
* Get the progress monitor for loading all cards at once.
*
* @return a progress monitor having only one phase; may be null
*/
BraidsProgressMonitor getCardLoadingProgressMonitor();
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);
}
// For the following two blocks, check if user has cancelled
// SplashFrame.
// Note: Error thrown sometimes because log file cannot be accessed
if (!this.splashFrame.getSplashHasBeenClosed()) {
AllZone.getCardFactory(); // forces preloading of all cards
}
if (!this.splashFrame.getSplashHasBeenClosed()) {
try {
CardFaceSymbols.loadImages();
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()));
// Enable only one of the following two lines.
// The second
// is useful for debugging.
FView.this.splashFrame.dispose();
// splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
FView.this.splashFrame = null;
AllZone.getSkin().loadFontAndImages();
GuiTopLevel g = new GuiTopLevel();
g.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
AllZone.setDisplay(g);
g.getController().changeState(ControlAllUI.HOME_SCREEN);
}
});
} catch (final Exception ex) {
ErrorViewer.showError(ex);
}
} // End if(splashHasBeenClosed)
} // End FView()
}

View File

@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.view.swing;
package forge.view;
import java.util.ArrayList;
@@ -27,7 +27,6 @@ import forge.Singletons;
import forge.error.ErrorViewer;
import forge.error.ExceptionHandler;
import forge.model.FModel;
import forge.view.FView;
import forge.view.toolbox.FSkin;
/**
@@ -54,8 +53,8 @@ public final class Main {
final FModel model = new FModel(null);
Singletons.setModel(model);
final FSkin skin = new FSkin(model.getPreferences().getSkin());
final FView view = new ApplicationView(skin);
final FSkin skin = new FSkin(Singletons.getModel().getPreferences().getSkin());
final FView view = new FView(skin);
Singletons.setView(view);
AllZone.setSkin(skin);

View File

@@ -1,164 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.view.swing;
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.FView;
import forge.view.GuiTopLevel;
import forge.view.home.SplashFrame;
import forge.view.toolbox.CardFaceSymbols;
import forge.view.toolbox.FSkin;
/**
* The main view for Forge: a java swing application. All view class instances
* should be accessible from here.
*/
public class ApplicationView implements FView {
private transient SplashFrame splashFrame;
/**
* The splashFrame field is guaranteed to exist when this constructor exits.
*
* @param skin
* the skin
*/
public ApplicationView(final FSkin skin) {
// 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() {
ApplicationView.this.splashFrame = new SplashFrame(skin);
}
});
SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on
// 8/18/11 11:37 PM
@Override
public void run() {
ApplicationView.this.splashFrame.setVisible(true);
}
});
}
/*
* (non-Javadoc)
*
* @see forge.view.FView#getCardLoadingProgressMonitor()
*/
@Override
public final BraidsProgressMonitor getCardLoadingProgressMonitor() {
BraidsProgressMonitor result;
if (this.splashFrame == null) {
result = null;
} else {
result = this.splashFrame.getMonitorModel();
}
return result;
}
/*
* (non-Javadoc)
*
* @see forge.view.FView#setModel(forge.model.FModel)
*/
@Override
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);
}
// For the following two blocks, check if user has cancelled
// SplashFrame.
// Note: Error thrown sometimes because log file cannot be accessed
if (!this.splashFrame.getSplashHasBeenClosed()) {
AllZone.getCardFactory(); // forces preloading of all cards
}
if (!this.splashFrame.getSplashHasBeenClosed()) {
try {
CardFaceSymbols.loadImages();
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()));
// Enable only one of the following two lines.
// The second
// is useful for debugging.
ApplicationView.this.splashFrame.dispose();
// splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
ApplicationView.this.splashFrame = null;
AllZone.getSkin().loadFontAndImages();
GuiTopLevel g = new GuiTopLevel();
g.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
AllZone.setDisplay(g);
g.getController().changeState(ControlAllUI.HOME_SCREEN);
}
});
} catch (final Exception ex) {
ErrorViewer.showError(ex);
}
} // End if(splashHasBeenClosed)
} // End ApplicationView()
}

View File

@@ -1,3 +0,0 @@
/** Primary swing implementation for Forge's View (as in model-view-controller). */
package forge.view.swing;

View File

@@ -17,7 +17,7 @@ import forge.card.cardfactory.LazyCardFactory;
import forge.card.cardfactory.PreloadingCardFactory;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.view.swing.Main;
import forge.view.Main;
//import net.slightlymagic.braids.testng.BraidsAssertFunctions;