Java Code Examples for javafx.scene.canvas.GraphicsContext#fillArc()

The following examples show how to use javafx.scene.canvas.GraphicsContext#fillArc() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Helper.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public static final void drawTimeAreas(final Clock CLOCK, final GraphicsContext CTX, final List<TimeSection> AREAS, final double SIZE,
                                       final double XY_INSIDE, final double XY_OUTSIDE, final double WH_INSIDE, final double WH_OUTSIDE) {
    if (AREAS.isEmpty()) return;
    TickLabelLocation tickLabelLocation = CLOCK.getTickLabelLocation();
    ZonedDateTime     time              = CLOCK.getTime();
    boolean           isAM              = time.get(ChronoField.AMPM_OF_DAY) == 0;
    double            xy                = TickLabelLocation.OUTSIDE == tickLabelLocation ? XY_OUTSIDE * SIZE : XY_INSIDE * SIZE;
    double            wh                = TickLabelLocation.OUTSIDE == tickLabelLocation ? WH_OUTSIDE * SIZE : WH_INSIDE * SIZE;
    double            offset            = 90;
    double            angleStep         = 360.0 / 60.0;
    int               listSize          = AREAS.size();
    boolean           highlightAreas    = CLOCK.isHighlightAreas();
    for (int i = 0; i < listSize ; i++) {
        TimeSection area      = AREAS.get(i);
        LocalTime   start     = area.getStart();
        LocalTime   stop      = area.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 (draw) {
            double areaStartAngle  = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;;
            double areaAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep;
            //TODO: Add an indicator to the area like -1 or similar
            // check if start was already yesterday
            if (start.getHour() > stop.getHour()) { areaAngleExtend = (360.0 - Math.abs(areaAngleExtend)); }
            CTX.save();
            if (highlightAreas) {
                CTX.setFill(area.contains(time.toLocalTime()) ? area.getHighlightColor() : area.getColor());
            } else {
                CTX.setFill(area.getColor());
            }
            CTX.fillArc(xy, xy, wh, wh, -(offset + areaStartAngle), -areaAngleExtend, ArcType.ROUND);
            CTX.restore();
        }
    }
}
 
Example 2
Source File: InteractiveGaugeSkin.java    From medusademo with Apache License 2.0 4 votes vote down vote up
private void drawAreasAndSections(final GraphicsContext CTX) {
    if (areas.isEmpty() && sections.isEmpty()) return;
    double value  = getSkinnable().getCurrentValue();
    double offset = 90 - startAngle;
    double xy;
    double wh;
    int    listSize;

    // Draw Areas
    if (areasVisible && !areas.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.0895 * size : 0.025 * size;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.821 : size * 0.95;
        listSize = areas.size();
        for (int i = 0; i < listSize ; i++) {
            Section area = areas.get(i);
            double areaStartAngle;
            if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) {
                if (area.getStart() < minValue && area.getStop() < maxValue) {
                    areaStartAngle = 0;
                } else {
                    areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep;
                }
                double areaAngleExtend;
                if (area.getStop() > maxValue) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep;
                } else if (Double.compare(area.getStart(), minValue) < 0) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep;
                } else {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightAreas) {
                    CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor());
                } else {
                    CTX.setFill(area.getColor());
                }
                CTX.fillArc(xy, xy, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND);
                CTX.restore();
            }
        }
    }

    // Draw Sections
    if (sectionsVisible && !sections.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.115 * size : 0.0515 * size;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.77 : size * 0.897;
        listSize = sections.size();
        CTX.setLineWidth(size * 0.052);
        CTX.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0; i < listSize; i++) {
            Section section = sections.get(i);
            double  sectionStartAngle;
            if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) {
                if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) {
                    sectionStartAngle = 0;
                } else {
                    sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep;
                }
                double sectionAngleExtend;
                if (Double.compare(section.getStop(), maxValue) > 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep;
                } else if (Double.compare(section.getStart(), minValue) < 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep;
                } else {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightSections) {
                    CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor());
                } else {
                    CTX.setStroke(section.getColor());
                }
                CTX.strokeArc(xy, xy, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
                CTX.restore();
            }
        }
    }
}
 
Example 3
Source File: HSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawAreasAndSections(final GraphicsContext CTX) {
    if (areas.isEmpty() && sections.isEmpty()) return;

    double value       = gauge.getCurrentValue();
    double scaledWidth = width * 0.9;
    double offset      = 90 - startAngle;
    double offsetY     = -0.1 * height;
    double xy;
    double wh;
    int    listSize;

    // Draw areas
    if (areasVisible && !areas.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.1445 * scaledWidth : 0.081 * scaledWidth;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledWidth * 0.821 : scaledWidth * 0.9505;
        listSize = areas.size();
        for (int i = 0 ; i < listSize ; i++) {
            Section area = areas.get(i);
            double areaStartAngle;
            if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) {
                if (area.getStart() < minValue && area.getStop() < maxValue) {
                    areaStartAngle = 0;
                } else {
                    areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep;
                }
                double areaAngleExtend;
                if (area.getStop() > maxValue) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep;
                } else if (Double.compare(area.getStart(), minValue) < 0) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep;
                } else {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightAreas) {
                    CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor());
                } else {
                    CTX.setFill(area.getColor());
                }
                CTX.fillArc(xy, xy + offsetY, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND);
                CTX.restore();
            }
        }
    }

    // Draw sections
    if (sectionsVisible && !sections.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.1705 * scaledWidth : 0.107 * scaledWidth;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledWidth * 0.77 : scaledWidth * 0.897;
        listSize = sections.size();
        CTX.setLineWidth(scaledWidth * 0.052);
        CTX.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0; i < listSize; i++) {
            Section section = sections.get(i);
            double  sectionStartAngle;
            if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) {
                if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) {
                    sectionStartAngle = 0;
                } else {
                    sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep;
                }
                double sectionAngleExtend;
                if (Double.compare(section.getStop(), maxValue) > 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep;
                } else if (Double.compare(section.getStart(), minValue) < 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep;
                } else {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightSections) {
                    CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor());
                } else {
                    CTX.setStroke(section.getColor());
                }
                CTX.strokeArc(xy, xy + offsetY, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
                CTX.restore();
            }
        }
    }
}
 
Example 4
Source File: QuarterSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawAreasAndSections(final GraphicsContext CTX) {
    if (areas.isEmpty() && sections.isEmpty()) return;
    double value        = gauge.getCurrentValue();
    Pos    knobPosition = gauge.getKnobPosition();
    double scaledSize   = size * 1.9;
    double offset       = 90 - startAngle;
    double offsetX;
    double offsetY;
    double xy;
    double wh;
    int    listSize;
    
    // Draw Areas
    if (areasVisible && !areas.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.078 * scaledSize : 0.0125 * scaledSize;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledSize * 0.846 : scaledSize * 0.97;
        offsetX  = Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? 0 : -scaledSize * 0.475;
        offsetY  = Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.475 : 0;
        listSize = areas.size();
        for (int i = 0 ; i < listSize ; i++) {
            Section area = areas.get(i);
            double areaStartAngle;
            if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) {
                if (area.getStart() < minValue && area.getStop() < maxValue) {
                    areaStartAngle = 0;
                } else {
                    areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep;
                }
                double areaAngleExtend;
                if (area.getStop() > maxValue) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep;
                } else if (Double.compare(area.getStart(), minValue) < 0) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep;
                } else {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightAreas) {
                    CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor());
                } else {
                    CTX.setFill(area.getColor());
                }
                CTX.fillArc(xy + offsetX, xy + offsetY, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND);
                CTX.restore();
            }
        }    
    }
    
    // Draw Sections
    if (sectionsVisible && !sections.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.11675 * scaledSize : 0.03265 * scaledSize;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledSize * 0.7745 : scaledSize * 0.935;
        offsetX  = TickLabelLocation.OUTSIDE == tickLabelLocation 
                 ? ( Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.0045 : -scaledSize * 0.4770 )
                 : ( Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? 0 : -scaledSize * 0.4738 );
        offsetY  = TickLabelLocation.OUTSIDE == tickLabelLocation 
                 ? ( Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.4770 : -scaledSize * 0.0045 )
                 : ( Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.4738 : 0 );
        listSize = sections.size();
        CTX.setLineWidth(scaledSize * 0.04);
        CTX.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0; i < listSize; i++) {
            Section section = sections.get(i);
            double  sectionStartAngle;
            if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) {
                if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) {
                    sectionStartAngle = 0;
                } else {
                    sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep;
                }
                double sectionAngleExtend;
                if (Double.compare(section.getStop(), maxValue) > 0) {
                    sectionAngleExtend =
                        ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep;
                } else if (Double.compare(section.getStart(), minValue) < 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep;
                } else {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ?
                                         (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightSections) {
                    CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor());
                } else {
                    CTX.setStroke(section.getColor());
                }
                CTX.strokeArc(xy + offsetX, xy + offsetY, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
                CTX.restore();
            }
        }
    }
}
 
Example 5
Source File: GaugeSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawAreasAndSections(final GraphicsContext CTX) {
    if (areas.isEmpty() && sections.isEmpty()) return;
    double value  = gauge.getCurrentValue();
    double offset = 90 - startAngle;
    double xy;
    double wh;
    int    listSize;

    // Draw Areas
    if (areasVisible && !areas.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.0895 * size : 0.025 * size;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.821 : size * 0.95;
        listSize = areas.size();
        for (int i = 0; i < listSize ; i++) {
            Section area = areas.get(i);
            double areaStartAngle;
            if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) {
                if (area.getStart() < minValue && area.getStop() < maxValue) {
                    areaStartAngle = 0;
                } else {
                    areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep;
                }
                double areaAngleExtend;
                if (area.getStop() > maxValue) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep;
                } else if (Double.compare(area.getStart(), minValue) < 0) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep;
                } else {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightAreas) {
                    CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor());
                } else {
                    CTX.setFill(area.getColor());
                }
                CTX.fillArc(xy, xy, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND);
                CTX.restore();
            }
        }
    }

    // Draw Sections
    if (sectionsVisible && !sections.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.115 * size : 0.0515 * size;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.77 : size * 0.897;
        listSize = sections.size();
        CTX.setLineWidth(size * 0.052);
        CTX.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0; i < listSize; i++) {
            Section section = sections.get(i);
            double  sectionStartAngle;
            if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) {
                if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) {
                    sectionStartAngle = 0;
                } else {
                    sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep;
                }
                double sectionAngleExtend;
                if (Double.compare(section.getStop(), maxValue) > 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep;
                } else if (Double.compare(section.getStart(), minValue) < 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep;
                } else {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightSections) {
                    CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor());
                } else {
                    CTX.setStroke(section.getColor());
                }
                CTX.strokeArc(xy, xy, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
                CTX.restore();
            }
        }
    }
}