1 19 20 package org.netbeans.api.progress.aggregate; 21 22 30 public final class ProgressContributor { 31 private String id; 32 private int workunits; 33 private int current; 34 private int parentUnits; 35 private int lastParentedUnit; 36 private AggregateProgressHandle parent; 37 38 39 ProgressContributor(String id) { 40 this.id = id; 41 workunits = 0; 42 current = 0; 43 lastParentedUnit = 0; 44 } 45 46 49 public String getTrackingId() { 50 return id; 51 } 52 53 void setParent(AggregateProgressHandle par) { 54 parent = par; 55 } 56 57 int getWorkUnits() { 58 return workunits; 59 } 60 61 int getRemainingParentWorkUnits() { 62 return parentUnits; 63 } 64 65 void setAvailableParentWorkUnits(int newCount) { 66 parentUnits = newCount; 67 } 68 69 double getCompletedRatio() { 70 return workunits == 0 ? 0 : (double)(current / workunits); 71 } 72 73 77 public void start(int workunits) { 78 if (parent == null) { 79 return; 80 } 81 this.workunits = workunits; 82 parent.processContributorStart(this, null); 83 } 84 85 86 90 public void finish() { 91 if (parent == null) { 92 return; 93 } 94 if (current < workunits) { 95 progress(null, workunits); 96 } 97 parent.processContributorFinish(this); 98 } 99 100 101 105 public void progress(int workunit) { 106 progress(null, workunit); 107 } 108 109 113 public void progress(String message) { 114 progress(message, current); 115 } 116 117 122 public void progress(String message, int unit) { 123 if (parent == null) { 124 return; 125 } 126 assert unit >= current && unit <= workunits; 127 if (message != null && unit == current) { 128 parent.processContributorStep(this, message, 0); 130 return; 131 } 132 current = unit; 133 int delta = current - lastParentedUnit; 134 double step = (1 / ((double)parentUnits / (double)(workunits - lastParentedUnit))); 135 if (delta >= step) { 140 int count = (int) (delta / step); 141 lastParentedUnit = lastParentedUnit + (int)(count * step); 142 parentUnits = parentUnits - count; 143 parent.processContributorStep(this, message, count); 148 } 149 } 150 } 151 | Popular Tags |