Skip to content

Commit

Permalink
Improve Macos shortcut handling (#95)
Browse files Browse the repository at this point in the history
* Improve Macos shortcut handling.

* Update github actions workflow.

* Update settings dialog sizing.

* Extend unit tests.

---------

Co-authored-by: Markus Fleischhacker <markus@Markus-MacBook-Pro.local>
  • Loading branch information
mfl28 and Markus Fleischhacker committed Oct 27, 2023
1 parent a08e876 commit 879866b
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 57 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ jobs:
uses: gradle/wrapper-validation-action@v1
- name: Build
run: ./gradlew --info --stacktrace build -x test
- name: Test setup
run: |
"/Library/Application Support/VMware Tools/vmware-resolutionSet" $TEST_SCREEN_WIDTH $TEST_SCREEN_HEIGHT
- name: Test
id: test
run: ./gradlew --info --stacktrace test
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'

// TestFx UI TesTing // https://mvnrepository.com/artifact/org.testfx/testfx-junit5
testImplementation('org.testfx:testfx-junit5:4.0.16-alpha') {
testImplementation('org.testfx:testfx-junit5:4.0.17') {
exclude group: 'org.hamcrest'
}

Expand Down Expand Up @@ -106,7 +106,7 @@ dependencies {
}

javafx {
version = '20'
version = '21.0.1'
modules = ['javafx.controls', 'javafx.swing']
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void onRegisterSceneKeyPressed(KeyEvent event) {
return;
}

if(event.getCode() == KeyCode.CONTROL || event.getCode() == KeyCode.META) {
if(event.isShortcutDown()) {
view.getEditorImagePane().setZoomableAndPannable(true);
}

Expand All @@ -520,7 +520,7 @@ public void onRegisterSceneKeyPressed(KeyEvent event) {
* @param event the short-cut key-event
*/
public void onRegisterSceneKeyReleased(KeyEvent event) {
if(event.getCode() == KeyCode.CONTROL || event.getCode() == KeyCode.META) {
if(!event.isShortcutDown()) {
view.getEditorImagePane().setZoomableAndPannable(false);
}

Expand Down Expand Up @@ -597,7 +597,7 @@ public void onRegisterImageViewMouseReleasedEvent(MouseEvent event) {
final EditorImagePaneView imagePane = view.getEditorImagePane();

if(imagePane.isImageFullyLoaded() && event.getButton().equals(MouseButton.PRIMARY)) {
if(event.isControlDown()) {
if(event.isShortcutDown()) {
view.getEditorImageView().setCursor(Cursor.OPEN_HAND);
}

Expand All @@ -622,7 +622,7 @@ public void onRegisterImageViewMousePressedEvent(MouseEvent event) {
EditorImagePaneView imagePaneView = view.getEditorImagePane();

if(imagePaneView.isImageFullyLoaded()
&& !event.isControlDown()
&& !event.isShortcutDown()
&& imagePaneView.isCategorySelected()) {
if(event.getButton().equals(MouseButton.PRIMARY)) {
if(imagePaneView.getDrawingMode() == EditorImagePaneView.DrawingMode.BOX) {
Expand Down Expand Up @@ -744,7 +744,7 @@ private List<KeyCombinationEventHandler> createKeyCombinationHandlers() {
navigatePreviousKeyPressed.set(false);
navigateNextKeyPressed.set(false);
},
event -> KeyCombinations.navigationReleaseKeyCodes.contains(event.getCode())),
event -> KeyCombinations.navigationReleaseKeyCodes.contains(event.getCode()) || !event.isShortcutDown()),
new KeyCombinationEventHandler(KeyCombinations.navigateNext,
event -> handleNavigateNextKeyPressed(), null),
new KeyCombinationEventHandler(KeyCombinations.navigatePrevious,
Expand Down Expand Up @@ -1596,7 +1596,8 @@ public static class KeyCombinations {
public static final KeyCombination navigatePrevious = new KeyCodeCombination(KeyCode.A,
KeyCombination.SHORTCUT_DOWN);

public static final List<KeyCode> navigationReleaseKeyCodes = List.of(KeyCode.A, KeyCode.D, KeyCode.CONTROL, KeyCode.META);
public static final List<KeyCode> navigationReleaseKeyCodes = List.of(
KeyCode.A, KeyCode.D);
public static final KeyCombination showAllBoundingShapes =
new KeyCodeCombination(KeyCode.V, KeyCombination.SHORTCUT_DOWN, KeyCombination.ALT_DOWN);
public static final KeyCombination hideAllBoundingShapes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void addMoveFunctionality() {
});

setOnMousePressed(event -> {
if(!event.isControlDown()) {
if(!event.isShortcutDown()) {
boundingShapeViewData.getToggleGroup().selectToggle(this);

if(event.getButton().equals(MouseButton.PRIMARY)) {
Expand All @@ -276,7 +276,7 @@ private void addMoveFunctionality() {
});

setOnMouseDragged(event -> {
if(!event.isControlDown()) {
if(!event.isShortcutDown()) {
if(event.getButton().equals(MouseButton.PRIMARY)) {
Point2D newXY = new Point2D(event.getX() - dragAnchor.getX(), event.getY() - dragAnchor.getY());
Point2D newXYConfined = MathUtils.clampWithinBounds(newXY, constructCurrentMoveBounds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ private void handleVerticesAdded(ListChangeListener.Change<? extends VertexHandl
}

private void handleMousePressed(MouseEvent event) {
if(!event.isControlDown()) {
if(!event.isShortcutDown()) {
boundingShapeViewData.getToggleGroup().selectToggle(this);

if(event.isShiftDown() && event.getButton().equals(MouseButton.MIDDLE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ private void setUpInternalListeners() {
private void setUpImageViewListeners() {
imageView.setOnMouseDragged(event -> {
if(isImageFullyLoaded()) {
if(event.isControlDown()) {
if(event.isShortcutDown()) {
imageView.setCursor(Cursor.CLOSED_HAND);
}

Expand Down Expand Up @@ -545,7 +545,7 @@ private void updateCurrentBoundingBoxFromMouseDrag(Point2D clampedEventXY) {

private void setUpContentPaneListeners() {
contentPane.setOnScroll(event -> {
if(isImageFullyLoaded() && event.isControlDown()) {
if(isImageFullyLoaded() && event.isShortcutDown()) {
Bounds contentPaneBounds = contentPane.getLayoutBounds();
Bounds viewportBounds = getViewportBounds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ private void setUpInternalListeners() {
// Empty or already existing tags are not added to the list of tags.
if(!text.isEmpty() && !tags.get().contains(text)) {
tags.get().add(text);
tagInputField.clear();
}
tagInputField.clear();
requestFocus();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javafx.event.ActionEvent;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

import java.util.HashMap;
Expand Down Expand Up @@ -57,6 +58,7 @@ public SettingsDialogView() {

setDialogPane(dialogPane);
setResizable(true);
dialogPane.setMinHeight(Region.USE_PREF_SIZE);

setUpInternalListeners();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ void onExportAnnotation_PVOC_WhenPreviouslyImportedAnnotation_ShouldProduceEquiv

// Zoom a bit to change the image-view size.
robot.moveTo(mainView.getEditorImageView())
.press(KeyCode.CONTROL)
.press(KeyCode.SHORTCUT)
.scroll(-30)
.release(KeyCode.CONTROL);
.release(KeyCode.SHORTCUT);

WaitForAsyncUtils.waitForFxEvents();
verifyThat(mainView.getStatusBar().getCurrentEventMessage(),
Expand Down Expand Up @@ -285,9 +285,9 @@ void onExportAnnotation_YOLO_WhenPreviouslyImportedAnnotation_ShouldProduceEquiv

// Zoom a bit to change the image-view size.
robot.moveTo(mainView.getEditorImageView())
.press(KeyCode.CONTROL)
.press(KeyCode.SHORTCUT)
.scroll(-30)
.release(KeyCode.CONTROL);
.release(KeyCode.SHORTCUT);

WaitForAsyncUtils.waitForFxEvents();
verifyThat(mainView.getStatusBar().getCurrentEventMessage(),
Expand Down Expand Up @@ -419,9 +419,9 @@ void onExportAnnotation_JSON_WhenPreviouslyImportedAnnotation_ShouldProduceEquiv

// Zoom a bit to change the image-view size.
robot.moveTo(mainView.getEditorImageView())
.press(KeyCode.CONTROL)
.press(KeyCode.SHORTCUT)
.scroll(-30)
.release(KeyCode.CONTROL);
.release(KeyCode.SHORTCUT);

WaitForAsyncUtils.waitForFxEvents();
verifyThat(mainView.getStatusBar().getCurrentEventMessage(),
Expand Down
Loading

0 comments on commit 879866b

Please sign in to comment.