Commit 298dd40d authored by Nico Mack's avatar Nico Mack

Improvements to reset behaviour.

Same InputChangeListener could be added multiple times to variable.
Fixed.
parent 0ce0f844
......@@ -319,7 +319,9 @@ public abstract class Variable<V> implements Cloneable {
* The {@link InputChangeListener} to add.
*/
public void addListener(InputChangeListener listener) {
listeners.add(listener);
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
/**
......
......@@ -125,17 +125,17 @@ public class DisplayWidget extends BaseWidget implements InputChangeListener {
Variable<?> variable = this.variables.get(variableName);
if (variable != null) {
if (variable.wasModified()) {
Object information = variable.getValue();
Collection<ValueCorona> displays = dispatcher.get(variableName);
if (displays != null) {
for (ValueCorona display : displays) {
display.setInformation(information);
}
} else {
LOGGER.warn("No matching display found for variable {}!", variableName); //$NON-NLS-1$
// if (variable.wasModified()) {
Object information = variable.getValue();
Collection<ValueCorona> displays = dispatcher.get(variableName);
if (displays != null) {
for (ValueCorona display : displays) {
display.setInformation(information);
}
} else {
LOGGER.warn("No matching display found for variable {}!", variableName); //$NON-NLS-1$
}
// }
} else {
LOGGER.warn("Required variable {} unkown to display widget!", variableName); //$NON-NLS-1$
}
......@@ -193,9 +193,11 @@ public class DisplayWidget extends BaseWidget implements InputChangeListener {
// }
public void setVariables(Collection<Variable<?>> newVariables) {
Preconditions.checkArgument(newVariables != null, "Set of variables can't be null!");
Preconditions.checkArgument(newVariables != null, "Set of variables can't be null!"); //$NON-NLS-1$
// $NON-NLS-1$
assert newVariables != null;
this.variables = new HashMap<>();
for (Variable<?> variable : newVariables) {
this.variables.put(variable.getName(), (NumericalVariable) variable);
......@@ -210,8 +212,7 @@ public class DisplayWidget extends BaseWidget implements InputChangeListener {
if (this.variables.containsKey(variableName)) {
display.setVariable(this.variables.get(variableName));
} else {
LOGGER.warn("Corona requires variable {} unkown to display widget!", variableName);
// $NON-NLS-1$
LOGGER.warn("Corona requires variable {} unkown to display widget!", variableName); //$NON-NLS-1$
}
}
}
......
......@@ -83,7 +83,7 @@ public class SelectorWidget extends ValueWidget {
// ***************************************************************************
// ---------------------------------------------------------------------------
private int getNumberOfPositions() {
protected int getNumberOfPositions() {
List<IndexedCorona> selectableCoronas = getCoronas(IndexedCorona.class);
HashSet<Integer> alreadySeen = new HashSet<>();
......@@ -105,10 +105,21 @@ public class SelectorWidget extends ValueWidget {
// ---------------------------------------------------------------------------
private int getCurrentPosition(float angle) {
protected float moduloTwoPi(float rawAngle) {
double angle = rawAngle % TWO_PI;
if (angle < 0)
angle += TWO_PI;
return (float) angle;
}
// ---------------------------------------------------------------------------
protected int getCurrentPosition(float newAngle) {
double segment = TWO_PI / numberOfPositions;
int current = 0;
float angle = this.moduloTwoPi(newAngle);
// detect in which segment the current rotation is
for (int position = 0; position < numberOfPositions; position++) {
double minrot = (position - 0.5) * segment;
......@@ -125,7 +136,7 @@ public class SelectorWidget extends ValueWidget {
// ---------------------------------------------------------------------------
private float getCurrentAngle(int position) {
protected float getCurrentAngle(int position) {
double segment = TWO_PI / numberOfPositions;
float angle = 0;
......@@ -140,7 +151,7 @@ public class SelectorWidget extends ValueWidget {
// ---------------------------------------------------------------------------
private void selectPosition(int position) {
protected void selectPosition(int position) {
if (position != currentPosition) {
this.getCoronas(IndexedCorona.class).forEach(indexed -> indexed.setSelected(indexed.getIndex() == position));
......@@ -164,7 +175,7 @@ public class SelectorWidget extends ValueWidget {
this.selectPosition(presetPosition);
Point centre = this.getPosition();
if (centre != null) {
presetAngleOffset = (float) ((this.getCurrentAngle(currentPosition) - (centre.getAngle() - presetAngleOffset)) % TWO_PI);
presetAngleOffset = this.moduloTwoPi(this.getCurrentAngle(currentPosition) - (centre.getAngle() - presetAngleOffset));
}
}
}
......@@ -194,7 +205,7 @@ public class SelectorWidget extends ValueWidget {
@Override
public void actionMove(TangibleObject tuioObject) {
double angle = (tuioObject.getAngle() + presetAngleOffset) % TWO_PI;
double angle = this.moduloTwoPi(tuioObject.getAngle() + presetAngleOffset);
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), (float) angle));
super.actionMove(clone);
......@@ -233,8 +244,7 @@ public class SelectorWidget extends ValueWidget {
isPersistent = this.isPersistent(tuioObject.getObjectId());
int position = (isPersistent) ? currentPosition : presetPosition;
presetAngleOffset = (isPersistent) ? (float) ((this.getCurrentAngle(position) - tuioObject.getAngle()) % TWO_PI) : 0;
presetAngleOffset = (isPersistent) ? this.moduloTwoPi(this.getCurrentAngle(position) - tuioObject.getAngle()) : 0;
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), presetAngleOffset));
super.actionDrop(clone);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment