X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FProgress.java;h=ce88f3d8f8c55941bccc094d58b2fd42954be59c;hb=c175bf6f922a807891d2616cf2f0bfe74dea1ffb;hp=38ce29f9c8b49e6c4a27dd939fbf4d89d330817f;hpb=d827da2aba3d8b0e4a76426b5a76a9045ca584b2;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/Progress.java b/src/be/nikiroo/utils/Progress.java index 38ce29f..ce88f3d 100644 --- a/src/be/nikiroo/utils/Progress.java +++ b/src/be/nikiroo/utils/Progress.java @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; /** * Progress reporting system, possibly nested. @@ -318,8 +317,10 @@ public class Progress { * * @return the children (Who will think of the children??) */ - public Set getChildren() { - return children.keySet(); + public List getChildren() { + synchronized (getLock()) { + return new ArrayList(children.keySet()); + } } /** @@ -359,7 +360,9 @@ public class Progress { * the listener */ public void addProgressListener(ProgressListener l) { - this.listeners.add(l); + synchronized (getLock()) { + this.listeners.add(l); + } } /** @@ -371,7 +374,9 @@ public class Progress { * @return TRUE if it was found (and removed) */ public boolean removeProgressListener(ProgressListener l) { - return this.listeners.remove(l); + synchronized (getLock()) { + return this.listeners.remove(l); + } } /** @@ -392,7 +397,7 @@ public class Progress { if (weight < min || weight > max) { throw new RuntimeException(String.format( "Progress object %s cannot have a weight of %f, " - + "it is outside of its parent (%s) range (%f)", + + "it is outside of its parent (%s) range (%d)", progress.name, weight, name, max)); } @@ -403,14 +408,19 @@ public class Progress { name, progress.parent.name)); } + progress.parent = this; + progress.addProgressListener(new ProgressListener() { @Override public void progress(Progress pg, String name) { synchronized (getLock()) { double total = relativeLocalProgress; - for (Entry entry : children.entrySet()) { - total += (entry.getValue() / (max - min)) - * entry.getKey().getRelativeProgress(); + synchronized (getLock()) { + for (Entry entry : children + .entrySet()) { + total += (entry.getValue() / (max - min)) + * entry.getKey().getRelativeProgress(); + } } setRelativeProgress(pg, name, total); @@ -418,7 +428,9 @@ public class Progress { } }); - this.children.put(progress, weight); + synchronized (getLock()) { + this.children.put(progress, weight); + } } /**