List of usage examples for javafx.scene.canvas GraphicsContext setFill
public void setFill(Paint p)
From source file:Main.java
@Override public void start(Stage stage) { Canvas canvas = new Canvas(300, 100); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setLineWidth(2.0);/* ww w . ja v a 2 s . c o m*/ gc.setFill(Color.RED); gc.strokeRoundRect(10, 10, 50, 50, 10, 10); gc.fillOval(70, 10, 50, 20); gc.strokeText("Hello Canvas", 150, 20); Pane root = new Pane(); root.getChildren().add(canvas); Scene scene = new Scene(root); stage.setScene(scene); stage.setTitle(""); stage.show(); }
From source file:ijfx.ui.previewToolbar.DefaultWidget.java
@Override public Image getImage(PreviewService previewService, int size) { if (image != null) return image; if (previewService == null) return null; if (previewService.getImageDisplayService().getActiveDataset() == null) { return null; } else if (this.getIcon().equals("preview")) { try {//from w w w. j av a2 s.co m previewService.setParameters(-1, -1, size, size); return previewService.getImageDisplay(action, this.getParameters()); } catch (Exception e) { e.printStackTrace(); FontAwesomeIconView fontAwesomeIconView = new FontAwesomeIconView(FontAwesomeIcon.AMBULANCE); return FontAwesomeIconUtils.FAItoImage(fontAwesomeIconView, size); } } else if (getIcon().startsWith("char:")) { Canvas canvas = new Canvas(size, size); GraphicsContext graphicsContext2D = canvas.getGraphicsContext2D(); graphicsContext2D.setFill(Color.WHITE); graphicsContext2D.setFont(javafx.scene.text.Font.font("Arial", size)); graphicsContext2D.fillText(getIcon().substring(5), size / 3, size * 0.8); final SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); // final WritableImage snapshot = canvas.snapshot(params, null); Task<WritableImage> getIcon = new CallbackTask<Canvas, WritableImage>(canvas) .run(input -> input.snapshot(params, null)); Platform.runLater(getIcon); try { // Image image = new Ima image = getIcon.get(); return image; } catch (InterruptedException ex) { Logger.getLogger(DefaultWidget.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(DefaultWidget.class.getName()).log(Level.SEVERE, null, ex); } return null; } //Check if icon exist in Enumeration else if (Arrays.stream(FontAwesomeIcon.values()).filter(e -> e.name().equals(icon)).count() > 0) { FontAwesomeIconView fontAwesomeIconView = new FontAwesomeIconView(FontAwesomeIcon.valueOf(icon)); return FontAwesomeIconUtils.FAItoImage(fontAwesomeIconView, size); } else { image = new Image(getClass().getResource(icon).toExternalForm(), size, size, true, true); return image; } }
From source file:qupath.lib.gui.plots.ScatterPlot.java
public void drawPlot(GraphicsContext g, Rectangle2D region, int maxPoints) { g.save();/* www.jav a 2 s. c o m*/ g.beginPath(); 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(); }