javafx.scene.canvas.Canvas Java Examples

The following examples show how to use javafx.scene.canvas.Canvas. 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: Watch.java    From jace with GNU General Public License v2.0 8 votes vote down vote up
public Watch(int address, final MetacheatUI outer) {
    super();
    this.outer = outer;
    this.address = address;
    cell = outer.cheatEngine.getMemoryCell(address);
    redraw = outer.animationTimer.scheduleAtFixedRate(this::redraw, MetacheatUI.FRAME_RATE, MetacheatUI.FRAME_RATE, TimeUnit.MILLISECONDS);
    setBackground(new Background(new BackgroundFill(Color.NAVY, CornerRadii.EMPTY, Insets.EMPTY)));
    Label addrLabel = new Label("$" + Integer.toHexString(address));
    addrLabel.setOnMouseClicked((evt)-> outer.inspectAddress(address));
    addrLabel.setTextAlignment(TextAlignment.CENTER);
    addrLabel.setMinWidth(GRAPH_WIDTH);
    addrLabel.setFont(new Font(Font.getDefault().getFamily(), 14));
    addrLabel.setTextFill(Color.WHITE);
    graph = new Canvas(GRAPH_WIDTH, GRAPH_HEIGHT);
    getChildren().add(addrLabel);
    getChildren().add(graph);
    CheckBox hold = new CheckBox("Hold");
    holding = hold.selectedProperty();
    holding.addListener((prop, oldVal, newVal) -> this.updateHold());
    getChildren().add(hold);
    hold.setTextFill(Color.WHITE);
}
 
Example #2
Source File: DragResizerUtilTests.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@Test
public void testResizeHandler() {
    final Rectangle rect = new Rectangle(/* minX */ 0.0, /* minY */ 0.0, /* width */ 100.0, /* height */ 50.0);

    assertDoesNotThrow(() -> DragResizerUtil.DEFAULT_LISTENER.onDrag(rect, 0, 0, 10, 20));
    assertEquals(10, rect.getWidth());
    assertEquals(20, rect.getHeight());
    assertDoesNotThrow(() -> DragResizerUtil.DEFAULT_LISTENER.onResize(rect, 0, 0, 11, 21));
    assertEquals(11, rect.getWidth());
    assertEquals(21, rect.getHeight());

    final Canvas canvas = new Canvas(100, 50);
    assertDoesNotThrow(() -> DragResizerUtil.DEFAULT_LISTENER.onDrag(canvas, 0, 0, 10, 20));
    assertEquals(10, canvas.getWidth());
    assertEquals(20, canvas.getHeight());

    final Region region = new Region();
    region.setMinSize(100, 50);
    assertDoesNotThrow(() -> DragResizerUtil.DEFAULT_LISTENER.onDrag(region, 0, 0, 10, 20));
    assertEquals(10, region.getPrefWidth());
    assertEquals(20, region.getPrefHeight());
}
 
Example #3
Source File: RoundLcdClock.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/digital.ttf"), (0.5833333333 * PREFERRED_HEIGHT));         // "Digital-7"
    //Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/digitalreadout.ttf"), (0.5833333333 * PREFERRED_HEIGHT));  // "Digital Readout Upright"


    canvasBkg = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctxBkg    = canvasBkg.getGraphicsContext2D();

    canvasFg  = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctxFg     = canvasFg.getGraphicsContext2D();

    pane      = new Pane();
    pane.getChildren().setAll(canvasBkg, canvasFg);

    getChildren().setAll(pane);
    resize();
}
 
Example #4
Source File: ImageScaling.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void start(final Stage stage)
{
    // Image with red border
    final WritableImage image = new WritableImage(WIDTH, HEIGHT);
    final PixelWriter writer = image.getPixelWriter();
    for (int x=0; x<WIDTH; ++x)
    {
        writer.setColor(x, 0, Color.RED);
        writer.setColor(x, HEIGHT-1, Color.RED);
    }
    for (int y=0; y<HEIGHT; ++y)
    {
        writer.setColor(0, y, Color.RED);
        writer.setColor(WIDTH-1, y, Color.RED);
    }

    // Draw into canvas, scaling 'up'
    final Canvas canvas = new Canvas(800, 600);
    canvas.getGraphicsContext2D().drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight());

    final Scene scene = new Scene(new Group(canvas), canvas.getWidth(), canvas.getHeight());
    stage.setScene(scene);
    stage.show();
}
 
Example #5
Source File: SideScroller.java    From Project-16x16 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called by Processing after settings().
 */
@Override
protected PSurface initSurface() {
	surface = (PSurfaceFX) super.initSurface();
	canvas = (Canvas) surface.getNative();
	canvas.widthProperty().unbind(); // used for scaling
	canvas.heightProperty().unbind(); // used for scaling
	scene = canvas.getScene();
	stage = (Stage) scene.getWindow();
	stage.setTitle("Project-16x16");
	stage.setResizable(false); // prevent abitrary user resize
	stage.setFullScreenExitHint(""); // disable fullscreen toggle hint
	stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH); // prevent ESC toggling fullscreen
	scene.getWindow().addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, this::closeWindowEvent);
	return surface;
}
 
Example #6
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Canvas createIcon(Edge pEdge)
{   //CSOFF: Magic numbers
	Canvas canvas = new Canvas(BUTTON_SIZE, BUTTON_SIZE);
	GraphicsContext graphics = canvas.getGraphicsContext2D();
	graphics.scale(0.6, 0.6);
	Line line = new Line(new Point(2,2), new Point(40,40));
	final double tangent = Math.tan(Math.toRadians(DEGREES_10));
	double dx = (line.getX2() - line.getX1()) / 2;
	double dy = (line.getY2() - line.getY1()) / 2;
	Point control = new Point((int)((line.getX1() + line.getX2()) / 2 + tangent * dy), 
			(int)((line.getY1() + line.getY2()) / 2 - tangent * dx));         
	
	Path path = new Path();
	MoveTo moveTo = new MoveTo(line.getPoint1().getX(), line.getPoint1().getY());
	QuadCurveTo curveTo = new QuadCurveTo(control.getX(), control.getY(), line.getPoint2().getX(), line.getPoint2().getY());
	path.getElements().addAll(moveTo, curveTo);
	
	ToolGraphics.strokeSharpPath(graphics, path, LineStyle.SOLID);
	ArrowHead.V.view().draw(graphics, control, new Point(40, 40));
	return canvas;
}
 
Example #7
Source File: ViewerUtilities.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param pElement The element for which we want an icon
 * @return An icon that represents this element
 * @pre pElement != null
 */
public static Canvas createIcon(DiagramElement pElement)
{
	/* 
	 * This method exists to cover the case where we wish to create an icon 
	 * for a diagram element without knowing whether it's a node or an edge.
	 */
	assert pElement != null;
	if( pElement instanceof Node )
	{
		return NodeViewerRegistry.createIcon((Node)pElement);
	}
	else
	{
		assert pElement instanceof Edge;
		return EdgeViewerRegistry.createIcon((Edge)pElement);
	}
}
 
Example #8
Source File: StreamChart.java    From charts with Apache License 2.0 6 votes vote down vote up
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();

    tooltip = new Tooltip();
    tooltip.setAutoHide(true);

    getChildren().setAll(canvas);
}
 
Example #9
Source File: Sandbox.java    From Aidos with GNU General Public License v3.0 6 votes vote down vote up
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);

    //load map
    try
    {
        loadMap(new File("Resources/maps/sandbox_map.txt"));
    } catch (IOException e)
    {
        System.err.println("Unable to load map file.");
        System.exit(1);
    }

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

}
 
Example #10
Source File: SimpleLineChartSkin.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.06 * PREFERRED_HEIGHT)); // "OpenSans"

    canvasBkg = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctxBkg    = canvasBkg.getGraphicsContext2D();

    canvasFg  = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctxFg     = canvasFg.getGraphicsContext2D();

    pane      = new Pane();
    pane.getChildren().setAll(canvasBkg, canvasFg);

    getChildren().setAll(pane);
    resize();
    drawBackground();
    drawForeground();
}
 
Example #11
Source File: TileImage.java    From mcaselector with MIT License 6 votes vote down vote up
static void createMarkedChunksImage(Tile tile, int zoomLevel) {
	WritableImage wImage = new WritableImage(Tile.SIZE / zoomLevel, Tile.SIZE / zoomLevel);

	Canvas canvas = new Canvas(Tile.SIZE / (float) zoomLevel, Tile.SIZE / (float) zoomLevel);
	GraphicsContext ctx = canvas.getGraphicsContext2D();
	ctx.setFill(Config.getChunkSelectionColor().makeJavaFXColor());

	for (Point2i markedChunk : tile.markedChunks) {
		Point2i regionChunk = markedChunk.mod(Tile.SIZE_IN_CHUNKS);
		if (regionChunk.getX() < 0) {
			regionChunk.setX(regionChunk.getX() + Tile.SIZE_IN_CHUNKS);
		}
		if (regionChunk.getY() < 0) {
			regionChunk.setY(regionChunk.getY() + Tile.SIZE_IN_CHUNKS);
		}

		ctx.fillRect(regionChunk.getX() * Tile.CHUNK_SIZE / (float) zoomLevel, regionChunk.getY() * Tile.CHUNK_SIZE / (float) zoomLevel, Tile.CHUNK_SIZE / (float) zoomLevel, Tile.CHUNK_SIZE / (float) zoomLevel);
	}

	SnapshotParameters params = new SnapshotParameters();
	params.setFill(Color.TRANSPARENT.makeJavaFXColor());

	canvas.snapshot(params, wImage);

	tile.markedChunksImage = wImage;
}
 
Example #12
Source File: XYPane.java    From charts with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #13
Source File: CoxcombChart.java    From charts with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #14
Source File: DigitalClockSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
@Override protected void initGraphics() {
    // Set initial size
    if (Double.compare(clock.getPrefWidth(), 0.0) <= 0 || Double.compare(clock.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(clock.getWidth(), 0.0) <= 0 || Double.compare(clock.getHeight(), 0.0) <= 0) {
        if (clock.getPrefWidth() > 0 && clock.getPrefHeight() > 0) {
            clock.setPrefSize(clock.getPrefWidth(), clock.getPrefHeight());
        } else {
            clock.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

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

    pane = new Pane(canvas);
    pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(clock.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(clock.getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example #15
Source File: CustomGaugeSkin.java    From medusademo with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    backgroundCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    backgroundCtx    = backgroundCanvas.getGraphicsContext2D();

    foregroundCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    foregroundCtx    = foregroundCanvas.getGraphicsContext2D();

    ledInnerShadow   = new InnerShadow(BlurType.TWO_PASS_BOX, Color.BLACK, 0.2 * PREFERRED_WIDTH, 0, 0, 0);
    ledDropShadow    = new DropShadow(BlurType.TWO_PASS_BOX, getSkinnable().getBarColor(), 0.3 * PREFERRED_WIDTH, 0, 0, 0);

    pane = new Pane(backgroundCanvas, foregroundCanvas);
    pane.setBorder(new Border(new BorderStroke(getSkinnable().getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1))));
    pane.setBackground(new Background(new BackgroundFill(getSkinnable().getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example #16
Source File: GraphPanel.java    From charts with Apache License 2.0 6 votes vote down vote up
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(width, height);
    ctx    = canvas.getGraphicsContext2D();

    pane = new Pane(canvas);
    getChildren().setAll(pane);
}
 
Example #17
Source File: ConcentricRingChart.java    From charts with Apache License 2.0 6 votes vote down vote up
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("concentric-ring-chart");

    canvas = new Canvas(size * 0.9, 0.9);
    ctx    = canvas.getGraphicsContext2D();

    pane = new Pane(canvas);

    getChildren().setAll(pane);
}
 
Example #18
Source File: CircularPlot.java    From charts with Apache License 2.0 6 votes vote down vote up
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();

    ctx.setLineCap(StrokeLineCap.BUTT);

    tooltip = new Tooltip();
    tooltip.setAutoHide(true);

    getChildren().setAll(canvas);
}
 
Example #19
Source File: DrawingApp.java    From FXTutorials with MIT License 6 votes vote down vote up
private Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(800, 600);

    Canvas canvas = new Canvas(800, 600);
    g = canvas.getGraphicsContext2D();

    AnimationTimer timer = new AnimationTimer() {
        @Override
        public void handle(long now) {
            t += 0.017;
            draw();
        }
    };
    timer.start();

    root.getChildren().add(canvas);
    return root;
}
 
Example #20
Source File: ComparisonRingChart.java    From charts with Apache License 2.0 6 votes vote down vote up
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("comparison-ring-chart");

    canvas = new Canvas(size * 0.9, 0.9);
    ctx    = canvas.getGraphicsContext2D();

    pane = new Pane(canvas);

    getChildren().setAll(pane);
}
 
Example #21
Source File: LegendItem.java    From charts with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #22
Source File: Grid.java    From charts with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #23
Source File: SelectableToolButton.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a button with an empty tool prototype.
 *
 * @param pIcon The button's icon.
 * @param pToolTip A short sentence describing the button.
 * @param pToggleGroup The toggle group this button is part of.
 * @pre pImage != null && pToolTip != null && pToggleGroup != null.
 */
public SelectableToolButton(Canvas pIcon, String pToolTip, ToggleGroup pToggleGroup)
{
	assert pIcon != null && pToolTip != null && pToggleGroup != null;
	setStyle(BUTTON_STYLE_CSS);
	setGraphic(pIcon);
	setToggleGroup(pToggleGroup);
	setSelected(true);
	setTooltip(new Tooltip(pToolTip));
	getTooltip().setStyle("-fx-font-size: 100%"); // Override JavaFX defaults
	getTooltip().setWrapText(true);
	getTooltip().setMaxWidth(TOOLTIP_WIDTH);
	setAlignment(Pos.BASELINE_LEFT);
	setOnAction( pEvent -> setSelected(true) );
}
 
Example #24
Source File: MnistTestFXApp.java    From java-ml-projects with Apache License 2.0 5 votes vote down vote up
private BufferedImage getScaledImage(Canvas canvas) {
	// for a better recognition we should improve this part of how we retrieve the image from the canvas
	WritableImage writableImage = new WritableImage(CANVAS_WIDTH, CANVAS_HEIGHT);
	canvas.snapshot(null, writableImage);
	Image tmp =  SwingFXUtils.fromFXImage(writableImage, null).getScaledInstance(28, 28, Image.SCALE_SMOOTH);
	BufferedImage scaledImg = new BufferedImage(28, 28, BufferedImage.TYPE_BYTE_GRAY);
	Graphics graphics = scaledImg.getGraphics();
	graphics.drawImage(tmp, 0, 0, null);
	graphics.dispose();
	return scaledImg;
}
 
Example #25
Source File: CallEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Canvas createIcon(Edge pEdge)
{
	final float scale = 0.6f;
	final int offset = 15;
	Canvas canvas = new Canvas(BUTTON_SIZE, BUTTON_SIZE);
	GraphicsContext graphics = canvas.getGraphicsContext2D();
	canvas.getGraphicsContext2D().scale(scale, scale);
	Path path = new Path();
	path.getElements().addAll(new MoveTo(1, offset), new LineTo(BUTTON_SIZE*(1/scale)-1, offset));
	ToolGraphics.strokeSharpPath(graphics, path, LineStyle.SOLID);
	ArrowHead.V.view().draw(graphics, new Point(1, offset), new Point((int)(BUTTON_SIZE*(1/scale)-1), offset));
	return canvas;
}
 
Example #26
Source File: RoundLcdClockSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
@Override protected void initGraphics() {
    // Set initial size
    if (Double.compare(clock.getPrefWidth(), 0.0) <= 0 || Double.compare(clock.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(clock.getWidth(), 0.0) <= 0 || Double.compare(clock.getHeight(), 0.0) <= 0) {
        if (clock.getPrefWidth() > 0 && clock.getPrefHeight() > 0) {
            clock.setPrefSize(clock.getPrefWidth(), clock.getPrefHeight());
        } else {
            clock.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    backgroundCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    backgroundCtx = backgroundCanvas.getGraphicsContext2D();

    foregroundCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    foregroundCtx = foregroundCanvas.getGraphicsContext2D();

    hoursCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    hoursCtx = hoursCanvas.getGraphicsContext2D();

    minutesCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    minutesCtx = minutesCanvas.getGraphicsContext2D();

    secondsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    secondsCtx = secondsCanvas.getGraphicsContext2D();

    pane = new Pane(backgroundCanvas, foregroundCanvas, hoursCanvas, minutesCanvas, secondsCanvas);
    pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(clock.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(clock.getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example #27
Source File: DragAndDropHandler.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected static Image createDragImage(FxDockPane client)
{
	SnapshotParameters sp = new SnapshotParameters();
	sp.setFill(Color.TRANSPARENT);
	
	WritableImage im = client.snapshot(sp, null);

	if(client.isPaneMode())
	{
		return im;
	}
	
	// include selected tab
	FxDockTabPane tp = (FxDockTabPane)DockTools.getParent(client);
	Node n = tp.lookup(".tab:selected");
	WritableImage tim = n.snapshot(sp, null);
	
	double dy = tim.getHeight();
	
	// must adjust for the tab
	deltay += dy;
	
	double w = Math.max(im.getWidth(), tim.getWidth());
	double h = im.getHeight() + dy;
	Canvas c = new Canvas(w, h);
	GraphicsContext g = c.getGraphicsContext2D();
	g.drawImage(tim, 0, 0);
	g.drawImage(im, 0, dy);
	return c.snapshot(sp, null);
}
 
Example #28
Source File: CycleStepTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
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();
    ctx    = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
}
 
Example #29
Source File: GraphApp.java    From big-math with MIT License 5 votes vote down vote up
private void setupCanvasEventHandlers(Canvas canvas) {
	canvas.setOnKeyPressed(event -> {
		switch (event.getCode()) {
		case UP: {
			zoom(BigDecimal.valueOf(0.5));
			break;
		}
		case DOWN: {
			zoom(BigDecimal.valueOf(2));
			break;
		}
		case W:
			translate(0, 1);
			break;
		case A:
			translate(-1, 0);
			break;
		case S:
			translate(0, -1);
			break;
		case D:
			translate(1, 0);
			break;
		default:
		}
		event.consume();
	});
}
 
Example #30
Source File: UseCaseDependencyEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Canvas createIcon(Edge pEdge)
{
	Canvas canvas = super.createIcon(pEdge);
	final float scale = 0.75f;
	canvas.getGraphicsContext2D().scale(scale, scale);
	new StringViewer(StringViewer.Align.CENTER, false, false)
	    .draw(getIconTag(pEdge), canvas.getGraphicsContext2D(), new Rectangle(1, BUTTON_SIZE, 1, 1));
	return canvas;
}