diff --git a/CPS/config/CpsNamespace.properties b/CPS/config/CpsNamespace.properties index 5a3d8f1ff5135f489ed7d81fa9bd6dd5f9257042..304abafe0fee1448e7b21aa00f71eb7e63e8a29d 100644 --- a/CPS/config/CpsNamespace.properties +++ b/CPS/config/CpsNamespace.properties @@ -3,6 +3,7 @@ BELOW_ELEMENT=below BLINK_ON_OUT_OF_RANGE_NODE=blinkOnOutOfRange CAPPED_DISPLAY_NODE=cappedDisplay ITEMS_VARIABLE_NODE=itemsVariable +HTML_TEMPLATE_NODE=htmlTemplate LABEL_NODE=label LOWER_BOUND_RADIUS_NODE=lowerBoundRadius LOWER_BOUND_VARIABLE_NODE=lowerBoundVariable diff --git a/CPS/src/lu/list/itis/dkd/tui/marker/DisplayMarker.java b/CPS/src/lu/list/itis/dkd/tui/marker/DisplayMarker.java index 7c2dd68437fe2dd5d9249b5a460e2395a2100ced..c11c66d5b36bb9b2b190d8878675c261ebffccec 100644 --- a/CPS/src/lu/list/itis/dkd/tui/marker/DisplayMarker.java +++ b/CPS/src/lu/list/itis/dkd/tui/marker/DisplayMarker.java @@ -2,6 +2,7 @@ package lu.list.itis.dkd.tui.marker; import lu.list.itis.dkd.tui.cps.InputChangeListener; import lu.list.itis.dkd.tui.cps.InputEvent; +import lu.list.itis.dkd.tui.cps.system.VariableBased; import lu.list.itis.dkd.tui.cps.variable.NumericalVariable; import lu.list.itis.dkd.tui.cps.variable.Variable; import lu.list.itis.dkd.tui.marker.builder.BaseDisplayMarkerBuilder; @@ -11,20 +12,20 @@ import org.python.google.common.base.Preconditions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.awt.Graphics2D; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.Map; // *************************************************************************** // * Class Definition and Members * // *************************************************************************** @SuppressWarnings("rawtypes") -public class DisplayMarker extends InfoMarker implements InputChangeListener { +public class DisplayMarker extends InfoMarker implements InputChangeListener, VariableBased { - private HashMap variables; + private HashMap> variables; HashMap dispatcher; // *************************************************************************** @@ -43,20 +44,8 @@ public class DisplayMarker extends InfoMarker implements InputChangeListener { public DisplayMarker(BaseDisplayMarkerBuilder builder) { super(builder); - if (builder.variables != null) { - this.setVariables(builder.variables); - } - - this.dispatcher = new HashMap(); - - List displays = this.getCoronas(ValueCorona.class); - for (ValueCorona display : displays) { - Variable variable = display.getVariable(); - if (variable != null) { - dispatcher.put(variable.getName(), display); - } - } - // TODO Auto-generated constructor stub + this.variables = new HashMap<>(); + this.dispatcher = new HashMap<>(); } // --------------------------------------------------------------------------- @@ -71,47 +60,40 @@ public class DisplayMarker extends InfoMarker implements InputChangeListener { // *************************************************************************** // --------------------------------------------------------------------------- - public void setVariables(Collection> newVariables) { - Preconditions.checkArgument(variables == null, "Set of variables can't be null!"); //$NON-NLS-1$ - - this.variables = new HashMap(); - for (Variable variable : newVariables) { - this.variables.put(variable.getName(), (NumericalVariable) variable); - } - - List displays = this.getCoronas(ValueCorona.class); - for (ValueCorona display : displays) { - Variable variable = display.getVariable(); - if (variable != null) { - String variableName = variable.getName(); - 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$ - } - } - } - } + // public void setVariables(Collection> newVariables) { + // Preconditions.checkArgument(variables == null, "Set of variables can't be null!"); //$NON-NLS-1$ + // + // this.variables = new HashMap(); + // for (Variable variable : newVariables) { + // this.variables.put(variable.getName(), (NumericalVariable) variable); + // } + // + // List displays = this.getCoronas(ValueCorona.class); + // for (ValueCorona display : displays) { + // Variable variable = display.getVariable(); + // if (variable != null) { + // String variableName = variable.getName(); + // 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$ + // } + // } + // } + // } // --------------------------------------------------------------------------- public Collection> getVariables() { - Collection> variables = new ArrayList<>(); - List displays = this.getCoronas(ValueCorona.class); - for (ValueCorona display : displays) { - Variable variable = display.getVariable(); - if (variable != null) { - variables.add(variable); - } - } - return variables; - } - - // --------------------------------------------------------------------------- - - @Override - public void paint(Graphics2D canvas) { - super.paint(canvas); + // Collection> variables = new ArrayList<>(); + // List displays = this.getCoronas(ValueCorona.class); + // for (ValueCorona display : displays) { + // Variable variable = display.getVariable(); + // if (variable != null) { + // variables.add(variable); + // } + // } + return variables.values(); } // --------------------------------------------------------------------------- @@ -129,5 +111,35 @@ public class DisplayMarker extends InfoMarker implements InputChangeListener { } // --------------------------------------------------------------------------- + /** {@inheritDoc} */ + // --------------------------------------------------------------------------- + + @Override + public List> connectWithSystemVariables(Map> systemVariables) { + List> connected = new ArrayList<>(); + + Preconditions.checkArgument(systemVariables != null, "Set of variables can't be null!"); //$NON-NLS-1$ + + List displays = this.getCoronas(VariableBased.class); + for (VariableBased display : displays) { + List> newlyConnected = display.connectWithSystemVariables(systemVariables); + connected.addAll(newlyConnected); + + if (display instanceof ValueCorona) { + for (Variable variable : newlyConnected) { + this.dispatcher.put(variable.getName(), (ValueCorona) display); + } + } + } + + for (Variable variable : connected) { + this.variables.put(variable.getName(), variable); + variable.addListener(this); + } + + return connected; + } + + // --------------------------------------------------------------------------- } diff --git a/CPS/src/lu/list/itis/dkd/tui/utility/CpsNamespace.java b/CPS/src/lu/list/itis/dkd/tui/utility/CpsNamespace.java index 96debe4c00da0b1db17da082d8bf140ab70c6752..7daa02dca2c935934023d0634808237f6f3d2e50 100644 --- a/CPS/src/lu/list/itis/dkd/tui/utility/CpsNamespace.java +++ b/CPS/src/lu/list/itis/dkd/tui/utility/CpsNamespace.java @@ -32,6 +32,8 @@ public class CpsNamespace extends NLS { public static String CAPPED_DISPLAY_NODE; + public static String HTML_TEMPLATE_NODE; + public static String ITEMS_VARIABLE_NODE; public static String LABEL_NODE; diff --git a/CPS/src/lu/list/itis/dkd/tui/utility/interpolation/Interpolator.java b/CPS/src/lu/list/itis/dkd/tui/utility/interpolation/Interpolator.java index 3120b9d5597565c1f738308ab6d035f0d8dc3388..67b6080770eb1251c8ff869a01fd9b7ec55f3330 100644 --- a/CPS/src/lu/list/itis/dkd/tui/utility/interpolation/Interpolator.java +++ b/CPS/src/lu/list/itis/dkd/tui/utility/interpolation/Interpolator.java @@ -108,6 +108,21 @@ public class Interpolator { // *************************************************************************** // --------------------------------------------------------------------------- + public static List extractVariableIdentifiers(String template) { + Matcher variableMatcher; + List identifiers = new ArrayList<>(); + + variableMatcher = VARIABLE_PATTERN.matcher(template); + + while (variableMatcher.find()) { + identifiers.add(variableMatcher.group(1)); + } + + return identifiers; + } + + // --------------------------------------------------------------------------- + public static List> decompose(String template, Map> parameters) { Matcher variableMatcher; String format; diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcRangeGraph.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcRangeGraph.java index 8d5256a71c636d62eae39d515cbf2061c7e9180a..e79c86ad5f800ca08e747249a43e7e5edaa4a8db 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcRangeGraph.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcRangeGraph.java @@ -40,6 +40,7 @@ public class ArcRangeGraph extends ValueRangeCorona { private double startAngle; private double arcSpan; private boolean relative; + private boolean blinkOnOutOfRange; private double reference; private int rampingTime; @@ -102,6 +103,7 @@ public class ArcRangeGraph extends ValueRangeCorona { this.startAngle = builder.startAngle; this.arcSpan = builder.arcSpan; this.relative = builder.relative; + this.blinkOnOutOfRange = builder.blinkOnOutOfRange; this.reference = builder.reference; this.rampingTime = builder.rampingTime; @@ -139,6 +141,7 @@ public class ArcRangeGraph extends ValueRangeCorona { this.startAngle = original.startAngle; this.arcSpan = original.arcSpan; this.relative = original.relative; + this.blinkOnOutOfRange = original.blinkOnOutOfRange; this.reference = original.reference; this.rampingTime = original.rampingTime; @@ -318,7 +321,7 @@ public class ArcRangeGraph extends ValueRangeCorona { this.updateLeader(); - if ((shownUpperValue == this.upperBoundVariable.getMaxValue()) || (relative && (shownLowerValue == this.lowerBoundVariable.getMinValue()))) + if (blinkOnOutOfRange && ((shownUpperValue == this.upperBoundVariable.getMaxValue()) || (relative && (shownLowerValue == this.lowerBoundVariable.getMinValue())))) this.startBlinking(); else this.stopBlinking(); 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 index aa00731b9f0a32ea07fbeb25e7c9ffe631d75e2b..99d763ada2cf61ecc04e1d7ec4b50e2b84b6759c 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java @@ -46,13 +46,11 @@ public class ShapeGraph extends ValueCorona { protected ColorPair strokeColour; protected int strokeWidth; protected Shape scaledShape; + protected boolean blinkOnOutOfRange; protected Timeline blinkingTimeline; protected Timeline balisticTimeline; private double shownValue; - private float angle; - private float opacity; - private double scale; private Stroke borderStroke; // --------------------------------------------------------------------------- @@ -67,6 +65,7 @@ public class ShapeGraph extends ValueCorona { super(builder); this.lowerBound = builder.lowerBound; this.upperBound = builder.upperBound; + this.blinkOnOutOfRange = builder.blinkOnOutOfRange; this.fillColour = builder.fillColour; this.strokeColour = builder.strokeColour; this.strokeWidth = builder.strokeWidth; @@ -92,6 +91,7 @@ public class ShapeGraph extends ValueCorona { this.lowerBound = original.lowerBound; this.upperBound = original.upperBound; + this.blinkOnOutOfRange = original.blinkOnOutOfRange; this.fillColour = original.fillColour; this.strokeColour = original.strokeColour; this.strokeWidth = original.strokeWidth; @@ -137,16 +137,14 @@ public class ShapeGraph extends ValueCorona { shownValue = value; if (variable != null) { - // double size = lowerBound + (upperBound - lowerBound) * (shownValue - this.variable.getMinValue()) - // / (this.variable.getMaxValue() - this.variable.getMinValue()); double size = lowerBound + ((upperBound - lowerBound) * this.variable.getNormalizedValue()); - if (size == upperBound) + if (blinkOnOutOfRange && (size == upperBound)) this.startBlinking(); else this.stopBlinking(); - scale = size / lowerBound; + double scale = size / lowerBound; AffineTransform scaler = AffineTransform.getScaleInstance(scale, scale); scaledShape = scaler.createTransformedShape(this.shape); diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/VariableHtmlBox.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/VariableHtmlBox.java new file mode 100644 index 0000000000000000000000000000000000000000..0978b1c4160b985ced59eb423d609edd4be5a0e6 --- /dev/null +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/VariableHtmlBox.java @@ -0,0 +1,122 @@ +/** + * 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.cps.InputChangeListener; +import lu.list.itis.dkd.tui.cps.InputEvent; +import lu.list.itis.dkd.tui.cps.system.VariableBased; +import lu.list.itis.dkd.tui.cps.variable.Variable; +import lu.list.itis.dkd.tui.utility.interpolation.Chunk; +import lu.list.itis.dkd.tui.utility.interpolation.Interpolator; +import lu.list.itis.dkd.tui.widget.corona.builder.BaseVariableHtmlBoxBuilder; + +import org.python.google.common.base.Strings; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Extends the static HtmlBox corona by allowing variables inside the Html content. + * + * @author Nico Mack [nico.mack@list.lu] + * @since 2.5.0 + * @version 2.5.0 + */ +// *************************************************************************** +// * Class Definition and Members * +// *************************************************************************** + +public class VariableHtmlBox extends HtmlBox implements VariableBased, InputChangeListener { + + private String htmlTemplate; + private List> htmlChunks; + private List identifiers; + private Map> parameters; + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Constructor(s) + // *************************************************************************** + // --------------------------------------------------------------------------- + /** + * @param builder + */ + // --------------------------------------------------------------------------- + + public VariableHtmlBox(BaseVariableHtmlBoxBuilder builder) { + super(builder); + htmlTemplate = builder.htmlTemplate; + + this.parameters = new HashMap<>(); + + if (!Strings.isNullOrEmpty(this.htmlTemplate)) { + identifiers = Interpolator.extractVariableIdentifiers(this.htmlTemplate); + } + } + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Primitive(s) + // *************************************************************************** + // --------------------------------------------------------------------------- + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Class Body + // *************************************************************************** + // --------------------------------------------------------------------------- + /** {@inheritDoc} */ + // --------------------------------------------------------------------------- + + @Override + public List> connectWithSystemVariables(Map> systemVariables) { + List> connected = new ArrayList<>(); + + for (String identifier : identifiers) { + if ((systemVariables != null) && systemVariables.containsKey(identifier)) { + Variable variable = systemVariables.get(identifier); + this.parameters.put(identifier, variable); + connected.add(variable); + variable.addListener(this); + } + } + + if (!connected.isEmpty()) { + htmlChunks = Interpolator.decompose(this.htmlTemplate, this.parameters); + } + + return connected; + } + + // --------------------------------------------------------------------------- + /** {@inheritDoc} */ + // --------------------------------------------------------------------------- + + @Override + public void inputChanged(InputEvent input) { + if (parameters.containsKey(input.getSource().getName())) { + this.htmlContent = Interpolator.render(htmlChunks); + this.setInformation(this.htmlContent); + } + } + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * End of Class + // *************************************************************************** + // --------------------------------------------------------------------------- + +} diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java index 25c69e368361290fd744f17210e201b4b16c6f8e..6b246a7cffbbb952510c61edafcf2ef558760183 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java @@ -38,6 +38,7 @@ public class ArcGraphBuilder extends ValueCoronaBuilder { public int arcSpan; public boolean relative; public boolean cappedDisplay; + public boolean blinkOnOutOfRange; public double reference; public int rampingTime; @@ -96,6 +97,7 @@ public class ArcGraphBuilder extends ValueCoronaBuilder { arcSpan = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.ARC_SPAN_NODE, BootstrappingUtils.MANDATORY, null, context); relative = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.RELATIVE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context); cappedDisplay = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.CAPPED_DISPLAY_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context); + blinkOnOutOfRange = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.BLINK_ON_OUT_OF_RANGE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context); reference = BootstrappingUtils.getContentAsDouble(rootElement, CpsNamespace.REFERENCE_NODE, BootstrappingUtils.OPTIONAL, 0d, context); innerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.INNER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context); @@ -113,6 +115,7 @@ public class ArcGraphBuilder extends ValueCoronaBuilder { 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); title = BootstrappingUtils.getContentAsString(rootElement, Externalization.TITLE_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context); diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/BaseArcRangeGraphBuilder.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/BaseArcRangeGraphBuilder.java index ed2ff10335c1fc79bfe1d9d81e8bad09111b32f4..54b5b7348b5f972a48eadb3919bd8f685b428fdf 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/BaseArcRangeGraphBuilder.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/BaseArcRangeGraphBuilder.java @@ -37,6 +37,7 @@ public abstract class BaseArcRangeGraphBuilder. + */ +package lu.list.itis.dkd.tui.widget.corona.builder; + +import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; +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.exception.BuildException; +import lu.list.itis.dkd.tui.utility.CpsNamespace; +import lu.list.itis.dkd.tui.utility.Point; +import lu.list.itis.dkd.tui.widget.corona.HtmlBox; + +import org.jdom2.Element; + +/** + * {@link CoronaBuilder} extension building {@link HtmlBox} coronas. + * + * @author Nico Mack [nico.mack@list.lu] + * @since 2.5.0 + * @version 2.5.0 + * @param + * The concrete builder. + */ +@NonNullByDefault +// *************************************************************************** +// * Class Definition and Members * +// *************************************************************************** + +public abstract class BaseVariableHtmlBoxBuilder> extends BaseHtmlBoxBuilder { + + public String htmlTemplate; + + // *************************************************************************** + // * Constants * + // *************************************************************************** + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Constructor(s) * + // *************************************************************************** + // --------------------------------------------------------------------------- + /** + * Constructor setting the centre of the corona. + * + * @param centre + * The centre of the corona, usually the centre of the handle. + */ + // --------------------------------------------------------------------------- + + public BaseVariableHtmlBoxBuilder(Point centre) { + super(centre); + } + + // --------------------------------------------------------------------------- + /** + * Constructor initializing the centre of the corona as well as a possible text and the appropriate + * font size and line height ratio. + * + * @param rootElement + * The element harbouring, on child nodes, the necessary information to initialize all fields + * of the builder. + * @throws BuildException + * Exception raised when the building of a corona instance cannot complete successfully due + * to the violation of one or more contracts associated with the instance, including + * missing, incomplete, or erroneous parameters or values thereof + */ + // --------------------------------------------------------------------------- + + public BaseVariableHtmlBoxBuilder(Element rootElement) throws BuildException { + super(rootElement); + this.buildFromBootstrap(rootElement, null, null); + } + + // --------------------------------------------------------------------------- + /** + * @param rootElement + * @param context + * @param callback + * @throws BuildException + */ + // --------------------------------------------------------------------------- + + public BaseVariableHtmlBoxBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException { + super(rootElement, context, callback); + this.buildFromBootstrap(rootElement, context, callback); + } + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Primitive(s) * + // *************************************************************************** + // --------------------------------------------------------------------------- + /** + * + * @param rootElement + * @param context + * @param callback + * @throws BuildException + */ + // --------------------------------------------------------------------------- + + private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException { + htmlTemplate = BootstrappingUtils.getContentAsString(rootElement, CpsNamespace.HTML_TEMPLATE_NODE, BootstrappingUtils.MANDATORY, null, context); + } + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Class Body * + // *************************************************************************** + // --------------------------------------------------------------------------- + + /** {@inheritDoc} */ + @Override + public abstract HtmlBox build(); + +} \ No newline at end of file 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 index bfa06bffbb15173b597aea8308e78d20409ab0b9..d1602519e9a12ee800894bcfdfc0d94ca76409b5 100644 --- 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 @@ -7,6 +7,7 @@ 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.CpsNamespace; 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; @@ -38,7 +39,7 @@ public class ShapeGraphBuilder extends ValueCoronaBuilder { public ColorPair strokeColour; public int strokeWidth; public Shape graphShape; - // public SVGIcon graphImage; + public boolean blinkOnOutOfRange; // *************************************************************************** // * Constants * @@ -88,38 +89,18 @@ public class ShapeGraphBuilder extends ValueCoronaBuilder { /** Optional fields */ + blinkOnOutOfRange = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.BLINK_ON_OUT_OF_RANGE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context); + 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); diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/VariableHtmlBoxBuilder.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/VariableHtmlBoxBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..6e6327d504f400020ec68c0d81c20acda8af3233 --- /dev/null +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/VariableHtmlBoxBuilder.java @@ -0,0 +1,92 @@ +package lu.list.itis.dkd.tui.widget.corona.builder; + +/** + * Copyright Luxembourg Institute of Science and Technology, 2016. + * + * This file is part of TULIP. + * + * TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3, + * as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST + * proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license. + * + * For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, version 3 of the License. + * + * TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with TULIP. If + * not, see . + */ + +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.utility.Point; +import lu.list.itis.dkd.tui.widget.corona.VariableHtmlBox; + +import org.jdom2.Element; + +/** + * Extends the static HtmlBox corona by allowing variables inside the Html content. + * + * @author Nico Mack [nico.mack@list.lu] + * @since 2.5.0 + * @version 2.5.0 + */ + +@NonNullByDefault +public final class VariableHtmlBoxBuilder extends BaseVariableHtmlBoxBuilder { + /** + * Constructor setting the centre of the corona. + * + * @param centre + * The centre of the corona, usually the centre of the handle. + */ + public VariableHtmlBoxBuilder(Point centre) { + super(centre); + } + + /** + * Constructor initializing the centre of the corona as well as a possible text and the appropriate + * font size and line height ratio. + * + * @param rootElement + * The element harbouring, on child nodes, the necessary information to initialize all fields + * of the builder. + * @throws BuildException + * Exception raised when the building of a corona instance cannot complete successfully due + * to the violation of one or more contracts associated with the instance, including + * missing, incomplete, or erroneous parameters or values thereof + */ + public VariableHtmlBoxBuilder(Element rootElement) throws BuildException { + super(rootElement); + } + + /** + * Constructor initializing the centre of the corona as well as a possible text and the appropriate + * font size and line height ratio. + * + * @param rootElement + * The element harbouring, on child nodes, the necessary information to initialize all fields + * of the builder. + * @param context + * @param callback + * @throws BuildException + * Exception raised when the building of a corona instance cannot complete successfully due + * to the violation of one or more contracts associated with the instance, including + * missing, incomplete, or erroneous parameters or values thereof + */ + public VariableHtmlBoxBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException { + super(rootElement, context, callback); + } + + /** {@inheritDoc} */ + @Override + public VariableHtmlBox build() { + return new VariableHtmlBox(this); + } +} \ No newline at end of file