/
ProgressCounter.java
81 lines (63 loc) · 1.76 KB
/
ProgressCounter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package msi.gama.util.file;
import org.geotools.util.SimpleInternationalString;
import org.opengis.util.InternationalString;
import org.opengis.util.ProgressListener;
import msi.gama.common.interfaces.IStatusDisplayer;
import msi.gama.runtime.GAMA;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
class ProgressCounter implements ProgressListener {
final IScope scope;
final String name;
float progress;
ProgressCounter(final IScope scope, final String name) {
this.scope = scope;
this.name = name;
}
IStatusDisplayer getDisplayer() {
return scope.getGui().getStatus(scope);
}
@Override
public void complete() {
getDisplayer().setSubStatusCompletion(1d);
}
@Override
public void dispose() {
getDisplayer().endSubStatus(name.toString());
}
@Override
public void exceptionOccurred(final Throwable arg0) {
GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.create(arg0, scope), true);
}
@Override
public float getProgress() {
return progress;
}
@Override
public InternationalString getTask() {
return new SimpleInternationalString(name);
}
@Override
public boolean isCanceled() {
return scope.interrupted();
}
@Override
public void progress(final float p) {
progress = p;
getDisplayer().setSubStatusCompletion(progress);
}
@Override
public void setCanceled(final boolean cancel) {
getDisplayer().endSubStatus(name.toString());
}
@Override
public void setTask(final InternationalString n) {}
@Override
public void started() {
getDisplayer().beginSubStatus(name.toString());
}
@Override
public void warningOccurred(final String source, final String location, final String warning) {
GAMA.reportAndThrowIfNeeded(scope, GamaRuntimeException.warning(warning, scope), false);
}
}