Commit 3de31f53 authored by Nico Mack's avatar Nico Mack

Added code to allow scripting of corona properties

parent df02c1c6
......@@ -94,14 +94,14 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
protected Timeline blinkingTimeline;
protected Timeline balisticTimeline;
private Area outer;
private Area inner;
private Area slice;
private Area face;
private Shape labelShape;
private double correctedAngle;
private double shownLowerValue;
private double shownUpperValue;
private Bound draggedBound;
private LineMetrics metrics;
// ***************************************************************************
// * Constants *
......@@ -199,7 +199,7 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
// double start = startAngle;
// double length = -arcSpan;
Rectangle2D bounds = new Rectangle2D.Double(centre.x - radius, centre.y - radius, (2 * radius), (2 * radius));
return new Arc2D.Double(bounds, startAngle, arcSpan, Arc2D.OPEN);
return new Arc2D.Double(bounds, correctedAngle, arcSpan, Arc2D.OPEN);
}
// ---------------------------------------------------------------------------
......@@ -222,7 +222,7 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
// ---------------------------------------------------------------------------
private Shape buildCircularText(List<String> lines, LineMetrics metrics) {
private Shape buildCircularText(List<String> lines) {
double labelRadius = lowerBoundRadius + metrics.getAscent() / 2;
Path2D compound = new Path2D.Float();
......@@ -240,7 +240,7 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
// ---------------------------------------------------------------------------
private Shape buildRadialText(List<String> lines, LineMetrics metrics, double angle) {
private Shape buildRadialText(List<String> lines, double angle) {
int numberOfLines = lines.size();
double radialAngle;
......@@ -272,17 +272,32 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
// ---------------------------------------------------------------------------
private void buildFromProperties() {
double diameter;
FontRenderContext renderingContext = new FontRenderContext(null, true, true);
LineMetrics metrics = textFont.getLineMetrics(label, renderingContext);
metrics = textFont.getLineMetrics(label, renderingContext);
this.updateSlice();
borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
this.draggedBound = Bound.NONE;
this.setInformation(new ValueRange<>(this.lowerBoundVariable.getValue(), this.upperBoundVariable.getValue()));
this.setSelected(this.isSelected);
}
// ---------------------------------------------------------------------------
private void updateSlice() {
double diameter;
List<String> lines;
Area outer;
Area inner;
// Java Arc2D 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 = AngleUtils.moduloThreeSixty(AngleUtils.THREE_SIXTY - startAngle - arcSpan);
correctedAngle = AngleUtils.moduloThreeSixty(AngleUtils.THREE_SIXTY - startAngle - arcSpan);
diameter = 2 * innerRadius;
inner = new Area(new Ellipse2D.Double(-innerRadius, -innerRadius, diameter, diameter));
......@@ -290,20 +305,18 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
diameter = 2 * lowerBoundRadius;
outer = new Area(new Ellipse2D.Double(-lowerBoundRadius, -lowerBoundRadius, diameter, diameter));
Shape sector = new Arc2D.Double(-lowerBoundRadius, -lowerBoundRadius, diameter, diameter, startAngle, arcSpan, Arc2D.PIE);
Shape sector = new Arc2D.Double(-lowerBoundRadius, -lowerBoundRadius, diameter, diameter, correctedAngle, arcSpan, Arc2D.PIE);
Area initial = new Area(sector);
initial.subtract(inner);
outer.subtract(inner);
shape = initial;
diameter = 2 * upperBoundRadius;
sector = new Arc2D.Double(-upperBoundRadius, -upperBoundRadius, diameter, diameter, startAngle, arcSpan, Arc2D.PIE);
sector = new Arc2D.Double(-upperBoundRadius, -upperBoundRadius, diameter, diameter, correctedAngle, arcSpan, Arc2D.PIE);
face = new Area(sector);
face.subtract(inner);
outer.subtract(inner);
borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
int availableWidth;
if (wrapToFit) {
......@@ -320,13 +333,10 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
}
if (!radialLayout) {
labelShape = this.buildCircularText(lines, metrics);
labelShape = this.buildCircularText(lines);
} else {
labelShape = this.buildRadialText(lines, metrics, startAngle);
labelShape = this.buildRadialText(lines, correctedAngle);
}
this.draggedBound = Bound.NONE;
this.setInformation(new ValueRange<>(this.lowerBoundVariable.getValue(), this.upperBoundVariable.getValue()));
this.setSelected(this.isSelected);
}
// ---------------------------------------------------------------------------
......@@ -418,7 +428,7 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
double upperDiameter = 2 * upperRadius;
Shape sector = new Arc2D.Double(-upperRadius, -upperRadius, upperDiameter, upperDiameter, startAngle, arcSpan, Arc2D.PIE);
Shape sector = new Arc2D.Double(-upperRadius, -upperRadius, upperDiameter, upperDiameter, correctedAngle, arcSpan, Arc2D.PIE);
slice = new Area(sector);
slice.subtract(lower);
shape = slice;
......@@ -483,6 +493,11 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
if (!active)
return;
if (this.readAndResetPropertyChanged()) {
this.updateSlice();
this.updateArcFromValues();
}
Graphics2D localCanvas = (Graphics2D) canvas.create();
AffineTransform translation = this.getTransform(null);
......
......@@ -93,11 +93,13 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
protected Timeline balisticTimeline;
private double normalizedValue;
private double correctedAngle;
private Area outer;
private Area inner;
private Area slice;
private Area face;
private Shape labelShape;
private LineMetrics metrics;
// ***************************************************************************
// * Constants *
......@@ -189,7 +191,7 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
// double start = startAngle;
// double length = -arcSpan;
Rectangle2D bounds = new Rectangle2D.Double(centre.x - radius, centre.y - radius, (2 * radius), (2 * radius));
return new Arc2D.Double(bounds, startAngle, arcSpan, Arc2D.OPEN);
return new Arc2D.Double(bounds, correctedAngle, arcSpan, Arc2D.OPEN);
}
// ---------------------------------------------------------------------------
......@@ -262,17 +264,77 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
// ---------------------------------------------------------------------------
private void buildFromProperties() {
double diameter;
// double diameter;
FontRenderContext renderingContext = new FontRenderContext(null, true, true);
LineMetrics metrics = textFont.getLineMetrics(label, renderingContext);
metrics = textFont.getLineMetrics(label, renderingContext);
List<String> lines;
// Java Arc2D 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 = AngleUtils.moduloThreeSixty(AngleUtils.THREE_SIXTY - startAngle - arcSpan);
this.updateSlice();
// correctedAngle = AngleUtils.moduloThreeSixty(AngleUtils.THREE_SIXTY - startAngle -
// arcSpan);
//
// diameter = 2 * innerRadius;
// inner = new Area(new Ellipse2D.Double(-innerRadius, -innerRadius, diameter, diameter));
//
// diameter = 2 * lowerBoundRadius;
// outer = new Area(new Ellipse2D.Double(-lowerBoundRadius, -lowerBoundRadius, diameter,
// diameter));
//
// Shape sector = new Arc2D.Double(-lowerBoundRadius, -lowerBoundRadius, diameter, diameter,
// correctedAngle, arcSpan, Arc2D.PIE);
// Area initial = new Area(sector);
// initial.subtract(inner);
// outer.subtract(inner);
// shape = initial;
//
// diameter = 2 * upperBoundRadius;
// sector = new Arc2D.Double(-upperBoundRadius, -upperBoundRadius, diameter, diameter,
// correctedAngle, arcSpan, Arc2D.PIE);
// face = new Area(sector);
// face.subtract(inner);
// outer.subtract(inner);
borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
// int availableWidth;
//
// if (wrapToFit) {
// if (!radialLayout) {
// double arcLength = Math.PI * ((upperBoundRadius + lowerBoundRadius) / 2) * (arcSpan /
// AngleUtils.ONE_EIGHTY);
// availableWidth = (int) arcLength - 2 * insetBorder;
// } else {
// availableWidth = (int) (upperBoundRadius - lowerBoundRadius - 2 * insetBorder);
// }
// lines = StringUtils.wrapToFit(label, availableWidth, textFont);
// } else {
// lines = new ArrayList<>();
// lines.add(label);
// }
//
// if (!radialLayout) {
// labelShape = this.buildCircularText(lines, metrics);
// } else {
// labelShape = this.buildRadialText(lines, metrics, correctedAngle);
// }
this.setInformation(this.variable.getValue());
this.setSelected(this.isSelected);
}
// ---------------------------------------------------------------------------
private void updateSlice() {
double diameter;
List<String> lines;
correctedAngle = AngleUtils.moduloThreeSixty(AngleUtils.THREE_SIXTY - startAngle - arcSpan);
diameter = 2 * innerRadius;
inner = new Area(new Ellipse2D.Double(-innerRadius, -innerRadius, diameter, diameter));
......@@ -280,20 +342,18 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
diameter = 2 * lowerBoundRadius;
outer = new Area(new Ellipse2D.Double(-lowerBoundRadius, -lowerBoundRadius, diameter, diameter));
Shape sector = new Arc2D.Double(-lowerBoundRadius, -lowerBoundRadius, diameter, diameter, startAngle, arcSpan, Arc2D.PIE);
Shape sector = new Arc2D.Double(-lowerBoundRadius, -lowerBoundRadius, diameter, diameter, correctedAngle, arcSpan, Arc2D.PIE);
Area initial = new Area(sector);
initial.subtract(inner);
outer.subtract(inner);
shape = initial;
diameter = 2 * upperBoundRadius;
sector = new Arc2D.Double(-upperBoundRadius, -upperBoundRadius, diameter, diameter, startAngle, arcSpan, Arc2D.PIE);
sector = new Arc2D.Double(-upperBoundRadius, -upperBoundRadius, diameter, diameter, correctedAngle, arcSpan, Arc2D.PIE);
face = new Area(sector);
face.subtract(inner);
outer.subtract(inner);
borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
int availableWidth;
if (wrapToFit) {
......@@ -312,11 +372,8 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
if (!radialLayout) {
labelShape = this.buildCircularText(lines, metrics);
} else {
labelShape = this.buildRadialText(lines, metrics, startAngle);
labelShape = this.buildRadialText(lines, metrics, correctedAngle);
}
this.setInformation(this.variable.getValue());
this.setSelected(this.isSelected);
}
// ---------------------------------------------------------------------------
......@@ -402,7 +459,7 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
}
double diameter = 2 * radius;
Shape sector = new Arc2D.Double(-radius, -radius, diameter, diameter, startAngle, arcSpan, Arc2D.PIE);
Shape sector = new Arc2D.Double(-radius, -radius, diameter, diameter, correctedAngle, arcSpan, Arc2D.PIE);
slice = new Area(sector);
slice.subtract(inner);
outer.subtract(inner);
......@@ -417,6 +474,10 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
if (!active)
return;
if (this.readAndResetPropertyChanged()) {
this.updateSlice();
}
Graphics2D localCanvas = (Graphics2D) canvas.create();
AffineTransform translation = this.getTransform(null);
......
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