X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph.db%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fdb%2FTGStatusMonitor.java;h=54d65ce98f307f2e6a4dd2a95f881837930295d5;hb=50dee4ff8fd82c2e6ad78246b5b1f6880865a3e8;hp=8f93639eac225667401e242bd1e1e0b8993cc6ff;hpb=0cbe7783b5f5297ab926fa742e023cfcbdcba43d;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TGStatusMonitor.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TGStatusMonitor.java index 8f93639ea..54d65ce98 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TGStatusMonitor.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TGStatusMonitor.java @@ -1,52 +1,52 @@ -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; - } - +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; + } + } \ No newline at end of file