package jira; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.NodeOrientation; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.layout.HBox; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.TextAlignment; import javafx.stage.Stage; public class RT26137 extends Application { double width = 300, height = 600; public static void main(String[] args) { launch(args); } private void drawCanvas(Canvas canvas) { GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setFill(Color.YELLOW); gc.fillRect(0, 0, width, height); gc.setFont(new Font(20)); gc.beginPath(); gc.moveTo(0, 0); gc.lineTo(80, 80); gc.stroke(); gc.setTextAlign(TextAlignment.LEFT); gc.strokeText("Text.", 4, 60); gc.setFill(Color.BLACK); gc.fillText("line1111\nline222\nline", 10, 100); gc.setTextAlign(TextAlignment.CENTER); gc.fillText("line1111\nline222\nline", 80, 200); gc.setTextAlign(TextAlignment.RIGHT); gc.fillText("line1111\nline222\nline", 190, 300); gc.setTextAlign(TextAlignment.LEFT); gc.fillText("small make to fit in 50px", 10, 400, 50); gc.setTextAlign(TextAlignment.CENTER); gc.fillText("small make to fit in 50px", 40, 450, 50); gc.setTextAlign(TextAlignment.RIGHT); gc.fillText("small make to fit in 50px", 80, 500, 50); gc.setFill(Color.RED); gc.fillOval(4, 60, 4, 4); gc.fillOval(10, 100, 4, 4); gc.fillOval(80, 200, 4, 4); gc.fillOval(190, 300, 4, 4); gc.fillOval(10, 400, 4, 4); gc.fillOval(40, 450, 4, 4); gc.fillOval(80, 500, 4, 4); } @Override public void start(Stage primaryStage) throws Exception { final Canvas canvas = new Canvas(width, height); final Canvas canvasRTL = new Canvas(width, height); canvasRTL.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); drawCanvas(canvas); drawCanvas(canvasRTL); HBox root = new HBox(canvas, canvasRTL); root.setSpacing(10); root.setPadding(new Insets(10)); Scene scene = new Scene(root); scene.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler() { @Override public void handle(KeyEvent event) { if (event.getCode() == KeyCode.ENTER) { if (canvas.getEffectiveNodeOrientation()==NodeOrientation.LEFT_TO_RIGHT) { canvas.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); } else { canvas.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT); } } } }); canvas.effectiveNodeOrientationProperty().addListener(new ChangeListener() { @Override public void changed( ObservableValue observable, NodeOrientation oldValue, NodeOrientation newValue) { System.out.println("changing to " + newValue + " " + canvas.getEffectiveNodeOrientation()); drawCanvas(canvas); } }); primaryStage.setScene(scene); primaryStage.show(); } }