*/
public void setName(String name) {
this.name = name;
- // will fire an action event:
- setProgress(this.localProgress);
+ changed(this);
}
/**
}
}
+ /**
+ * 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 is >= its max value).
+ * if its progress value == its max value).
*
* @return TRUE if it is
*/
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.
* @return the progress
*/
public double getRelativeProgress() {
+ if (max == min) {
+ return 1;
+ }
+
return (((double) progress) / (max - min));
}
/**
* 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<Progress> getChildren() {
return children.keySet();
*/
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);
}