Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit 7f040371 authored by Valérie Maquil's avatar Valérie Maquil Committed by Valérie Maquil

added ConditionalTextBox corona

fixed the paint method of ConditionalCorona (correct order of rotations
and translations) to support features related to rotateWithHandle
parent 62ef0780
......@@ -30,6 +30,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.builder.BaseValueWidgetBuilder;
import lu.list.itis.dkd.tui.widget.builder.ValueWidgetBuilder;
import lu.list.itis.dkd.tui.widget.corona.ConditionalCorona;
import lu.list.itis.dkd.tui.widget.corona.ConditionalTextBox;
import lu.list.itis.dkd.tui.widget.corona.Corona;
import java.awt.Graphics2D;
......@@ -206,6 +207,9 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
for (ConditionalCorona conditionalCorona : getCoronas(ConditionalCorona.class)) {
conditionalCorona.addVariable(variable);
}
for (ConditionalTextBox conditionalTextBox : getCoronas(ConditionalTextBox.class)) {
conditionalTextBox.addVariable(variable);
}
}
@SuppressWarnings("unchecked")
......
......@@ -26,8 +26,9 @@ import java.util.LinkedHashSet;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @author Valérie Maquil [valerie.maquil@list.lu]
* @since 1.3
* @version 1.3.2
* @version 1.4.2
*/
@NonNullByDefault
public class ConditionalCorona extends Corona {
......@@ -69,32 +70,28 @@ public class ConditionalCorona extends Corona {
}
centre.toScreenCoordinates();
if (initialTranslation != null) {
initialTranslation.toScreenCoordinates();
} else {
initialTranslation = new Point();
}
Point drawAt = centre.add(initialTranslation);
AffineTransform transformation = new AffineTransform();
AffineTransform rotation = new AffineTransform();
rotation.rotate(rotateWithHandle ? drawAt.getAngle() : initialTranslation != null ? initialTranslation.getAngle() : 0, centre.getX(), centre.getY());
rotation.translate(drawAt.x, drawAt.y);
transformation.translate(centre.x, centre.y);
if (Double.compare(initialRotation, 0d) != 0)
transformation.rotate(initialRotation);
transformation.rotate(rotateWithHandle ? centre.getAngle() : 0);
transformation.translate(initialTranslation.x, initialTranslation.y);
transformation.rotate(rotateWithHandle && spinOnCoronaCentre ? -centre.getAngle() : 0);
transformation.translate(spinOnCoronaCentre ? -image.getWidth(null) / 2 : 0, spinOnCoronaCentre ? -image.getHeight(null) / 2 : 0);
if (spinOnCoronaCentre) {
rotation.rotate(rotateWithHandle ? -drawAt.getAngle() : 0);
rotation.translate(-image.getWidth(null) / 2, -image.getHeight(null) / 2);
}
canvas.setTransform(transformation);
rotation.transform(new Point(), drawAt);
canvas.drawImage(image, 0, 0, null);
if (Double.compare(initialRotation, 0d) != 0) {
AffineTransform transformation = new AffineTransform();
transformation.rotate(initialRotation, spinOnCoronaCentre ? drawAt.getX() + image.getWidth(null) / 2 : drawAt.getX(), spinOnCoronaCentre ? drawAt.getY() + image.getHeight(null) / 2 : drawAt.getY());
canvas.setTransform(transformation);
}
canvas.drawImage(image, (int) drawAt.x, (int) drawAt.y, null);
canvas.setTransform(new AffineTransform());
}
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2016. 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.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.cps.system.Equation;
import lu.list.itis.dkd.tui.cps.variable.BooleanVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.TextHelper;
import lu.list.itis.dkd.tui.widget.corona.builder.ConditionalTextBoxBuilder;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.util.LinkedHashSet;
/**
* @author Valérie Maquil [valerie.maquil@list.lu]
* @since 1.4
* @version 1.4.0
*/
@NonNullByDefault
public class ConditionalTextBox extends Corona {
/** The equation that will evaluate the trigger condition. */
private Equation trigger;
/** All variables that will be needed to evaluate the trigger condition. */
private LinkedHashSet<Variable> variables;
/** Variable used to easily gather the output from the trigger equation. */
private BooleanVariable triggerVariable = new BooleanVariable("TBTrigger", false); //$NON-NLS-1$
/**
* The list of trigger variables by their name. These are placeholders and will be used to
* populate the list of variables the instance will react to once the overarching equation
* system has been initialized, thus making the variable instances globally available.
*/
private LinkedHashSet<String> triggers = new LinkedHashSet<>();
/** Field holding the text to visualise. */
private String text;
private Font font = new Font("Arial", Font.PLAIN, 13); //$NON-NLS-1$
private int fontSize = 13;
private Color colour = Color.BLACK;
private boolean centred = false;
private int lineWidth = 20;
/**
* @param builder
*
*/
public ConditionalTextBox(ConditionalTextBoxBuilder builder) {
super(builder);
this.trigger = builder.trigger;
this.triggerVariable = builder.triggerVariable;
this.triggers = builder.triggers;
this.variables = builder.variables;
text = builder.text;
font = builder.font;
fontSize = builder.fontSize;
colour = builder.colour;
centred = builder.centred;
lineWidth = builder.lineWidth;
}
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
trigger.evaluate();
if (!active || !triggerVariable.getValue()) {
return;
}
centre.toScreenCoordinates();
if (initialTranslation != null) {
initialTranslation.toScreenCoordinates();
}
Point drawAt = centre.add(initialTranslation);
AffineTransform rotation = new AffineTransform();
rotation.rotate(rotateWithHandle ? drawAt.getAngle() : initialTranslation != null ? initialTranslation.getAngle() : 0, centre.getX(), centre.getY());
rotation.transform(drawAt, drawAt);
if (Double.compare(initialRotation, 0d) != 0) {
AffineTransform transformation = new AffineTransform();
transformation.rotate(initialRotation, drawAt.getX(), drawAt.getY());
canvas.setTransform(transformation);
}
canvas.setPaint(Color.black);
String textToShow = text;
TextHelper.configure(font, fontSize, colour, centred);
TextHelper.drawText(canvas, drawAt, lineWidth, textToShow);
canvas.setTransform(new AffineTransform());
}
/**
* Method used to add a variable to the set of variables held by this corona.
*
* @param variable
* The variable to add.
*/
public void addVariable(Variable variable) {
variables.add(variable);
}
/**
* Method used to retrieve the set of triggers the corona will react to.
*
* @return The set of triggers, respectively their name.
*/
public LinkedHashSet<String> getTriggers() {
return triggers;
}
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2016. 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.builder;
import lu.list.itis.dkd.tui.cps.system.Equation;
import lu.list.itis.dkd.tui.cps.system.Mapping;
import lu.list.itis.dkd.tui.cps.system.executor.JavascriptExecutor;
import lu.list.itis.dkd.tui.cps.variable.BooleanVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.corona.ConditionalTextBox;
import com.google.common.base.Strings;
import org.jdom2.Element;
import java.awt.Color;
import java.awt.Font;
import java.lang.reflect.Field;
import java.util.LinkedHashSet;
/**
* {@link CoronaBuilder} extension building {@link ConditionalTextBox} coronas.
*
* @author Valérie Maquil [valerie.maquil@list.lu]
* @since 1.4
* @version 1.4.0
* @param <B>
* The concrete builder.
*/
public abstract class BaseConditionalTextBoxBuilder<B extends BaseConditionalTextBoxBuilder<B>> extends CoronaBuilder<B> {
/** The equation that will evaluate the trigger condition. */
public Equation trigger;
/** All variables that will be needed to evaluate the trigger condition. */
public LinkedHashSet<Variable> variables = new LinkedHashSet<>();
/** Variable used to easily gather the output from the trigger equation. */
public BooleanVariable triggerVariable = new BooleanVariable("Trigger", false); //$NON-NLS-1$
/** Field holding the text that the corona should display when built. */
public String text = ""; //$NON-NLS-1$
/** The font to be used. */
public Font font = new Font("Arial", Font.PLAIN, 13); //$NON-NLS-1$
/** The font size to be used. */
public int fontSize = 13;
/** The colour the font is drawn in. */
public Color colour = Color.BLACK;
/** True if the text should be centred. */
public boolean centred = false;
/** The maximum width of any written line. */
public int lineWidth = 20;
/**
* The list of trigger variables by their name. These are placeholders and will be used to
* populate the list of variables the instance will react to once the overarching equation
* system has been initialized, thus making the variable instances globally available.
*/
public LinkedHashSet<String> triggers = new LinkedHashSet<>();
/**
* Constructor initializing all local fields.
*
* @param element
* 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 BaseConditionalTextBoxBuilder(Element element) throws BuildException {
super(element);
final String triggerCondition = element.getChildText(Externalization.TRIGGER_CONDITION_NODE);
if (null != element.getChild(Externalization.TRIGGERS_NODE)) {
element.getChild(Externalization.TRIGGERS_NODE).getChildren().forEach(c -> triggers.add(c.getText()));
}
LinkedHashSet<Variable> triggerVariables = new LinkedHashSet<>();
triggerVariables.add(triggerVariable);
trigger = new Equation(new Mapping(variables, triggerVariables), triggerCondition);
// trigger.setScriptEngine(new ScriptEngineManager().getEngineByName("js")); //$NON-NLS-1$
trigger.setExecutor(new JavascriptExecutor()); // $NON-NLS-1$
Element centredNode = element.getChild(Externalization.CENTRED_NODE);
if (null != centredNode) {
centred = Boolean.parseBoolean(centredNode.getText());
}
Element colourNode = element.getChild(Externalization.COLOUR_NODE);
try {
if (null != colourNode) {
Field field = Class.forName(Externalization.JAVA_AWT_COLOR_NAMESPACE).getField(colourNode.getText().toLowerCase());
colour = (Color) field.get(null);
}
} catch (ReflectiveOperationException roe) {
try {
colour = Color.decode(colourNode.getText());
} catch (NumberFormatException nfe) {
throw new BuildException("An error occured while trying to resolve the colour! The colour needs to either mirror the java.awt.Color fields or represent a hexadecimal colour code!", nfe); //$NON-NLS-1$
}
}
Element fontNode = element.getChild(Externalization.FONT_NODE);
if (null != fontNode) {
font = Font.decode(fontNode.getText());
}
try {
Element fontSizeNode = element.getChild(Externalization.FONT_SIZE_NODE);
if (null != fontSizeNode) {
fontSize = Integer.parseInt(fontSizeNode.getText());
}
} catch (NumberFormatException nfe) {
throw new BuildException("The provided font size must be an integer value!", nfe); //$NON-NLS-1$
}
// TODO the addition of an information provider per bootstrapping is not supported at this
// moment.
try {
Element lineWidthNode = element.getChild(Externalization.LINE_WIDTH_NODE);
if (null != lineWidthNode) {
lineWidth = Integer.parseInt(lineWidthNode.getText());
}
} catch (NumberFormatException nfe) {
throw new BuildException("The provided line width must be an integer value!", nfe); //$NON-NLS-1$
}
text = Strings.nullToEmpty(element.getChildText(Externalization.TEXT_NODE));
}
/**
* Method used to assign a triggering condition in the form of an equation to the
* {@link ConditionalTextBox} instance that can be built using this builder.
*
* @param equation
* The equation expressing the trigger.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withTrigger(Equation equation) {
this.trigger = equation;
return (B) this;
}
/**
* Method invoked to set the text that the corona will display.
*
* @param message
* The message the corona is used to convey.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withText(String message) {
this.text = message;
return (B) this;
}
/**
* Method for setting the font to use in the {@link ConditionalTextBox}.
*
* @param textFont
* The {@link Font} to use.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withFont(Font textFont) {
this.font = textFont;
return (B) this;
}
/**
* Method for setting the font colour to use in the {@link ConditionalTextBox}.
*
* @param textColour
* The {@link Color} to draw the text in.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withColour(Color textColour) {
this.colour = textColour;
return (B) this;
}
/**
* Method for setting whether the text should be centred on the point of drawing or not.
*
* @param textIsCentred
* <code>True</code> if the text is to be centred.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B centreText(boolean textIsCentred) {
this.centred = textIsCentred;
return (B) this;
}
/**
* Method for setting the font size to use in the {@link ConditionalTextBox}.
*
* @param size
* The size the {@link Font} should be drawn in.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withFontSize(int size) {
this.fontSize = size;
return (B) this;
}
/**
* Method for setting the line width to use in the {@link ConditionalTextBox}.
*
* @param width
* The line width of the text to display.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withLineWidth(int width) {
this.lineWidth = width;
return (B) this;
}
/** {@inheritDoc} */
@Override
public abstract ConditionalTextBox build();
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2016. 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.builder;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.widget.corona.ConditionalTextBox;
import org.jdom2.Element;
/**
* Builder used to initialize a {@link ConditionalTextBoxBuilder} instance that can be used to build
* {@link ConditionalTextBox} instances.
*
* @author Valérie Maquil [valerie.maquil@list.lu]
* @since 1.4
* @version 1.4.0
*/
public class ConditionalTextBoxBuilder extends BaseConditionalTextBoxBuilder<ConditionalTextBoxBuilder> {
/**
* Constructor forwarding the call to the super constructor.
*
* @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 ConditionalTextBoxBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
/** {@inheritDoc} */
@Override
public ConditionalTextBox build() {
return new ConditionalTextBox(this);
}
}
\ 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