diff --git a/CPS/pom.xml b/CPS/pom.xml
index 7595255972966dd2d0071b61c088fa13c3e70b57..45c625e4f82e45929e6f1bf0052d800d86239a25 100644
--- a/CPS/pom.xml
+++ b/CPS/pom.xml
@@ -93,7 +93,7 @@
0.9.5.2
runtime
-
+
diff --git a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java
index 04be55e69048d41d1c0b12ea265dd3823944f4bc..db1b80bed0bd692c825d8a900164435e9e46afc9 100644
--- a/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java
+++ b/CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java
@@ -103,13 +103,20 @@ public class PythonExecutor extends Executor {
@Override
public boolean eval(String script) {
+ boolean success = true;
+ this.executionErrors.reset();
long elapsed = System.currentTimeMillis();
engine.exec(script);
elapsed = System.currentTimeMillis() - elapsed;
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Eval took {} ms | {}", elapsed, script); //$NON-NLS-1$
}
- return true;
+ if (this.executionErrors.size() > 0) {
+ LOGGER.error("Eval returned an error: {}", this.executionErrors.toString()); //$NON-NLS-1$
+ success = false;
+ }
+
+ return success;
}
@Override
@@ -132,7 +139,28 @@ public class PythonExecutor extends Executor {
}
}
- variable.setValueFromObject((result != null) ? result.__tojava__(Double.class) : null);
+ if ((variable instanceof VectorVariable) && (result != null)) {
+ VectorVariable> vector = (VectorVariable>) variable;
+ vector.suspendListenerNotification(true);
+ vector.clear();
+ if (Double.class.isAssignableFrom(vector.getClassOfValues())) {
+ for (PyObject item : result.asIterable()) {
+ vector.add(item.__tojava__(Double.class));
+ }
+ } else if (Integer.class.isAssignableFrom(vector.getClassOfValues())) {
+ for (PyObject item : result.asIterable()) {
+ vector.add(item.__tojava__(Integer.class));
+ }
+ } else {
+ for (PyObject item : result.asIterable()) {
+ vector.add(item.__tojava__(Object.class));
+ }
+ }
+ vector.suspendListenerNotification(false);
+ vector.notifyInputChangeListeners();
+ } else {
+ variable.setValueFromObject((result != null) ? result.__tojava__(Double.class) : null);
+ }
return variable;
}
}
diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java
index 199f0faf5de3412a5b41f874fdd8ab10e0af9f16..80608737b88f45b107a67f4368d91cef719eddb6 100644
--- a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java
+++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java
@@ -263,7 +263,7 @@ public class ArcGraph extends ValueCorona {
balisticTimeline.play();
if (textFont != null) {
- StringBuilder labelBuilder = new StringBuilder(this.variable.getName()).append(" "); //$NON-NLS-1$
+ StringBuilder labelBuilder = new StringBuilder(this.variable.getDisplayName()).append(" "); //$NON-NLS-1$
labelBuilder.append(this.variable.toString());
this.label = labelBuilder.toString();
this.labelMetrics = textFont.getLineMetrics(label.toString(), new FontRenderContext(null, true, true));
diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java
new file mode 100644
index 0000000000000000000000000000000000000000..5f5560b3aade948d6a5c83019f6bcfbea7d14971
--- /dev/null
+++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java
@@ -0,0 +1,198 @@
+/**
+ * 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.widget.corona;
+
+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.ShapeGraphBuilder;
+
+import org.pushingpixels.trident.Timeline;
+import org.pushingpixels.trident.Timeline.RepeatBehavior;
+
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.geom.AffineTransform;
+
+/**
+ * @author mack
+ * @since [major].[minor]
+ * @version [major].[minor].[micro]
+ */
+// ***************************************************************************
+// * Class Definition and Members *
+// ***************************************************************************
+
+public class ShapeGraph extends ValueCorona {
+
+ /** The minimum value to be stored by the widget. */
+ protected double lowerBound;
+ /** The maximum value to be stored by the widget. */
+ protected double upperBound;
+ /** The lower bound of the angle the widget can be turned to. */
+ protected ColorPair fillColour;
+ protected ColorPair strokeColour;
+ protected int strokeWidth;
+ protected Shape graphShape;
+
+ protected Timeline blinkingTimeline;
+ protected Timeline balisticTimeline;
+ private double shownValue;
+ private float angle;
+ private float opacity;
+ private double scale;
+ private Stroke borderStroke;
+
+ // ---------------------------------------------------------------------------
+ // ***************************************************************************
+ // * Constructor(s) *
+ // ***************************************************************************
+ // ---------------------------------------------------------------------------
+ /**
+ * @param builder
+ */
+ public ShapeGraph(ShapeGraphBuilder builder) {
+ super(builder);
+ this.lowerBound = builder.lowerBound;
+ this.upperBound = builder.upperBound;
+ this.fillColour = builder.fillColour;
+ this.strokeColour = builder.strokeColour;
+ this.strokeWidth = builder.strokeWidth;
+ this.graphShape = builder.graphShape;
+
+ borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null;
+
+ this.setInformation(this.variable.getMinValue());
+
+ }
+ // ---------------------------------------------------------------------------
+ // ***************************************************************************
+ // * Primitives *
+ // ***************************************************************************
+ // ---------------------------------------------------------------------------
+
+ private void startBlinking() {
+ if ((blinkingTimeline != null) && (!blinkingTimeline.isDone()))
+ blinkingTimeline.cancel();
+
+ blinkingTimeline = new Timeline(this);
+ blinkingTimeline.addPropertyToInterpolate("opacity", 1.0f, 0.0f); //$NON-NLS-1$
+ blinkingTimeline.setDuration(500);
+ blinkingTimeline.playLoop(RepeatBehavior.REVERSE);
+ }
+
+ // ---------------------------------------------------------------------------
+
+ private void stopBlinking() {
+ if ((blinkingTimeline != null) && (!blinkingTimeline.isDone()))
+ blinkingTimeline.cancel();
+ this.opacity = 1.0f;
+ }
+
+ // ---------------------------------------------------------------------------
+ // ***************************************************************************
+ // * Class Body *
+ // ***************************************************************************
+ // ---------------------------------------------------------------------------
+ // ---------------------------------------------------------------------------
+
+ public void setShownValue(double value) {
+ shownValue = value;
+
+ if (variable != null) {
+ double size = lowerBound + (upperBound - lowerBound) * (shownValue - this.variable.getMinValue()) / (this.variable.getMaxValue() - this.variable.getMinValue());
+
+ if (size == upperBound)
+ this.startBlinking();
+ else
+ this.stopBlinking();
+
+ scale = size / lowerBound;
+ }
+ }
+
+ // ---------------------------------------------------------------------------
+
+ @Override
+ public void paint(Graphics2D canvas) {
+ if (!active)
+ 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() % TWO_PI);
+ }
+
+ AffineTransform translation = new AffineTransform();
+ translation.translate(drawAt.x, drawAt.y);
+ translation.rotate(angle);
+ translation.scale(scale, scale);
+ localCanvas.setTransform(translation);
+
+ if (this.opacity < 1.0f)
+ localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
+
+ if (graphShape != null) {
+ if (fillColour != null) {
+ localCanvas.setPaint(fillColour.getColor());
+ localCanvas.fill(graphShape);
+ }
+
+ if (strokeColour != null) {
+ localCanvas.setPaint(strokeColour.getColor());
+ if (borderStroke != null) {
+ localCanvas.setStroke(borderStroke);
+ localCanvas.draw(graphShape);
+ }
+ }
+ }
+
+ if (this.opacity < 1.0f)
+ localCanvas.setComposite(AlphaComposite.SrcOver.derive(1.0f));
+
+ localCanvas.dispose();
+ }
+
+ // ---------------------------------------------------------------------------
+
+ @Override
+ public void setInformation(Object information) {
+ if (variable != null) {
+ double value = this.variable.getValue();
+
+ if ((balisticTimeline != null) && (!balisticTimeline.isDone()))
+ balisticTimeline.cancel();
+
+ balisticTimeline = new Timeline(this);
+ balisticTimeline.addPropertyToInterpolate("shownValue", shownValue, value); //$NON-NLS-1$
+ balisticTimeline.setDuration(500);
+ balisticTimeline.play();
+ }
+ }
+
+ // ---------------------------------------------------------------------------
+ // ***************************************************************************
+ // * End of Class *
+ // ***************************************************************************
+ // ---------------------------------------------------------------------------
+
+}
diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ShapeGraphBuilder.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ShapeGraphBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..bfa06bffbb15173b597aea8308e78d20409ab0b9
--- /dev/null
+++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ShapeGraphBuilder.java
@@ -0,0 +1,183 @@
+package lu.list.itis.dkd.tui.widget.corona.builder;
+
+import lu.list.itis.dkd.dbc.annotation.Nullable;
+import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
+import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
+import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
+import lu.list.itis.dkd.tui.bootstrapping.ShapeBootstrapper;
+import lu.list.itis.dkd.tui.exception.BuildException;
+import lu.list.itis.dkd.tui.utility.ColorPair;
+import lu.list.itis.dkd.tui.utility.Externalization;
+import lu.list.itis.dkd.tui.utility.Point;
+import lu.list.itis.dkd.tui.widget.corona.ShapeGraph;
+
+import org.jdom2.Element;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.awt.Color;
+import java.awt.Shape;
+
+/**
+ * @author nmack
+ * @date 08 Jan 2016
+ *
+ *
+ * $Log: ArcGraphBuilder.java,v $
+ */
+
+// ***************************************************************************
+// * Class Definition and Members *
+// ***************************************************************************
+
+public class ShapeGraphBuilder extends ValueCoronaBuilder {
+
+ public double lowerBound;
+ public double upperBound;
+ public ColorPair fillColour;
+ public ColorPair strokeColour;
+ public int strokeWidth;
+ public Shape graphShape;
+ // public SVGIcon graphImage;
+
+ // ***************************************************************************
+ // * Constants *
+ // ***************************************************************************
+
+ private static Logger LOGGER = LoggerFactory.getLogger(ShapeGraphBuilder.class.getSimpleName());
+
+ // ---------------------------------------------------------------------------
+ // ***************************************************************************
+ // * Constructor(s) *
+ // ***************************************************************************
+ // ---------------------------------------------------------------------------
+
+ public ShapeGraphBuilder(Point centre) {
+ super(centre);
+ }
+
+ /**
+ * @param rootElement
+ * @throws BuildException
+ */
+ public ShapeGraphBuilder(Element rootElement) throws BuildException {
+ super(rootElement);
+ this.buildFromBootstrap(rootElement, null, null);
+ /** Mandatory fields */
+ }
+
+ /**
+ * @param rootElement
+ * @throws BuildException
+ */
+ public ShapeGraphBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
+ super(rootElement, context, callback);
+ this.buildFromBootstrap(rootElement, context, callback);/** Mandatory fields */
+ }
+
+ // ---------------------------------------------------------------------------
+ // ***************************************************************************
+ // * Primitives *
+ // ***************************************************************************
+ // ---------------------------------------------------------------------------
+
+ private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
+
+ lowerBound = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.LOWER_BOUND_NODE, BootstrappingUtils.MANDATORY, null, context);
+ upperBound = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.UPPER_BOUND_NODE, BootstrappingUtils.MANDATORY, null, context);
+
+ /** Optional fields */
+
+ strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context);
+
+ fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), context);
+ strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), context);
+
+ graphShape = ShapeBootstrapper.getShape(rootElement.getChild(Externalization.SHAPE_NODE), context, callback);
+ // String graphImagePath = BootstrappingUtils.getContentAsString(rootElement,
+ // Externalization.IMAGE_ELEMENT, BootstrappingUtils.OPTIONAL, null, context);
+ // if (!Strings.isNullOrEmpty(graphImagePath)) {
+ // this.graphImage = this.loadSVGResource(graphImagePath);
+ // }
+ }
+
+ // ---------------------------------------------------------------------------
+
+ // private SVGIcon loadSVGResource(String resourcePath) {
+ // SVGIcon icon = null;
+ // try {
+ // URI uri = SVGCache.getSVGUniverse().loadSVG(new BufferedReader(new
+ // InputStreamReader(getClass().getResource(resourcePath).openStream())), "shape");
+ // //$NON-NLS-1$
+ // icon = new SVGIcon();
+ // icon.setSvgURI(uri);
+ // icon.setAntiAlias(true);
+ // } catch (IOException e) {
+ // LOGGER.error("Failed to load SVG resource {}!", resourcePath); //$NON-NLS-1$
+ // }
+ // return icon;
+ // }
+
+ // ---------------------------------------------------------------------------
+
+ private ColorPair buildColorPair(Element rootElement, BootstrapContext context) throws BuildException {
+ Color selectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.SELECTED_ELEMENT, BootstrappingUtils.MANDATORY, null, context);
+ Color deselectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.DESELECTED_ELEMENT, BootstrappingUtils.MANDATORY, null, context);
+
+ return new ColorPair(selectedColour, deselectedColour);
+ }
+
+ // ---------------------------------------------------------------------------
+ // ***************************************************************************
+ // * Class Body *
+ // ***************************************************************************
+ // ---------------------------------------------------------------------------
+
+ // ---------------------------------------------------------------------------
+
+ public ShapeGraphBuilder withFillColours(Color selectedColour, Color deselectedColour) {
+ fillColour = new ColorPair(selectedColour, deselectedColour);
+ return this;
+ }
+
+ // ---------------------------------------------------------------------------
+
+ public ShapeGraphBuilder withStrokeColours(Color selectedColour, Color deselectedColour) {
+ strokeColour = new ColorPair(selectedColour, deselectedColour);
+ return this;
+ }
+
+ // ---------------------------------------------------------------------------
+
+ public ShapeGraphBuilder withStrokeWidth(int width) {
+ this.strokeWidth = width;
+ return this;
+ }
+
+ // ---------------------------------------------------------------------------
+
+ public ShapeGraphBuilder withGraphShape(Shape shape) {
+ graphShape = shape;
+ return this;
+ }
+
+ // // ---------------------------------------------------------------------------
+ //
+ // public ShapeGraphBuilder withGraphImage(SVGIcon image) {
+ // graphImage = image;
+ // return this;
+ // }
+ //
+ // ---------------------------------------------------------------------------
+
+ @Override
+ public ShapeGraph build() throws BuildException {
+ return new ShapeGraph(this);
+ }
+
+ // ---------------------------------------------------------------------------
+ // ***************************************************************************
+ // * End of Class *
+ // ***************************************************************************
+ // ---------------------------------------------------------------------------
+}
\ No newline at end of file