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

The following examples show how to use javafx.scene.canvas.GraphicsContext#strokeArc() . 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: XorGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintGate(GraphicsContext graphics, CircuitState circuitState) {
	int x = getScreenX();
	int y = getScreenY();
	int width = 4 * GuiUtils.BLOCK_SIZE;
	int height = 4 * GuiUtils.BLOCK_SIZE;
	
	graphics.beginPath();
	graphics.moveTo(x + width * 0.1, y + height);
	graphics.arc(x + width * 0.1, y + height * 0.5, width * 0.25, height * 0.5, 270, 180);
	graphics.arcTo(x + width * 0.66, y, x + width * 1.25, y + height, width);
	graphics.arcTo(x + width * 0.66, y + height, x + width * 0.1, y + height, width);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
	
	graphics.strokeArc(x - width * 0.3, y, width * 0.5, height, 270, 180, ArcType.OPEN);
}
 
Example 2
Source File: XnorGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintGate(GraphicsContext graphics, CircuitState circuitState) {
	int x = getScreenX();
	int y = getScreenY();
	int width = 4 * GuiUtils.BLOCK_SIZE;
	int height = 4 * GuiUtils.BLOCK_SIZE;
	
	graphics.beginPath();
	graphics.moveTo(x + width * 0.1, y + height);
	graphics.arc(x + width * 0.1, y + height * 0.5, width * 0.25, height * 0.5, 270, 180);
	graphics.arcTo(x + width * 0.66, y, x + width, y + height * 1.3, width * 0.7);
	graphics.arcTo(x + width * 0.66, y + height, x + width * 0.1, y + height, width * 0.7);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
	
	graphics.strokeArc(x - width * 0.3, y, width * 0.5, height, 270, 180, ArcType.OPEN);
	
	graphics.fillOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2);
	graphics.strokeOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2);
}
 
Example 3
Source File: Helper.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public static final void drawTimeSections(final Clock CLOCK, final GraphicsContext CTX, final List<TimeSection> SECTIONS, final double SIZE,
                                          final double XY_INSIDE, final double XY_OUTSIDE, final double WH_INSIDE, final double WH_OUTSIDE,
                                          final double LINE_WIDTH) {
    if (SECTIONS.isEmpty()) return;
    TickLabelLocation tickLabelLocation = CLOCK.getTickLabelLocation();
    ZonedDateTime     time              = CLOCK.getTime();
    boolean           isAM              = time.get(ChronoField.AMPM_OF_DAY) == 0;
    double            xy                = TickLabelLocation.INSIDE == tickLabelLocation ? XY_INSIDE * SIZE : XY_OUTSIDE * SIZE;
    double            wh                = TickLabelLocation.INSIDE == tickLabelLocation ? WH_INSIDE * SIZE : WH_OUTSIDE * SIZE;
    double            offset            = 90;
    int               listSize          = SECTIONS.size();
    double            angleStep         = 360.0 / 60.0;
    boolean           highlightSections = CLOCK.isHighlightSections();
    for (int i = 0 ; i < listSize ; i++) {
        TimeSection section   = SECTIONS.get(i);
        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 (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;
            //TODO: Add an indicator to the section like -1 or similar
            // check if start was already yesterday
            if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); }
            CTX.save();
            if (highlightSections) {
                CTX.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor());
            } else {
                CTX.setStroke(section.getColor());
            }
            CTX.setLineWidth(SIZE * LINE_WIDTH);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(xy, xy, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example 4
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
private void drawSelfEdge(Edge pEdge, GraphicsContext pGraphics)
{
	Arc arc = (Arc) getShape(pEdge);
	double width = pGraphics.getLineWidth();
	pGraphics.setLineWidth(LINE_WIDTH);
	pGraphics.strokeArc(arc.getCenterX(), arc.getCenterY(), arc.getRadiusX(), arc.getRadiusY(), arc.getStartAngle(), 
			arc.getLength(), arc.getType());
	pGraphics.setLineWidth(width);
}
 
Example 5
Source File: RadialBargraphSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private final void drawSections(final GraphicsContext CTX) {
    final double xy        = (size - 0.87 * size) * 0.5;
    final double wh        = size * 0.87;
    final double MIN_VALUE = getSkinnable().getMinValue();
    final double OFFSET = 90 - getSkinnable().getStartAngle();
    for (int i = 0 ; i < getSkinnable().getSections().size() ; i++) {
        final Section SECTION      = getSkinnable().getSections().get(i);
        final double  ANGLE_START  = (SECTION.getStart() - MIN_VALUE) * angleStep;
        final double  ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
        CTX.save();
        switch(i) {
            case 0: CTX.setStroke(getSkinnable().getSectionFill0()); break;
            case 1: CTX.setStroke(getSkinnable().getSectionFill1()); break;
            case 2: CTX.setStroke(getSkinnable().getSectionFill2()); break;
            case 3: CTX.setStroke(getSkinnable().getSectionFill3()); break;
            case 4: CTX.setStroke(getSkinnable().getSectionFill4()); break;
            case 5: CTX.setStroke(getSkinnable().getSectionFill5()); break;
            case 6: CTX.setStroke(getSkinnable().getSectionFill6()); break;
            case 7: CTX.setStroke(getSkinnable().getSectionFill7()); break;
            case 8: CTX.setStroke(getSkinnable().getSectionFill8()); break;
            case 9: CTX.setStroke(getSkinnable().getSectionFill9()); break;
        }
        CTX.setLineWidth(size * 0.1);
        CTX.setLineCap(StrokeLineCap.BUTT);
        CTX.strokeArc(xy, xy, wh, wh, -(OFFSET + ANGLE_START), -ANGLE_EXTEND, ArcType.OPEN);
        CTX.restore();
    }
}
 
Example 6
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 7
Source File: CustomPlainAmpSkin.java    From medusademo with Apache License 2.0 4 votes vote down vote up
private void drawSections(final GraphicsContext CTX) {
    final double                  x                 = -width * 0.03;
    final double                  y                 = height * 0.345;
    final double                  w                 = width * 1.06;
    final double                  h                 = height * 2.085;
    final double                  MIN_VALUE         = gauge.getMinValue();
    final double                  MAX_VALUE         = gauge.getMaxValue();
    final double                  OFFSET            = 90 - START_ANGLE;
    final ObservableList<Section> sections          = gauge.getSections();
    final boolean                 highlightSections = gauge.isHighlightSections();

    double value    = gauge.getCurrentValue();
    int    listSize = sections.size();
    for (int i = 0 ; i < listSize ; i++) {
        final Section SECTION = sections.get(i);
        final double  SECTION_START_ANGLE;
        if (Double.compare(SECTION.getStart(), MAX_VALUE) <= 0 && Double.compare(SECTION.getStop(), MIN_VALUE) >= 0) {
            if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
                SECTION_START_ANGLE = 0;
            } else {
                SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
            }
            final double SECTION_ANGLE_EXTEND;
            if (SECTION.getStop() > MAX_VALUE) {
                SECTION_ANGLE_EXTEND = (MAX_VALUE - SECTION.getStart()) * angleStep;
            } else {
                SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
            }

            CTX.save();
            if (highlightSections) {
                CTX.setStroke(SECTION.contains(value) ? SECTION.getHighlightColor() : SECTION.getColor());
            } else {
                CTX.setStroke(SECTION.getColor());
            }
            CTX.setLineWidth(height * 0.0415);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(x, y, w, h, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example 8
Source File: PlainAmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawSections(final GraphicsContext CTX) {
    final double                  x                 = -width * 0.03;
    final double                  y                 = height * 0.345;
    final double                  w                 = width * 1.06;
    final double                  h                 = height * 2.085;
    final double                  MIN_VALUE         = gauge.getMinValue();
    final double                  MAX_VALUE         = gauge.getMaxValue();
    final double                  OFFSET            = 90 - START_ANGLE;
    final ObservableList<Section> sections          = gauge.getSections();
    final boolean                 highlightSections = gauge.isHighlightSections();

    double value    = gauge.getCurrentValue();
    int    listSize = sections.size();
    for (int i = 0 ; i < listSize ; i++) {
        final Section SECTION = sections.get(i);
        final double  SECTION_START_ANGLE;
        if (Double.compare(SECTION.getStart(), MAX_VALUE) <= 0 && Double.compare(SECTION.getStop(), MIN_VALUE) >= 0) {
            if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
                SECTION_START_ANGLE = 0;
            } else {
                SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
            }
            final double SECTION_ANGLE_EXTEND;
            if (SECTION.getStop() > MAX_VALUE) {
                SECTION_ANGLE_EXTEND = (MAX_VALUE - SECTION.getStart()) * angleStep;
            } else {
                SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
            }

            CTX.save();
            if (highlightSections) {
                CTX.setStroke(SECTION.contains(value) ? SECTION.getHighlightColor() : SECTION.getColor());
            } else {
                CTX.setStroke(SECTION.getColor());
            }
            CTX.setLineWidth(height * 0.0415);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(x, y, w, h, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example 9
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 10
Source File: AmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawSections(final GraphicsContext CTX) {
    final double x                         = width * 0.06;
    final double y                         = width * 0.21;
    final double w                         = width * 0.88;
    final double h                         = height * 1.05;
    final double MIN_VALUE                 = gauge.getMinValue();
    final double MAX_VALUE                 = gauge.getMaxValue();
    final double OFFSET                    = 90 - START_ANGLE;
    final ObservableList<Section> sections = gauge.getSections();
    final boolean highlightSections        = gauge.isHighlightSections();

    double value    = gauge.getCurrentValue();
    int    listSize = sections.size();
    for (int i = 0 ; i < listSize ; i++) {
        final Section SECTION = sections.get(i);
        final double  SECTION_START_ANGLE;
        if (Double.compare(SECTION.getStart(), MAX_VALUE) <= 0 && Double.compare(SECTION.getStop(), MIN_VALUE) >= 0) {
            if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
                SECTION_START_ANGLE = 0;
            } else {
                SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
            }
            final double SECTION_ANGLE_EXTEND;
            if (SECTION.getStop() > MAX_VALUE) {
                SECTION_ANGLE_EXTEND = (MAX_VALUE - SECTION.getStart()) * angleStep;
            } else {
                SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
            }

            CTX.save();
            if (highlightSections) {
                CTX.setStroke(SECTION.contains(value) ? SECTION.getHighlightColor() : SECTION.getColor());
            } else {
                CTX.setStroke(SECTION.getColor());
            }
            CTX.setLineWidth(height * 0.0415);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(x, y, w, h, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example 11
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 12
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();
            }
        }
    }
}
 
Example 13
Source File: GaugeSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    if (getSkinnable().isHistogramEnabled()) {
        double xy;
        double wh;
        double step         = 0;
        double OFFSET       = 90 - getSkinnable().getStartAngle();
        double ANGLE_EXTEND = (getSkinnable().getMaxValue()) * angleStep;
        CTX.setStroke(Color.rgb(200, 200, 200));
        CTX.setLineWidth(size * 0.001);
        CTX.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0 ; i < 5 ; i++) {
            xy = (size - (0.435 + step) * size) / 2;
            wh = size * (0.435 + step);
            CTX.strokeArc(xy, xy, wh, wh, -OFFSET, -ANGLE_EXTEND, ArcType.OPEN);
            step += 0.075;
        }
    }

    double  sinValue;
    double  cosValue;
    double  startAngle = getSkinnable().getStartAngle();
    double  orthText   = Gauge.TickLabelOrientation.ORTHOGONAL == getSkinnable().getTickLabelOrientation() ? 0.33 : 0.31;
    Point2D center     = new Point2D(size * 0.5, size * 0.5);
    for (double angle = 0, counter = getSkinnable().getMinValue() ; Double.compare(counter, getSkinnable().getMaxValue()) <= 0 ; angle -= angleStep, counter++) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerMainPoint   = new Point2D(center.getX() + size * 0.368 * sinValue, center.getY() + size * 0.368 * cosValue);
        Point2D innerMediumPoint = new Point2D(center.getX() + size * 0.388 * sinValue, center.getY() + size * 0.388 * cosValue);
        Point2D innerMinorPoint  = new Point2D(center.getX() + size * 0.3975 * sinValue, center.getY() + size * 0.3975 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + size * 0.432 * sinValue, center.getY() + size * 0.432 * cosValue);
        Point2D textPoint        = new Point2D(center.getX() + size * orthText * sinValue, center.getY() + size * orthText * cosValue);

        CTX.setStroke(getSkinnable().getTickMarkFill());
        if (counter % getSkinnable().getMajorTickSpace() == 0) {
            // Draw major tickmark
            CTX.setLineWidth(size * 0.0055);
            CTX.strokeLine(innerMainPoint.getX(), innerMainPoint.getY(), outerPoint.getX(), outerPoint.getY());

            // Draw text
            CTX.save();
            CTX.translate(textPoint.getX(), textPoint.getY());
            switch(getSkinnable().getTickLabelOrientation()) {
                case ORTHOGONAL:
                    if ((360 - startAngle - angle) % 360 > 90 && (360 - startAngle - angle) % 360 < 270) {
                        CTX.rotate((180 - startAngle - angle) % 360);
                    } else {
                        CTX.rotate((360 - startAngle - angle) % 360);
                    }
                    break;
                case TANGENT:
                    if ((360 - startAngle - angle - 90) % 360 > 90 && (360 - startAngle - angle - 90) % 360 < 270) {
                        CTX.rotate((90 - startAngle - angle) % 360);
                    } else {
                        CTX.rotate((270 - startAngle - angle) % 360);
                    }
                    break;
                case HORIZONTAL:
                default:
                    break;
            }
            CTX.setFont(Font.font("Verdana", FontWeight.NORMAL, 0.045 * size));
            CTX.setTextAlign(TextAlignment.CENTER);
            CTX.setTextBaseline(VPos.CENTER);
            CTX.setFill(getSkinnable().getTickLabelFill());
            CTX.fillText(Integer.toString((int) counter), 0, 0);
            CTX.restore();
        } else if (getSkinnable().getMinorTickSpace() % 2 != 0 && counter % 5 == 0) {
            CTX.setLineWidth(size * 0.0035);
            CTX.strokeLine(innerMediumPoint.getX(), innerMediumPoint.getY(), outerPoint.getX(), outerPoint.getY());
        } else if (counter % getSkinnable().getMinorTickSpace() == 0) {
            CTX.setLineWidth(size * 0.00225);
            CTX.strokeLine(innerMinorPoint.getX(), innerMinorPoint.getY(), outerPoint.getX(), outerPoint.getY());
        }
    }
}
 
Example 14
Source File: GaugeSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private final void drawSections(final GraphicsContext CTX) {
    final double xy        = (size - 0.83 * size) / 2;
    final double wh        = size * 0.83;
    final double MIN_VALUE = getSkinnable().getMinValue();
    final double MAX_VALUE = getSkinnable().getMaxValue();
    final double OFFSET = 90 - getSkinnable().getStartAngle();
    for (int i = 0 ; i < getSkinnable().getSections().size() ; i++) {
        final Section SECTION = getSkinnable().getSections().get(i);

        if (SECTION.getStart() > MAX_VALUE || SECTION.getStop() < MIN_VALUE) continue;

        final double SECTION_START_ANGLE;
        if (SECTION.getStart() > MAX_VALUE || SECTION.getStop() < MIN_VALUE) continue;

        if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
            SECTION_START_ANGLE = MIN_VALUE * angleStep;
        } else {
            SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
        }
        final double SECTION_ANGLE_EXTEND;
        if (SECTION.getStop() > MAX_VALUE) {
            SECTION_ANGLE_EXTEND = MAX_VALUE * angleStep;
        } else {
            SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
        }

        CTX.save();
        switch(i) {
            case 0: CTX.setStroke(getSkinnable().getSectionFill0()); break;
            case 1: CTX.setStroke(getSkinnable().getSectionFill1()); break;
            case 2: CTX.setStroke(getSkinnable().getSectionFill2()); break;
            case 3: CTX.setStroke(getSkinnable().getSectionFill3()); break;
            case 4: CTX.setStroke(getSkinnable().getSectionFill4()); break;
            case 5: CTX.setStroke(getSkinnable().getSectionFill5()); break;
            case 6: CTX.setStroke(getSkinnable().getSectionFill6()); break;
            case 7: CTX.setStroke(getSkinnable().getSectionFill7()); break;
            case 8: CTX.setStroke(getSkinnable().getSectionFill8()); break;
            case 9: CTX.setStroke(getSkinnable().getSectionFill9()); break;
        }
        CTX.setLineWidth(size * 0.037);
        CTX.setLineCap(StrokeLineCap.BUTT);
        CTX.strokeArc(xy, xy, wh, wh, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
        CTX.restore();
    }
}