当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.getGraphicsContext2D方法代码示例

本文整理汇总了Java中javafx.scene.canvas.Canvas.getGraphicsContext2D方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.getGraphicsContext2D方法的具体用法?Java Canvas.getGraphicsContext2D怎么用?Java Canvas.getGraphicsContext2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.scene.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.getGraphicsContext2D方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    pane   = new Pane(canvas);

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:18,代码来源:Grid.java

示例2: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    getStyleClass().add("coxcomb-chart");

    popup = new InfoPopup();

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    ctx.setLineCap(StrokeLineCap.BUTT);
    ctx.setTextBaseline(VPos.CENTER);
    ctx.setTextAlign(TextAlignment.CENTER);

    pane = new Pane(canvas);

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:26,代码来源:CoxcombChart.java

示例3: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    canvas = new Canvas(PREFERRED_HEIGHT, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();
    ctx.setTextAlign(TextAlignment.LEFT);
    ctx.setTextBaseline(VPos.CENTER);

    pane   = new Pane(canvas);

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:20,代码来源:LegendItem.java

示例4: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    getStyleClass().add("circular-plot");

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    ctx.setLineCap(StrokeLineCap.BUTT);

    getChildren().setAll(canvas);
}
 
开发者ID:HanSolo,项目名称:circularplot,代码行数:20,代码来源:CircularPlot.java

示例5: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    getStyleClass().setAll("chart", "xy-chart");

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:18,代码来源:XYPane.java

示例6: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    // prefill matrix with dotOffColor
    for (int y = 0 ; y < rows ; y++) {
        for (int x = 0 ; x < cols ; x++) {
            matrix[x][y] = dotOffColor;
        }
    }

    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
        Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(preferredWidth, preferredHeight);
        }
    }

    canvas = new Canvas(preferredWidth, preferredHeight);
    ctx = canvas.getGraphicsContext2D();

    pane = new StackPane(canvas);

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:dotmatrix,代码行数:25,代码来源:DotMatrix.java

示例7: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    getStyleClass().add("sankey-plot");

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
}
 
开发者ID:HanSolo,项目名称:sankeyplot,代码行数:18,代码来源:SankeyPlot.java

示例8: init

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private static void init() {
    root = new Group();
    s = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
    c = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
    root.getChildren().add(c);
    gc = c.getGraphicsContext2D();
    gc.setStroke(Color.BLUE);
    gc.setLineWidth(2);
    gc.setFill(Color.BLUE);
    Renderer.init();
    GameLoop.start(gc);

    //Initialize Objects
    Player p = new Player();
    setPlayer(p);
    
    //load map
    loadMap();

    //should be called at last it based on player
    EventHandler.attachEventHandlers(s);

}
 
开发者ID:ashish2199,项目名称:Aidos,代码行数:24,代码来源:Sandbox.java

示例9: setCanvas

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
/**
 * Sets the {@link Canvas} for use during drawing.
 * <p>
 * Prompts a draw.
 *
 * @param canvas the {@link Canvas} on which drawing will take place
 */
public void setCanvas(final Canvas canvas) {
    this.graphicsContext = canvas.getGraphicsContext2D();
    this.canvasWidth = canvas.widthProperty();
    this.canvasHeight = canvas.heightProperty();

    canvasWidth.addListener((observable, oldValue, newValue) -> draw());
    canvasHeight.addListener((observable, oldValue, newValue) -> draw());

    draw();
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:18,代码来源:HeatMapDrawing.java

示例10: addGrid

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
/**
 * Add a grid to the canvas, send it to the back
 */
public void addGrid() {
    double w = getBoundsInLocal().getWidth();
    double h = getBoundsInLocal().getHeight();

    // add grid
    Canvas grid = new Canvas(w, h);

    // don't catch mouse events
    grid.setMouseTransparent(true);

    GraphicsContext gc = grid.getGraphicsContext2D();

    gc.setStroke(Color.GRAY);
    gc.setLineWidth(1);

    // draw grid lines
    double offset = 50;
    for (double i = offset; i < w; i += offset) {
        gc.strokeLine(i, 0, i, h);
        gc.strokeLine(0, i, w, i);
    }

    getChildren().add(grid);

    grid.toBack();
}
 
开发者ID:INAETICS,项目名称:Drones-Simulator,代码行数:30,代码来源:PannableCanvas.java

示例11: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:16,代码来源:AreaHeatMap.java

示例12: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    segmentPane = new Pane();

    chartCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    chartCanvas.setMouseTransparent(true);

    chartCtx    = chartCanvas.getGraphicsContext2D();

    pane = new Pane(segmentPane, chartCanvas);
    pane.setBackground(new Background(new BackgroundFill(backgroundPaint, CornerRadii.EMPTY, Insets.EMPTY)));
    pane.setBorder(new Border(new BorderStroke(borderPaint, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(borderWidth))));

    getChildren().setAll(pane);

    prepareData();
}
 
开发者ID:HanSolo,项目名称:SunburstChart,代码行数:26,代码来源:SunburstChart.java

示例13: SimpleHeatMap

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
public SimpleHeatMap(final double WIDTH, final double HEIGHT, ColorMapping COLOR_MAPPING, final double EVENT_RADIUS, final boolean FADE_COLORS) {
    SNAPSHOT_PARAMETERS.setFill(Color.TRANSPARENT);
    colorMapping        = COLOR_MAPPING;
    mappingGradient     = colorMapping.mapping;
    fadeColors          = FADE_COLORS;
    radius              = EVENT_RADIUS;
    opacityDistribution = OpacityDistribution.CUSTOM;
    eventImage          = createEventImage(radius, opacityDistribution);
    monochromeCanvas    = new Canvas(WIDTH, HEIGHT);
    ctx                 = monochromeCanvas.getGraphicsContext2D();
    monochromeImage     = new WritableImage((int) WIDTH, (int) HEIGHT);
    heatMapView         = new ImageView(heatMap);
    heatMapView.setMouseTransparent(true);
    heatMapView.setOpacity(0.5);
}
 
开发者ID:HanSolo,项目名称:worldheatmap,代码行数:16,代码来源:SimpleHeatMap.java

示例14: initGraphics

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
        Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    pane = new Pane(canvas);
    pane.setBackground(new Background(new BackgroundFill(backgroundPaint, CornerRadii.EMPTY, Insets.EMPTY)));
    pane.setBorder(new Border(new BorderStroke(borderPaint, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(borderWidth))));

    getChildren().setAll(pane);
}
 
开发者ID:HanSolo,项目名称:radialchart,代码行数:20,代码来源:RadialChart.java

示例15: createLeftPane

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private void createLeftPane() {
    canvas = new Canvas(image.getWidth(), image.getHeight());
    canvas.addEventFilter(MouseEvent.ANY, new ImagePanelMouseListener());
    graphics = canvas.getGraphicsContext2D();
    anchorPane.setMaxWidth(image.getWidth());
    anchorPane.setMaxHeight(image.getHeight());
    anchorPane.getChildren().add(canvas);
    initializeAnnotations();
    drawGraphics();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:11,代码来源:ImagePanel.java


注:本文中的javafx.scene.canvas.Canvas.getGraphicsContext2D方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。