diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/variable/NumericalVariable.java b/CPS/src/lu/list/itis/dkd/tui/cps/variable/NumericalVariable.java index 441694c201f49a0b6be738426dc3faf008d57b8c..40de7e464ea8be898eb16cd5c56bb814bb7f66a6 100644 --- a/CPS/src/lu/list/itis/dkd/tui/cps/variable/NumericalVariable.java +++ b/CPS/src/lu/list/itis/dkd/tui/cps/variable/NumericalVariable.java @@ -487,7 +487,7 @@ public class NumericalVariable extends Variable { public double getConstrainedValue() { this.normalizedValue = this.normalizeValue(this.value); - return this.minValue + (this.normalizedValue * this.valueRange); + return roundToPrecision(this.minValue + (this.normalizedValue * this.valueRange)); } // --------------------------------------------------------------------------- diff --git a/CPS/src/lu/list/itis/dkd/tui/utility/ThrottlingExecutor.java b/CPS/src/lu/list/itis/dkd/tui/utility/ThrottlingExecutor.java index eee6c8ad909582bc52536518738bf9c45635d5d1..02175ec8c4cf3afc407664d7f34d3e6ab01c22fd 100644 --- a/CPS/src/lu/list/itis/dkd/tui/utility/ThrottlingExecutor.java +++ b/CPS/src/lu/list/itis/dkd/tui/utility/ThrottlingExecutor.java @@ -34,6 +34,7 @@ import java.util.concurrent.TimeUnit; public class ThrottlingExecutor { private long last; + private long projected; private ScheduledFuture scheduled; private long coalescePeriod; @@ -54,6 +55,7 @@ public class ThrottlingExecutor { public ThrottlingExecutor() { this.coalescePeriod = 0; this.last = 0; + this.projected = 0; } // --------------------------------------------------------------------------- @@ -91,12 +93,15 @@ public class ThrottlingExecutor { public void submit(TimerTask task) { long now = System.currentTimeMillis(); - if ((this.coalescePeriod > 0) && (last > 0)) { + if (this.coalescePeriod > 0) { long elapsed = now - last; + long delay = 0; if (elapsed < this.coalescePeriod) { + delay = this.coalescePeriod - elapsed; + if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Task submitted within {} ms coalesce period! Deferred execution in {} ms!", this.coalescePeriod, (this.coalescePeriod - elapsed)); //$NON-NLS-1$ + LOGGER.debug("Task submitted within {} ms coalesce period! Deferred execution in {} ms!", this.coalescePeriod, delay); //$NON-NLS-1$ } if (scheduled != null) { @@ -106,13 +111,18 @@ public class ThrottlingExecutor { } } - scheduled = executor.schedule(task, (this.coalescePeriod - elapsed), TimeUnit.MILLISECONDS); + projected = last + coalescePeriod; + scheduled = executor.schedule(task, delay, TimeUnit.MILLISECONDS); return; } + + elapsed = now - projected; + delay = (elapsed < this.coalescePeriod) ? this.coalescePeriod - elapsed : 0; + scheduled = executor.schedule(task, delay, TimeUnit.MILLISECONDS); + last = now + delay; + } else { + scheduled = executor.schedule(task, 0, TimeUnit.MILLISECONDS); } - executor.schedule(task, 0, TimeUnit.MILLISECONDS); - last = now; - scheduled = null; } // --------------------------------------------------------------------------- diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java b/CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java index fb6cc43951559393206b67c841d2b30ab2457941..55dca49f74e2ff4052af033ea22a32d3ebb93cf7 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java @@ -219,21 +219,21 @@ public class ValueWidget extends TetherableWidget implements InformationProvider */ // --------------------------------------------------------------------------- - private void updateDisplays() { + private void updateDisplays(double newValue) { for (ValueCorona display : dispatcher) { - display.setInformation(this.variable.getConstrainedValue()); + display.setInformation(newValue); } } // --------------------------------------------------------------------------- - @SuppressWarnings("unchecked") - protected void updateTethers(Double value) { + @SuppressWarnings({"unchecked", "rawtypes"}) + protected void updateTethers(Double newValue) { if (this.isTethered()) { List dataFeeds = this.getTethers(InformationFeed.class); for (InformationFeed tether : dataFeeds) { - tether.setInformation(value); + tether.setInformation(newValue); } } } @@ -272,8 +272,10 @@ public class ValueWidget extends TetherableWidget implements InformationProvider value = Math.min(value, this.upperBound); variable.setValue(value); + value = variable.getConstrainedValue(); + this.updateTethers(value); - this.updateDisplays(); + this.updateDisplays(value); if (LOGGER.isDebugEnabled()) { LOGGER.debug("{} = {}", variable.getName(), value); //$NON-NLS-1$ @@ -290,7 +292,8 @@ public class ValueWidget extends TetherableWidget implements InformationProvider public void actionDrop(TangibleObject tuioObject) { if (Double.isNaN(dropAngle)) { - dropAngle = (isPersistent) ? 0 : AngleUtils.moduloTwoPi(tuioObject.getAngle()); + // dropAngle = (isPersistent) ? 0 : AngleUtils.moduloTwoPi(tuioObject.getAngle()); + dropAngle = AngleUtils.moduloTwoPi(tuioObject.getAngle()); } if (!isPersistent) { @@ -316,6 +319,8 @@ public class ValueWidget extends TetherableWidget implements InformationProvider if (!this.isPersistent(tuioObject.getObjectId())) { getVariable().setValue(initialValue); } + + dropAngle = Double.NaN; } // ---------------------------------------------------------------------------