Commit 37e3695e authored by Nico Mack's avatar Nico Mack

Preparation for multiple widgets with identical object IDs.

parent a91b8acb
...@@ -54,7 +54,7 @@ public class BooleanVariable extends Variable<Boolean> { ...@@ -54,7 +54,7 @@ public class BooleanVariable extends Variable<Boolean> {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public Variable<Boolean> clone() { public BooleanVariable clone() {
BooleanVariable variable = new BooleanVariable(name, value); BooleanVariable variable = new BooleanVariable(name, value);
variable.listeners = new Vector<>(listeners); variable.listeners = new Vector<>(listeners);
return variable; return variable;
......
...@@ -24,6 +24,8 @@ import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; ...@@ -24,6 +24,8 @@ import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable; import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.cps.utility.Externalization; import lu.list.itis.dkd.tui.cps.utility.Externalization;
import com.google.common.base.Objects;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -46,7 +48,7 @@ public class NumericalVariable extends Variable<Double> { ...@@ -46,7 +48,7 @@ public class NumericalVariable extends Variable<Double> {
private DecimalFormat format; private DecimalFormat format;
private static final Logger logger = LoggerFactory.getLogger(NumericalVariable.class.getSimpleName()); private static final Logger LOGGER = LoggerFactory.getLogger(NumericalVariable.class.getSimpleName());
/** /**
* Constructor resorting to the super constructor to initialise the name and unit and locally * Constructor resorting to the super constructor to initialise the name and unit and locally
...@@ -116,7 +118,7 @@ public class NumericalVariable extends Variable<Double> { ...@@ -116,7 +118,7 @@ public class NumericalVariable extends Variable<Double> {
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
return toString().hashCode(); return Objects.hashCode(name, unit, value);
} }
/** /**
...@@ -146,14 +148,15 @@ public class NumericalVariable extends Variable<Double> { ...@@ -146,14 +148,15 @@ public class NumericalVariable extends Variable<Double> {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setValue(Double newValue) { public void setValue(Double newValue) {
// Double newValue;
// newValue = (Double) this.valueFromString(value.toString()); double val = (newValue != null) ? newValue : 0d;
if (newValue < this.minValue)
newValue = this.minValue; if (val < this.minValue)
else if (newValue > this.maxValue) val = this.minValue;
newValue = this.maxValue; else if (val > this.maxValue)
val = this.maxValue;
super.setValue(newValue);
super.setValue(val);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -252,7 +255,7 @@ public class NumericalVariable extends Variable<Double> { ...@@ -252,7 +255,7 @@ public class NumericalVariable extends Variable<Double> {
try { try {
newValue = Double.parseDouble(stringValue); newValue = Double.parseDouble(stringValue);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
logger.error("The provided value ({}) does not match the format stored by this variable instance.", stringValue, e); //$NON-NLS-1$ LOGGER.error("The provided value ({}) does not match the format stored by this variable instance.", stringValue, e); //$NON-NLS-1$
throw e; throw e;
} }
return newValue; return newValue;
......
...@@ -52,6 +52,7 @@ public class ArcGraph extends ValueCorona { ...@@ -52,6 +52,7 @@ public class ArcGraph extends ValueCorona {
private Shape labelShape; private Shape labelShape;
private Font textFont; private Font textFont;
private Stroke borderStroke; private Stroke borderStroke;
private int strokeWidth;
private Area outer; private Area outer;
private Area inner; private Area inner;
...@@ -80,8 +81,6 @@ public class ArcGraph extends ValueCorona { ...@@ -80,8 +81,6 @@ public class ArcGraph extends ValueCorona {
public ArcGraph(ArcGraphBuilder builder) { public ArcGraph(ArcGraphBuilder builder) {
super(builder); super(builder);
double diameter;
this.startAngle = builder.startAngle; this.startAngle = builder.startAngle;
this.arcSpan = builder.arcSpan; this.arcSpan = builder.arcSpan;
this.relative = builder.relative; this.relative = builder.relative;
...@@ -97,6 +96,51 @@ public class ArcGraph extends ValueCorona { ...@@ -97,6 +96,51 @@ public class ArcGraph extends ValueCorona {
this.bezelColour = builder.bezelColour; this.bezelColour = builder.bezelColour;
this.labelShape = builder.labelShape; this.labelShape = builder.labelShape;
this.textFont = builder.textFont; this.textFont = builder.textFont;
this.strokeWidth = builder.strokeWidth;
this.buildFromProperties();
}
// ---------------------------------------------------------------------------
/**
* Copy constructor to clone corona.
*
* @param original
* specifies the original corona to create an exact copy from.
*/
// ---------------------------------------------------------------------------
public ArcGraph(ArcGraph original) {
super(original);
this.startAngle = original.startAngle;
this.arcSpan = original.arcSpan;
this.relative = original.relative;
this.reference = original.reference;
this.innerRadius = original.innerRadius;
this.outerRadius = original.outerRadius;
this.fillColour = original.fillColour;
this.strokeColour = original.strokeColour;
this.labelColour = original.labelColour;
this.textColour = original.textColour;
this.faceColour = original.faceColour;
this.bezelColour = original.bezelColour;
this.labelShape = original.labelShape;
this.textFont = original.textFont;
this.strokeWidth = original.strokeWidth;
this.buildFromProperties();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildFromProperties() {
double diameter;
diameter = 2 * innerRadius; diameter = 2 * innerRadius;
inner = new Area(new Ellipse2D.Double(-innerRadius, -innerRadius, diameter, diameter)); inner = new Area(new Ellipse2D.Double(-innerRadius, -innerRadius, diameter, diameter));
...@@ -119,15 +163,11 @@ public class ArcGraph extends ValueCorona { ...@@ -119,15 +163,11 @@ public class ArcGraph extends ValueCorona {
labelShape = originTranslator.createTransformedShape(labelShape); labelShape = originTranslator.createTransformedShape(labelShape);
} }
borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null; borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
this.setInformation((relative) ? this.reference : this.variable.getMinValue()); this.setInformation((relative) ? this.reference : this.variable.getMinValue());
} }
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
private Point getOffsetFromCenter() { private Point getOffsetFromCenter() {
...@@ -338,6 +378,13 @@ public class ArcGraph extends ValueCorona { ...@@ -338,6 +378,13 @@ public class ArcGraph extends ValueCorona {
} }
} }
// ---------------------------------------------------------------------------
@Override
public ArcGraph clone() {
return new ArcGraph(this);
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * End of Class * // * End of Class *
......
...@@ -17,7 +17,9 @@ import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; ...@@ -17,7 +17,9 @@ import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.cps.system.Equation; 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.BooleanVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable; import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.utility.ImageUtilities;
import lu.list.itis.dkd.tui.utility.Point; import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.widget.corona.builder.ConditionalCoronaBuilder; import lu.list.itis.dkd.tui.widget.corona.builder.ConditionalCoronaBuilder;
import java.awt.Graphics2D; import java.awt.Graphics2D;
...@@ -44,7 +46,8 @@ public class ConditionalCorona extends Corona { ...@@ -44,7 +46,8 @@ public class ConditionalCorona extends Corona {
*/ */
private LinkedHashSet<String> triggers = new LinkedHashSet<>(); private LinkedHashSet<String> triggers = new LinkedHashSet<>();
private java.awt.Image image; protected java.awt.Image image;
protected Point imageCentre;
/** /**
* @param builder * @param builder
...@@ -58,6 +61,22 @@ public class ConditionalCorona extends Corona { ...@@ -58,6 +61,22 @@ public class ConditionalCorona extends Corona {
this.triggers = builder.triggers; this.triggers = builder.triggers;
this.variables = builder.variables; this.variables = builder.variables;
this.image = builder.image; this.image = builder.image;
imageCentre = (image != null) ? new Point(image.getWidth(null) / 2, image.getHeight(null) / 2, 0, ScreenCoordinates.class)
: new Point();
}
public ConditionalCorona(ConditionalCorona original) {
super(original);
this.trigger = original.trigger;
this.triggerVariable = original.triggerVariable.clone();
this.triggers = new LinkedHashSet<>(original.triggers);
this.variables = new LinkedHashSet<>(original.variables);
this.image = ImageUtilities.deepCopy(original.image);
imageCentre = (image != null) ? new Point(image.getWidth(null) / 2, image.getHeight(null) / 2, 0, ScreenCoordinates.class)
: new Point();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -68,37 +87,39 @@ public class ConditionalCorona extends Corona { ...@@ -68,37 +87,39 @@ public class ConditionalCorona extends Corona {
return; return;
} }
centre.toScreenCoordinates(); // centre.toScreenCoordinates();
if (initialTranslation != null) { // if (initialTranslation != null) {
initialTranslation.toScreenCoordinates(); // initialTranslation.toScreenCoordinates();
} else { // } else {
initialTranslation = new Point(); // initialTranslation = new Point();
} // }
//
Point drawAt = centre.add(initialTranslation); // Point drawAt = centre.add(initialTranslation);
//
AffineTransform rotation = new AffineTransform(); // AffineTransform rotation = new AffineTransform();
rotation.rotate(rotateWithHandle ? drawAt.getAngle() : initialTranslation != null ? initialTranslation.getAngle() : 0, centre.getX(), centre.getY()); // rotation.rotate(rotateWithHandle ? drawAt.getAngle() : initialTranslation != null ?
rotation.translate(drawAt.x, drawAt.y); // initialTranslation.getAngle() : 0, centre.getX(), centre.getY());
// rotation.translate(drawAt.x, drawAt.y);
if (spinOnCoronaCentre) { //
rotation.rotate(rotateWithHandle ? -drawAt.getAngle() : 0); // if (spinOnCoronaCentre) {
rotation.translate(-image.getWidth(null) / 2, -image.getHeight(null) / 2); // rotation.rotate(rotateWithHandle ? -drawAt.getAngle() : 0);
} // rotation.translate(-image.getWidth(null) / 2, -image.getHeight(null) / 2);
// }
rotation.transform(new Point(), drawAt); //
// rotation.transform(new Point(), drawAt);
if (Double.compare(initialRotation, 0d) != 0) { //
AffineTransform transformation = new AffineTransform(); // if (Double.compare(initialRotation, 0d) != 0) {
transformation.rotate(initialRotation, spinOnCoronaCentre ? drawAt.getX() + image.getWidth(null) / 2 : drawAt.getX(), spinOnCoronaCentre ? drawAt.getY() + image.getHeight(null) / 2 : drawAt.getY()); // AffineTransform transformation = new AffineTransform();
canvas.setTransform(transformation); // transformation.rotate(initialRotation, spinOnCoronaCentre ? drawAt.getX() +
} // image.getWidth(null) / 2 : drawAt.getX(), spinOnCoronaCentre ? drawAt.getY() +
// image.getHeight(null) / 2 : drawAt.getY());
canvas.drawImage(image, (int) drawAt.x, (int) drawAt.y, null); // canvas.setTransform(transformation);
canvas.setTransform(new AffineTransform()); // }
AffineTransform transform = this.getTransform(imageCentre);
canvas.drawImage(image, transform, null);
} }
/** /**
* Method used to add a variable to the set of variables held by this corona. * Method used to add a variable to the set of variables held by this corona.
* *
...@@ -117,4 +138,10 @@ public class ConditionalCorona extends Corona { ...@@ -117,4 +138,10 @@ public class ConditionalCorona extends Corona {
public LinkedHashSet<String> getTriggers() { public LinkedHashSet<String> getTriggers() {
return triggers; return triggers;
} }
@Override
public ConditionalCorona clone() {
return new ConditionalCorona(this);
}
} }
\ No newline at end of file
...@@ -76,8 +76,32 @@ public class ShapeGraph extends ValueCorona { ...@@ -76,8 +76,32 @@ public class ShapeGraph 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(this.variable.getMinValue());
}
// ---------------------------------------------------------------------------
/**
* Copy constructor to clone corona.
*
* @param original
* specifies the original corona to create an exact copy from.
*/
// ---------------------------------------------------------------------------
public ShapeGraph(ShapeGraph original) {
super(original);
this.lowerBound = original.lowerBound;
this.upperBound = original.upperBound;
this.fillColour = original.fillColour;
this.strokeColour = original.strokeColour;
this.strokeWidth = original.strokeWidth;
this.graphShape = original.graphShape;
borderStroke = (original.strokeWidth > 0) ? new BasicStroke(original.strokeWidth) : null;
this.setInformation(this.variable.getMinValue());
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Primitives * // * Primitives *
...@@ -189,6 +213,13 @@ public class ShapeGraph extends ValueCorona { ...@@ -189,6 +213,13 @@ public class ShapeGraph extends ValueCorona {
} }
} }
// ---------------------------------------------------------------------------
@Override
public ShapeGraph clone() {
return new ShapeGraph(this);
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * End of Class * // * End of Class *
......
...@@ -35,6 +35,14 @@ public class ValueCorona extends Corona implements InformationReceiver<Object> { ...@@ -35,6 +35,14 @@ public class ValueCorona extends Corona implements InformationReceiver<Object> {
this.selected = false; this.selected = false;
} }
// ---------------------------------------------------------------------------
public ValueCorona(ValueCorona original) {
super(original);
this.variable = (original.variable != null) ? original.variable.clone() : null;
this.selected = false;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Primitives * // * Primitives *
...@@ -82,6 +90,13 @@ public class ValueCorona extends Corona implements InformationReceiver<Object> { ...@@ -82,6 +90,13 @@ public class ValueCorona extends Corona implements InformationReceiver<Object> {
} }
} }
// ---------------------------------------------------------------------------
@Override
public ValueCorona clone() {
return new ValueCorona(this);
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * End of Class * // * End of Class *
......
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