Commit bc8b0bda authored by Nico Mack's avatar Nico Mack

Bug Fixes and Improvements

parent 99e5146f
......@@ -28,6 +28,8 @@ import lu.list.itis.dkd.tui.cps.InputEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
/**
......@@ -40,7 +42,7 @@ import java.util.Vector;
@NonNullByDefault
public abstract class System implements InputDriver, InputChangeListener {
/** Field holding the {@link Vector} of nested {@link System} instances. */
protected Vector<System> nestedSystems;
protected List<System> nestedSystems;
protected boolean lockSystemForNesting = true;
private static final Logger logger = LoggerFactory.getLogger(System.class.getSimpleName());
......@@ -49,7 +51,7 @@ public abstract class System implements InputDriver, InputChangeListener {
* Constructor.
*/
public System() {
nestedSystems = new Vector<>();
nestedSystems = new ArrayList<>();
}
/**
......
......@@ -62,8 +62,9 @@ public class SqlExecutor extends Executor {
private static final String SQL_USER_PASSWORD = "sql.user.password"; //$NON-NLS-1$
private static final Pattern SQL_VAR_PATTERN = Pattern.compile("([\\$@])\\{([a-z0-9\\-_]+)\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final String SQL_PLACEHOLDER = "?"; //$NON-NLS-1$
private static Logger LOGGER = LoggerFactory.getLogger(SqlExecutor.class.getSimpleName());
private static final Logger LOGGER = LoggerFactory.getLogger(SqlExecutor.class.getSimpleName());
private static final int MAX_CONNECTION_ATTEMPTS = 3;
private static HashMap<Class<?>, String> JavaToJdbcMapping = new HashMap<>();
......@@ -197,7 +198,7 @@ public class SqlExecutor extends Executor {
placeholders.add(variable);
if (SCALAR.equals(type)) {
interpolated.append("?"); //$NON-NLS-1$
interpolated.append(SQL_PLACEHOLDER);
if (positionalParameters)
interpolated.append(index++);
}
......@@ -206,21 +207,21 @@ public class SqlExecutor extends Executor {
if (value instanceof Collection) {
Collection<?> collection = (Collection<?>) value;
String separator = "";
if (collection.size() > 0) {
if (!collection.isEmpty()) {
for (int count = 0; count < collection.size(); count++) {
interpolated.append(separator);
interpolated.append("?");
interpolated.append(SQL_PLACEHOLDER);
if (positionalParameters)
interpolated.append(index++);
separator = ",";
}
} else {
interpolated.append("?"); //$NON-NLS-1$
interpolated.append(SQL_PLACEHOLDER);
if (positionalParameters)
interpolated.append(index++);
}
} else {
interpolated.append("?"); //$NON-NLS-1$
interpolated.append(SQL_PLACEHOLDER);
if (positionalParameters)
interpolated.append(index++);
}
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.utility;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 2.5.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class Interpolator {
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{([a-z0-9\\-_]+)(\\.(%[bhscxegat\\+\\.0-9]+))?\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s)
// ***************************************************************************
// ---------------------------------------------------------------------------
private Interpolator() {}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
public static String interpolate(String template, Map<String, Object> parameters) {
Matcher interpolator;
String format;
String variable;
int position = 0;
StringBuilder interpolated;
interpolator = VARIABLE_PATTERN.matcher(template);
interpolated = new StringBuilder();
while (interpolator.find()) {
interpolated.append(template.substring(position, interpolator.start()));
variable = interpolator.group(1);
format = (interpolator.groupCount() == 3) ? interpolator.group(3) : ""; //$NON-NLS-1$
if ((variable != null) && (!variable.isEmpty())) {
if (parameters.containsKey(variable)) {
if (!format.isEmpty()) {
interpolated.append(String.format(format, parameters.get(variable)));
} else {
interpolated.append(parameters.get(variable));
}
}
} else {
interpolated.append(interpolated.substring(interpolator.start(), interpolator.end()));
}
position = interpolator.end();
}
interpolated.append(template.substring(position));
return interpolated.toString();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.widget;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.utility.AngleUtils;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.builder.SelectorWidgetBuilder;
import lu.list.itis.dkd.tui.widget.corona.SelectableCorona;
......@@ -121,7 +122,7 @@ public class SelectorWidget extends ValueWidget {
double segment = TWO_PI / numberOfPositions;
int current = 0;
float angle = Point.moduloTwoPi(newAngle);
float angle = (float) AngleUtils.moduloTwoPi(newAngle);
// detect in which segment the current rotation is
for (int position = 0; position < numberOfPositions; position++) {
......@@ -178,7 +179,7 @@ public class SelectorWidget extends ValueWidget {
this.selectPosition(presetPosition);
Point centre = this.getPosition();
if (centre != null) {
presetAngleOffset = Point.moduloTwoPi(this.getCurrentAngle(currentPosition) - (centre.getAngle() - presetAngleOffset));
presetAngleOffset = (float) AngleUtils.moduloTwoPi(this.getCurrentAngle(currentPosition) - (centre.getAngle() - presetAngleOffset));
}
}
}
......@@ -208,17 +209,17 @@ public class SelectorWidget extends ValueWidget {
@Override
public void actionMove(TangibleObject tuioObject) {
double angle = Point.moduloTwoPi(tuioObject.getAngle() + presetAngleOffset);
double angle = AngleUtils.moduloTwoPi(tuioObject.getAngle() + presetAngleOffset);
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), (float) angle));
super.actionMove(clone);
int position = getCurrentPosition(clone.getAngle());
int widgetId = tuioObject.getObjectId();
StateManager manager = states.get(widgetId);
if (manager.isRotating()) {
int position = getCurrentPosition(clone.getAngle());
if (position != currentPosition) {
this.selectPosition(position);
}
......@@ -240,7 +241,7 @@ public class SelectorWidget extends ValueWidget {
isPersistent = this.isPersistent(tuioObject.getObjectId());
int position = (isPersistent) ? currentPosition : presetPosition;
presetAngleOffset = (isPersistent) ? Point.moduloTwoPi(this.getCurrentAngle(position) - tuioObject.getAngle()) : 0;
presetAngleOffset = (isPersistent) ? (float) AngleUtils.moduloTwoPi(this.getCurrentAngle(position) - tuioObject.getAngle()) : 0;
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), presetAngleOffset));
super.actionDrop(clone);
......
package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.builder.ArcGraphBuilder;
......@@ -40,6 +41,7 @@ public class ArcGraph extends ValueCorona {
private int startAngle;
private int arcSpan;
private boolean relative;
private boolean cappedDisplay;
private double reference;
private ColorPair fillColour;
......@@ -66,10 +68,7 @@ public class ArcGraph extends ValueCorona {
protected Timeline blinkingTimeline;
protected Timeline balisticTimeline;
private float opacity;
private float angle;
private float rotation;
private double shownValue;
private double normalizedValue;
// ***************************************************************************
// * Constants *
......@@ -89,6 +88,7 @@ public class ArcGraph extends ValueCorona {
this.startAngle = builder.startAngle;
this.arcSpan = builder.arcSpan;
this.relative = builder.relative;
this.cappedDisplay = builder.cappedDisplay;
this.reference = builder.reference;
this.innerRadius = builder.innerRadius;
......@@ -122,6 +122,7 @@ public class ArcGraph extends ValueCorona {
this.startAngle = original.startAngle;
this.arcSpan = original.arcSpan;
this.relative = original.relative;
this.cappedDisplay = original.cappedDisplay;
this.reference = original.reference;
this.innerRadius = original.innerRadius;
......@@ -223,7 +224,6 @@ public class ArcGraph extends ValueCorona {
faceColour.setSwitched(isNegative);
if (bezelColour != null)
bezelColour.setSwitched(isNegative);
}
}
......@@ -251,32 +251,24 @@ public class ArcGraph extends ValueCorona {
// ---------------------------------------------------------------------------
public void setOpacity(float newOpacity) {
this.opacity = newOpacity;
}
// ---------------------------------------------------------------------------
public void setShownValue(double value) {
shownValue = value;
public void setNormalizedValue(double value) {
normalizedValue = value;
if (variable != null) {
double extend = 0;
double start = 0;
double valueRange = this.variable.getMaxValue() - this.variable.getMinValue();
double normalizedReference = this.variable.getNormalizedValueOf(reference);
if (relative) {
start = startAngle + (arcSpan * (this.variable.getMaxValue() / valueRange));
extend = arcSpan * (shownValue / valueRange);
switchColours(shownValue <= 0);
start = startAngle + (arcSpan * normalizedReference);
extend = arcSpan * (normalizedValue - normalizedReference);
switchColours(normalizedValue <= normalizedReference);
} else {
start = startAngle;
extend = arcSpan * (shownValue - this.variable.getMinValue()) / valueRange;
extend = arcSpan * normalizedValue;
}
if ((shownValue == this.variable.getMaxValue()) || (relative && (shownValue == this.variable.getMinValue())))
if (NumericalVariable.isEqual(normalizedValue, 1d) || (relative && NumericalVariable.isEqual(normalizedValue, 0d)))
this.startBlinking();
else
this.stopBlinking();
......@@ -297,48 +289,31 @@ public class ArcGraph extends ValueCorona {
return;
Graphics2D localCanvas = (Graphics2D) canvas.create();
// centre.toScreenCoordinates();
// if (initialTranslation != null)
// initialTranslation.toScreenCoordinates();
// Point drawAt = centre.add(initialTranslation);
//
// if (this.rotateWithHandle) {
// angle = (float) ((drawAt.getAngle() - rotation) % TWO_PI);
// } else {
// rotation = (float) ((drawAt.getAngle() - angle) % TWO_PI);
// }
//
// AffineTransform translation = new AffineTransform();
// translation.translate(drawAt.x, drawAt.y);
// translation.rotate(angle);
AffineTransform translation = this.getTransform(null);
localCanvas.setTransform(translation);
if (this.opacity < 1.0f)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
if (faceColour != null) {
if ((face != null) && (faceColour != null)) {
localCanvas.setPaint(faceColour.getColor());
localCanvas.fill(face);
}
if (bezelColour != null) {
if ((face != null) && (bezelColour != null)) {
localCanvas.setPaint(bezelColour.getColor());
if (borderStroke != null)
localCanvas.setStroke(borderStroke);
localCanvas.draw(face);
}
if (fillColour != null) {
if ((arc != null) && (fillColour != null)) {
localCanvas.setPaint(fillColour.getColor());
localCanvas.fill(arc);
}
if (strokeColour != null) {
if ((arc != null) && (strokeColour != null)) {
localCanvas.setPaint(strokeColour.getColor());
if (borderStroke != null)
localCanvas.setStroke(borderStroke);
......@@ -373,24 +348,24 @@ public class ArcGraph extends ValueCorona {
@Override
public void setInformation(Object information) {
if (variable != null) {
double value = this.variable.getValue();
double value = this.variable.getNormalizedValue();
if (rampingTime > 0) {
if ((balisticTimeline != null) && (!balisticTimeline.isDone()))
balisticTimeline.cancel();
balisticTimeline = new Timeline(this);
balisticTimeline.addPropertyToInterpolate("shownValue", shownValue, value); //$NON-NLS-1$
balisticTimeline.addPropertyToInterpolate("normalizedValue", normalizedValue, value); //$NON-NLS-1$
balisticTimeline.setDuration(rampingTime);
balisticTimeline.play();
} else {
this.setShownValue(value);
this.setNormalizedValue(value);
}
if (textFont != null) {
StringBuilder labelBuilder = new StringBuilder(this.title).append(" "); //$NON-NLS-1$
labelBuilder.append(this.variable.toString());
labelBuilder.append(this.variable.toString(this.cappedDisplay));
this.label = labelBuilder.toString();
this.labelMetrics = textFont.getLineMetrics(this.label, new FontRenderContext(null, true, true));
}
......
......@@ -2,8 +2,6 @@ package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.Leader;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.utility.ValueRange;
import lu.list.itis.dkd.tui.utility.VariableFormat;
import lu.list.itis.dkd.tui.widget.corona.builder.ArcRangeGraphBuilder;
......@@ -39,8 +37,8 @@ public class ArcRangeGraph extends ValueRangeCorona {
private String title;
private double innerRadius;
private double outerRadius;
private int startAngle;
private int arcSpan;
private double startAngle;
private double arcSpan;
private boolean relative;
private double reference;
private int rampingTime;
......@@ -90,8 +88,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
// * Constants *
// ***************************************************************************
private static final Point ZERO_ORIGIN = new Point(0, 0, 0, ScreenCoordinates.class);
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -180,6 +176,13 @@ public class ArcRangeGraph extends ValueRangeCorona {
diameter = 2 * outerRadius;
outerArea = new Area(new Ellipse2D.Double(-outerRadius, -outerRadius, diameter, diameter));
// Java Arc3D start angle and extend are expressed in counter clockwise rotation. Since
// TULIP follows the clockwise TUIO convention, we need to convert both startAngle and
// extend.
startAngle = (THREE_SIXTY - startAngle);
arcSpan = -arcSpan;
Shape sector = new Arc2D.Double(-outerRadius, -outerRadius, diameter, diameter, startAngle, arcSpan, Arc2D.PIE);
face = new Area(sector);
face.subtract(innerArea);
......
......@@ -36,6 +36,7 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> {
public int startAngle;
public int arcSpan;
public boolean relative;
public boolean cappedDisplay;
public double reference;
public int rampingTime;
......@@ -93,6 +94,7 @@ public class ArcGraphBuilder extends ValueCoronaBuilder<ArcGraphBuilder> {
startAngle = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.START_ANGLE_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);
cappedDisplay = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.CAPPED_DISPLAY_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);
......
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