package visualiser.model; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; /** * The abstract class for the resizable race canvases. */ public abstract class ResizableCanvas extends Canvas { protected final GraphicsContext gc; public ResizableCanvas(){ this.gc = this.getGraphicsContext2D(); // Redraw canvas when size changes. widthProperty().addListener(evt -> draw()); heightProperty().addListener(evt -> draw()); } abstract void draw(); /** * Set the Canvas to resizable. * * @return That the Canvas is resizable. */ @Override public boolean isResizable() { return true; } /** * Returns the preferred width of the Canvas * * @param width of canvas * @return Returns the width of the Canvas */ @Override public double prefWidth(double width) { return getWidth(); } /** * Returns the preferred height of the Canvas * * @param height of canvas * @return Returns the height of the Canvas */ @Override public double prefHeight(double height) { return getHeight(); } }