Commit 8dfaee8c authored by Nico Mack's avatar Nico Mack

Bug Fixes in Selector and Value Widgets. Added relative mode to ArcGraph

as well as Face and Bezel Colour Properties
parent eda4c510
...@@ -144,6 +144,7 @@ public class DisplayWidgetBootstrapper implements BootstrapCallback { ...@@ -144,6 +144,7 @@ public class DisplayWidgetBootstrapper implements BootstrapCallback {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public BootstrapContext reset(BootstrapContext context) { public BootstrapContext reset(BootstrapContext context) {
this.index = 0;
variableIterator = variables.iterator(); variableIterator = variables.iterator();
if (variableIterator.hasNext()) { if (variableIterator.hasNext()) {
this.variable = variableIterator.next(); this.variable = variableIterator.next();
......
...@@ -113,7 +113,7 @@ public class Equation { ...@@ -113,7 +113,7 @@ public class Equation {
scriptExecutor.eval(this.script); scriptExecutor.eval(this.script);
} catch (Exception exception) { } catch (Exception exception) {
LOGGER.error("Error while evaluating script {}", this.script); //$NON-NLS-1$ LOGGER.error("Error while evaluating script {}", this.script); //$NON-NLS-1$
LOGGER.error("Engine threw an exception", exception); //$NON-NLS-1$ LOGGER.error("Engine threw an exception {}", exception.toString()); //$NON-NLS-1$
} }
dependentVariables = mapping.getDependentVariables(); dependentVariables = mapping.getDependentVariables();
......
...@@ -69,7 +69,7 @@ public class PythonExecutor extends Executor { ...@@ -69,7 +69,7 @@ public class PythonExecutor extends Executor {
} }
engine.set(variable.getName(), array); engine.set(variable.getName(), array);
if (LOGGER.isInfoEnabled()) { if (LOGGER.isInfoEnabled()) {
LOGGER.info("Parameter -> {} = {}", variable.getName(), list.toString()); //$NON-NLS-1$ LOGGER.info("Parameter -> {} = {}", variable.getName(), array.toString()); //$NON-NLS-1$
} }
} else if (Integer.class.isAssignableFrom(vector.getClassOfValues())) { } else if (Integer.class.isAssignableFrom(vector.getClassOfValues())) {
...@@ -84,7 +84,7 @@ public class PythonExecutor extends Executor { ...@@ -84,7 +84,7 @@ public class PythonExecutor extends Executor {
} }
engine.set(variable.getName(), array); engine.set(variable.getName(), array);
if (LOGGER.isInfoEnabled()) { if (LOGGER.isInfoEnabled()) {
LOGGER.info("Parameter -> {} = {}", variable.getName(), list.toString()); //$NON-NLS-1$ LOGGER.info("Parameter -> {} = {}", variable.getName(), array.toString()); //$NON-NLS-1$
} }
} }
} else { } else {
......
...@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory; ...@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author nmack * @author nmack
...@@ -75,12 +76,27 @@ public class DisplayWidget extends BaseWidget implements InputChangeListener { ...@@ -75,12 +76,27 @@ public class DisplayWidget extends BaseWidget implements InputChangeListener {
// *************************************************************************** // ***************************************************************************
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
public void connectWithOutputs(Map<String, Variable<?>> outputs) {
for (String variableName : variables.keySet()) {
NumericalVariable variable = variables.get(variableName);
if ((outputs != null) && outputs.containsKey(variableName)) {
Variable<?> output = outputs.get(variableName);
if (variable.getClass().isAssignableFrom(output.getClass())) {
NumericalVariable numeric = (NumericalVariable) output;
variables.put(variableName, numeric);
}
}
}
}
public void setVariables(Collection<Variable<?>> newVariables) { public void setVariables(Collection<Variable<?>> newVariables) {
Preconditions.checkArgument(variables == null, "Set of variables can't be null!"); //$NON-NLS-1$ Preconditions.checkArgument(newVariables != null, "Set of variables can't be null!"); //$NON-NLS-1$
this.variables = new HashMap<String, NumericalVariable>(); this.variables = new HashMap<String, NumericalVariable>();
for (Variable<?> variable : newVariables) { for (Variable<?> variable : newVariables) {
this.variables.put(variable.getName(), (NumericalVariable) variable); this.variables.put(variable.getName(), (NumericalVariable) variable);
variable.addListener(this);
} }
List<ValueCorona> displays = this.getCoronas(ValueCorona.class); List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
......
package lu.list.itis.dkd.tui.widget; package lu.list.itis.dkd.tui.widget;
import lu.list.itis.dkd.tui.adapter.TangibleObject; import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.builder.SelectorWidgetBuilder; import lu.list.itis.dkd.tui.widget.builder.SelectorWidgetBuilder;
import lu.list.itis.dkd.tui.widget.corona.FadingCorona; import lu.list.itis.dkd.tui.widget.corona.FadingCorona;
import lu.list.itis.dkd.tui.widget.corona.IndexedCorona; import lu.list.itis.dkd.tui.widget.corona.IndexedCorona;
...@@ -103,6 +104,21 @@ public class SelectorWidget extends ValueWidget { ...@@ -103,6 +104,21 @@ public class SelectorWidget extends ValueWidget {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
private float getCurrentAngle(int position) {
double segment = TWO_PI / numberOfPositions;
float angle = 0;
if ((position >= 0) && (position < numberOfPositions)) {
double minrot = (position - 0.5) * segment;
double maxrot = (position + 0.5) * segment;
angle = (float) (minrot + maxrot) / 2f;
}
return angle;
}
// ---------------------------------------------------------------------------
private void selectPosition(int position) { private void selectPosition(int position) {
if (position != currentPosition) { if (position != currentPosition) {
...@@ -149,10 +165,14 @@ public class SelectorWidget extends ValueWidget { ...@@ -149,10 +165,14 @@ public class SelectorWidget extends ValueWidget {
int position = getCurrentPosition(tuioObject.getAngle()); int position = getCurrentPosition(tuioObject.getAngle());
int widgetId = tuioObject.getObjectId(); int widgetId = tuioObject.getObjectId();
StateManager manager = states.get(widgetId);
boolean fadeIn = manager.isMoving() || manager.isRotating();
if (fadeIn) {
Stream<FadingCorona> autoFading = this.getCoronas(FadingCorona.class).stream().filter(corona -> corona.fadesWithHandle()); Stream<FadingCorona> autoFading = this.getCoronas(FadingCorona.class).stream().filter(corona -> corona.fadesWithHandle());
autoFading.forEach(corona -> corona.fadeIn()); autoFading.forEach(corona -> corona.fadeIn());
}
StateManager manager = states.get(widgetId);
if (manager.isRotating()) { if (manager.isRotating()) {
if (position != currentPosition) { if (position != currentPosition) {
...@@ -174,7 +194,11 @@ public class SelectorWidget extends ValueWidget { ...@@ -174,7 +194,11 @@ public class SelectorWidget extends ValueWidget {
@Override @Override
public void actionDrop(TangibleObject tuioObject) { public void actionDrop(TangibleObject tuioObject) {
int position = (this.isPersistent(tuioObject.getObjectId())) ? currentPosition : presetPosition; int position = (this.isPersistent(tuioObject.getObjectId())) ? currentPosition : presetPosition;
super.actionDrop(tuioObject); float angle = this.getCurrentAngle(position);
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), angle));
super.actionDrop(clone);
this.selectPosition(position); this.selectPosition(position);
} }
......
...@@ -144,17 +144,13 @@ public class ValueWidget extends TetherableWidget implements InformationProvider ...@@ -144,17 +144,13 @@ public class ValueWidget extends TetherableWidget implements InformationProvider
public void actionLift(TangibleObject tangibleObject) { public void actionLift(TangibleObject tangibleObject) {
super.actionLift(tangibleObject); super.actionLift(tangibleObject);
// set to 0 only if placing widget if (!this.isPersistent(tangibleObject.getObjectId())) {
if (!modifyValueOnRotation) { if (!modifyValueOnRotation) {
getVariable().setValue(0d); getVariable().setValue(0d);
} } else {
else {
getVariable().setValue(initialValue); getVariable().setValue(initialValue);
} }
}
} }
@Override @Override
......
...@@ -38,10 +38,17 @@ public class ArcGraph extends ValueCorona { ...@@ -38,10 +38,17 @@ public class ArcGraph extends ValueCorona {
private double outerRadius; private double outerRadius;
private int startAngle; private int startAngle;
private int arcSpan; private int arcSpan;
private boolean relative;
private double reference;
private ColorPair fillColour; private ColorPair fillColour;
private ColorPair strokeColour; private ColorPair strokeColour;
private ColorPair labelColour; private ColorPair labelColour;
private ColorPair textColour; private ColorPair textColour;
private ColorPair faceColour;
private ColorPair bezelColour;
private Shape labelShape; private Shape labelShape;
private Font textFont; private Font textFont;
private Stroke borderStroke; private Stroke borderStroke;
...@@ -49,6 +56,7 @@ public class ArcGraph extends ValueCorona { ...@@ -49,6 +56,7 @@ public class ArcGraph extends ValueCorona {
private Area outer; private Area outer;
private Area inner; private Area inner;
private Area arc; private Area arc;
private Area face;
private String label; private String label;
private LineMetrics labelMetrics; private LineMetrics labelMetrics;
...@@ -76,12 +84,17 @@ public class ArcGraph extends ValueCorona { ...@@ -76,12 +84,17 @@ public class ArcGraph extends ValueCorona {
this.startAngle = builder.startAngle; this.startAngle = builder.startAngle;
this.arcSpan = builder.arcSpan; this.arcSpan = builder.arcSpan;
this.relative = builder.relative;
this.reference = builder.reference;
this.innerRadius = builder.innerRadius; this.innerRadius = builder.innerRadius;
this.outerRadius = builder.outerRadius; this.outerRadius = builder.outerRadius;
this.fillColour = builder.fillColour; this.fillColour = builder.fillColour;
this.strokeColour = builder.strokeColour; this.strokeColour = builder.strokeColour;
this.labelColour = builder.labelColour; this.labelColour = builder.labelColour;
this.textColour = builder.textColour; this.textColour = builder.textColour;
this.faceColour = builder.faceColour;
this.bezelColour = builder.bezelColour;
this.labelShape = builder.labelShape; this.labelShape = builder.labelShape;
this.textFont = builder.textFont; this.textFont = builder.textFont;
...@@ -91,6 +104,12 @@ public class ArcGraph extends ValueCorona { ...@@ -91,6 +104,12 @@ public class ArcGraph extends ValueCorona {
diameter = 2 * outerRadius; diameter = 2 * outerRadius;
outer = new Area(new Ellipse2D.Double(-outerRadius, -outerRadius, diameter, diameter)); outer = new Area(new Ellipse2D.Double(-outerRadius, -outerRadius, diameter, diameter));
Shape sector = new Arc2D.Double(-outerRadius, -outerRadius, diameter, diameter, startAngle, arcSpan, Arc2D.PIE);
face = new Area(sector);
face.subtract(inner);
outer.subtract(inner);
if (this.labelShape != null) { if (this.labelShape != null) {
AffineTransform originTranslator = new AffineTransform(); AffineTransform originTranslator = new AffineTransform();
...@@ -102,7 +121,7 @@ public class ArcGraph extends ValueCorona { ...@@ -102,7 +121,7 @@ public class ArcGraph extends ValueCorona {
borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null; borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null;
this.setInformation(this.variable.getMinValue()); this.setInformation((relative) ? this.reference : this.variable.getMinValue());
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -142,6 +161,22 @@ public class ArcGraph extends ValueCorona { ...@@ -142,6 +161,22 @@ public class ArcGraph extends ValueCorona {
this.opacity = 1.0f; this.opacity = 1.0f;
} }
// ---------------------------------------------------------------------------
private void switchColours(boolean isNegative) {
if (relative) {
fillColour.setSwitched(isNegative);
strokeColour.setSwitched(isNegative);
labelColour.setSwitched(isNegative);
textColour.setSwitched(isNegative);
if (faceColour != null)
faceColour.setSwitched(isNegative);
if (bezelColour != null)
bezelColour.setSwitched(isNegative);
}
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Class Body * // * Class Body *
...@@ -151,10 +186,17 @@ public class ArcGraph extends ValueCorona { ...@@ -151,10 +186,17 @@ public class ArcGraph extends ValueCorona {
@Override @Override
public void setSelected(boolean selectIt) { public void setSelected(boolean selectIt) {
super.setSelected(selectIt); super.setSelected(selectIt);
fillColour.setSelected(selectIt);
strokeColour.setSelected(selectIt); if (!relative) {
labelColour.setSelected(selectIt); fillColour.setSwitched(selectIt);
textColour.setSelected(selectIt); strokeColour.setSwitched(selectIt);
labelColour.setSwitched(selectIt);
textColour.setSwitched(selectIt);
if (faceColour != null)
faceColour.setSwitched(selectIt);
if (bezelColour != null)
bezelColour.setSwitched(selectIt);
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -169,15 +211,28 @@ public class ArcGraph extends ValueCorona { ...@@ -169,15 +211,28 @@ public class ArcGraph extends ValueCorona {
shownValue = value; shownValue = value;
if (variable != null) { if (variable != null) {
double extend = arcSpan * (shownValue - this.variable.getMinValue()) / (this.variable.getMaxValue() - this.variable.getMinValue());
if (extend == arcSpan) double extend = 0;
double start = 0;
double valueRange = this.variable.getMaxValue() - this.variable.getMinValue();
if (relative) {
start = startAngle + (arcSpan * (this.variable.getMaxValue() / valueRange));
extend = arcSpan * (shownValue / valueRange);
switchColours(shownValue <= 0);
} else {
start = startAngle;
extend = arcSpan * (shownValue - this.variable.getMinValue()) / valueRange;
}
if ((shownValue == this.variable.getMaxValue()) || (relative && (shownValue == this.variable.getMinValue())))
this.startBlinking(); this.startBlinking();
else else
this.stopBlinking(); this.stopBlinking();
double diameter = 2 * outerRadius; double diameter = 2 * outerRadius;
Shape sector = new Arc2D.Double(-outerRadius, -outerRadius, diameter, diameter, startAngle, extend, Arc2D.PIE); Shape sector = new Arc2D.Double(-outerRadius, -outerRadius, diameter, diameter, start, extend, Arc2D.PIE);
arc = new Area(sector); arc = new Area(sector);
arc.subtract(inner); arc.subtract(inner);
outer.subtract(inner); outer.subtract(inner);
...@@ -212,6 +267,18 @@ public class ArcGraph extends ValueCorona { ...@@ -212,6 +267,18 @@ public class ArcGraph extends ValueCorona {
if (this.opacity < 1.0f) if (this.opacity < 1.0f)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity)); localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
if (faceColour != null) {
localCanvas.setPaint(faceColour.getColor());
localCanvas.fill(face);
}
if (bezelColour != null) {
localCanvas.setPaint(bezelColour.getColor());
if (borderStroke != null)
localCanvas.setStroke(borderStroke);
localCanvas.draw(face);
}
if (fillColour != null) { if (fillColour != null) {
localCanvas.setPaint(fillColour.getColor()); localCanvas.setPaint(fillColour.getColor());
localCanvas.fill(arc); localCanvas.fill(arc);
......
...@@ -34,11 +34,15 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> { ...@@ -34,11 +34,15 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> {
public double outerRadius; public double outerRadius;
public int startAngle; public int startAngle;
public int arcSpan; public int arcSpan;
public boolean relative;
public double reference;
public ColorPair fillColour; public ColorPair fillColour;
public ColorPair strokeColour; public ColorPair strokeColour;
public ColorPair labelColour; public ColorPair labelColour;
public ColorPair textColour; public ColorPair textColour;
public ColorPair faceColour;
public ColorPair bezelColour;
public int strokeWidth; public int strokeWidth;
public Shape labelShape; public Shape labelShape;
public Font textFont; public Font textFont;
...@@ -86,6 +90,8 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> { ...@@ -86,6 +90,8 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> {
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException { private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
startAngle = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.START_ANGLE_NODE, BootstrappingUtils.MANDATORY, null, context); startAngle = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.START_ANGLE_NODE, BootstrappingUtils.MANDATORY, null, context);
arcSpan = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.ARC_SPAN_NODE, BootstrappingUtils.MANDATORY, null, context); arcSpan = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.ARC_SPAN_NODE, BootstrappingUtils.MANDATORY, null, context);
relative = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.RELATIVE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context);
reference = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.REFERENCE_NODE, BootstrappingUtils.OPTIONAL, 0d, context);
innerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.INNER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context); innerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.INNER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context);
outerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.OUTER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context); outerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.OUTER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context);
...@@ -94,10 +100,12 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> { ...@@ -94,10 +100,12 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> {
strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context); strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context);
fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), context); fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), context); textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), context); strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
labelColour = buildColorPair(rootElement.getChild(Externalization.LABEL_COLOUR_ELEMENT), context); labelColour = buildColorPair(rootElement.getChild(Externalization.LABEL_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
faceColour = buildColorPair(rootElement.getChild(Externalization.FACE_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
bezelColour = buildColorPair(rootElement.getChild(Externalization.BEZEL_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
labelShape = ShapeBootstrapper.getShape(rootElement.getChild(Externalization.LABEL_SHAPE_NODE), context, callback); labelShape = ShapeBootstrapper.getShape(rootElement.getChild(Externalization.LABEL_SHAPE_NODE), context, callback);
...@@ -111,11 +119,23 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> { ...@@ -111,11 +119,23 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
private ColorPair buildColorPair(Element rootElement, BootstrapContext context) throws BuildException { private ColorPair buildColorPair(Element rootElement, boolean optional, BootstrapContext context) throws BuildException {
Color selectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.SELECTED_ELEMENT, BootstrappingUtils.MANDATORY, null, context); ColorPair color = null;
Color deselectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.DESELECTED_ELEMENT, BootstrappingUtils.MANDATORY, null, context);
return new ColorPair(selectedColour, deselectedColour); if (rootElement == null)
return null;
if (!relative) {
Color selectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.SELECTED_ELEMENT, optional, null, context);
Color deselectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.DESELECTED_ELEMENT, optional, null, context);
color = new ColorPair(selectedColour, deselectedColour);
} else {
Color aboveColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.ABOVE_ELEMENT, optional, null, context);
Color belowColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.BELOW_ELEMENT, optional, null, context);
color = new ColorPair(belowColour, aboveColour);
}
return color;
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
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