mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Separated model/view for splash frame preloader using Braids' progress monitor heirarchy.
Possibly deprecated: forge/gui/MultiPhaseProgressMonitorWithETA Possibly deprecated: forge/gui_progressbarwindow
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -9862,6 +9862,8 @@ src/main/java/net/slightlymagic/braids/util/lambda/package-info.java svneol=nati
|
|||||||
src/main/java/net/slightlymagic/braids/util/package-info.java svneol=native#text/plain
|
src/main/java/net/slightlymagic/braids/util/package-info.java svneol=native#text/plain
|
||||||
src/main/java/net/slightlymagic/braids/util/progress_monitor/BaseProgressMonitor.java svneol=native#text/plain
|
src/main/java/net/slightlymagic/braids/util/progress_monitor/BaseProgressMonitor.java svneol=native#text/plain
|
||||||
src/main/java/net/slightlymagic/braids/util/progress_monitor/BraidsProgressMonitor.java svneol=native#text/plain
|
src/main/java/net/slightlymagic/braids/util/progress_monitor/BraidsProgressMonitor.java svneol=native#text/plain
|
||||||
|
src/main/java/net/slightlymagic/braids/util/progress_monitor/SplashModelProgressMonitor.java -text
|
||||||
|
src/main/java/net/slightlymagic/braids/util/progress_monitor/SplashViewProgressMonitor.java -text
|
||||||
src/main/java/net/slightlymagic/braids/util/progress_monitor/StderrProgressMonitor.java svneol=native#text/plain
|
src/main/java/net/slightlymagic/braids/util/progress_monitor/StderrProgressMonitor.java svneol=native#text/plain
|
||||||
src/main/java/net/slightlymagic/braids/util/progress_monitor/package-info.java svneol=native#text/plain
|
src/main/java/net/slightlymagic/braids/util/progress_monitor/package-info.java svneol=native#text/plain
|
||||||
src/main/java/net/slightlymagic/maxmtg/Predicate.java -text
|
src/main/java/net/slightlymagic/maxmtg/Predicate.java -text
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ import java.util.zip.ZipFile;
|
|||||||
import net.slightlymagic.braids.util.UtilFunctions;
|
import net.slightlymagic.braids.util.UtilFunctions;
|
||||||
import net.slightlymagic.braids.util.generator.FindNonDirectoriesSkipDotDirectoriesGenerator;
|
import net.slightlymagic.braids.util.generator.FindNonDirectoriesSkipDotDirectoriesGenerator;
|
||||||
import net.slightlymagic.braids.util.generator.GeneratorFunctions;
|
import net.slightlymagic.braids.util.generator.GeneratorFunctions;
|
||||||
import forge.view.util.ProgressBar_Base;
|
import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
|
||||||
|
import net.slightlymagic.braids.util.progress_monitor.StderrProgressMonitor;
|
||||||
|
|
||||||
import com.google.code.jyield.Generator;
|
import com.google.code.jyield.Generator;
|
||||||
import com.google.code.jyield.YieldUtils;
|
import com.google.code.jyield.YieldUtils;
|
||||||
@@ -184,16 +185,20 @@ public class CardReader
|
|||||||
protected final Card loadCardsUntilYouFind(final String cardName) {
|
protected final Card loadCardsUntilYouFind(final String cardName) {
|
||||||
Card result = null;
|
Card result = null;
|
||||||
|
|
||||||
ProgressBar_Base monitor = null;
|
// Try to retrieve card loading progress monitor model.
|
||||||
|
// If no progress monitor present, output results to console.
|
||||||
|
BaseProgressMonitor monitor = null;
|
||||||
final FView view = Singletons.getView();
|
final FView view = Singletons.getView();
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
monitor = view.getCardLoadingProgressMonitor();
|
monitor = view.getCardLoadingProgressMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (monitor == null) {
|
if (monitor == null) {
|
||||||
// monitor = new StderrProgressMonitor(1, 0L);
|
monitor = new StderrProgressMonitor(1, 0L);
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
// Iterate through txt files or zip archive.
|
||||||
|
// Report relevant numbers to progress monitor model.
|
||||||
if (zip == null) {
|
if (zip == null) {
|
||||||
if (estimatedFilesRemaining == UNKNOWN_NUMBER_OF_FILES_REMAINING) {
|
if (estimatedFilesRemaining == UNKNOWN_NUMBER_OF_FILES_REMAINING) {
|
||||||
final Generator<File> findNonDirsGen = new FindNonDirectoriesSkipDotDirectoriesGenerator(cardsfolder);
|
final Generator<File> findNonDirsGen = new FindNonDirectoriesSkipDotDirectoriesGenerator(cardsfolder);
|
||||||
@@ -241,10 +246,6 @@ public class CardReader
|
|||||||
|
|
||||||
} //endif
|
} //endif
|
||||||
|
|
||||||
if (monitor != null) {
|
|
||||||
monitor.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} //loadCardsUntilYouFind(String)
|
} //loadCardsUntilYouFind(String)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package forge.view;
|
package forge.view;
|
||||||
|
|
||||||
import forge.view.util.ProgressBar_Base;
|
import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,6 +21,5 @@ public interface FView {
|
|||||||
*
|
*
|
||||||
* @return a progress monitor having only one phase; may be null
|
* @return a progress monitor having only one phase; may be null
|
||||||
*/
|
*/
|
||||||
ProgressBar_Base getCardLoadingProgressMonitor();
|
BaseProgressMonitor getCardLoadingProgressMonitor();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package forge.view.swing;
|
package forge.view.swing;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
import net.slightlymagic.braids.util.UtilFunctions;
|
import net.slightlymagic.braids.util.UtilFunctions;
|
||||||
import forge.view.util.ProgressBar_Base;
|
import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
|
||||||
|
|
||||||
import com.esotericsoftware.minlog.Log;
|
import com.esotericsoftware.minlog.Log;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ import forge.view.swing.OldGuiNewGame.CardStackOffsetAction;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The main view for Forge: a java swing application.
|
* The main view for Forge: a java swing application.
|
||||||
|
* All view class instances should be accessible from here.
|
||||||
*/
|
*/
|
||||||
public class ApplicationView implements FView {
|
public class ApplicationView implements FView {
|
||||||
|
|
||||||
@@ -48,20 +50,21 @@ public class ApplicationView implements FView {
|
|||||||
splashFrame.setVisible(true);
|
splashFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.view.FView#getCardLoadingProgressMonitor()
|
* @see forge.view.FView#getCardLoadingProgressMonitor()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final ProgressBar_Base getCardLoadingProgressMonitor() {
|
public final BaseProgressMonitor getCardLoadingProgressMonitor() {
|
||||||
ProgressBar_Base result;
|
BaseProgressMonitor result;
|
||||||
|
|
||||||
if (splashFrame == null) {
|
if (splashFrame == null) {
|
||||||
result = null;
|
result = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = splashFrame.getBar();
|
result = splashFrame.getMonitorModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -70,6 +73,7 @@ public class ApplicationView implements FView {
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.view.FView#setModel(forge.model.FModel)
|
* @see forge.view.FView#setModel(forge.model.FModel)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setModel(final FModel model) {
|
public final void setModel(final FModel model) {
|
||||||
try {
|
try {
|
||||||
@@ -121,8 +125,6 @@ public class ApplicationView implements FView {
|
|||||||
public void run() {
|
public void run() {
|
||||||
AllZone.setComputer(new ComputerAI_Input(new ComputerAI_General()));
|
AllZone.setComputer(new ComputerAI_Input(new ComputerAI_General()));
|
||||||
|
|
||||||
getCardLoadingProgressMonitor().dispose();
|
|
||||||
|
|
||||||
// Enable only one of the following two lines. The second
|
// Enable only one of the following two lines. The second
|
||||||
// is useful for debugging.
|
// is useful for debugging.
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ import javax.swing.JLabel;
|
|||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import forge.view.util.ProgressBar_Embedded;
|
import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
|
||||||
|
import net.slightlymagic.braids.util.progress_monitor.SplashModelProgressMonitor;
|
||||||
|
import net.slightlymagic.braids.util.progress_monitor.SplashViewProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the splash frame as the application starts.
|
* Shows the splash frame as the application starts.
|
||||||
@@ -33,7 +34,8 @@ public class SplashFrame extends JFrame {
|
|||||||
private static final int DISCLAIMER_FONT_SIZE = 9;
|
private static final int DISCLAIMER_FONT_SIZE = 9;
|
||||||
private static final Color DISCLAIMER_COLOR = Color.white;
|
private static final Color DISCLAIMER_COLOR = Color.white;
|
||||||
|
|
||||||
private ProgressBar_Embedded bar;
|
private SplashModelProgressMonitor monitorModel = null;
|
||||||
|
private SplashViewProgressMonitor monitorView = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Create the frame; this <strong>must</strong> be called from an event
|
* <p>Create the frame; this <strong>must</strong> be called from an event
|
||||||
@@ -67,7 +69,7 @@ public class SplashFrame extends JFrame {
|
|||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
contentPane.setLayout(null);
|
contentPane.setLayout(null);
|
||||||
|
|
||||||
// Add disclaimer and progress bar.
|
// Add disclaimer
|
||||||
final JLabel lblDisclaimer = new JLabel("<html><center>Forge is not affiliated in any way with Wizards of the Coast.<br>Forge is open source software, released under the GNU Public License.</center></html>");
|
final JLabel lblDisclaimer = new JLabel("<html><center>Forge is not affiliated in any way with Wizards of the Coast.<br>Forge is open source software, released under the GNU Public License.</center></html>");
|
||||||
|
|
||||||
lblDisclaimer.setBounds(PADDING_X, DISCLAIMER_TOP_PX,
|
lblDisclaimer.setBounds(PADDING_X, DISCLAIMER_TOP_PX,
|
||||||
@@ -78,15 +80,19 @@ public class SplashFrame extends JFrame {
|
|||||||
lblDisclaimer.setForeground(DISCLAIMER_COLOR);
|
lblDisclaimer.setForeground(DISCLAIMER_COLOR);
|
||||||
contentPane.add(lblDisclaimer);
|
contentPane.add(lblDisclaimer);
|
||||||
|
|
||||||
bar = new ProgressBar_Embedded(1, 1);
|
// Instantiate model and view and tie together.
|
||||||
bar.setBounds(PADDING_X, splashHeightPx - PADDING_Y - BAR_HEIGHT_PX,
|
monitorModel = new SplashModelProgressMonitor(1);
|
||||||
|
monitorView = new SplashViewProgressMonitor();
|
||||||
|
|
||||||
|
monitorModel.setCurrentView(monitorView);
|
||||||
|
monitorView.setCurrentModel(monitorModel);
|
||||||
|
|
||||||
|
// Add prog bar + message, bg image
|
||||||
|
monitorView.displayUpdate("Assembling file list...");
|
||||||
|
monitorView.setBounds(PADDING_X, splashHeightPx - PADDING_Y - BAR_HEIGHT_PX,
|
||||||
splashWidthPx - (2 * PADDING_X), BAR_HEIGHT_PX);
|
splashWidthPx - (2 * PADDING_X), BAR_HEIGHT_PX);
|
||||||
|
contentPane.add(monitorView);
|
||||||
|
|
||||||
contentPane.add(bar);
|
|
||||||
|
|
||||||
bar.displayUpdate("Assembling file list...");
|
|
||||||
|
|
||||||
// Add background image and close button
|
|
||||||
contentPane.setOpaque(false);
|
contentPane.setOpaque(false);
|
||||||
final JLabel bgLabel = new JLabel(bgIcon);
|
final JLabel bgLabel = new JLabel(bgIcon);
|
||||||
|
|
||||||
@@ -100,18 +106,19 @@ public class SplashFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for progress bar.
|
* Getter for progress bar view.
|
||||||
* @return the ProgressBar_Embedded object used in the splash frame.
|
* @return the SplashViewProgressMonitor progress bar used in the splash frame.
|
||||||
*/
|
*/
|
||||||
public final ProgressBar_Embedded getBar() {
|
public final SplashViewProgressMonitor getMonitorView() {
|
||||||
return bar;
|
return monitorView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for progress bar.
|
* Getter for progress monitor model.
|
||||||
* @param neoBar the ProgressBar_Embedded used in the splash frame.
|
* @return the BaseProgressMonitor model used in the splash frame.
|
||||||
*/
|
*/
|
||||||
protected final void setBar(final ProgressBar_Embedded neoBar) {
|
public final BaseProgressMonitor getMonitorModel() {
|
||||||
this.bar = neoBar;
|
return monitorModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
|
|||||||
public final int SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
|
public final int SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
|
||||||
public final int SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
|
public final int SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience for
|
||||||
|
* BaseProgressMonitor(numPhases, 1, 2.0f, null).
|
||||||
|
*
|
||||||
|
* @see #BaseProgressMonitor(int,long,float,float[])
|
||||||
|
*/
|
||||||
|
public BaseProgressMonitor(int numPhases) {
|
||||||
|
this(numPhases, 1L, 2.0f, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience for
|
* Convenience for
|
||||||
@@ -286,6 +295,7 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
|
|||||||
this.unitsCompletedSoFarThisPhase += numUnits;
|
this.unitsCompletedSoFarThisPhase += numUnits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclasses must call this immediately after updating the UI, to
|
* Subclasses must call this immediately after updating the UI, to
|
||||||
* preserve the integrity of the shouldUpdateUI method.
|
* preserve the integrity of the shouldUpdateUI method.
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package net.slightlymagic.braids.util.progress_monitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SplashModelProgressMonitor extends BaseProgressMonitor {
|
||||||
|
|
||||||
|
private SplashViewProgressMonitor currentView = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for Constructor.
|
||||||
|
* @param numPhases
|
||||||
|
*/
|
||||||
|
public SplashModelProgressMonitor(int numPhases) {
|
||||||
|
super(numPhases);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
/**
|
||||||
|
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#incrementUnitsCompletedThisPhase(long)
|
||||||
|
*/
|
||||||
|
public void incrementUnitsCompletedThisPhase(long numUnits) {
|
||||||
|
super.incrementUnitsCompletedThisPhase(numUnits);
|
||||||
|
getCurrentView().incrementProgressBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentView(SplashViewProgressMonitor neoView) {
|
||||||
|
currentView = neoView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SplashViewProgressMonitor getCurrentView() {
|
||||||
|
return currentView;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package net.slightlymagic.braids.util.progress_monitor;
|
||||||
|
|
||||||
|
import javax.swing.JProgressBar;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swing component view, to be used with BaseProgressMonitor.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class SplashViewProgressMonitor extends JProgressBar {
|
||||||
|
private BaseProgressMonitor currentModel;
|
||||||
|
private double completed;
|
||||||
|
private double total;
|
||||||
|
|
||||||
|
public SplashViewProgressMonitor() {
|
||||||
|
super();
|
||||||
|
setString("");
|
||||||
|
setStringPainted(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void incrementProgressBar() {
|
||||||
|
// Update bar "stripe"
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
stripeUpdate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update bar message
|
||||||
|
// Note: shouldUpdateUI() severely retards motion
|
||||||
|
// of the preloader, so is temporarily disabled.
|
||||||
|
//if (getCurrentModel().shouldUpdateUI()) {
|
||||||
|
if ((getCurrentModel().getNumPhases() > 1)) {
|
||||||
|
displayUpdate(
|
||||||
|
"Phase " + getCurrentModel().getCurrentPhase() + ". "
|
||||||
|
//+ getUnitsCompletedSoFarThisPhase() + " units processed. "
|
||||||
|
//+ "Overall: " + getTotalPercentCompleteAsString() + "% complete, "
|
||||||
|
+ "Overall ETA in " + getCurrentModel().getRelativeETAAsString() + "."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
displayUpdate(
|
||||||
|
//"Overall: " +
|
||||||
|
getCurrentModel().getUnitsCompletedSoFarThisPhase() + " units processed; "
|
||||||
|
//+ "(" + getTotalPercentCompleteAsString() + "%); "
|
||||||
|
+ "ETA in " + getCurrentModel().getRelativeETAAsString() + "."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// getCurrentModel().justUpdatedUI();
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
if (getCurrentModel().getCurrentPhase() == getCurrentModel().getNumPhases()
|
||||||
|
&& getCurrentModel().getUnitsCompletedSoFarThisPhase() >= getCurrentModel().getTotalUnitsThisPhase())
|
||||||
|
{
|
||||||
|
displayUpdate("Done! Firing up the GUI...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the message inside the progress dialog; does not always work on
|
||||||
|
* all platforms.
|
||||||
|
*
|
||||||
|
* @param message the message to display
|
||||||
|
*/
|
||||||
|
public final void displayUpdate(final String message) {
|
||||||
|
final Runnable proc = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
setString(message);
|
||||||
|
getCurrentModel().justUpdatedUI();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (SwingUtilities.isEventDispatchThread()) {
|
||||||
|
proc.run();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SwingUtilities.invokeLater(proc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the stripe inside the progress dialog.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public final void stripeUpdate() {
|
||||||
|
completed = getCurrentModel().getUnitsCompletedSoFarThisPhase();
|
||||||
|
total = getCurrentModel().getTotalUnitsThisPhase();
|
||||||
|
|
||||||
|
setValue((int)Math.round((int)completed/total*100));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the stripe inside the progress dialog back to zero.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public final void stripeReset() {
|
||||||
|
setValue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentModel(BaseProgressMonitor neoModel) {
|
||||||
|
currentModel = neoModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseProgressMonitor getCurrentModel() {
|
||||||
|
return currentModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user