本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}