-package org.simantics.graph.db;\r
-\r
-public interface TGStatusMonitor {\r
-\r
- void status(int percentage);\r
- boolean isCanceled();\r
-\r
- public static class NullMonitor implements TGStatusMonitor {\r
- @Override\r
- public void status(int percentage) {\r
- }\r
- @Override\r
- public boolean isCanceled() {\r
- return false;\r
- }\r
- }\r
-\r
- public static final TGStatusMonitor NULL_MONITOR = new NullMonitor();\r
-\r
- public static class Updater {\r
- private final TGStatusMonitor monitor;\r
- private final int total;\r
- private int low;\r
- private int high;\r
- private int current;\r
- private int worked;\r
-\r
- public Updater(TGStatusMonitor monitor, int lowPercentage, int highPercentage, int totalWork) {\r
- this.monitor = monitor;\r
- this.low = lowPercentage;\r
- this.high = highPercentage;\r
- this.total = totalWork;\r
- }\r
-\r
- public int worked(int work) {\r
- worked += work;\r
- return current = updatePercentage(monitor, low, high, current, worked, total);\r
- }\r
- }\r
-\r
- public static int updatePercentage(TGStatusMonitor monitor, int low, int high, int oldPercentage, int done, int total) {\r
- int range = high - low;\r
- int current = low + (range * done) / total;\r
- if (current != oldPercentage) {\r
- oldPercentage = current;\r
- if (monitor != null) \r
- monitor.status(oldPercentage);\r
- }\r
- return oldPercentage;\r
- }\r
-\r
+package org.simantics.graph.db;
+
+public interface TGStatusMonitor {
+
+ void status(int percentage);
+ boolean isCanceled();
+
+ public static class NullMonitor implements TGStatusMonitor {
+ @Override
+ public void status(int percentage) {
+ }
+ @Override
+ public boolean isCanceled() {
+ return false;
+ }
+ }
+
+ public static final TGStatusMonitor NULL_MONITOR = new NullMonitor();
+
+ public static class Updater {
+ private final TGStatusMonitor monitor;
+ private final int total;
+ private int low;
+ private int high;
+ private int current;
+ private int worked;
+
+ public Updater(TGStatusMonitor monitor, int lowPercentage, int highPercentage, int totalWork) {
+ this.monitor = monitor;
+ this.low = lowPercentage;
+ this.high = highPercentage;
+ this.total = totalWork;
+ }
+
+ public int worked(int work) {
+ worked += work;
+ return current = updatePercentage(monitor, low, high, current, worked, total);
+ }
+ }
+
+ public static int updatePercentage(TGStatusMonitor monitor, int low, int high, int oldPercentage, int done, int total) {
+ int range = high - low;
+ int current = low + (range * done) / total;
+ if (current != oldPercentage) {
+ oldPercentage = current;
+ if (monitor != null)
+ monitor.status(oldPercentage);
+ }
+ return oldPercentage;
+ }
+