Search in sources :

Example 6 with Section

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());
}
Also used : Line(javafx.scene.shape.Line) Arc(javafx.scene.shape.Arc) Tooltip(javafx.scene.control.Tooltip) ArrayList(java.util.ArrayList) Section(eu.hansolo.tilesfx.Section) CacheHint(javafx.scene.CacheHint)

Aggregations

Section (eu.hansolo.tilesfx.Section)6 CacheHint (javafx.scene.CacheHint)3 Point (eu.hansolo.tilesfx.tools.Point)2 Tooltip (javafx.scene.control.Tooltip)2 Arc (javafx.scene.shape.Arc)2 ArrayList (java.util.ArrayList)1 Pane (javafx.scene.layout.Pane)1 Color (javafx.scene.paint.Color)1 ClosePath (javafx.scene.shape.ClosePath)1 Line (javafx.scene.shape.Line)1 Path (javafx.scene.shape.Path)1 Rectangle (javafx.scene.shape.Rectangle)1 Text (javafx.scene.text.Text)1 TextFlow (javafx.scene.text.TextFlow)1 Rotate (javafx.scene.transform.Rotate)1