X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FProgress.java;h=5ee32217d466c1ad7bbb13e21ecf24e6fe457f57;hp=b6137f18bf6144d72f186b8e93b6bd70768846b5;hb=refs%2Ftags%2Fnikiroo-utils-1.4.1;hpb=2a35af0bc418c83eaf2be88f706fbfb06d4e9674 diff --git a/src/be/nikiroo/utils/Progress.java b/src/be/nikiroo/utils/Progress.java index b6137f1..5ee3221 100644 --- a/src/be/nikiroo/utils/Progress.java +++ b/src/be/nikiroo/utils/Progress.java @@ -227,6 +227,18 @@ public class Progress { } } + /** + * Add some value to the current progression of this {@link Progress}. + * + * @param step + * the amount to add + */ + public void add(int step) { + synchronized (getLock()) { + setProgress(localProgress + step); + } + } + /** * Check if the action corresponding to this {@link Progress} is done (i.e., * if its progress value == its max value). @@ -237,6 +249,13 @@ public class Progress { return progress >= max; } + /** + * Mark the {@link Progress} as done by setting its value to max. + */ + public void done() { + setProgress(getMax()); + } + /** * Get the total progress value (including the optional children * {@link Progress}) on a 0.0 to 1.0 scale. @@ -244,6 +263,10 @@ public class Progress { * @return the progress */ public double getRelativeProgress() { + if (max == min) { + return 1; + } + return (((double) progress) / (max - min)); }