Example usage for javafx.scene.canvas GraphicsContext save

List of usage examples for javafx.scene.canvas GraphicsContext save

Introduction

In this page you can find the example usage for javafx.scene.canvas GraphicsContext save.

Prototype

public void save() 

Source Link

Document

Saves the following attributes onto a stack.

Usage

From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartCanvas.java

/**
 * Draws the content of the canvas and updates the 
 * {@code renderingInfo} attribute with the latest rendering 
 * information./*  w  w  w  .j a v  a 2 s.c  o  m*/
 */
public final void draw() {
    GraphicsContext ctx = getGraphicsContext2D();
    ctx.save();
    double width = getWidth();
    double height = getHeight();
    if (width > 0 && height > 0) {
        ctx.clearRect(0, 0, width, height);
        this.info = new ChartRenderingInfo();
        this.chart.draw(this.g2, new Rectangle((int) width, (int) height), this.anchor, this.info);
    }
    ctx.restore();
    this.anchor = null;
}

From source file:qupath.lib.gui.plots.ScatterPlot.java

public void drawPlot(GraphicsContext g, Rectangle2D region, int maxPoints) {

    g.save();

    g.beginPath();// w w  w  .  j av a  2s .  c o m
    g.moveTo(region.getMinX(), region.getMinY());
    g.lineTo(region.getMaxX(), region.getMinY());
    g.lineTo(region.getMaxX(), region.getMaxY());
    g.lineTo(region.getMinX(), region.getMaxY());
    g.closePath();
    g.clip();

    //      int pad = 10;
    double scaleX = region.getWidth() / (maxX - minX);
    double scaleY = region.getHeight() / (maxY - minY);

    g.setLineWidth(1.5f);

    //      g.setStroke(javafx.scene.paint.Color.GRAY);
    //      g.strokeRect(region.getX(), region.getY(), region.getWidth(), region.getHeight());

    g.translate(region.getMinX(), region.getMinY());

    //      g2d.drawLine(0, 0, 0, region.height);
    //      g2d.drawLine(0, region.height, region.width, region.height);

    double increment;
    if (maxPoints < 0 || x.length <= maxPoints)
        increment = 1;
    else
        increment = (double) x.length / maxPoints;

    for (double i = 0; i < x.length; i += increment) {
        int ind = (int) i;
        double xx = x[ind];
        double yy = y[ind];
        //         // Skip if out of range
        //         if (xx < minX || xx > maxX || yy < minY || yy > maxY)
        //            continue;

        double xo = (xx - minX) * scaleX - markerSize / 2;
        double yo = region.getHeight() - (yy - minY) * scaleY - markerSize / 2;

        Color cDraw = colorDraw == null ? null : colorDraw[ind];
        if (fillMarkers) {
            Color cFill = colorFill[ind] == null ? cDraw : colorFill[ind];
            if (cFill != null) {
                g.setFill(cFill);
                g.fillOval(xo, yo, markerSize, markerSize);
                // Don't need to draw if it would be the same color anyway
                if (cFill == cDraw)
                    continue;
            }
        }
        if (cDraw != null) {
            g.setStroke(cDraw);
            g.strokeOval(xo, yo, markerSize, markerSize);
        }
    }

    g.restore();
}