use of eu.hansolo.tilesfx.Section in project tilesfx by HanSolo.
the class GaugeTileSkin method drawSections.
private void drawSections() {
sectionPane.getChildren().clear();
if (!sectionsVisible || sections.isEmpty())
return;
double centerX = width * 0.5;
double centerY = height * 0.5;
double innerRadius = size * 0.2775;
double outerRadius = size * 0.3225;
int noOfSections = sections.size();
List<Line> sectionLines = new ArrayList<>(noOfSections);
for (int i = 0; i < noOfSections - 1; i++) {
Section section = sections.get(i);
double angle = Helper.clamp(90.0, 270.0, (section.getStop() - minValue) * angleStep + 90.0);
Line line = new Line(centerX + innerRadius * Math.sin(-Math.toRadians(angle)), centerY + innerRadius * Math.cos(-Math.toRadians(angle)), centerX + outerRadius * Math.sin(-Math.toRadians(angle)), centerY + outerRadius * Math.cos(-Math.toRadians(angle)));
line.setStroke(tile.getBackgroundColor());
sectionLines.add(line);
}
sectionPane.getChildren().addAll(sectionLines);
double barRadius = size * 0.3;
double barWidth = size * 0.045;
double maxValue = tile.getMaxValue();
for (Section section : sections) {
double startAngle = (section.getStart() - minValue) * angleStep - angleRange;
double length;
if (section.getStop() > maxValue) {
length = (maxValue - section.getStart()) * angleStep;
} else if (Double.compare(section.getStart(), minValue) < 0) {
length = (section.getStop() - minValue) * angleStep;
} else {
length = (section.getStop() - section.getStart()) * angleStep;
}
Arc sectionArc = new Arc(centerX, centerY + size * 0.2825, barRadius, barRadius, -startAngle, -length);
sectionArc.setType(ArcType.OPEN);
sectionArc.setStroke(section.getColor());
sectionArc.setStrokeWidth(barWidth);
sectionArc.setStrokeLineCap(StrokeLineCap.BUTT);
sectionArc.setFill(null);
sectionArc.setVisible(!highlightSections);
sectionArc.setOpacity(highlightSections ? 1.0 : 0.25);
Tooltip sectionTooltip = new Tooltip(section.getText());
sectionTooltip.setTextAlignment(TextAlignment.CENTER);
Tooltip.install(sectionArc, sectionTooltip);
sectionMap.put(section, sectionArc);
}
sectionPane.getChildren().addAll(sectionMap.values());
}
Aggregations