import javafx.application.Application; import javafx.geometry.Bounds; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.CornerRadii; import javafx.scene.layout.Region; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.text.Text; import javafx.stage.Stage; public class ShapeAASettingLeak extends Application { static final double CELL_WIDTH = 100; static final double CELL_HEIGHT = 100; static final double AAedge = 0.8; static final double Rinset = 10; static final double RX = Rinset + AAedge; static final double RY = Rinset + AAedge; static final double RW = CELL_WIDTH - (Rinset + AAedge) * 2.0; static final double RH = CELL_HEIGHT - (Rinset + AAedge) * 2.0; @Override public void start(Stage stage) { Region regionaa = makeRegion(Color.GREEN); Region regionnonaa = makeRegion(Color.BLUE); Canvas cvaa = makeCanvas(Color.GREEN); Canvas cvnonaa = makeCanvas(Color.BLUE); Group root = new Group(wrapAA(regionaa, true, 0, 0), wrapAA(regionnonaa, false, 0, CELL_HEIGHT), wrapAA(cvaa, true, CELL_WIDTH*2, 0), wrapAA(cvnonaa, false, CELL_WIDTH*2, CELL_HEIGHT)); Scene scene = new Scene(root, 400, 200); stage.setScene(scene); stage.show(); } Region makeRegion(Color c) { Region region = new Region(); region.setBackground(new Background(new BackgroundFill(c, new CornerRadii(Rinset), new Insets(Rinset + AAedge)))); region.setPrefWidth(CELL_WIDTH); region.setPrefHeight(CELL_HEIGHT); return region; } Canvas makeCanvas(Color c) { Canvas cv = new Canvas(CELL_WIDTH, CELL_HEIGHT); GraphicsContext gc = cv.getGraphicsContext2D(); gc.setFill(c); gc.fillOval(RX, RY, RW, RH); return cv; } Node wrapAA(Node target, boolean isAA, double x, double y) { Rectangle rect = new Rectangle(RX, RY, RW, RH); rect.setFill(isAA ? Color.GREEN : Color.BLUE); rect.setSmooth(isAA); double rcx = RX + RW/2.0; double rcy = RY + RH/2.0; Text text = new Text(isAA ? "AA" : "nonAA"); Bounds bb = text.getBoundsInParent(); double tcx = (bb.getMinX() + bb.getMaxX()) / 2.0; double tcy = (bb.getMinY() + bb.getMaxY()) / 2.0; text.setTranslateX(rcx - tcx); text.setTranslateY(rcy - tcy); text.setFill(Color.WHITE); target.setTranslateX(CELL_WIDTH); Group g = new Group(rect, target, text); g.setTranslateX(x); g.setTranslateY(y); return g; } }