リビジョン 8102177d
| learn/java/javafx/ZoomPanCanvas/src/zoompancanvas/ZoomPanCanvas.fxml | ||
|---|---|---|
|
<?import javafx.scene.control.*?>
|
||
|
<?import javafx.scene.layout.*?>
|
||
|
|
||
|
<AnchorPane id="AnchorPane" prefHeight="300.0" prefWidth="400.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="zoompancanvas.ZoomPanCanvasController">
|
||
|
<AnchorPane id="AnchorPane" prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="zoompancanvas.ZoomPanCanvasController">
|
||
|
<children>
|
||
|
<Button fx:id="button" layoutX="251.0" layoutY="188.0" onAction="#handleButtonAction" text="Click Me!" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" /><Canvas fx:id="canvas" height="260.0" width="320.0" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="82.0" AnchorPane.topAnchor="0.0" /><Label fx:id="scaleLabel" layoutX="14.0" layoutY="278.0" text="Label" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="14.0" />
|
||
|
<Button fx:id="button" layoutX="251.0" layoutY="188.0" onAction="#handleButtonAction" text="真ん中表示" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" /><Canvas fx:id="canvas" height="260.0" width="320.0" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="82.0" AnchorPane.topAnchor="0.0" /><Label fx:id="scaleLabel" layoutX="14.0" layoutY="278.0" text="Label" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="14.0" />
|
||
|
</children>
|
||
|
</AnchorPane>
|
||
| learn/java/javafx/ZoomPanCanvas/src/zoompancanvas/ZoomPanCanvasController.java | ||
|---|---|---|
|
private Point2D translate = new Point2D(0f, 0f);
|
||
|
private Point2D prevDragPoint;
|
||
|
|
||
|
/**
|
||
|
* データの中心を画面表示中心に合わせ、拡大率を1.0に設定する。
|
||
|
*
|
||
|
* @param event
|
||
|
*/
|
||
|
@FXML
|
||
|
private void handleButtonAction(ActionEvent event) {
|
||
|
logger.info("Draw button pressed.");
|
||
|
translate = new Point2D(canvas.getWidth() / 2f, canvas.getHeight() / 2f);
|
||
|
scale.set(1f / Math.pow(1.4f, 6));
|
||
|
drawCanvas();
|
||
|
}
|
||
|
|
||
ボタンを押すと表示位置をリセットするよう修正
データ中心を画面中心とする
拡大率を6段階縮小とする