mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
- Splash view/model renamed, moved to forge.view.swing folder
- Small fix to decouple interface from implementation - Add dispatch thread test - Updated javadoc
This commit is contained in:
@@ -19,7 +19,7 @@ import java.util.zip.ZipFile;
|
||||
import net.slightlymagic.braids.util.UtilFunctions;
|
||||
import net.slightlymagic.braids.util.generator.FindNonDirectoriesSkipDotDirectoriesGenerator;
|
||||
import net.slightlymagic.braids.util.generator.GeneratorFunctions;
|
||||
import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
|
||||
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
|
||||
import net.slightlymagic.braids.util.progress_monitor.StderrProgressMonitor;
|
||||
|
||||
import com.google.code.jyield.Generator;
|
||||
@@ -187,7 +187,7 @@ public class CardReader
|
||||
|
||||
// Try to retrieve card loading progress monitor model.
|
||||
// If no progress monitor present, output results to console.
|
||||
BaseProgressMonitor monitor = null;
|
||||
BraidsProgressMonitor monitor = null;
|
||||
final FView view = Singletons.getView();
|
||||
if (view != null) {
|
||||
monitor = view.getCardLoadingProgressMonitor();
|
||||
@@ -206,7 +206,9 @@ public class CardReader
|
||||
findNonDirsIterable = YieldUtils.toIterable(findNonDirsGen);
|
||||
}
|
||||
|
||||
monitor.setTotalUnitsThisPhase(estimatedFilesRemaining);
|
||||
if(monitor!=null) {
|
||||
monitor.setTotalUnitsThisPhase(estimatedFilesRemaining);
|
||||
}
|
||||
|
||||
for (File cardTxtFile : findNonDirsIterable) {
|
||||
if (!cardTxtFile.getName().endsWith(CARD_FILE_DOT_EXTENSION)) {
|
||||
|
||||
@@ -31,6 +31,16 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
|
||||
|
||||
/**
|
||||
* Convenience for
|
||||
* BaseProgressMonitor(1, 1, 2.0f, null).
|
||||
*
|
||||
* @see #BaseProgressMonitor(int,long,float,float[])
|
||||
*/
|
||||
public BaseProgressMonitor() {
|
||||
this(1, 1L, 2.0f, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience for
|
||||
* BaseProgressMonitor(numPhases, 1, 2.0f, null).
|
||||
*
|
||||
* @see #BaseProgressMonitor(int,long,float,float[])
|
||||
@@ -300,7 +310,7 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
|
||||
* Subclasses must call this immediately after updating the UI, to
|
||||
* preserve the integrity of the shouldUpdateUI method.
|
||||
*/
|
||||
protected void justUpdatedUI() {
|
||||
public void justUpdatedUI() {
|
||||
this.lastUIUpdateTime = new Date().getTime()/1000;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,12 @@ public interface BraidsProgressMonitor {
|
||||
* even if it would otherwise be too soon to update the UI.
|
||||
*/
|
||||
public abstract boolean shouldUpdateUI();
|
||||
|
||||
/**
|
||||
* Subclasses must call this immediately after updating the UI, to
|
||||
* preserve the integrity of the shouldUpdateUI method.
|
||||
*/
|
||||
public abstract void justUpdatedUI();
|
||||
|
||||
/**
|
||||
* This is the only way to advance the phase number.
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
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