- private void setTotalProgress(Progress pg, String name, int progress) {
- synchronized (getLock()) {
- progress = Math.max(min, progress);
- progress = Math.min(max, progress);
-
- if (progress != this.progress) {
- this.progress = progress;
- changed(pg);
- }
+ private void setRelativeProgress(Progress pg, String name,
+ double relativeProgress) {
+ synchronized (lock) {
+ relativeProgress = Math.max(0, relativeProgress);
+ relativeProgress = Math.min(1, relativeProgress);
+ this.relativeProgress = relativeProgress;
+
+ changed(pg, name);
+ }
+ }
+
+ /**
+ * Get the total progress value (including the optional children
+ * {@link Progress}) on a 0 to 1 scale.
+ *
+ * @return the progress the value
+ */
+ private int getLocalProgress() {
+ return (int) Math.round(relativeLocalProgress * (max - min));
+ }
+
+ /**
+ * Add some value to the current progression of this {@link Progress}.
+ *
+ * @param step
+ * the amount to add
+ */
+ public void add(int step) {
+ synchronized (lock) {
+ setProgress(getLocalProgress() + step);
+ }
+ }
+
+ /**
+ * Check if the action corresponding to this {@link Progress} is done (i.e.,
+ * if its progress value == its max value).
+ *
+ * @return TRUE if it is
+ */
+ public boolean isDone() {
+ return getProgress() == max;
+ }
+
+ /**
+ * Mark the {@link Progress} as done by setting its value to max.
+ */
+ public void done() {
+ synchronized (lock) {
+ double childrenProgress = relativeProgress - relativeLocalProgress;
+ relativeLocalProgress = 1 - childrenProgress;
+ setRelativeProgress(this, name, 1d);
+ }
+ }
+
+ /**
+ * Return the list of direct children of this {@link Progress}.
+ *
+ * @return the children (Who will think of the children??)
+ */
+ public List<Progress> getChildren() {
+ synchronized (lock) {
+ return new ArrayList<Progress>(children.keySet());