diff --git a/.gitattributes b/.gitattributes index 71cc24a14ba..e50922ac06c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9850,17 +9850,9 @@ 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/OldGuiNewGame.java svneol=native#text/plain src/main/java/forge/view/swing/SplashFrame.java -text -src/main/java/forge/view/swing/SplashModelProgressMonitor.java -text -src/main/java/forge/view/swing/SplashViewProgressMonitor.java -text +src/main/java/forge/view/swing/SplashProgressComponent.java -text +src/main/java/forge/view/swing/SplashProgressModel.java -text src/main/java/forge/view/swing/package-info.java svneol=native#text/plain -src/main/java/forge/view/swing/util/ProgressBarBase.java -text -src/main/java/forge/view/swing/util/ProgressBarEmbedded.java -text -src/main/java/forge/view/swing/util/ProgressBarInterface.java -text -src/main/java/forge/view/swing/util/package-info.java -text -src/main/java/forge/view/util/ProgressBar_Base.java -text -src/main/java/forge/view/util/ProgressBar_Embedded.java -text -src/main/java/forge/view/util/ProgressBar_Interface.java -text -src/main/java/forge/view/util/package-info.java -text src/main/java/net/slightlymagic/braids/LICENSE.txt svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/ClumsyRunnable.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/ImmutableIterableFrom.java svneol=native#text/plain diff --git a/src/main/java/forge/view/FView.java b/src/main/java/forge/view/FView.java index cfa6ea32106..337f9cf2391 100644 --- a/src/main/java/forge/view/FView.java +++ b/src/main/java/forge/view/FView.java @@ -1,6 +1,6 @@ package forge.view; -import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; +import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor; import forge.model.FModel; /** @@ -21,5 +21,5 @@ public interface FView { * * @return a progress monitor having only one phase; may be null */ - BaseProgressMonitor getCardLoadingProgressMonitor(); + BraidsProgressMonitor getCardLoadingProgressMonitor(); } diff --git a/src/main/java/forge/view/swing/ApplicationView.java b/src/main/java/forge/view/swing/ApplicationView.java index ddc4d0fb89b..b7c4602b86e 100644 --- a/src/main/java/forge/view/swing/ApplicationView.java +++ b/src/main/java/forge/view/swing/ApplicationView.java @@ -6,6 +6,7 @@ import javax.swing.UIManager; import net.slightlymagic.braids.util.UtilFunctions; import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; +import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor; import com.esotericsoftware.minlog.Log; @@ -57,8 +58,8 @@ public class ApplicationView implements FView { * @see forge.view.FView#getCardLoadingProgressMonitor() */ @Override - public final BaseProgressMonitor getCardLoadingProgressMonitor() { - BaseProgressMonitor result; + public final BraidsProgressMonitor getCardLoadingProgressMonitor() { + BraidsProgressMonitor result; if (splashFrame == null) { result = null; diff --git a/src/main/java/forge/view/swing/SplashFrame.java b/src/main/java/forge/view/swing/SplashFrame.java index 4d28f419941..74478d27505 100644 --- a/src/main/java/forge/view/swing/SplashFrame.java +++ b/src/main/java/forge/view/swing/SplashFrame.java @@ -12,6 +12,7 @@ import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; +import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor; /** * Shows the splash frame as the application starts. @@ -32,8 +33,8 @@ public class SplashFrame extends JFrame { private static final int DISCLAIMER_FONT_SIZE = 9; private static final Color DISCLAIMER_COLOR = Color.white; - private SplashModelProgressMonitor monitorModel = null; - private SplashViewProgressMonitor monitorView = null; + private SplashProgressModel monitorModel = null; + private SplashProgressComponent monitorView = null; /** *

Create the frame; this must be called from an event @@ -79,8 +80,8 @@ public class SplashFrame extends JFrame { contentPane.add(lblDisclaimer); // Instantiate model and view and tie together. - monitorModel = new SplashModelProgressMonitor(1); - monitorView = new SplashViewProgressMonitor(); + monitorModel = new SplashProgressModel(); + monitorView = new SplashProgressComponent(); monitorModel.setCurrentView(monitorView); monitorView.setCurrentModel(monitorModel); @@ -107,7 +108,7 @@ public class SplashFrame extends JFrame { * Getter for progress bar view. * @return the SplashViewProgressMonitor progress bar used in the splash frame. */ - public final SplashViewProgressMonitor getMonitorView() { + public final SplashProgressComponent getMonitorView() { return monitorView; } @@ -115,7 +116,7 @@ public class SplashFrame extends JFrame { * Getter for progress monitor model. * @return the BaseProgressMonitor model used in the splash frame. */ - public final BaseProgressMonitor getMonitorModel() { + public final BraidsProgressMonitor getMonitorModel() { return monitorModel; } diff --git a/src/main/java/forge/view/swing/SplashModelProgressMonitor.java b/src/main/java/forge/view/swing/SplashModelProgressMonitor.java deleted file mode 100644 index 2fbd97336d3..00000000000 --- a/src/main/java/forge/view/swing/SplashModelProgressMonitor.java +++ /dev/null @@ -1,38 +0,0 @@ -package forge.view.swing; - -import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; - -/** - * 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; - } - -} diff --git a/src/main/java/forge/view/swing/SplashViewProgressMonitor.java b/src/main/java/forge/view/swing/SplashProgressComponent.java similarity index 75% rename from src/main/java/forge/view/swing/SplashViewProgressMonitor.java rename to src/main/java/forge/view/swing/SplashProgressComponent.java index ca813bd4a78..8df91f032b6 100644 --- a/src/main/java/forge/view/swing/SplashViewProgressMonitor.java +++ b/src/main/java/forge/view/swing/SplashProgressComponent.java @@ -2,25 +2,40 @@ package forge.view.swing; import javax.swing.JProgressBar; import javax.swing.SwingUtilities; + import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; +import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor; /** * Swing component view, to be used with BaseProgressMonitor. * */ @SuppressWarnings("serial") -public class SplashViewProgressMonitor extends JProgressBar { +public class SplashProgressComponent extends JProgressBar { private BaseProgressMonitor currentModel; private double completed; private double total; - public SplashViewProgressMonitor() { + /** + * Constructor: Must be called from an event dispatch thread. + * + */ + public SplashProgressComponent() { super(); + + if (!SwingUtilities.isEventDispatchThread()) { + throw new IllegalStateException("must be called from within an event dispatch thread"); + } + setString(""); setStringPainted(true); } - public final void incrementProgressBar() { + /** + * Updates progress bar stripe and text with current state of model. + * + */ + public final void updateProgressBar() { // Update bar "stripe" SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -37,7 +52,7 @@ public class SplashViewProgressMonitor extends JProgressBar { "Phase " + getCurrentModel().getCurrentPhase() + ". " //+ getUnitsCompletedSoFarThisPhase() + " units processed. " //+ "Overall: " + getTotalPercentCompleteAsString() + "% complete, " - + "Overall ETA in " + getCurrentModel().getRelativeETAAsString() + "." + + "Overall ETA in " + getCurrentModel().getRelativeETAAsString(true) + "." ); } else { @@ -45,7 +60,7 @@ public class SplashViewProgressMonitor extends JProgressBar { //"Overall: " + getCurrentModel().getUnitsCompletedSoFarThisPhase() + " units processed; " //+ "(" + getTotalPercentCompleteAsString() + "%); " - + "ETA in " + getCurrentModel().getRelativeETAAsString() + "." + + "ETA in " + getCurrentModel().getRelativeETAAsString(true) + "." ); } // getCurrentModel().justUpdatedUI(); @@ -100,11 +115,21 @@ public class SplashViewProgressMonitor extends JProgressBar { setValue(0); } + /** + * Retrieves the model from which this component uses data. + * + * @param neoModel + */ public void setCurrentModel(BaseProgressMonitor neoModel) { currentModel = neoModel; } - public BaseProgressMonitor getCurrentModel() { + /** + * Sets model from which this component uses data. + * + * @return + */ + public BraidsProgressMonitor getCurrentModel() { return currentModel; } } diff --git a/src/main/java/forge/view/swing/SplashProgressModel.java b/src/main/java/forge/view/swing/SplashProgressModel.java new file mode 100644 index 00000000000..bee8761c276 --- /dev/null +++ b/src/main/java/forge/view/swing/SplashProgressModel.java @@ -0,0 +1,51 @@ +package forge.view.swing; + +import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; + +/** + * Creates an instance of BaseProgressMonitor that is used in the splash frame. + * + * Not all mutators notify the view yet. + * + */ +public class SplashProgressModel extends BaseProgressMonitor { + + private SplashProgressComponent currentView = null; + + /** + * Constructor called with no arguments, indicating 1 phase + * and number of phase units assumed to be 1 also (can be updated later). + * @param numPhases + */ + public SplashProgressModel() { + super(); + } + + @Override + /** + * @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#incrementUnitsCompletedThisPhase(long) + */ + public void incrementUnitsCompletedThisPhase(long numUnits) { + super.incrementUnitsCompletedThisPhase(numUnits); + getCurrentView().updateProgressBar(); + } + + /** + * Gets view from which data is sent for display + * + * @return + */ + public SplashProgressComponent getCurrentView() { + return currentView; + } + + /** + * Sets view to which data is sent for display + * + * @param neoView + */ + public void setCurrentView(SplashProgressComponent neoView) { + currentView = neoView; + } + +} diff --git a/src/main/java/forge/view/swing/util/ProgressBarBase.java b/src/main/java/forge/view/swing/util/ProgressBarBase.java deleted file mode 100644 index 4cf78052b7c..00000000000 --- a/src/main/java/forge/view/swing/util/ProgressBarBase.java +++ /dev/null @@ -1,576 +0,0 @@ -package forge.view.swing.util; - -import java.util.Date; -import java.util.Hashtable; -import javax.swing.JProgressBar; -import com.esotericsoftware.minlog.Log; - -/** - * This base class also acts as a "null" progress monitor; it doesn't display - * anything when updated. - * - * Absolute times are measured in seconds, in congruence with ProgressMonitor. - * - * @see forge.view.swing.util.ProgressBarInterface - */ -@SuppressWarnings("serial") -public class ProgressBarBase extends JProgressBar implements ProgressBarInterface { - private int numPhases; - private int currentPhase; - private long totalUnitsThisPhase; - private long unitsCompletedSoFarThisPhase; - private float minUIUpdateIntervalSec; - private long lastUIUpdateTime; - private long phaseOneStartTime; - private long currentPhaseStartTime; - private float currentPhaseExponent; - private long[] phaseDurationHistorySecList; - private float[] phaseWeights; - private Hashtable phaseNames; - - public final int SECONDS_PER_MINUTE = 60; - public final int SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE; - public final int SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR; - - - /** - * Convenience for - * ProgressBar_Base(numPhases, totalUnitsFirstPhase, 2.0f, null). - * - * @see #ProgressBar_Base(int,long,float,float[]) - */ - public ProgressBarBase(int numPhases, long totalUnitsFirstPhase) { - this(numPhases, totalUnitsFirstPhase, 2.0f, null); - } - - /** - * Convenience for - * ProgressBar_Base(numPhases, totalUnitsFirstPhase, - * minUIUpdateIntervalSec, null). - * - * @see #ProgressBar_Base(int,long,float,float[]) - */ - public ProgressBarBase(int numPhases, long totalUnitsFirstPhase, - float minUIUpdateIntervalSec) - { - this(numPhases, totalUnitsFirstPhase, minUIUpdateIntervalSec, null); - } - - /** - * Initializes fields and starts the timers. - * - * @param numPhases the total number of phases we will monitor - * - * @param totalUnitsFirstPhase how many units to expect in phase 1 - * - * @param minUIUpdateIntervalSec the approximate interval at which we - * update the user interface, in seconds - * - * @param phaseWeights may be null; if not null, this indicates the - * relative weight of each phase in terms of time to complete all phases. - * Index 0 of this array indicates phase 1's weight, index 1 indicates - * the weight of phase 2, and so on. If null, all phases are considered to - * take an equal amount of time to complete, which is equivalent to setting - * all phase weights to 1.0f. For example, if there are two phases, and - * the phase weights are set to {2.0f, 1.0f}, then the methods that compute - * the final ETA (Estimated Time of Arrival or completion) will assume that - * phase 2 takes half as long as phase 1. In other words, the operation - * will spend 67% of its time in phase 1, and 33% of its time in phase 2. - */ - public ProgressBarBase(int numPhases, long totalUnitsFirstPhase, - float minUIUpdateIntervalSec, float[] phaseWeights) - { - super(); - - this.numPhases = numPhases; - this.currentPhase = 1; - this.unitsCompletedSoFarThisPhase = 0L; - this.minUIUpdateIntervalSec = minUIUpdateIntervalSec; - this.lastUIUpdateTime = 0L; - this.phaseOneStartTime = new Date().getTime()/1000; - this.currentPhaseStartTime = this.phaseOneStartTime; - this.currentPhaseExponent = 1; - this.phaseDurationHistorySecList = new long[numPhases]; - - if (phaseWeights == null) { - this.phaseWeights = new float[numPhases]; - for (int ix = 0; ix < numPhases; ix++) { - this.phaseWeights[ix] = 1.0f; - } - } - else { - this.phaseWeights = phaseWeights; - } - - if (phaseNames == null) { - this.phaseNames = new Hashtable(); - for(int i=1;i<=numPhases;i++) { - this.phaseNames.put(i, "Phase "+i); - } - } - - setTotalUnitsThisPhase(totalUnitsFirstPhase); - } - - /** - * Does nothing. - */ - public void dispose() { - ; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getNumPhases() - */ - public int getNumPhases() { - return this.numPhases; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getMinUpdateIntervalSec() - */ - public float getMinUpdateIntervalSec() { - return this.minUIUpdateIntervalSec; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getCurrentPhase() - */ - public int getCurrentPhase() { - return this.currentPhase; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getUnitsCompletedSoFarThisPhase() - */ - public long getUnitsCompletedSoFarThisPhase() { - return this.unitsCompletedSoFarThisPhase; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getTotalUnitsThisPhase() - */ - public long getTotalUnitsThisPhase() { - return this.totalUnitsThisPhase; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getLastUIUpdateTime() - */ - public long getLastUIUpdateTime() { - return this.lastUIUpdateTime; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getPhaseOneStartTime() - */ - public long getPhaseOneStartTime() { - return this.phaseOneStartTime; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getCurrentPhaseStartTime() - */ - public long getCurrentPhaseStartTime() { - return this.currentPhaseStartTime; - } - - - /** - * @see forge.view.swing.util.ProgressBarInterface#setMinUpdateIntervalSec(float) - */ - public void setMinUpdateIntervalSec(float value) { - this.minUIUpdateIntervalSec = value; - } - - - /** - * @see forge.view.swing.util.ProgressBarInterface#setTotalUnitsThisPhase(long) - */ - public void setTotalUnitsThisPhase(long value) { - // Doublestrike sez - why is this called twice? - - if (value > Integer.MAX_VALUE) { - throw new IllegalArgumentException("numUnits must be <= " + Integer.MAX_VALUE); - } - else { - this.totalUnitsThisPhase = value; - - // (Temporary solution until I know a better way) - this.setProgressRange(0,(int)value); - } - } - - /** - *

setProgressRange.

- * - * @param min an int. - * @param max an int. - */ - public void setProgressRange(int min, int max) { - this.setMinimum(min); - this.setMaximum(max); - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getPercentCompleteOfThisPhaseAsString() - */ - public String getPercentCompleteOfThisPhaseAsString() { - - Float percent = getPercentCompleteOfThisPhaseAsFloat(); - - if (percent != null) { - return Integer.toString((int) (float) percent); - } - else { - return "??"; - } - } - - - /** - * @see forge.view.swing.util.ProgressBarInterface#getTotalPercentCompleteAsString() - */ - public String getTotalPercentCompleteAsString() { - Float percent = getTotalPercentCompleteAsFloat(); - - if (percent == null) { - return "??"; - } - else { - return Integer.toString((int) (float) percent); - } - } - - - /** - * Convenience for getRelativeETAAsString(false), meaning to compute the - * value for the end of the last phase. - * - * @see #getRelativeETAAsString(boolean) - */ - public String getRelativeETAAsString() { - return getRelativeETAAsString(false); - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getRelativeETAAsString(boolean) - */ - public String getRelativeETAAsString(boolean thisPhaseOnly) { - - Integer etaSec = getRelativeETASec(thisPhaseOnly); - - if (etaSec == null) { - return "unknown"; - } - - String result = ""; - if (etaSec > SECONDS_PER_DAY) { - result += Integer.toString(etaSec / SECONDS_PER_DAY); - result += " da, "; - etaSec %= SECONDS_PER_DAY; // Shave off the portion recorded. - } - if (result.length() > 0 || etaSec > SECONDS_PER_HOUR) { - result += Integer.toString(etaSec / SECONDS_PER_HOUR); - result += " hr, "; - etaSec %= SECONDS_PER_HOUR; // Shave off the portion recorded. - } - if (result.length() > 0 || etaSec > SECONDS_PER_MINUTE) { - result += Integer.toString(etaSec / SECONDS_PER_MINUTE); - result += " min, "; - etaSec %= SECONDS_PER_MINUTE; // Shave off the portion recorded. - } - - result += Integer.toString(etaSec); - result += " sec"; - - return result; - } - - /** - * Convenience for getAbsoluteETAAsLocalTimeString(false), meaning to - * compute the value for the end of the last phase. - * - * @see #getAbsoluteETAAsLocalTimeString(boolean) - */ - public String getAbsoluteETAAsLocalTimeString() { - return getAbsoluteETAAsLocalTimeString(false); - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#getAbsoluteETAAsLocalTimeString(boolean) - */ - public String getAbsoluteETAAsLocalTimeString(boolean thisPhaseOnly) { - Long etaTime = getAbsoluteETATime(thisPhaseOnly); - - if (etaTime == null) { - return "unknown"; - } - - return (new Date(etaTime*1000).toString()); - } - - - /** - * @see forge.view.swing.util.ProgressBarInterface#incrementUnitsCompletedThisPhase(long) - */ - public void incrementUnitsCompletedThisPhase(long numUnits) { - this.unitsCompletedSoFarThisPhase += numUnits; - } - - public void increment() { - setValue(getValue() + 1); - if (getValue() % 10 == 0) { repaint(); } - } - - /** - * Subclasses must call this immediately after updating the UI, to - * preserve the integrity of the shouldUpdateUI method. - */ - protected void justUpdatedUI() { - this.lastUIUpdateTime = new Date().getTime()/1000; - } - - /** - * @see forge.view.swing.util.ProgressBarInterface#shouldUpdateUI() - */ - public boolean shouldUpdateUI() { - - doctorStartTimes(); - long nowTime = (new Date().getTime()/1000); - - if (nowTime - this.lastUIUpdateTime >= this.minUIUpdateIntervalSec || - (this.getUnitsCompletedSoFarThisPhase() == - this.getTotalUnitsThisPhase())) - { - return true; - } - else { - return false; - } - } - - - /** - * @see forge.view.swing.util.ProgressBarInterface#markCurrentPhaseAsComplete(long) - */ - public void markCurrentPhaseAsComplete(long totalUnitsNextPhase) { - - if ((this.currentPhase > this.numPhases)) { - String message = "The phase just completed ("; - message += this.currentPhase; - message += ") is greater than the total number "; - message += "of anticipated phases ("; - message += this.numPhases; - message += "); the latter is probably incorrect."; - - Log.warn(message); - } - - this.currentPhase += 1; - this.unitsCompletedSoFarThisPhase = 0; - setTotalUnitsThisPhase(totalUnitsNextPhase); - this.currentPhaseExponent = 1; - - long nowTime = (new Date().getTime()/1000); - long durationOfThisPhaseSec = nowTime - this.currentPhaseStartTime; - if (durationOfThisPhaseSec < 0) { - durationOfThisPhaseSec = 0; - } - - if (0 <= currentPhase-2 && currentPhase-2 < phaseDurationHistorySecList.length) { - this.phaseDurationHistorySecList[currentPhase-2] = durationOfThisPhaseSec; - } - this.currentPhaseStartTime = nowTime; - - if (this.currentPhase >= this.numPhases) { - String message = "Actual individual phase durations: ["; - for (int ix = 0 ; ix < phaseDurationHistorySecList.length ; ix++) { - message += phaseDurationHistorySecList[ix] + ", "; - } - - Log.info(message + ']'); - } - } - - - /** - * @see forge.view.swing.util.ProgressBarInterface#sendMessage(java.lang.String) - */ - public void sendMessage(String message) { - ; - } - - - /** - * @see forge.view.swing.util.ProgressBarInterface#setCurrentPhaseAsExponential(float) - */ - public void setCurrentPhaseAsExponential(float value) { - this.currentPhaseExponent = value; - } - - - /** - * @see forge.view.swing.util.ProgressBarInterface#getCurrentPhaseExponent() - */ - public float getCurrentPhaseExponent() { - return this.currentPhaseExponent; - } - - /** - * Sets the name of a phase in the process (e.g. "Phase 1" becomes "Loading XML") - */ - public void setPhaseName(int i, String name) { - - } - - public String getPhaseName(int i) { - return phaseNames.get(i); - } - - /** - * @return number in range [0.0, 100.0] or null. - */ - protected Float getPercentCompleteOfThisPhaseAsFloat() { - if (this.totalUnitsThisPhase < 1 || - this.unitsCompletedSoFarThisPhase > this.totalUnitsThisPhase) { - return null; - } - else { - float ratio = ((float) (this.unitsCompletedSoFarThisPhase)) / - ((float) this.totalUnitsThisPhase); - - ratio = (float) Math.pow(ratio, this.getCurrentPhaseExponent()); - - return (ratio * 100.0f); - } - } - - - /** - * Returns number in range [0.0, 100.0] or null. - */ - protected Float getTotalPercentCompleteAsFloat() { - long totalPoints = 0; - for (float weight : this.phaseWeights) { - totalPoints += weight * 100; - } - - Float percentThisPhase = getPercentCompleteOfThisPhaseAsFloat(); - - if (percentThisPhase == null) { - // If we can't know the percentage for this phase, use a - // conservative estimate. - percentThisPhase = 0.0f; - } - - long pointsSoFar = 0; - for (int ix = 0; ix < this.currentPhase-1; ix++) { - // We get full points for (all the phases completed prior to this one. - pointsSoFar += phaseWeights[ix] * 100; - } - - pointsSoFar += percentThisPhase * this.phaseWeights[this.currentPhase-1]; - - if (totalPoints <= 0.0 || pointsSoFar > totalPoints) { - return null; - } - else { - return (100.0f * pointsSoFar) / totalPoints; - } - } - - - /** - * Convenience for getRelativeETASec(false), meaning to compute the value - * for the end of the last phase. - * - * @see #getRelativeETASec(boolean) - */ - protected Integer getRelativeETASec() { - return getRelativeETASec(false); - } - - /** - * @return estimated seconds until completion for either thisPhaseOnly - * or for the entire operation. May return null if unknown. - */ - protected Integer getRelativeETASec(boolean thisPhaseOnly) { - - Long absoluteETATime = getAbsoluteETATime(thisPhaseOnly); - if (absoluteETATime == null) { - return null; - } - return (int) (absoluteETATime - (new Date().getTime()/1000)); - } - - - /** - * Convenience for getAbsoluteETATime(false), meaning to compute the value - * for the end of all phases. - * - * @see #getAbsoluteETATime(boolean) - */ - protected Long getAbsoluteETATime() { - return getAbsoluteETATime(false); - } - - /** - * @return the estimated time (in absolute seconds) at which thisPhaseOnly - * or the entire operation will be completed. May return null if (unknown. - */ - protected Long getAbsoluteETATime(boolean thisPhaseOnly) { - doctorStartTimes(); - - // If we're in the last phase, the overall ETA is the same as the ETA - // for (this particular phase. - if (this.getCurrentPhase() >= this.getNumPhases()) { - thisPhaseOnly = true; - } - - Float percentDone = null; - long startTime = 0L; - - if (thisPhaseOnly) { - percentDone = getPercentCompleteOfThisPhaseAsFloat(); - startTime = this.currentPhaseStartTime; - } - else { - percentDone = getTotalPercentCompleteAsFloat(); - startTime = this.phaseOneStartTime; - } - - if (percentDone == null || percentDone <= 0.001) { - return null; - } - - // Elapsed time is to percent done as total time is to total done => - // elapsed/percentDone == totalTime/100.0 => - long totalTime = (long) (100.0f * ((new Date().getTime()/1000) - startTime) / percentDone); - - return totalTime + startTime; - } - - - /** - * Repair the start times in case the system clock has been moved - * backwards. - */ - protected void doctorStartTimes() { - - long nowTime = (new Date().getTime()/1000); - - if (this.lastUIUpdateTime > nowTime) { - this.lastUIUpdateTime = 0; - } - - if (this.phaseOneStartTime > nowTime) { - this.phaseOneStartTime = nowTime; - } - - if (this.currentPhaseStartTime > nowTime) { - this.currentPhaseStartTime = nowTime; - } - } - -} diff --git a/src/main/java/forge/view/swing/util/ProgressBarEmbedded.java b/src/main/java/forge/view/swing/util/ProgressBarEmbedded.java deleted file mode 100644 index 5c0fbd097ff..00000000000 --- a/src/main/java/forge/view/swing/util/ProgressBarEmbedded.java +++ /dev/null @@ -1,97 +0,0 @@ -package forge.view.swing.util; - -import javax.swing.SwingUtilities; - -import forge.view.swing.util.ProgressBarBase; - -/** - * GUI Progress Monitor that displays the ETA (Estimated Time of Arrival or - * completion) on some platforms and supports one or multiple phases of - * progress. - * - * In this implementation, the progress bar must be embedded in a parent component. - */ -@SuppressWarnings("serial") -public class ProgressBarEmbedded extends ProgressBarBase { - - public ProgressBarEmbedded(int numPhases, long totalUnitsFirstPhase) { - super(numPhases, totalUnitsFirstPhase); - - setIndeterminate(false); - setString(""); - setStringPainted(true); - setValue(0); - } - - // public void increment() { - // setValue(getValue() + 1); - // System.out.println("x"); - // //if (getValue() % 10 == 0) { repaint(); } - // } - - @Override - /** - * @see forge.view.util.ProgressBar_Base#incrementUnitsCompletedThisPhase(long) - */ - public final void incrementUnitsCompletedThisPhase(final long numUnits) { - super.incrementUnitsCompletedThisPhase(numUnits); - SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/18/11 11:18 PM - public void run() { - for (int i = 0; i < numUnits; i++) { - increment(); - } - } - }); - - if (shouldUpdateUI()) { - - if ((getNumPhases() > 1)) { - displayUpdate( - "Phase " + getCurrentPhase() + ". " - //+ getUnitsCompletedSoFarThisPhase() + " units processed. " - //+ "Overall: " + getTotalPercentCompleteAsString() + "% complete, " - + "Overall ETA in " + getRelativeETAAsString() + "." - ); - } - else { - displayUpdate( - //"Overall: " + - getUnitsCompletedSoFarThisPhase() + " units processed; " - //+ "(" + getTotalPercentCompleteAsString() + "%); " - + "ETA in " + getRelativeETAAsString() + "." - ); - } - } - - if (getCurrentPhase() == getNumPhases() - && getUnitsCompletedSoFarThisPhase() >= getTotalUnitsThisPhase()) - { - displayUpdate("Done!"); - } - } - - /** - * 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() { // NOPMD by Braids on 8/18/11 11:18 PM - public void run() { - setString(message); - justUpdatedUI(); - } - }; - - if (SwingUtilities.isEventDispatchThread()) { - proc.run(); - } - else { - SwingUtilities.invokeLater(proc); - } - } - - -} diff --git a/src/main/java/forge/view/swing/util/ProgressBarInterface.java b/src/main/java/forge/view/swing/util/ProgressBarInterface.java deleted file mode 100644 index 98f92a9b223..00000000000 --- a/src/main/java/forge/view/swing/util/ProgressBarInterface.java +++ /dev/null @@ -1,152 +0,0 @@ -package forge.view.swing.util; - -/** - * Interface for a progress monitor that can have multiple phases - * and periodically update its UI. - * - * All times must be in seconds; absolute times are measured in seconds since - * 01 Jan 1970 00:00:00 UTC (GMT) a la (new Date().getTime()/1000). - */ -public interface ProgressBarInterface { - - /** - * Destroy this progress monitor, making it no longer usable and/or - * visible. - */ - public void dispose(); - - /** - * @return the total number of phases monitored by this object. - */ - public abstract int getNumPhases(); - - /** - * @return the approximate minimum interval in seconds at which the UI - * should be updated. - */ - public abstract float getMinUpdateIntervalSec(); - - /** - * @return the current phase number; this is never less than 1 (one). - */ - public abstract int getCurrentPhase(); - - /** - * @return the number of units (an intentionally vague amount) completed - * so far in the current phase. - */ - public abstract long getUnitsCompletedSoFarThisPhase(); - - /** - * @return the total units we expect to process in this phase - */ - public abstract long getTotalUnitsThisPhase(); - - /** - * @return the time in absolute seconds since the UI was last updated - */ - public abstract long getLastUIUpdateTime(); - - /** - * @return the time in absolute seconds at which the first phase started - */ - public abstract long getPhaseOneStartTime(); - - /** - * @return the time in absolute seconds at which the current phase started - */ - public abstract long getCurrentPhaseStartTime(); - - /** - * @param value - * the approximate time in relative seconds at which the UI - * should be updated periodically - */ - public abstract void setMinUpdateIntervalSec(float value); - - /** - * @param value the total number of units expected to processed in this - * phase - */ - public abstract void setTotalUnitsThisPhase(long value); - - /** - * Resulting string does not contain a percent sign. - * - * @return the percentage completion of this phase as a String with no - * percent sign. - */ - public abstract String getPercentCompleteOfThisPhaseAsString(); - - /** - * Resulting string does not contain a percent sign. - * - * @return the percentage completion at this point, taking into account all - * phases and phase-weights, as a String with no percent sign. - */ - public abstract String getTotalPercentCompleteAsString(); - - /** - * May return "unknown" - */ - public abstract String getRelativeETAAsString(boolean thisPhaseOnly); - - /** - * May return "unknown" - */ - public abstract String getAbsoluteETAAsLocalTimeString(boolean thisPhaseOnly); - - /** - * Note this will NOT advance the phase. - * To do that, use markCurrentPhaseAsComplete(). - */ - public abstract void incrementUnitsCompletedThisPhase(long numUnits); - - /** - * Returns a boolean, whether or not to display the updated information. - * This throttles the update so it doesn't refresh so fast that it is - * unreadable. Implementers should call this method from their own - * incrementUnitsCompletedThisPhase method. - * - * If we have just reached 100% for (the current phase, we return true, - * even if it would otherwise be too soon to update the UI. - */ - public abstract boolean shouldUpdateUI(); - - /** - * This is the only way to advance the phase number. - * It automatically "starts the clock" for the next phase. - * - * @param totalUnitsNextPhase if unknown, use zero (0), and be sure to call - * setTotalUnitsThisPhase() soon after. - */ - public abstract void markCurrentPhaseAsComplete(long totalUnitsNextPhase); - - /** - * Attempt to display a message to the user; not all implementations - * support this. - * - * If they do not, they may silently ignore this call. - * - * @param message the message to display - */ - public abstract void sendMessage(String message); - - - /** - * Mark the current phase as having an exponential rate; such phases - * reach their totalUnits slower and slower as they process more units. - * - * By default, a phase is considered to be linear, meaning this value is - * 1.0f. - * - * @param value usually less than 1.0f; often determined empirically. - */ - public abstract void setCurrentPhaseAsExponential(float value); - - /** - * @return the exponent for this phase - */ - public abstract float getCurrentPhaseExponent(); - -} diff --git a/src/main/java/forge/view/swing/util/package-info.java b/src/main/java/forge/view/swing/util/package-info.java deleted file mode 100644 index c3918a06b6f..00000000000 --- a/src/main/java/forge/view/swing/util/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -/** Forge Card Game */ -package forge.view.swing.util; diff --git a/src/main/java/forge/view/util/ProgressBar_Base.java b/src/main/java/forge/view/util/ProgressBar_Base.java deleted file mode 100644 index f2a8b60a318..00000000000 --- a/src/main/java/forge/view/util/ProgressBar_Base.java +++ /dev/null @@ -1,576 +0,0 @@ -package forge.view.util; - -import java.util.Date; -import java.util.Hashtable; -import javax.swing.JProgressBar; -import com.esotericsoftware.minlog.Log; - -/** - * This base class also acts as a "null" progress monitor; it doesn't display - * anything when updated. - * - * Absolute times are measured in seconds, in congruence with ProgressMonitor. - * - * @see forge.view.util.ProgressBar_Interface - */ -@SuppressWarnings("serial") -public class ProgressBar_Base extends JProgressBar implements ProgressBar_Interface { - private int numPhases; - private int currentPhase; - private long totalUnitsThisPhase; - private long unitsCompletedSoFarThisPhase; - private float minUIUpdateIntervalSec; - private long lastUIUpdateTime; - private long phaseOneStartTime; - private long currentPhaseStartTime; - private float currentPhaseExponent; - private long[] phaseDurationHistorySecList; - private float[] phaseWeights; - private Hashtable phaseNames; - - public final int SECONDS_PER_MINUTE = 60; - public final int SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE; - public final int SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR; - - - /** - * Convenience for - * ProgressBar_Base(numPhases, totalUnitsFirstPhase, 2.0f, null). - * - * @see #ProgressBar_Base(int,long,float,float[]) - */ - public ProgressBar_Base(int numPhases, long totalUnitsFirstPhase) { - this(numPhases, totalUnitsFirstPhase, 2.0f, null); - } - - /** - * Convenience for - * ProgressBar_Base(numPhases, totalUnitsFirstPhase, - * minUIUpdateIntervalSec, null). - * - * @see #ProgressBar_Base(int,long,float,float[]) - */ - public ProgressBar_Base(int numPhases, long totalUnitsFirstPhase, - float minUIUpdateIntervalSec) - { - this(numPhases, totalUnitsFirstPhase, minUIUpdateIntervalSec, null); - } - - /** - * Initializes fields and starts the timers. - * - * @param numPhases the total number of phases we will monitor - * - * @param totalUnitsFirstPhase how many units to expect in phase 1 - * - * @param minUIUpdateIntervalSec the approximate interval at which we - * update the user interface, in seconds - * - * @param phaseWeights may be null; if not null, this indicates the - * relative weight of each phase in terms of time to complete all phases. - * Index 0 of this array indicates phase 1's weight, index 1 indicates - * the weight of phase 2, and so on. If null, all phases are considered to - * take an equal amount of time to complete, which is equivalent to setting - * all phase weights to 1.0f. For example, if there are two phases, and - * the phase weights are set to {2.0f, 1.0f}, then the methods that compute - * the final ETA (Estimated Time of Arrival or completion) will assume that - * phase 2 takes half as long as phase 1. In other words, the operation - * will spend 67% of its time in phase 1, and 33% of its time in phase 2. - */ - public ProgressBar_Base(int numPhases, long totalUnitsFirstPhase, - float minUIUpdateIntervalSec, float[] phaseWeights) - { - super(); - - this.numPhases = numPhases; - this.currentPhase = 1; - this.unitsCompletedSoFarThisPhase = 0L; - this.minUIUpdateIntervalSec = minUIUpdateIntervalSec; - this.lastUIUpdateTime = 0L; - this.phaseOneStartTime = new Date().getTime()/1000; - this.currentPhaseStartTime = this.phaseOneStartTime; - this.currentPhaseExponent = 1; - this.phaseDurationHistorySecList = new long[numPhases]; - - if (phaseWeights == null) { - this.phaseWeights = new float[numPhases]; - for (int ix = 0; ix < numPhases; ix++) { - this.phaseWeights[ix] = 1.0f; - } - } - else { - this.phaseWeights = phaseWeights; - } - - if (phaseNames == null) { - this.phaseNames = new Hashtable(); - for(int i=1;i<=numPhases;i++) { - this.phaseNames.put(i, "Phase "+i); - } - } - - setTotalUnitsThisPhase(totalUnitsFirstPhase); - } - - /** - * Does nothing. - */ - public void dispose() { - ; - } - - /** - * @see forge.view.util.ProgressBar_Interface#getNumPhases() - */ - public int getNumPhases() { - return this.numPhases; - } - - /** - * @see forge.view.util.ProgressBar_Interface#getMinUpdateIntervalSec() - */ - public float getMinUpdateIntervalSec() { - return this.minUIUpdateIntervalSec; - } - - /** - * @see forge.view.util.ProgressBar_Interface#getCurrentPhase() - */ - public int getCurrentPhase() { - return this.currentPhase; - } - - /** - * @see forge.view.util.ProgressBar_Interface#getUnitsCompletedSoFarThisPhase() - */ - public long getUnitsCompletedSoFarThisPhase() { - return this.unitsCompletedSoFarThisPhase; - } - - /** - * @see forge.view.util.ProgressBar_Interface#getTotalUnitsThisPhase() - */ - public long getTotalUnitsThisPhase() { - return this.totalUnitsThisPhase; - } - - /** - * @see forge.view.util.ProgressBar_Interface#getLastUIUpdateTime() - */ - public long getLastUIUpdateTime() { - return this.lastUIUpdateTime; - } - - /** - * @see forge.view.util.ProgressBar_Interface#getPhaseOneStartTime() - */ - public long getPhaseOneStartTime() { - return this.phaseOneStartTime; - } - - /** - * @see forge.view.util.ProgressBar_Interface#getCurrentPhaseStartTime() - */ - public long getCurrentPhaseStartTime() { - return this.currentPhaseStartTime; - } - - - /** - * @see forge.view.util.ProgressBar_Interface#setMinUpdateIntervalSec(float) - */ - public void setMinUpdateIntervalSec(float value) { - this.minUIUpdateIntervalSec = value; - } - - - /** - * @see forge.view.util.ProgressBar_Interface#setTotalUnitsThisPhase(long) - */ - public void setTotalUnitsThisPhase(long value) { - // Doublestrike sez - why is this called twice? - - if (value > Integer.MAX_VALUE) { - throw new IllegalArgumentException("numUnits must be <= " + Integer.MAX_VALUE); - } - else { - this.totalUnitsThisPhase = value; - - // (Temporary solution until I know a better way) - this.setProgressRange(0,(int)value); - } - } - - /** - *

setProgressRange.

- * - * @param min an int. - * @param max an int. - */ - public void setProgressRange(int min, int max) { - this.setMinimum(min); - this.setMaximum(max); - } - - /** - * @see forge.view.util.ProgressBar_Interface#getPercentCompleteOfThisPhaseAsString() - */ - public String getPercentCompleteOfThisPhaseAsString() { - - Float percent = getPercentCompleteOfThisPhaseAsFloat(); - - if (percent != null) { - return Integer.toString((int) (float) percent); - } - else { - return "??"; - } - } - - - /** - * @see forge.view.util.ProgressBar_Interface#getTotalPercentCompleteAsString() - */ - public String getTotalPercentCompleteAsString() { - Float percent = getTotalPercentCompleteAsFloat(); - - if (percent == null) { - return "??"; - } - else { - return Integer.toString((int) (float) percent); - } - } - - - /** - * Convenience for getRelativeETAAsString(false), meaning to compute the - * value for the end of the last phase. - * - * @see #getRelativeETAAsString(boolean) - */ - public String getRelativeETAAsString() { - return getRelativeETAAsString(false); - } - - /** - * @see forge.view.util.ProgressBar_Interface#getRelativeETAAsString(boolean) - */ - public String getRelativeETAAsString(boolean thisPhaseOnly) { - - Integer etaSec = getRelativeETASec(thisPhaseOnly); - - if (etaSec == null) { - return "unknown"; - } - - String result = ""; - if (etaSec > SECONDS_PER_DAY) { - result += Integer.toString(etaSec / SECONDS_PER_DAY); - result += " da, "; - etaSec %= SECONDS_PER_DAY; // Shave off the portion recorded. - } - if (result.length() > 0 || etaSec > SECONDS_PER_HOUR) { - result += Integer.toString(etaSec / SECONDS_PER_HOUR); - result += " hr, "; - etaSec %= SECONDS_PER_HOUR; // Shave off the portion recorded. - } - if (result.length() > 0 || etaSec > SECONDS_PER_MINUTE) { - result += Integer.toString(etaSec / SECONDS_PER_MINUTE); - result += " min, "; - etaSec %= SECONDS_PER_MINUTE; // Shave off the portion recorded. - } - - result += Integer.toString(etaSec); - result += " sec"; - - return result; - } - - /** - * Convenience for getAbsoluteETAAsLocalTimeString(false), meaning to - * compute the value for the end of the last phase. - * - * @see #getAbsoluteETAAsLocalTimeString(boolean) - */ - public String getAbsoluteETAAsLocalTimeString() { - return getAbsoluteETAAsLocalTimeString(false); - } - - /** - * @see forge.view.util.ProgressBar_Interface#getAbsoluteETAAsLocalTimeString(boolean) - */ - public String getAbsoluteETAAsLocalTimeString(boolean thisPhaseOnly) { - Long etaTime = getAbsoluteETATime(thisPhaseOnly); - - if (etaTime == null) { - return "unknown"; - } - - return (new Date(etaTime*1000).toString()); - } - - - /** - * @see forge.view.util.ProgressBar_Interface#incrementUnitsCompletedThisPhase(long) - */ - public void incrementUnitsCompletedThisPhase(long numUnits) { - this.unitsCompletedSoFarThisPhase += numUnits; - } - - public void increment() { - setValue(getValue() + 1); - if (getValue() % 10 == 0) { repaint(); } - } - - /** - * Subclasses must call this immediately after updating the UI, to - * preserve the integrity of the shouldUpdateUI method. - */ - protected void justUpdatedUI() { - this.lastUIUpdateTime = new Date().getTime()/1000; - } - - /** - * @see forge.view.util.ProgressBar_Interface#shouldUpdateUI() - */ - public boolean shouldUpdateUI() { - - doctorStartTimes(); - long nowTime = (new Date().getTime()/1000); - - if (nowTime - this.lastUIUpdateTime >= this.minUIUpdateIntervalSec || - (this.getUnitsCompletedSoFarThisPhase() == - this.getTotalUnitsThisPhase())) - { - return true; - } - else { - return false; - } - } - - - /** - * @see forge.view.util.ProgressBar_Interface#markCurrentPhaseAsComplete(long) - */ - public void markCurrentPhaseAsComplete(long totalUnitsNextPhase) { - - if ((this.currentPhase > this.numPhases)) { - String message = "The phase just completed ("; - message += this.currentPhase; - message += ") is greater than the total number "; - message += "of anticipated phases ("; - message += this.numPhases; - message += "); the latter is probably incorrect."; - - Log.warn(message); - } - - this.currentPhase += 1; - this.unitsCompletedSoFarThisPhase = 0; - setTotalUnitsThisPhase(totalUnitsNextPhase); - this.currentPhaseExponent = 1; - - long nowTime = (new Date().getTime()/1000); - long durationOfThisPhaseSec = nowTime - this.currentPhaseStartTime; - if (durationOfThisPhaseSec < 0) { - durationOfThisPhaseSec = 0; - } - - if (0 <= currentPhase-2 && currentPhase-2 < phaseDurationHistorySecList.length) { - this.phaseDurationHistorySecList[currentPhase-2] = durationOfThisPhaseSec; - } - this.currentPhaseStartTime = nowTime; - - if (this.currentPhase >= this.numPhases) { - String message = "Actual individual phase durations: ["; - for (int ix = 0 ; ix < phaseDurationHistorySecList.length ; ix++) { - message += phaseDurationHistorySecList[ix] + ", "; - } - - Log.info(message + ']'); - } - } - - - /** - * @see forge.view.util.ProgressBar_Interface#sendMessage(java.lang.String) - */ - public void sendMessage(String message) { - ; - } - - - /** - * @see forge.view.util.ProgressBar_Interface#setCurrentPhaseAsExponential(float) - */ - public void setCurrentPhaseAsExponential(float value) { - this.currentPhaseExponent = value; - } - - - /** - * @see forge.view.util.ProgressBar_Interface#getCurrentPhaseExponent() - */ - public float getCurrentPhaseExponent() { - return this.currentPhaseExponent; - } - - /** - * Sets the name of a phase in the process (e.g. "Phase 1" becomes "Loading XML") - */ - public void setPhaseName(int i, String name) { - - } - - public String getPhaseName(int i) { - return phaseNames.get(i); - } - - /** - * @return number in range [0.0, 100.0] or null. - */ - protected Float getPercentCompleteOfThisPhaseAsFloat() { - if (this.totalUnitsThisPhase < 1 || - this.unitsCompletedSoFarThisPhase > this.totalUnitsThisPhase) { - return null; - } - else { - float ratio = ((float) (this.unitsCompletedSoFarThisPhase)) / - ((float) this.totalUnitsThisPhase); - - ratio = (float) Math.pow(ratio, this.getCurrentPhaseExponent()); - - return (ratio * 100.0f); - } - } - - - /** - * Returns number in range [0.0, 100.0] or null. - */ - protected Float getTotalPercentCompleteAsFloat() { - long totalPoints = 0; - for (float weight : this.phaseWeights) { - totalPoints += weight * 100; - } - - Float percentThisPhase = getPercentCompleteOfThisPhaseAsFloat(); - - if (percentThisPhase == null) { - // If we can't know the percentage for this phase, use a - // conservative estimate. - percentThisPhase = 0.0f; - } - - long pointsSoFar = 0; - for (int ix = 0; ix < this.currentPhase-1; ix++) { - // We get full points for (all the phases completed prior to this one. - pointsSoFar += phaseWeights[ix] * 100; - } - - pointsSoFar += percentThisPhase * this.phaseWeights[this.currentPhase-1]; - - if (totalPoints <= 0.0 || pointsSoFar > totalPoints) { - return null; - } - else { - return (100.0f * pointsSoFar) / totalPoints; - } - } - - - /** - * Convenience for getRelativeETASec(false), meaning to compute the value - * for the end of the last phase. - * - * @see #getRelativeETASec(boolean) - */ - protected Integer getRelativeETASec() { - return getRelativeETASec(false); - } - - /** - * @return estimated seconds until completion for either thisPhaseOnly - * or for the entire operation. May return null if unknown. - */ - protected Integer getRelativeETASec(boolean thisPhaseOnly) { - - Long absoluteETATime = getAbsoluteETATime(thisPhaseOnly); - if (absoluteETATime == null) { - return null; - } - return (int) (absoluteETATime - (new Date().getTime()/1000)); - } - - - /** - * Convenience for getAbsoluteETATime(false), meaning to compute the value - * for the end of all phases. - * - * @see #getAbsoluteETATime(boolean) - */ - protected Long getAbsoluteETATime() { - return getAbsoluteETATime(false); - } - - /** - * @return the estimated time (in absolute seconds) at which thisPhaseOnly - * or the entire operation will be completed. May return null if (unknown. - */ - protected Long getAbsoluteETATime(boolean thisPhaseOnly) { - doctorStartTimes(); - - // If we're in the last phase, the overall ETA is the same as the ETA - // for (this particular phase. - if (this.getCurrentPhase() >= this.getNumPhases()) { - thisPhaseOnly = true; - } - - Float percentDone = null; - long startTime = 0L; - - if (thisPhaseOnly) { - percentDone = getPercentCompleteOfThisPhaseAsFloat(); - startTime = this.currentPhaseStartTime; - } - else { - percentDone = getTotalPercentCompleteAsFloat(); - startTime = this.phaseOneStartTime; - } - - if (percentDone == null || percentDone <= 0.001) { - return null; - } - - // Elapsed time is to percent done as total time is to total done => - // elapsed/percentDone == totalTime/100.0 => - long totalTime = (long) (100.0f * ((new Date().getTime()/1000) - startTime) / percentDone); - - return totalTime + startTime; - } - - - /** - * Repair the start times in case the system clock has been moved - * backwards. - */ - protected void doctorStartTimes() { - - long nowTime = (new Date().getTime()/1000); - - if (this.lastUIUpdateTime > nowTime) { - this.lastUIUpdateTime = 0; - } - - if (this.phaseOneStartTime > nowTime) { - this.phaseOneStartTime = nowTime; - } - - if (this.currentPhaseStartTime > nowTime) { - this.currentPhaseStartTime = nowTime; - } - } - -} diff --git a/src/main/java/forge/view/util/ProgressBar_Embedded.java b/src/main/java/forge/view/util/ProgressBar_Embedded.java deleted file mode 100644 index e99f931874b..00000000000 --- a/src/main/java/forge/view/util/ProgressBar_Embedded.java +++ /dev/null @@ -1,97 +0,0 @@ -package forge.view.util; - -import javax.swing.SwingUtilities; - -import forge.view.util.ProgressBar_Base; - -/** - * GUI Progress Monitor that displays the ETA (Estimated Time of Arrival or - * completion) on some platforms and supports one or multiple phases of - * progress. - * - * In this implementation, the progress bar must be embedded in a parent component. - */ -@SuppressWarnings("serial") -public class ProgressBar_Embedded extends ProgressBar_Base { - - public ProgressBar_Embedded(int numPhases, long totalUnitsFirstPhase) { - super(numPhases, totalUnitsFirstPhase); - - setIndeterminate(false); - setString(""); - setStringPainted(true); - setValue(0); - } - - // public void increment() { - // setValue(getValue() + 1); - // System.out.println("x"); - // //if (getValue() % 10 == 0) { repaint(); } - // } - - @Override - /** - * @see forge.view.util.ProgressBar_Base#incrementUnitsCompletedThisPhase(long) - */ - public final void incrementUnitsCompletedThisPhase(final long numUnits) { - super.incrementUnitsCompletedThisPhase(numUnits); - SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/18/11 11:18 PM - public void run() { - for (int i = 0; i < numUnits; i++) { - increment(); - } - } - }); - - if (shouldUpdateUI()) { - - if ((getNumPhases() > 1)) { - displayUpdate( - "Phase " + getCurrentPhase() + ". " - //+ getUnitsCompletedSoFarThisPhase() + " units processed. " - //+ "Overall: " + getTotalPercentCompleteAsString() + "% complete, " - + "Overall ETA in " + getRelativeETAAsString() + "." - ); - } - else { - displayUpdate( - //"Overall: " + - getUnitsCompletedSoFarThisPhase() + " units processed; " - //+ "(" + getTotalPercentCompleteAsString() + "%); " - + "ETA in " + getRelativeETAAsString() + "." - ); - } - } - - if (getCurrentPhase() == getNumPhases() - && getUnitsCompletedSoFarThisPhase() >= getTotalUnitsThisPhase()) - { - displayUpdate("Done!"); - } - } - - /** - * 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() { // NOPMD by Braids on 8/18/11 11:18 PM - public void run() { - setString(message); - justUpdatedUI(); - } - }; - - if (SwingUtilities.isEventDispatchThread()) { - proc.run(); - } - else { - SwingUtilities.invokeLater(proc); - } - } - - -} diff --git a/src/main/java/forge/view/util/ProgressBar_Interface.java b/src/main/java/forge/view/util/ProgressBar_Interface.java deleted file mode 100644 index e1c72019ec6..00000000000 --- a/src/main/java/forge/view/util/ProgressBar_Interface.java +++ /dev/null @@ -1,152 +0,0 @@ -package forge.view.util; - -/** - * Interface for a progress monitor that can have multiple phases - * and periodically update its UI. - * - * All times must be in seconds; absolute times are measured in seconds since - * 01 Jan 1970 00:00:00 UTC (GMT) a la (new Date().getTime()/1000). - */ -public interface ProgressBar_Interface { - - /** - * Destroy this progress monitor, making it no longer usable and/or - * visible. - */ - public void dispose(); - - /** - * @return the total number of phases monitored by this object. - */ - public abstract int getNumPhases(); - - /** - * @return the approximate minimum interval in seconds at which the UI - * should be updated. - */ - public abstract float getMinUpdateIntervalSec(); - - /** - * @return the current phase number; this is never less than 1 (one). - */ - public abstract int getCurrentPhase(); - - /** - * @return the number of units (an intentionally vague amount) completed - * so far in the current phase. - */ - public abstract long getUnitsCompletedSoFarThisPhase(); - - /** - * @return the total units we expect to process in this phase - */ - public abstract long getTotalUnitsThisPhase(); - - /** - * @return the time in absolute seconds since the UI was last updated - */ - public abstract long getLastUIUpdateTime(); - - /** - * @return the time in absolute seconds at which the first phase started - */ - public abstract long getPhaseOneStartTime(); - - /** - * @return the time in absolute seconds at which the current phase started - */ - public abstract long getCurrentPhaseStartTime(); - - /** - * @param value - * the approximate time in relative seconds at which the UI - * should be updated periodically - */ - public abstract void setMinUpdateIntervalSec(float value); - - /** - * @param value the total number of units expected to processed in this - * phase - */ - public abstract void setTotalUnitsThisPhase(long value); - - /** - * Resulting string does not contain a percent sign. - * - * @return the percentage completion of this phase as a String with no - * percent sign. - */ - public abstract String getPercentCompleteOfThisPhaseAsString(); - - /** - * Resulting string does not contain a percent sign. - * - * @return the percentage completion at this point, taking into account all - * phases and phase-weights, as a String with no percent sign. - */ - public abstract String getTotalPercentCompleteAsString(); - - /** - * May return "unknown" - */ - public abstract String getRelativeETAAsString(boolean thisPhaseOnly); - - /** - * May return "unknown" - */ - public abstract String getAbsoluteETAAsLocalTimeString(boolean thisPhaseOnly); - - /** - * Note this will NOT advance the phase. - * To do that, use markCurrentPhaseAsComplete(). - */ - public abstract void incrementUnitsCompletedThisPhase(long numUnits); - - /** - * Returns a boolean, whether or not to display the updated information. - * This throttles the update so it doesn't refresh so fast that it is - * unreadable. Implementers should call this method from their own - * incrementUnitsCompletedThisPhase method. - * - * If we have just reached 100% for (the current phase, we return true, - * even if it would otherwise be too soon to update the UI. - */ - public abstract boolean shouldUpdateUI(); - - /** - * This is the only way to advance the phase number. - * It automatically "starts the clock" for the next phase. - * - * @param totalUnitsNextPhase if unknown, use zero (0), and be sure to call - * setTotalUnitsThisPhase() soon after. - */ - public abstract void markCurrentPhaseAsComplete(long totalUnitsNextPhase); - - /** - * Attempt to display a message to the user; not all implementations - * support this. - * - * If they do not, they may silently ignore this call. - * - * @param message the message to display - */ - public abstract void sendMessage(String message); - - - /** - * Mark the current phase as having an exponential rate; such phases - * reach their totalUnits slower and slower as they process more units. - * - * By default, a phase is considered to be linear, meaning this value is - * 1.0f. - * - * @param value usually less than 1.0f; often determined empirically. - */ - public abstract void setCurrentPhaseAsExponential(float value); - - /** - * @return the exponent for this phase - */ - public abstract float getCurrentPhaseExponent(); - -} diff --git a/src/main/java/forge/view/util/package-info.java b/src/main/java/forge/view/util/package-info.java deleted file mode 100644 index 62e9fbefa63..00000000000 --- a/src/main/java/forge/view/util/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -/** Forge Card Game */ -package forge.view.util;