From e31fa430705f6cd9a111132f12f6875c9bee9f99 Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Wed, 19 Oct 2022 19:32:22 +0200 Subject: [PATCH 1/9] Zoom-in/Zoom-out works now with CTRL+Numpad-Add and CTRL+Numpad-Divide. --- .../javafx/scenebuilder/app/menubar/MenuBarController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java index c7f74f77c..f078695ca 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java @@ -1275,12 +1275,12 @@ private void updateZoomMenu() { final MenuItem zoomInMenuItem = new MenuItem(I18N.getString("menu.title.zoom.in")); zoomInMenuItem.setUserData(new ZoomInActionController()); - zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); //NOI18N + zoomInMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.ADD, modifier)); //NOI18N zoomMenu.getItems().add(zoomInMenuItem); - + final MenuItem zoomOutMenuItem = new MenuItem(I18N.getString("menu.title.zoom.out")); zoomOutMenuItem.setUserData(new ZoomOutActionController()); - zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("/", modifier)); //NOI18N + zoomOutMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.DIVIDE, modifier)); //NOI18N zoomMenu.getItems().add(zoomOutMenuItem); zoomMenu.getItems().add(new SeparatorMenuItem()); From 8f82c9d1788c42e9226a1ac617cf675214cfe586 Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Wed, 19 Oct 2022 20:23:05 +0200 Subject: [PATCH 2/9] Exposed zoomIn and zoomOut functionality so that DocumentWindowController can handle a 2nd set of accelerators. --- .../app/DocumentWindowController.java | 15 +++++++++++ .../app/menubar/MenuBarController.java | 27 ++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java index b5af4e0fe..64b0da460 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java @@ -316,6 +316,21 @@ public enum ActionStatus { } event.consume(); } + + // Zoom actions are defined using "+" and "/" keys. Those keys + // may exist in standard keys and also on numpad/keypad. + // As each menu item can only handle one accelerator, here + // the standard keys are handled. The menuBarController handles + // KeyCode.ADD (+) and KeyCode.DIVIDE (/) + if (KeyCode.PLUS.equals(event.getCode()) && modifierDown) { + menuBarController.zoomIn(); + event.consume(); + } + + if (KeyCode.SLASH.equals(event.getCode()) && modifierDown) { + menuBarController.zoomOut(); + event.consume(); + } }; /* diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java index f078695ca..0b06cd4bc 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java @@ -209,7 +209,11 @@ public class MenuBarController { private MenuItem showSampleControllerMenuItem; @FXML private Menu zoomMenu; - + + private ZoomInActionController zoomInController; + + private ZoomOutActionController zoomOutController; + // Modify @FXML private MenuItem fitToParentMenuItem; @@ -1269,17 +1273,19 @@ private void handleOnActionMenu(MenuItem i) { */ final static double[] scalingTable = {0.25, 0.50, 0.75, 1.00, 1.50, 2.0, 4.0}; - + private void updateZoomMenu() { final double[] scalingTable = {0.25, 0.50, 0.75, 1.00, 1.50, 2.0, 4.0}; + zoomInController = new ZoomInActionController(); final MenuItem zoomInMenuItem = new MenuItem(I18N.getString("menu.title.zoom.in")); - zoomInMenuItem.setUserData(new ZoomInActionController()); + zoomInMenuItem.setUserData(zoomInController); zoomInMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.ADD, modifier)); //NOI18N zoomMenu.getItems().add(zoomInMenuItem); + zoomOutController = new ZoomOutActionController(); final MenuItem zoomOutMenuItem = new MenuItem(I18N.getString("menu.title.zoom.out")); - zoomOutMenuItem.setUserData(new ZoomOutActionController()); + zoomOutMenuItem.setUserData(zoomOutController); zoomOutMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.DIVIDE, modifier)); //NOI18N zoomMenu.getItems().add(zoomOutMenuItem); @@ -1294,7 +1300,20 @@ private void updateZoomMenu() { } } + public void zoomIn() { + runActionController(zoomInController); + } + + public void zoomOut() { + runActionController(zoomOutController); + } + private void runActionController(MenuItemController controllerToRun) { + if (controllerToRun.canPerform()) { + controllerToRun.perform(); + } + } + private static int findZoomScaleIndex(double zoomScale) { int result = -1; From e9a0f0e30829f982dda5b5ae52a9e843586993f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Wed, 19 Oct 2022 21:56:09 +0200 Subject: [PATCH 3/9] Reworked key mapping on macOS. CMD+ or CMD- zoom in/out. Unfortunately key code assignment seems to be broken as it does not match with given system locale. --- .../app/DocumentWindowController.java | 17 ++----- .../app/menubar/MenuBarController.java | 51 ++++++++++++++----- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java index 64b0da460..95ba3db99 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java @@ -316,21 +316,10 @@ public enum ActionStatus { } event.consume(); } + + System.out.println(event); - // Zoom actions are defined using "+" and "/" keys. Those keys - // may exist in standard keys and also on numpad/keypad. - // As each menu item can only handle one accelerator, here - // the standard keys are handled. The menuBarController handles - // KeyCode.ADD (+) and KeyCode.DIVIDE (/) - if (KeyCode.PLUS.equals(event.getCode()) && modifierDown) { - menuBarController.zoomIn(); - event.consume(); - } - - if (KeyCode.SLASH.equals(event.getCode()) && modifierDown) { - menuBarController.zoomOut(); - event.consume(); - } + menuBarController.handleAdditionalZoomAccelerators(event, modifierDown); }; /* diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java index 0b06cd4bc..8c78e5b7a 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java @@ -87,6 +87,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javafx.scene.input.KeyCombination; +import javafx.scene.input.KeyEvent; import javafx.scene.layout.StackPane; /** @@ -1280,15 +1281,14 @@ private void updateZoomMenu() { zoomInController = new ZoomInActionController(); final MenuItem zoomInMenuItem = new MenuItem(I18N.getString("menu.title.zoom.in")); zoomInMenuItem.setUserData(zoomInController); - zoomInMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.ADD, modifier)); //NOI18N zoomMenu.getItems().add(zoomInMenuItem); zoomOutController = new ZoomOutActionController(); final MenuItem zoomOutMenuItem = new MenuItem(I18N.getString("menu.title.zoom.out")); zoomOutMenuItem.setUserData(zoomOutController); - zoomOutMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.DIVIDE, modifier)); //NOI18N - zoomMenu.getItems().add(zoomOutMenuItem); - + zoomMenu.getItems().add(zoomOutMenuItem); + zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); //NOI18N + zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); //NOI18N zoomMenu.getItems().add(new SeparatorMenuItem()); for (int i = 0; i < scalingTable.length; i++) { @@ -1300,19 +1300,46 @@ private void updateZoomMenu() { } } - public void zoomIn() { - runActionController(zoomInController); - } - - public void zoomOut() { - runActionController(zoomOutController); - } - private void runActionController(MenuItemController controllerToRun) { if (controllerToRun.canPerform()) { controllerToRun.perform(); } } + + public void handleAdditionalZoomAccelerators(KeyEvent event, boolean modifierDown) { + boolean shiftDown = event.isShiftDown(); + if (EditorPlatform.IS_MAC) { + // This handling is required as the "-" is not properly accepted when used inside the accelerator + if ("-".equals(event.getText())) { + runActionController(zoomOutController); + } + + // On de_DE keyboard layout "MINUS" is mapped to "ß" which is wrong + // if (KeyCode.MINUS.equals(event.getCode()) && modifierDown) { + // runActionController(zoomOutController); + // } + if (KeyCode.RIGHT.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomInController); + } + if (KeyCode.UP.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomInController); + } + if (KeyCode.LEFT.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomOutController); + } + if (KeyCode.DOWN.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomOutController); + } + } else { + if (KeyCode.ADD.equals(event.getCode()) && modifierDown) { + runActionController(zoomInController); + } + + if (KeyCode.MINUS.equals(event.getCode()) && modifierDown) { + runActionController(zoomOutController); + } + } + } private static int findZoomScaleIndex(double zoomScale) { int result = -1; From 8af8548b76a9b0e572d24a78108db078bd3ae91e Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Wed, 19 Oct 2022 22:09:56 +0200 Subject: [PATCH 4/9] Reworked Windows key assignments. --- .../app/menubar/MenuBarController.java | 91 ++++++++++++------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java index 8c78e5b7a..238d95656 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java @@ -1286,11 +1286,23 @@ private void updateZoomMenu() { zoomOutController = new ZoomOutActionController(); final MenuItem zoomOutMenuItem = new MenuItem(I18N.getString("menu.title.zoom.out")); zoomOutMenuItem.setUserData(zoomOutController); - zoomMenu.getItems().add(zoomOutMenuItem); - zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); //NOI18N - zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); //NOI18N + zoomMenu.getItems().add(zoomOutMenuItem); + if (EditorPlatform.IS_LINUX) { + zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); // NOI18N + zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); // NOI18N + } else { + // Accelerators for standard keyboard (not keypad) + zoomInMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.PLUS, modifier)); // NOI18N + zoomOutMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.MINUS, modifier)); // NOI18N + + // Does not work on Windows: + // zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); // NOI18N + // + // Works in Windows: + // zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); // NOI18N + } zoomMenu.getItems().add(new SeparatorMenuItem()); - + for (int i = 0; i < scalingTable.length; i++) { final double scaling = scalingTable[i]; final String title = String.format("%.0f%%", scaling * 100); //NOI18N @@ -1309,35 +1321,50 @@ private void runActionController(MenuItemController controllerToRun) { public void handleAdditionalZoomAccelerators(KeyEvent event, boolean modifierDown) { boolean shiftDown = event.isShiftDown(); if (EditorPlatform.IS_MAC) { - // This handling is required as the "-" is not properly accepted when used inside the accelerator - if ("-".equals(event.getText())) { - runActionController(zoomOutController); - } - - // On de_DE keyboard layout "MINUS" is mapped to "ß" which is wrong - // if (KeyCode.MINUS.equals(event.getCode()) && modifierDown) { - // runActionController(zoomOutController); - // } - if (KeyCode.RIGHT.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomInController); - } - if (KeyCode.UP.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomInController); - } - if (KeyCode.LEFT.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomOutController); - } - if (KeyCode.DOWN.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomOutController); - } + // This handling is required as the "-" is not properly accepted when used + // inside the accelerator + if ("-".equals(event.getText())) { + runActionController(zoomOutController); + } + + // On de_DE keyboard layout "MINUS" is mapped to "ß" which is wrong + // if (KeyCode.MINUS.equals(event.getCode()) && modifierDown) { + // runActionController(zoomOutController); + // } + if (KeyCode.RIGHT.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomInController); + } + if (KeyCode.UP.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomInController); + } + if (KeyCode.LEFT.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomOutController); + } + if (KeyCode.DOWN.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomOutController); + } } else { - if (KeyCode.ADD.equals(event.getCode()) && modifierDown) { - runActionController(zoomInController); - } - - if (KeyCode.MINUS.equals(event.getCode()) && modifierDown) { - runActionController(zoomOutController); - } + // Works well on windows for num key pad + if (KeyCode.ADD.equals(event.getCode()) && modifierDown) { + runActionController(zoomInController); + } + if (KeyCode.SUBTRACT.equals(event.getCode()) && modifierDown) { + runActionController(zoomOutController); + } + + // Works also very well on Windows + if (KeyCode.RIGHT.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomInController); + } + if (KeyCode.UP.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomInController); + } + if (KeyCode.LEFT.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomOutController); + } + if (KeyCode.DOWN.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomOutController); + } } } From d7c661570d57e2f3f4e5c39c473b93f9a3002fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Wed, 19 Oct 2022 22:28:06 +0200 Subject: [PATCH 5/9] First version of zoom accelerators which works nicely on Windows/macOS and Linux. --- .../app/menubar/MenuBarController.java | 80 ++++++++----------- 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java index 238d95656..be54c139a 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java @@ -1287,9 +1287,11 @@ private void updateZoomMenu() { final MenuItem zoomOutMenuItem = new MenuItem(I18N.getString("menu.title.zoom.out")); zoomOutMenuItem.setUserData(zoomOutController); zoomMenu.getItems().add(zoomOutMenuItem); - if (EditorPlatform.IS_LINUX) { + if (EditorPlatform.IS_MAC) { zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); // NOI18N zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); // NOI18N + + } else { // Accelerators for standard keyboard (not keypad) zoomInMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.PLUS, modifier)); // NOI18N @@ -1319,52 +1321,36 @@ private void runActionController(MenuItemController controllerToRun) { } public void handleAdditionalZoomAccelerators(KeyEvent event, boolean modifierDown) { - boolean shiftDown = event.isShiftDown(); - if (EditorPlatform.IS_MAC) { - // This handling is required as the "-" is not properly accepted when used - // inside the accelerator - if ("-".equals(event.getText())) { - runActionController(zoomOutController); - } - - // On de_DE keyboard layout "MINUS" is mapped to "ß" which is wrong - // if (KeyCode.MINUS.equals(event.getCode()) && modifierDown) { - // runActionController(zoomOutController); - // } - if (KeyCode.RIGHT.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomInController); - } - if (KeyCode.UP.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomInController); - } - if (KeyCode.LEFT.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomOutController); - } - if (KeyCode.DOWN.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomOutController); - } - } else { - // Works well on windows for num key pad - if (KeyCode.ADD.equals(event.getCode()) && modifierDown) { - runActionController(zoomInController); - } - if (KeyCode.SUBTRACT.equals(event.getCode()) && modifierDown) { - runActionController(zoomOutController); - } - - // Works also very well on Windows - if (KeyCode.RIGHT.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomInController); - } - if (KeyCode.UP.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomInController); - } - if (KeyCode.LEFT.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomOutController); - } - if (KeyCode.DOWN.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomOutController); - } + // Zooming using numerical keypad: works for Windows and Linux + // no chance to test on macOS yet + if (KeyCode.ADD.equals(event.getCode()) && modifierDown) { + runActionController(zoomInController); + } + if (KeyCode.SUBTRACT.equals(event.getCode()) && modifierDown) { + runActionController(zoomOutController); + } + + // Zooming using arrow keys - works on all 3 platforms + // as COMMAND+arrows is already used, an additional modifier is required + boolean shiftDown = event.isShiftDown(); + if (KeyCode.RIGHT.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomInController); + } + if (KeyCode.UP.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomInController); + } + if (KeyCode.LEFT.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomOutController); + } + if (KeyCode.DOWN.equals(event.getCode()) && modifierDown && shiftDown) { + runActionController(zoomOutController); + } + + // on macOS 12.0.1, Java 17/JavaFX 19, + // for unknown reasons the "-" key is not properly detected + // this condition works + if (EditorPlatform.IS_MAC && "-".equals(event.getText())) { + runActionController(zoomOutController); } } From 409f7f9ed8508f809b58ba9cb1da5aa74de7ee2a Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Wed, 19 Oct 2022 22:54:02 +0200 Subject: [PATCH 6/9] Reworked additional keys handling. Added Javadoc for public method. --- .../app/DocumentWindowController.java | 6 +- .../app/menubar/MenuBarController.java | 77 ++++++++++--------- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java index 95ba3db99..8347c8731 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java @@ -316,10 +316,10 @@ public enum ActionStatus { } event.consume(); } - - System.out.println(event); - menuBarController.handleAdditionalZoomAccelerators(event, modifierDown); + if (modifierDown) { + menuBarController.handleAdditionalZoomAccelerators(event); + } }; /* diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java index be54c139a..8a0735668 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java @@ -1290,13 +1290,12 @@ private void updateZoomMenu() { if (EditorPlatform.IS_MAC) { zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); // NOI18N zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); // NOI18N - - + // Neither KeyCode.MINUS or KeyCode.SUBTRACT seem to work on macOS. + // No chance to test on keyboard with num key pad yet. } else { - // Accelerators for standard keyboard (not keypad) + // Accelerators for standard keyboard (not num key pad) zoomInMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.PLUS, modifier)); // NOI18N zoomOutMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.MINUS, modifier)); // NOI18N - // Does not work on Windows: // zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); // NOI18N // @@ -1314,45 +1313,53 @@ private void updateZoomMenu() { } } - private void runActionController(MenuItemController controllerToRun) { + private void runActionController(MenuItemController controllerToRun, KeyEvent event) { if (controllerToRun.canPerform()) { controllerToRun.perform(); } + event.consume(); } - - public void handleAdditionalZoomAccelerators(KeyEvent event, boolean modifierDown) { - // Zooming using numerical keypad: works for Windows and Linux - // no chance to test on macOS yet - if (KeyCode.ADD.equals(event.getCode()) && modifierDown) { - runActionController(zoomInController); - } - if (KeyCode.SUBTRACT.equals(event.getCode()) && modifierDown) { - runActionController(zoomOutController); - } - - // Zooming using arrow keys - works on all 3 platforms - // as COMMAND+arrows is already used, an additional modifier is required - boolean shiftDown = event.isShiftDown(); - if (KeyCode.RIGHT.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomInController); - } - if (KeyCode.UP.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomInController); + + /** + * Provides handling for additional keyboard accelerators assigned to document view + * zoom in/out operation. Zoom is controllable via [+]/[-] keys on standard keyboard + * and on numerical key pad. + * + * Additionally zoom in via arrow keys (up/right) and zoom out (left/down) is possible. + * + * @param event {@link KeyEvent} If any action is triggered, the event will be consumed. + */ + public void handleAdditionalZoomAccelerators(KeyEvent event) { + // For unknown reasons, on macOS 12.0.1 with Java 17/JavaFX 19 the "-" key code + // is not properly accepted hence this handling here. + if (EditorPlatform.IS_MAC && "-".equals(event.getText())) { + runActionController(zoomOutController, event); + return; } - if (KeyCode.LEFT.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomOutController); + + if (event.isShiftDown()) { + handleArrowKeysForZoom(event); + return; } - if (KeyCode.DOWN.equals(event.getCode()) && modifierDown && shiftDown) { - runActionController(zoomOutController); + + switch(event.getCode()) { + case ADD -> runActionController(zoomInController, event); + case SUBTRACT ->runActionController(zoomOutController, event); + default -> {/* no action*/} } - - // on macOS 12.0.1, Java 17/JavaFX 19, - // for unknown reasons the "-" key is not properly detected - // this condition works - if (EditorPlatform.IS_MAC && "-".equals(event.getText())) { - runActionController(zoomOutController); + return; + } + + private void handleArrowKeysForZoom(KeyEvent event) { + switch (event.getCode()) { + case RIGHT -> runActionController(zoomInController, event); + case UP -> runActionController(zoomInController, event); + case LEFT -> runActionController(zoomOutController, event); + case DOWN -> runActionController(zoomOutController, event); + default -> {/* no action*/} } - } + return; + } private static int findZoomScaleIndex(double zoomScale) { int result = -1; From 0db86409e012995ed6766cfd1a918b9eb66fa0a6 Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Wed, 19 Oct 2022 23:15:40 +0200 Subject: [PATCH 7/9] Removed redundant returns. Numpad key handling is now a separate method. --- .../javafx/scenebuilder/app/menubar/MenuBarController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java index 8a0735668..e1fea0910 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java @@ -1339,15 +1339,17 @@ public void handleAdditionalZoomAccelerators(KeyEvent event) { if (event.isShiftDown()) { handleArrowKeysForZoom(event); - return; + } else { + handleNumPadKeys(event); } + } + private void handleNumPadKeys(KeyEvent event) { switch(event.getCode()) { case ADD -> runActionController(zoomInController, event); case SUBTRACT ->runActionController(zoomOutController, event); default -> {/* no action*/} } - return; } private void handleArrowKeysForZoom(KeyEvent event) { From addcd870aa4e8bf9954aa0c62fcd486de02445ae Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Thu, 30 Mar 2023 21:51:39 +0200 Subject: [PATCH 8/9] Added workaround for "+" on Mac as well. --- .../javafx/scenebuilder/app/DocumentWindowController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java index 64afdb7a8..32fd42e5e 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Gluon and/or its affiliates. + * Copyright (c) 2016, 2023, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * From fdec9b9ae13ca590509429672e5056f8d6088b8c Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Thu, 30 Mar 2023 21:57:40 +0200 Subject: [PATCH 9/9] Added workaround for + on Mac as well. --- .../app/menubar/MenuBarController.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java index eca7e198f..71464d9d9 100644 --- a/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java +++ b/app/src/main/java/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java @@ -1342,18 +1342,23 @@ public void handleAdditionalZoomAccelerators(KeyEvent event) { return; } + if (EditorPlatform.IS_MAC && "+".equals(event.getText())) { + runActionController(zoomInController, event); + return; + } + if (event.isShiftDown()) { handleArrowKeysForZoom(event); - } else { + } else { handleNumPadKeys(event); } } private void handleNumPadKeys(KeyEvent event) { - switch(event.getCode()) { + switch (event.getCode()) { case ADD -> runActionController(zoomInController, event); - case SUBTRACT ->runActionController(zoomOutController, event); - default -> {/* no action*/} + case SUBTRACT -> runActionController(zoomOutController, event); + default -> { /* no action*/ } } } @@ -1363,7 +1368,7 @@ private void handleArrowKeysForZoom(KeyEvent event) { case UP -> runActionController(zoomInController, event); case LEFT -> runActionController(zoomOutController, event); case DOWN -> runActionController(zoomOutController, event); - default -> {/* no action*/} + default -> { /* no action*/ } } return; }