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

The following examples show how to use javafx.scene.canvas.GraphicsContext#setLineCap() . 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: WidgetColorPropertyField.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** @param color Color to display */
public void setColor(final WidgetColor color)
{
    final GraphicsContext gc = blob.getGraphicsContext2D();

    gc.setFill(JFXUtil.convert(color));
    gc.fillRect(0, 0, 16, 16);

    gc.setLineCap(StrokeLineCap.SQUARE);
    gc.setLineJoin(StrokeLineJoin.MITER);
    gc.setLineWidth(1.75);
    gc.setStroke(Color.BLACK);
    gc.strokeRect(0, 0, 16, 16);

    button.setText(String.valueOf(color));
}
 
Example 2
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 3
Source File: HeatControlSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {        
    CTX.clearRect(0, 0, size, size);
    double  sinValue;        
    double  cosValue;
    double  startAngle     = getSkinnable().getStartAngle();                
    Point2D center         = new Point2D(size * 0.5, size * 0.5);
    double  stdLineWidth   = size * 0.003;
    double  rangeLineWidth = size * 0.007;
    for (double angle = 0, counter = getSkinnable().getMinValue() ; Double.compare(counter, getSkinnable().getMaxValue()) <= 0 ; angle -= angleStep / 3, counter+= 0.33333) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerPoint = new Point2D(center.getX() + size * 0.368 * sinValue, center.getY() + size * 0.368 * cosValue);            
        Point2D outerPoint = new Point2D(center.getX() + size * 0.457 * sinValue, center.getY() + size * 0.457 * cosValue);            

        CTX.setStroke(getSkinnable().getTickMarkFill());                        
        if (getSkinnable().isTargetEnabled() && 
            counter > getSkinnable().getValue() && counter < getSkinnable().getTarget() ||
            counter > getSkinnable().getTarget() && counter < getSkinnable().getValue()) {
            CTX.setLineWidth(rangeLineWidth);
        } else {
            CTX.setLineWidth(stdLineWidth);    
        }
        CTX.setLineCap(StrokeLineCap.ROUND);
        CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY());                            
    }
}
 
Example 4
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 5
Source File: MnistTestFXApp.java    From java-ml-projects with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
	Canvas canvas = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
	ImageView imgView = new ImageView();
	GraphicsContext ctx = canvas.getGraphicsContext2D();
	
	model = ModelSerializer.restoreMultiLayerNetwork(new File("minist-model.zip"));
	loader = new NativeImageLoader(28,28,1,true);
	imgView.setFitHeight(100);
	imgView.setFitWidth(100);
	ctx.setLineWidth(10);
	ctx.setLineCap(StrokeLineCap.SQUARE);
	lblResult = new Label();
	
	HBox hbBottom = new HBox(10, imgView, lblResult);
	VBox root = new VBox(5, canvas, hbBottom);
	hbBottom.setAlignment(Pos.CENTER);
	root.setAlignment(Pos.CENTER);
	
	Scene scene = new Scene(root, 520, 300);
	stage.setScene(scene);
	stage.show();
	stage.setTitle("Handwritten digits recognition");
	
	canvas.setOnMousePressed(e -> {
		ctx.setStroke(Color.WHITE);
           ctx.beginPath();
           ctx.moveTo(e.getX(), e.getY());
           ctx.stroke();
	});
	canvas.setOnMouseDragged(e -> {
		ctx.setStroke(Color.WHITE);
		ctx.lineTo(e.getX(), e.getY());
		ctx.stroke();
	});
	canvas.setOnMouseClicked(e -> {
		if (e.getButton() == MouseButton.SECONDARY) {
			clear(ctx);
		}
	});
	canvas.setOnKeyReleased(e -> {
		if(e.getCode() == KeyCode.ENTER) {
               BufferedImage scaledImg = getScaledImage(canvas);
               imgView.setImage(SwingFXUtils.toFXImage(scaledImg, null));
               try {
               	predictImage(scaledImg);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
               
		}
	});
	clear(ctx);
	canvas.requestFocus();
}
 
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: ModernSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    double               sinValue;
    double               cosValue;
    double               centerX                = size * 0.5;
    double               centerY                = size * 0.5;
    double               minorTickSpace         = gauge.getMinorTickSpace();
    double               minValue               = gauge.getMinValue();
    double               maxValue               = gauge.getMaxValue();
    double               tmpAngleStep           = angleStep * minorTickSpace;
    int                  decimals               = gauge.getTickLabelDecimals();
    BigDecimal           minorTickSpaceBD       = BigDecimal.valueOf(minorTickSpace);
    BigDecimal           majorTickSpaceBD       = BigDecimal.valueOf(gauge.getMajorTickSpace());
    BigDecimal           mediumCheck2           = BigDecimal.valueOf(2 * minorTickSpace);
    BigDecimal           mediumCheck5           = BigDecimal.valueOf(5 * minorTickSpace);
    BigDecimal           counterBD              = BigDecimal.valueOf(minValue);
    double               counter                = minValue;
    boolean              majorTickMarksVisible  = gauge.getMajorTickMarksVisible();
    boolean              mediumTickMarksVisible = gauge.getMediumTickMarksVisible();
    boolean              tickLabelsVisible      = gauge.getTickLabelsVisible();
    TickLabelOrientation tickLabelOrientation   = gauge.getTickLabelOrientation();
    Color                tickMarkColor          = gauge.getTickMarkColor();
    Color                majorTickMarkColor     = tickMarkColor;
    Color                mediumTickMarkColor    = tickMarkColor;
    Color                tickLabelColor         = gauge.getTickLabelColor();

    double innerPointX;
    double innerPointY;
    double outerPointX;
    double outerPointY;
    double innerMediumPointX;
    double innerMediumPointY;
    double outerMediumPointX;
    double outerMediumPointY;
    double textPointX;
    double textPointY;

    double orthTextFactor = 0.46; //TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.46 : 0.46;

    Font tickLabelFont = Fonts.robotoCondensedLight((decimals == 0 ? 0.047 : 0.040) * size);
    CTX.setFont(tickLabelFont);
    CTX.setTextAlign(TextAlignment.CENTER);
    CTX.setTextBaseline(VPos.CENTER);

    CTX.setLineCap(StrokeLineCap.BUTT);
    CTX.setLineWidth(size * 0.0035);
    for (double angle = 0 ; Double.compare(-ANGLE_RANGE - tmpAngleStep, angle) < 0 ; angle -= tmpAngleStep) {
        sinValue = Math.sin(Math.toRadians(angle + START_ANGLE));
        cosValue = Math.cos(Math.toRadians(angle + START_ANGLE));

        innerPointX       = centerX + size * 0.375 * sinValue;
        innerPointY       = centerY + size * 0.375 * cosValue;
        outerPointX       = centerX + size * 0.425 * sinValue;
        outerPointY       = centerY + size * 0.425 * cosValue;
        innerMediumPointX = centerX + size * 0.35 * sinValue;
        innerMediumPointY = centerY + size * 0.35 * cosValue;
        outerMediumPointX = centerX + size * 0.4 * sinValue;
        outerMediumPointY = centerY + size * 0.4 * cosValue;
        textPointX        = centerX + size * orthTextFactor * sinValue;
        textPointY        = centerY + size * orthTextFactor * cosValue;

        // Set the general tickmark color
        CTX.setStroke(tickMarkColor);

        if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) {
            // Draw major tick mark
            if (majorTickMarksVisible) {
                CTX.setFill(majorTickMarkColor);
                CTX.setStroke(majorTickMarkColor);
                CTX.strokeLine(innerPointX, innerPointY, outerPointX, outerPointY);
            }
            // Draw tick label text
            if (tickLabelsVisible) {
                CTX.save();
                CTX.translate(textPointX, textPointY);

                Helper.rotateContextForText(CTX, START_ANGLE, angle, tickLabelOrientation);

                CTX.setFill(tickLabelColor);
                if (TickLabelOrientation.HORIZONTAL == tickLabelOrientation &&
                    (Double.compare(counter, minValue) == 0 ||
                    Double.compare(counter, maxValue) == 0)) {
                        CTX.setFill(Color.TRANSPARENT);
                }
                CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0);
                CTX.restore();
            }
        } else if (mediumTickMarksVisible &&
                   Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 &&
                   Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) {
            // Draw medium tick mark
            CTX.setFill(mediumTickMarkColor);
            CTX.setStroke(mediumTickMarkColor);
            CTX.strokeLine(innerMediumPointX, innerMediumPointY, outerMediumPointX, outerMediumPointY);
        }
        counterBD = counterBD.add(minorTickSpaceBD);
        counter   = counterBD.doubleValue();
    }
}
 
Example 13
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 14
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 15
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();
    }
}