Commit eb8b4c6e authored by Nico Mack's avatar Nico Mack

Changes caused by common code refactoring of TextBaselineUtils class

Implementation of label display in SegementArcGraph corona
parent 57f7a740
......@@ -10,7 +10,6 @@ FACE_IS_TOUCHABLE_NODE=faceIsTouchable
FOREGROUND_NODE=foreground
ITEMS_VARIABLE_NODE=itemsVariable
HTML_TEMPLATE_NODE=htmlTemplate
LABEL_NODE=label
LABEL_TRANSLATION_NODE=labelTranslation
LANDING_LINE_LENGTH_NODE=landingLineLength
LEADER_COLOUR_NODE=leaderColour
......
......@@ -43,7 +43,6 @@ public class CpsNamespace extends NLS {
public static String ITEMS_VARIABLE_NODE;
public static String LABEL_NODE;
public static String LABEL_TRANSLATION_NODE;
public static String LANDING_LINE_LENGTH_NODE;
......
......@@ -183,7 +183,7 @@ public class ColourScale<T extends Comparable<T>> {
ValueRange<Double> range = new ValueRange<>(lowerBound, upperBound);
mapping = (ColourMapping<T>) new ColourMapping<>(range, colour);
String label = BootstrappingUtils.getAttributeAsString(rootElement, CpsNamespace.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING);
String label = BootstrappingUtils.getAttributeAsString(rootElement, Externalization.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING);
if (Strings.isNotBlank(label)) {
mapping.setLabel(label);
}
......
......@@ -23,6 +23,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.PolarCoordinateHelper;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.utility.StringUtils;
import lu.list.itis.dkd.tui.utility.TextBaselineUtils;
import lu.list.itis.dkd.tui.utility.TextStroke;
import lu.list.itis.dkd.tui.utility.ValueRange;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseCoxcombRangeSliceBuilder;
......@@ -44,9 +45,7 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
......@@ -195,12 +194,13 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
// ***************************************************************************
// ---------------------------------------------------------------------------
private Shape buildCircularBaseline(double radius) {
// 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, correctedAngle, arcSpan, Arc2D.OPEN);
}
// private Shape buildCircularBaseline(double radius) {
// // 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, correctedAngle, arcSpan, Arc2D.OPEN);
// }
// ---------------------------------------------------------------------------
/**
......@@ -214,21 +214,23 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
*/
// ---------------------------------------------------------------------------
private Shape buildRadialBaseline(double angle, double lineHeight) {
Shape centreLine = new Line2D.Double(lowerBoundRadius + insetBorder, lineHeight, upperBoundRadius - insetBorder, lineHeight);
AffineTransform rotate = AffineTransform.getRotateInstance(AngleUtils.moduloTwoPi(AngleUtils.TWO_PI - angle));
return rotate.createTransformedShape(centreLine);
}
// private Shape buildRadialBaseline(double angle, double lineHeight) {
// Shape centreLine = new Line2D.Double(lowerBoundRadius + insetBorder, lineHeight,
// upperBoundRadius - insetBorder, lineHeight);
// AffineTransform rotate =
// AffineTransform.getRotateInstance(AngleUtils.moduloTwoPi(AngleUtils.TWO_PI - angle));
// return rotate.createTransformedShape(centreLine);
// }
// ---------------------------------------------------------------------------
private Shape buildCircularText(List<String> lines) {
double lineHeight = metrics.getAscent();
double labelRadius = lowerBoundRadius + metrics.getAscent() / 2;
Path2D compound = new Path2D.Float();
for (String line : lines) {
Shape labelPath = this.buildCircularBaseline(labelRadius);
Shape labelPath = TextBaselineUtils.buildCircularBaseline(correctedAngle, arcSpan, labelRadius, lineHeight, false);
TextStroke stroke = new TextStroke(line, textFont, false, centered, false);
Shape circularText = stroke.createStrokedShape(labelPath);
compound.append(circularText, false);
......@@ -241,7 +243,6 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
// ---------------------------------------------------------------------------
private Shape buildRadialText(List<String> lines, double angle) {
int numberOfLines = lines.size();
double radialAngle;
double angularSpan = Math.toRadians(arcSpan);
......@@ -259,7 +260,7 @@ public class CoxcombRangeSlice extends ValueRangeCorona {
double baselineAngle = AngleUtils.moduloTwoPi(Math.toRadians(angle) + radialAngle);
for (String line : lines) {
Shape labelPath = this.buildRadialBaseline(baselineAngle, lineHeight);
Shape labelPath = TextBaselineUtils.buildRadialBaseline(baselineAngle, lowerBoundRadius, upperBoundRadius, lineHeight, insetBorder);
TextStroke stroke = new TextStroke(line, textFont, false, centered, false);
Shape radialText = stroke.createStrokedShape(labelPath);
compound.append(radialText, false);
......
......@@ -24,6 +24,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.PolarCoordinateHelper;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.utility.StringUtils;
import lu.list.itis.dkd.tui.utility.TextBaselineUtils;
import lu.list.itis.dkd.tui.utility.TextStroke;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseCoxcombSliceBuilder;
......@@ -42,9 +43,7 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
......@@ -187,12 +186,13 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
// ***************************************************************************
// ---------------------------------------------------------------------------
private Shape buildCircularBaseline(double radius) {
// 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, correctedAngle, arcSpan, Arc2D.OPEN);
}
// private Shape buildCircularBaseline(double radius) {
// // 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, correctedAngle, arcSpan, Arc2D.OPEN);
// }
// ---------------------------------------------------------------------------
/**
......@@ -206,21 +206,24 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
*/
// ---------------------------------------------------------------------------
private Shape buildRadialBaseline(double angle, double lineHeight) {
Shape centreLine = new Line2D.Double(lowerBoundRadius + insetBorder, lineHeight, upperBoundRadius - insetBorder, lineHeight);
AffineTransform rotate = AffineTransform.getRotateInstance(AngleUtils.moduloTwoPi(AngleUtils.TWO_PI - angle));
return rotate.createTransformedShape(centreLine);
}
// private Shape buildRadialBaseline(double angle, double lineHeight) {
// Shape centreLine = new Line2D.Double(lowerBoundRadius + insetBorder, lineHeight,
// upperBoundRadius - insetBorder, lineHeight);
// AffineTransform rotate =
// AffineTransform.getRotateInstance(AngleUtils.moduloTwoPi(AngleUtils.TWO_PI - angle));
// return rotate.createTransformedShape(centreLine);
// }
// ---------------------------------------------------------------------------
private Shape buildCircularText(List<String> lines, LineMetrics metrics) {
double labelRadius = lowerBoundRadius + metrics.getAscent() / 2;
double lineHeight = metrics.getAscent();
double labelRadius = lowerBoundRadius + lineHeight / 2;
Path2D compound = new Path2D.Float();
for (String line : lines) {
Shape labelPath = this.buildCircularBaseline(labelRadius);
Shape labelPath = TextBaselineUtils.buildCircularBaseline(correctedAngle, arcSpan, labelRadius, lineHeight, false);
TextStroke stroke = new TextStroke(line, textFont, false, centered, false);
Shape circularText = stroke.createStrokedShape(labelPath);
compound.append(circularText, false);
......@@ -251,7 +254,7 @@ public class CoxcombSlice extends ValueCorona implements InformationProvider<Obj
double baselineAngle = AngleUtils.moduloTwoPi(Math.toRadians(angle) + radialAngle);
for (String line : lines) {
Shape labelPath = this.buildRadialBaseline(baselineAngle, lineHeight);
Shape labelPath = TextBaselineUtils.buildRadialBaseline(baselineAngle, lowerBoundRadius, upperBoundRadius, lineHeight, insetBorder);
TextStroke stroke = new TextStroke(line, textFont, false, centered, false);
Shape radialText = stroke.createStrokedShape(labelPath);
compound.append(radialText, false);
......
......@@ -153,9 +153,9 @@ public class SegmentedArcGraph extends SegmentedArc implements InformationReceiv
if (this.opacity < OPAQUE)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
for (int index = 0; index < segments.size(); index++) {
Shape segment = segments.get(index);
SegmentedArcGraphProperties properties = (SegmentedArcGraphProperties) segmentProperties.get(index);
for (int current = 0; current < segments.size(); current++) {
Shape segment = segments.get(current);
SegmentedArcGraphProperties properties = (SegmentedArcGraphProperties) segmentProperties.get(current);
if (properties.fillColour != null) {
localCanvas.setPaint(properties.fillColour.getColor());
......@@ -167,6 +167,13 @@ public class SegmentedArcGraph extends SegmentedArc implements InformationReceiv
localCanvas.setStroke(properties.stroke);
localCanvas.draw(segment);
}
Shape label = labels.get(current);
if ((label != null) && (properties.textColour != null)) {
localCanvas.setPaint(properties.textColour.getColor());
localCanvas.fill(label);
}
}
localCanvas.dispose();
......
......@@ -127,7 +127,7 @@ public abstract class BaseCoxcombRangeSliceBuilder<B extends BaseCoxcombRangeSli
/** Optional fields */
label = BootstrappingUtils.getContentAsString(rootElement, CpsNamespace.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
label = BootstrappingUtils.getContentAsString(rootElement, Externalization.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
labelAngle = BootstrappingUtils.getContentAsDegrees(rootElement, Externalization.LABEL_ANGLE_NODE, BootstrappingUtils.OPTIONAL, Double.NaN, context);
radialLayout = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.RADIAL_LAYOUT_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context);
......
......@@ -127,7 +127,7 @@ public abstract class BaseCoxcombSliceBuilder<B extends BaseCoxcombSliceBuilder<
/** Optional fields */
label = BootstrappingUtils.getContentAsString(rootElement, CpsNamespace.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
label = BootstrappingUtils.getContentAsString(rootElement, Externalization.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
labelAngle = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.LABEL_ANGLE_NODE, BootstrappingUtils.OPTIONAL, Double.NaN, context);
radialLayout = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.RADIAL_LAYOUT_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context);
......
......@@ -131,7 +131,7 @@ public abstract class BaseSegmentedArcGraphBuilder<B extends BaseSegmentedArcGra
@Override
protected SegmentedArcGraphProperties buildSegmentProperty(@NonNull Element segmentElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
SegmentedArcGraphProperties property = new SegmentedArcGraphProperties();
property.title = BootstrappingUtils.getContentAsString(segmentElement, Externalization.TITLE_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
property.label = BootstrappingUtils.getContentAsString(segmentElement, Externalization.LABEL_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
property.fillColour = buildColorPair(segmentElement.getChild(Externalization.FILL_COLOUR_ELEMENT), context);
property.textColour = buildColorPair(segmentElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), context);
property.strokeColour = buildColorPair(segmentElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), context);
......
......@@ -18,8 +18,6 @@ package lu.list.itis.dkd.tui.widget.corona.inner;
import lu.list.itis.dkd.tui.utility.ColorPair;
import java.awt.Stroke;
/**
* Class encapsulating all properties pertaining to an individual arc segment.
*
......@@ -33,9 +31,7 @@ import java.awt.Stroke;
// ***************************************************************************
public class SegmentedArcGraphProperties extends SegmentedArcProperties {
public String title;
public ColorPair fillColour;
public ColorPair strokeColour;
public ColorPair textColour;
public Stroke stroke;
}
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