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

Correct Class hierarchy of SectorBuilder

Implemented proper handling of drawPrioirity property of coronas
parent 82018905
......@@ -24,6 +24,7 @@ import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.network.adapter.NetworkAdapter;
import lu.list.itis.dkd.tui.utility.CoronaComparator;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.Positionable;
import lu.list.itis.dkd.tui.widget.builder.BaseBuilder;
......@@ -206,6 +207,9 @@ public class BaseWidget implements Positionable, Touchable {
synchronized (this.coronas) {
allCoronas.addAll(coronas.values());
}
Collections.sort(allCoronas, new CoronaComparator());
return allCoronas;
}
......
......@@ -3,7 +3,7 @@ package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.utility.AngleUtils;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.TextStroke;
import lu.list.itis.dkd.tui.widget.corona.builder.SectorBuilder;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseSectorBuilder;
import lu.list.itis.dkd.tui.widget.touch.TouchEvent;
import lu.list.itis.dkd.tui.widget.touch.TouchManager;
......@@ -69,7 +69,7 @@ public class Sector extends SelectableCorona {
*/
// ---------------------------------------------------------------------------
public Sector(SectorBuilder builder) {
public Sector(BaseSectorBuilder<?> builder) {
super(builder);
label = builder.title;
......@@ -126,15 +126,18 @@ public class Sector extends SelectableCorona {
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildSectorFromProperties() {
size = 2 * outerRadius;
private double getAngle() {
double angle = AngleUtils.moduloThreeSixty(startAngle);
angle += ((double) gap / 2);
arcSpan -= gap;
return angle;
}
int quadrant = AngleUtils.getQuadrant(Math.toRadians(angle));
boolean flipped = (quadrant == 2) || (quadrant == 3);
// ---------------------------------------------------------------------------
private void buildSectorFromProperties() {
size = 2 * outerRadius;
double angle = this.getAngle();
arcSpan -= gap;
// Java Arc3D start angle and extend are expressed in counter clockwise rotation. Since
// TULIP follows the clockwise TUIO convention, we need to convert both startAngle and
......@@ -152,26 +155,42 @@ public class Sector extends SelectableCorona {
borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
if ((label != null) && (label.length() > 0)) {
this.renderLabel(label);
this.setSelected(this.isSelected);
}
// ---------------------------------------------------------------------------
protected void renderLabel(String newLabel) {
if ((newLabel != null) && (newLabel.length() > 0)) {
double angle = this.getAngle();
int quadrant = AngleUtils.getQuadrant(Math.toRadians(angle));
boolean flipped = (quadrant == 2) || (quadrant == 3);
angle = (THREE_SIXTY - angle);
FontRenderContext renderingContext = new FontRenderContext(null, true, true);
LineMetrics metrics = textFont.getLineMetrics(label, renderingContext);
LineMetrics metrics = textFont.getLineMetrics(newLabel, renderingContext);
double labelRadius = outerRadius - metrics.getAscent() / 2;
Rectangle2D bounds = new Rectangle2D.Double(centre.x - labelRadius, centre.y - labelRadius, (2 * labelRadius), (2 * labelRadius));
// Rectangle2D bounds = new Rectangle2D.Double(centre.x - labelRadius, centre.y - labelRadius, (2 *
// labelRadius), (2 * labelRadius));
Rectangle2D bounds = new Rectangle2D.Double(-labelRadius, -labelRadius, (2 * labelRadius), (2 * labelRadius));
double start = (!flipped) ? angle - arcSpan : angle;
int length = (!flipped) ? arcSpan : -arcSpan;
Shape path = new Arc2D.Double(bounds, start, length, Arc2D.OPEN);
TextStroke stroke = new TextStroke(label, textFont, false, centered, false);
TextStroke stroke = new TextStroke(newLabel, textFont, false, centered, false);
stroke.setFlipped(flipped);
curvedText = stroke.createStrokedShape(path);
this.label = newLabel;
}
this.setSelected(this.isSelected);
}
// ---------------------------------------------------------------------------
......
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