Commit 99497bba authored by Nico Mack's avatar Nico Mack

Improvements and extension on PositionWidget.

Implementation of instantiation code of SpatialVariables in
VariableBootstrapper class.
parent 690d5317
......@@ -30,6 +30,8 @@ SELECTED_ITEMS_VARIABLE_NODE=selectedItemsVariable
SELECTED_RADIUS_NODE=selectedRadius
STEP_SIZE_NODE=stepSize
STRETCH_TO_FIT_NODE=stretchToFit
TRACK_ROTATION_CONTINUOUSLY_NODE=trackRotationContinuously
TRACK_TRANSLATION_CONTINUOUSLY_NODE=trackTranslationContinuously
UPPER_BOUND_RADIUS_NODE=upperBoundRadius
UPPER_BOUND_VARIABLE_NODE=upperBoundVariable
UPPER_STOP_ANGLE_NODE=upperStopAngle
......
......@@ -17,10 +17,13 @@ import lu.list.itis.dkd.tui.cps.utility.EquationSystemBundle;
import lu.list.itis.dkd.tui.cps.variable.BooleanVariable;
import lu.list.itis.dkd.tui.cps.variable.MapVariable;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.SpatialVariable;
import lu.list.itis.dkd.tui.cps.variable.TextVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.cps.variable.VectorVariable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.CoordinateState;
import lu.list.itis.dkd.tui.utility.Point;
import org.jdom2.Element;
......@@ -84,6 +87,21 @@ public class VariableBootstrapper {
variable = textVariable;
break;
case EquationSystemBundle.SPATIAL_TYPE:
SpatialVariable spatialVariable = new SpatialVariable(name);
Point initialPosition;
Element initialNode = variableNode.getChild(EquationSystemBundle.INITIAL_ATTRIBUTE);
if (initialNode != null) {
initialPosition = new Point(initialNode, context, callback);
} else {
CoordinateState state = CoordinateStateBootstrapper.getCoordinateState(variableNode, new Point(), context, callback);
initialPosition = new Point(state.getClass());
}
spatialVariable.setValue(initialPosition);
variable = spatialVariable;
break;
default:
throw new BuildException("Don't know how to build a Variable of type " + type); //$NON-NLS-1$
}
......
......@@ -56,7 +56,6 @@ public class CpsNamespace extends NLS {
public static String MODIFY_VALUE_ON_ROTATION_NODE;
public static String MODIFY_VALUE_ON_TRANSLATION_NODE;
public static String MULTITURN_NODE;
public static String POSITIONS_NODE;
public static String RANGE_SEPARATOR_ATTRIBUTE;
......@@ -71,6 +70,9 @@ public class CpsNamespace extends NLS {
public static String STEP_SIZE_NODE;
public static String STRETCH_TO_FIT_NODE;
public static String TRACK_ROTATION_CONTINUOUSLY_NODE;
public static String TRACK_TRANSLATION_CONTINUOUSLY_NODE;
public static String UPPER_BOUND_RADIUS_NODE;
public static String UPPER_BOUND_VARIABLE_NODE;
public static String UPPER_STOP_ANGLE_NODE;
......
......@@ -18,6 +18,8 @@ import lu.list.itis.dkd.tui.content.InformationProvider;
import lu.list.itis.dkd.tui.cps.system.VariableBased;
import lu.list.itis.dkd.tui.cps.variable.SpatialVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.event.TimerEvent;
import lu.list.itis.dkd.tui.event.TimerEventListener;
import lu.list.itis.dkd.tui.utility.CoordinateState;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.builder.BasePositionWidgetBuilder;
......@@ -36,16 +38,21 @@ import java.util.Map;
// * Class Definition and Members *
// ***************************************************************************
public class PositionWidget extends PointingWidget implements InformationProvider<Point>, VariableBased {
public class PositionWidget extends PointingWidget implements InformationProvider<Point>, TimerEventListener, VariableBased {
private SpatialVariable variable;
protected boolean modifyValueOnRotation = false;
protected boolean modifyValueOnTranslation = false;
protected boolean modifyValueOnRotation;
protected boolean modifyValueOnTranslation;
protected boolean trackRotationContinuously;
protected boolean trackTranslationContinuously;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final boolean SINGLE = false;
private static final boolean CONTINUOUS = true;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -60,6 +67,11 @@ public class PositionWidget extends PointingWidget implements InformationProvide
public PositionWidget(BasePositionWidgetBuilder<?> builder) {
super(builder);
this.variable = builder.variable;
this.modifyValueOnRotation = builder.modifyValueOnRotation;
this.modifyValueOnTranslation = builder.modifyValueOnTranslation;
this.trackRotationContinuously = builder.trackRotationContinuously;
this.trackTranslationContinuously = builder.trackTranslationContinuously;
}
// ---------------------------------------------------------------------------
......@@ -68,17 +80,18 @@ public class PositionWidget extends PointingWidget implements InformationProvide
// ***************************************************************************
// ---------------------------------------------------------------------------
private void updateFromMove(Point newPosition) {
private void updateFromMove(Point newPosition, boolean continuous) {
if (this.variable != null) {
Point position = this.variable.getValue();
if (position != null) {
CoordinateState coordinates = position.getState();
newPosition = newPosition.toCoordinates(coordinates.getClass());
if (modifyValueOnRotation) {
if (modifyValueOnRotation && (!continuous || trackRotationContinuously)) {
position.setAngle(newPosition.getAngle());
}
if (modifyValueOnTranslation) {
if (modifyValueOnTranslation && (!continuous || trackTranslationContinuously)) {
position.setLocation(newPosition.x, newPosition.y);
}
this.variable.setValue(position);
......@@ -98,7 +111,7 @@ public class PositionWidget extends PointingWidget implements InformationProvide
public void actionDrop(TangibleObject tuioObject) {
super.actionDrop(tuioObject);
Point position = this.getPointingLocation(tuioObject.getPosition());
this.updateFromMove(position);
this.updateFromMove(position, SINGLE);
}
// ---------------------------------------------------------------------------
......@@ -107,11 +120,8 @@ public class PositionWidget extends PointingWidget implements InformationProvide
public void actionMove(TangibleObject tuioObject) {
super.actionMove(tuioObject);
StateManager manager = objectStates.get(tuioObject.getObjectId());
if (manager.wasRotating() || manager.wasMoving()) {
Point position = this.getPointingLocation(tuioObject.getPosition());
this.updateFromMove(position);
if (this.trackRotationContinuously || this.trackTranslationContinuously) {
this.updateFromMove(tuioObject.getPosition(), CONTINUOUS);
}
}
......@@ -161,6 +171,34 @@ public class PositionWidget extends PointingWidget implements InformationProvide
return (this.variable != null) ? this.variable.getValue() : null;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void stoppedMoving(TimerEvent event) {
if (!this.modifyValueOnTranslation)
return;
Point position = ((StateManager) event.getSource()).getLastPosition();
Point pointer = this.getPointingLocation(position);
this.updateFromMove(pointer, SINGLE);
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void stoppedRotating(TimerEvent event) {
if (!this.modifyValueOnRotation)
return;
Point position = ((StateManager) event.getSource()).getLastPosition();
Point pointer = this.getPointingLocation(position);
this.updateFromMove(pointer, SINGLE);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
......
......@@ -30,6 +30,8 @@ public abstract class BasePositionWidgetBuilder<B extends BasePositionWidgetBuil
public SpatialVariable variable;
public boolean modifyValueOnRotation;
public boolean modifyValueOnTranslation;
public boolean trackRotationContinuously;
public boolean trackTranslationContinuously;
// ***************************************************************************
// * Constants *
......@@ -67,6 +69,8 @@ public abstract class BasePositionWidgetBuilder<B extends BasePositionWidgetBuil
this.variable = (SpatialVariable) VariableBootstrapper.buildVariableFromElement(rootElement.getChild(CpsNamespace.VARIABLE_NODE), context, callback);
this.modifyValueOnRotation = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.MODIFY_VALUE_ON_ROTATION_NODE, BootstrappingUtils.OPTIONAL, true, context);
this.modifyValueOnTranslation = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.MODIFY_VALUE_ON_TRANSLATION_NODE, BootstrappingUtils.OPTIONAL, true, context);
this.trackRotationContinuously = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.TRACK_ROTATION_CONTINUOUSLY_NODE, BootstrappingUtils.OPTIONAL, false, context);
this.trackTranslationContinuously = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.TRACK_TRANSLATION_CONTINUOUSLY_NODE, BootstrappingUtils.OPTIONAL, false, context);
}
// ---------------------------------------------------------------------------
......
......@@ -20,11 +20,13 @@
*/
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.widget.PositionWidget;
import lu.list.itis.dkd.tui.widget.ValueWidget;
import lu.list.itis.dkd.tui.widget.state.StateManager;
import org.jdom2.Element;
......@@ -75,9 +77,19 @@ public class PositionWidgetBuilder extends BasePositionWidgetBuilder<PositionWid
super(rootElement, context, callback);
}
@NonNullByDefault
protected void addAsListener(PositionWidget widget) {
for (StateManager manager : widget.getManagers()) {
manager.addListener(widget);
}
}
/** {@inheritDoc} */
@Override
public PositionWidget build() {
return new PositionWidget(this);
PositionWidget widget = new PositionWidget(this);
this.addAsListener(widget);
return widget;
}
}
\ No newline at end of file
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