X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FProgress.java;h=b6137f18bf6144d72f186b8e93b6bd70768846b5;hp=5af7b30d83b357654d2b34e3bff3faa3eb8de9d6;hb=2a35af0bc418c83eaf2be88f706fbfb06d4e9674;hpb=0924c45dd84be115c6c622b075445855b13951e5 diff --git a/src/be/nikiroo/utils/Progress.java b/src/be/nikiroo/utils/Progress.java index 5af7b30..b6137f1 100644 --- a/src/be/nikiroo/utils/Progress.java +++ b/src/be/nikiroo/utils/Progress.java @@ -106,8 +106,7 @@ public class Progress { */ public void setName(String name) { this.name = name; - // will fire an action event: - setProgress(this.localProgress); + changed(this); } /** @@ -230,7 +229,7 @@ public class Progress { /** * Check if the action corresponding to this {@link Progress} is done (i.e., - * if its progress value is >= its max value). + * if its progress value == its max value). * * @return TRUE if it is */ @@ -251,7 +250,7 @@ public class Progress { /** * Return the list of direct children of this {@link Progress}. * - * @return the children (who will think of them??) + * @return the children (Who will think of the children??) */ public Set getChildren() { return children.keySet(); @@ -273,8 +272,28 @@ public class Progress { */ private void setTotalProgress(Progress pg, String name, int progress) { synchronized (getLock()) { - this.progress = progress; + progress = Math.max(min, progress); + progress = Math.min(max, progress); + if (progress != this.progress) { + this.progress = progress; + changed(pg); + } + } + } + + /** + * Notify the listeners that this {@link Progress} changed value. + * + * @param pg + * the emmiter + */ + private void changed(Progress pg) { + if (pg == null) { + pg = this; + } + + synchronized (getLock()) { for (ProgressListener l : listeners) { l.progress(pg, name); }