Commit 62ace793 authored by Nico Mack's avatar Nico Mack

Added centred property to sector

Safer handling of points in getPointRelativeToCentre method of corona
parent c39a492d
......@@ -581,12 +581,17 @@ public abstract class Corona implements Comparable<Corona>, Cloneable, Touchable
// ---------------------------------------------------------------------------
public Point getPointRelativeToCentre(Point point) {
Point relativePoint = new Point(0, 0, 0, ScreenCoordinates.class);
AffineTransform transform = this.getTransform(null);
try {
transform.inverseTransform(point.toCoordinates(ScreenCoordinates.class), relativePoint);
} catch (NoninvertibleTransformException e) {
LOGGER.error("Failed to get point relative to centre", e); //$NON-NLS-1$
Point relativePoint = null;
if (point != null) {
relativePoint = new Point(0, 0, 0, ScreenCoordinates.class);
Point absolutePoint = point.clone().toCoordinates(ScreenCoordinates.class);
AffineTransform transform = this.getTransform(null);
try {
transform.inverseTransform(absolutePoint, relativePoint);
} catch (NoninvertibleTransformException e) {
LOGGER.error("Failed to get point relative to centre", e); //$NON-NLS-1$
}
}
return relativePoint;
}
......
......@@ -51,6 +51,7 @@ public class Sector extends SelectableCorona {
protected Shape curvedText;
protected Stroke borderStroke;
protected Font textFont;
protected boolean centered;
protected TouchManager touchManager;
......@@ -82,6 +83,7 @@ public class Sector extends SelectableCorona {
gap = builder.gap;
this.startAngle = builder.startAngle;
arcSpan = builder.arcSpan;
centered = builder.centered;
this.buildSectorFromProperties();
......@@ -111,6 +113,7 @@ public class Sector extends SelectableCorona {
gap = original.gap;
startAngle = original.startAngle;
arcSpan = original.arcSpan;
centered = original.centered;
this.buildSectorFromProperties();
......@@ -162,7 +165,7 @@ public class Sector extends SelectableCorona {
Shape path = new Arc2D.Double(bounds, start, length, Arc2D.OPEN);
TextStroke stroke = new TextStroke(label, textFont, false, true, false);
TextStroke stroke = new TextStroke(label, textFont, false, centered, false);
stroke.setFlipped(flipped);
......
......@@ -54,6 +54,8 @@ public class SectorBuilder extends BaseSelectableCoronaBuilder<SectorBuilder> {
/** Specifies the font to be used for rendering the title */
public Font textFont;
public boolean centered;
// ***************************************************************************
// * Constants *
// ***************************************************************************
......@@ -123,6 +125,7 @@ public class SectorBuilder extends BaseSelectableCoronaBuilder<SectorBuilder> {
String fontName = BootstrappingUtils.getContentAsString(rootElement, Externalization.FONT_NODE, BootstrappingUtils.OPTIONAL, "Monospaced", context); //$NON-NLS-1$
Integer fontSize = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.FONT_SIZE_NODE, BootstrappingUtils.OPTIONAL, 14, context);
centered = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.CENTRED_NODE, BootstrappingUtils.OPTIONAL, Boolean.TRUE, context);
if ((fontName != null) && (fontName.length() > 0)) {
textFont = new Font(fontName, Font.BOLD, fontSize);
......
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