Search in sources :

Example 21 with Arc

use of javafx.scene.shape.Arc in project tilesfx by HanSolo.

the class TimerControlTileSkin method drawTimeSections.

private void drawTimeSections() {
    if (sectionMap.isEmpty())
        return;
    ZonedDateTime time = tile.getTime();
    DayOfWeek day = time.getDayOfWeek();
    boolean isAM = time.get(ChronoField.AMPM_OF_DAY) == 0;
    double offset = 90;
    double angleStep = 360.0 / 60.0;
    boolean highlightSections = tile.isHighlightSections();
    for (TimeSection section : sectionMap.keySet()) {
        LocalTime start = section.getStart();
        LocalTime stop = section.getStop();
        boolean isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean isStopAM = stop.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean draw = isAM ? (isStartAM || isStopAM) : (!isStartAM || !isStopAM);
        if (!section.getDays().contains(day)) {
            draw = false;
        }
        if (!section.isActive()) {
            draw = false;
        }
        if (draw) {
            double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;
            double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep;
            if (start.getHour() > stop.getHour()) {
                sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend));
            }
            Arc arc = sectionMap.get(section);
            arc.setCenterX(clockSize * 0.5);
            arc.setCenterY(clockSize * 0.5);
            arc.setRadiusX(clockSize * 0.45);
            arc.setRadiusY(clockSize * 0.45);
            arc.setStartAngle(-(offset + sectionStartAngle));
            arc.setLength(-sectionAngleExtend);
            arc.setType(ArcType.OPEN);
            arc.setStrokeWidth(clockSize * 0.04);
            arc.setStrokeLineCap(StrokeLineCap.BUTT);
            arc.setFill(null);
            if (highlightSections) {
                arc.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor());
            } else {
                arc.setStroke(section.getColor());
            }
        }
    }
}
Also used : DayOfWeek(java.time.DayOfWeek) Arc(javafx.scene.shape.Arc) TimeSection(eu.hansolo.tilesfx.TimeSection) LocalTime(java.time.LocalTime) ZonedDateTime(java.time.ZonedDateTime)

Example 22 with Arc

use of javafx.scene.shape.Arc in project tilesfx by HanSolo.

the class CircularProgressTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    if (tile.isAutoScale())
        tile.calcAutoScale();
    minValue = tile.getMinValue();
    range = tile.getRange();
    angleStep = ANGLE_RANGE / range;
    sectionsVisible = tile.getSectionsVisible();
    sections = tile.getSections();
    formatString = new StringBuilder("%.").append(Integer.toString(tile.getDecimals())).append("f").toString();
    locale = tile.getLocale();
    currentValueListener = o -> setBar(tile.getCurrentValue());
    graphicListener = (o, ov, nv) -> {
        if (nv != null) {
            graphicContainer.getChildren().setAll(tile.getGraphic());
        }
    };
    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    enableNode(titleText, !tile.getTitle().isEmpty());
    text = new Text(tile.getText());
    text.setFill(tile.getTextColor());
    enableNode(text, tile.isTextVisible());
    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.468, PREFERRED_HEIGHT * 0.468, 90, 360);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(tile.getBarBackgroundColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.1);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);
    bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.468, PREFERRED_HEIGHT * 0.468, 90, 0);
    bar.setType(ArcType.OPEN);
    bar.setStroke(tile.getBarColor());
    bar.setStrokeWidth(PREFERRED_WIDTH * 0.1);
    bar.setStrokeLineCap(StrokeLineCap.BUTT);
    bar.setFill(null);
    separator = new Line(PREFERRED_WIDTH * 0.5, 1, PREFERRED_WIDTH * 0.5, 0.16667 * PREFERRED_HEIGHT);
    separator.setStroke(tile.getBackgroundColor());
    separator.setFill(Color.TRANSPARENT);
    percentageValueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
    percentageValueText.setFont(Fonts.latoRegular(PREFERRED_WIDTH * 0.27333));
    percentageValueText.setFill(tile.getValueColor());
    percentageValueText.setTextOrigin(VPos.CENTER);
    percentageUnitText = new Text(tile.getUnit());
    percentageUnitText = new Text("\u0025");
    percentageUnitText.setFont(Fonts.latoLight(PREFERRED_WIDTH * 0.08));
    percentageUnitText.setFill(tile.getUnitColor());
    percentageFlow = new TextFlow(percentageValueText, percentageUnitText);
    percentageFlow.setTextAlignment(TextAlignment.CENTER);
    valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
    valueText.setFont(Fonts.latoRegular(PREFERRED_WIDTH * 0.27333));
    valueText.setFill(tile.getValueColor());
    valueText.setTextOrigin(VPos.CENTER);
    enableNode(valueText, tile.isValueVisible());
    unitText = new Text(tile.getUnit());
    unitText = new Text("\u0025");
    unitText.setFont(Fonts.latoLight(PREFERRED_WIDTH * 0.08));
    unitText.setFill(tile.getUnitColor());
    enableNode(unitText, !tile.getUnit().isEmpty());
    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.CENTER);
    graphicContainer = new StackPane();
    graphicContainer.setMinSize(size * 0.9, tile.isTextVisible() ? size * 0.72 : size * 0.795);
    graphicContainer.setMaxSize(size * 0.9, tile.isTextVisible() ? size * 0.72 : size * 0.795);
    graphicContainer.setPrefSize(size * 0.9, tile.isTextVisible() ? size * 0.72 : size * 0.795);
    if (null == tile.getGraphic()) {
        enableNode(graphicContainer, false);
    } else {
        graphicContainer.getChildren().setAll(tile.getGraphic());
    }
    getPane().getChildren().addAll(barBackground, bar, separator, titleText, text, graphicContainer, percentageFlow, valueUnitFlow);
}
Also used : Line(javafx.scene.shape.Line) Arc(javafx.scene.shape.Arc) Text(javafx.scene.text.Text) TextFlow(javafx.scene.text.TextFlow) StackPane(javafx.scene.layout.StackPane)

Example 23 with Arc

use of javafx.scene.shape.Arc in project tilesfx by HanSolo.

the class GaugeTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    if (tile.isAutoScale())
        tile.calcAutoScale();
    oldValue = tile.getValue();
    sectionMap = new HashMap<>(sections.size());
    for (Section section : sections) {
        sectionMap.put(section, new Arc());
    }
    barColor = tile.getBarColor();
    thresholdColor = tile.getThresholdColor();
    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(barColor);
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);
    thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
    thresholdBar.setType(ArcType.OPEN);
    thresholdBar.setStroke(tile.getThresholdColor());
    thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
    thresholdBar.setFill(null);
    Helper.enableNode(thresholdBar, !tile.getSectionsVisible());
    sectionPane = new Pane();
    Helper.enableNode(sectionPane, tile.getSectionsVisible());
    if (sectionsVisible) {
        drawSections();
    }
    alertIcon = new Path();
    alertIcon.setFillRule(FillRule.EVEN_ODD);
    alertIcon.setFill(Color.YELLOW);
    alertIcon.setStroke(null);
    Helper.enableNode(alertIcon, tile.isAlert());
    alertTooltip = new Tooltip(tile.getAlertMessage());
    Tooltip.install(alertIcon, alertTooltip);
    needleRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
    needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
    needleRect = new Rectangle();
    needleRect.setFill(tile.getBackgroundColor());
    needleRect.getTransforms().setAll(needleRectRotate);
    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(tile.getNeedleColor());
    needle.setStrokeWidth(0);
    needle.setStroke(Color.TRANSPARENT);
    titleText = new Text(tile.getTitle());
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
    valueText.setFill(tile.getValueColor());
    valueText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());
    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    unitText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(unitText, tile.isValueVisible() && !tile.isAlert());
    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.CENTER);
    minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
    minValueText.setFill(tile.getTitleColor());
    maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
    maxValueText.setFill(tile.getTitleColor());
    thresholdRect = new Rectangle();
    thresholdRect.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getValue() > tile.getThreshold() ? tile.getThresholdColor() : Tile.GRAY);
    Helper.enableNode(thresholdRect, tile.isThresholdVisible());
    thresholdText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getThreshold()));
    thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : Tile.GRAY);
    Helper.enableNode(thresholdText, tile.isThresholdVisible());
    getPane().getChildren().addAll(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueUnitFlow, minValueText, maxValueText, thresholdRect, thresholdText);
}
Also used : Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) Arc(javafx.scene.shape.Arc) Rotate(javafx.scene.transform.Rotate) Tooltip(javafx.scene.control.Tooltip) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) TextFlow(javafx.scene.text.TextFlow) Section(eu.hansolo.tilesfx.Section) Pane(javafx.scene.layout.Pane)

Example 24 with Arc

use of javafx.scene.shape.Arc 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

Arc (javafx.scene.shape.Arc)24 ICircleArc (net.sf.latexdraw.models.interfaces.shape.ICircleArc)10 Text (javafx.scene.text.Text)8 Pane (javafx.scene.layout.Pane)5 Line (javafx.scene.shape.Line)5 Rectangle (javafx.scene.shape.Rectangle)5 Theory (org.junit.experimental.theories.Theory)5 Circle (javafx.scene.shape.Circle)4 TextFlow (javafx.scene.text.TextFlow)4 Rotate (javafx.scene.transform.Rotate)4 Canvas (javafx.scene.canvas.Canvas)3 DropShadow (javafx.scene.effect.DropShadow)3 Path (javafx.scene.shape.Path)3 Test (org.junit.Test)3 Section (eu.hansolo.tilesfx.Section)2 TimeSection (eu.hansolo.tilesfx.TimeSection)2 CacheHint (javafx.scene.CacheHint)2 Group (javafx.scene.Group)2 Tooltip (javafx.scene.control.Tooltip)2 InnerShadow (javafx.scene.effect.InnerShadow)2