1 package org.simantics.graph.db;
\r
3 public interface TGStatusMonitor {
\r
5 void status(int percentage);
\r
6 boolean isCanceled();
\r
8 public static class NullMonitor implements TGStatusMonitor {
\r
10 public void status(int percentage) {
\r
13 public boolean isCanceled() {
\r
18 public static final TGStatusMonitor NULL_MONITOR = new NullMonitor();
\r
20 public static class Updater {
\r
21 private final TGStatusMonitor monitor;
\r
22 private final int total;
\r
25 private int current;
\r
28 public Updater(TGStatusMonitor monitor, int lowPercentage, int highPercentage, int totalWork) {
\r
29 this.monitor = monitor;
\r
30 this.low = lowPercentage;
\r
31 this.high = highPercentage;
\r
32 this.total = totalWork;
\r
35 public int worked(int work) {
\r
37 return current = updatePercentage(monitor, low, high, current, worked, total);
\r
41 public static int updatePercentage(TGStatusMonitor monitor, int low, int high, int oldPercentage, int done, int total) {
\r
42 int range = high - low;
\r
43 int current = low + (range * done) / total;
\r
44 if (current != oldPercentage) {
\r
45 oldPercentage = current;
\r
46 if (monitor != null)
\r
47 monitor.status(oldPercentage);
\r
49 return oldPercentage;
\r