Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor key-combinations into separate class #136

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1617,63 +1617,4 @@ private void setupStage() {
}
});
}

/**
* Class containing possible key-combinations.
*/
public static class KeyCombinations {
public static final KeyCombination navigateNext = new KeyCodeCombination(KeyCode.D,
KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination navigatePrevious = new KeyCodeCombination(KeyCode.A,
KeyCombination.SHORTCUT_DOWN);

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 =
new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN, KeyCombination.ALT_DOWN);
public static final KeyCombination showSelectedBoundingShape =
new KeyCodeCombination(KeyCode.V, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination hideSelectedBoundingShape =
new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN);

public static final KeyCombination resetSizeAndCenterImage =
new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination focusCategoryNameTextField =
new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination focusCategorySearchField =
new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination focusTagTextField =
new KeyCodeCombination(KeyCode.T, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination focusFileSearchField =
new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN, KeyCombination.ALT_DOWN);
public static final KeyCombination deleteSelectedBoundingShape = new KeyCodeCombination(KeyCode.DELETE);
public static final KeyCombination selectRectangleDrawingMode =
new KeyCodeCombination(KeyCode.DIGIT1, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination selectPolygonDrawingMode =
new KeyCodeCombination(KeyCode.DIGIT2, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination selectFreehandDrawingMode =
new KeyCodeCombination(KeyCode.DIGIT3, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination removeEditingVerticesWhenBoundingPolygonSelected =
new KeyCodeCombination(KeyCode.DELETE, KeyCombination.SHIFT_DOWN);
public static final KeyCombination addVerticesToPolygon =
KeyCombination.keyCombination("Shift + Middle-Click inside Polygon");
public static final KeyCombination changeSelectedBoundingShapeCategory =
new KeyCodeCombination(KeyCode.C, KeyCombination.SHIFT_DOWN);
public static final KeyCombination hideNonSelectedBoundingShapes =
new KeyCodeCombination(KeyCode.H, KeyCombination.SHIFT_DOWN);

public static final KeyCombination simplifyPolygon =
new KeyCodeCombination(KeyCode.S, KeyCombination.SHIFT_DOWN);
public static final KeyCombination saveBoundingShapeAsImage =
new KeyCodeCombination(KeyCode.I, KeyCombination.SHIFT_DOWN);

public static final KeyCombination openSettings =
new KeyCodeCombination(KeyCode.COMMA, KeyCombination.SHORTCUT_DOWN);

private KeyCombinations() {
throw new IllegalStateException("Key Combination Class");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2024 Markus Fleischhacker <[email protected]>
*
* This file is part of Bounding Box Editor
*
* Bounding Box Editor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bounding Box Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Bounding Box Editor. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.mfl28.boundingboxeditor.controller;

import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;

import java.util.List;

/**
* Class containing possible key-combinations.
*/
public class KeyCombinations {
public static final KeyCombination navigateNext = new KeyCodeCombination(KeyCode.D,
KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination navigatePrevious = new KeyCodeCombination(KeyCode.A,
KeyCombination.SHORTCUT_DOWN);

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 =
new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN, KeyCombination.ALT_DOWN);
public static final KeyCombination showSelectedBoundingShape =
new KeyCodeCombination(KeyCode.V, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination hideSelectedBoundingShape =
new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN);

public static final KeyCombination resetSizeAndCenterImage =
new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination focusCategoryNameTextField =
new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination focusCategorySearchField =
new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination focusTagTextField =
new KeyCodeCombination(KeyCode.T, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination focusFileSearchField =
new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN, KeyCombination.ALT_DOWN);
public static final KeyCombination deleteSelectedBoundingShape = new KeyCodeCombination(KeyCode.DELETE);
public static final KeyCombination selectRectangleDrawingMode =
new KeyCodeCombination(KeyCode.DIGIT1, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination selectPolygonDrawingMode =
new KeyCodeCombination(KeyCode.DIGIT2, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination selectFreehandDrawingMode =
new KeyCodeCombination(KeyCode.DIGIT3, KeyCombination.SHORTCUT_DOWN);
public static final KeyCombination removeEditingVerticesWhenBoundingPolygonSelected =
new KeyCodeCombination(KeyCode.DELETE, KeyCombination.SHIFT_DOWN);
public static final KeyCombination addVerticesToPolygon =
KeyCombination.keyCombination("Shift + Middle-Click inside Polygon");
public static final KeyCombination changeSelectedBoundingShapeCategory =
new KeyCodeCombination(KeyCode.C, KeyCombination.SHIFT_DOWN);
public static final KeyCombination hideNonSelectedBoundingShapes =
new KeyCodeCombination(KeyCode.H, KeyCombination.SHIFT_DOWN);

public static final KeyCombination simplifyPolygon =
new KeyCodeCombination(KeyCode.S, KeyCombination.SHIFT_DOWN);
public static final KeyCombination saveBoundingShapeAsImage =
new KeyCodeCombination(KeyCode.I, KeyCombination.SHIFT_DOWN);

public static final KeyCombination openSettings =
new KeyCodeCombination(KeyCode.COMMA, KeyCombination.SHORTCUT_DOWN);

private KeyCombinations() {
throw new IllegalStateException("Key Combination Class");

Check warning on line 82 in src/main/java/com/github/mfl28/boundingboxeditor/controller/KeyCombinations.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/mfl28/boundingboxeditor/controller/KeyCombinations.java#L81-L82

Added lines #L81 - L82 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.mfl28.boundingboxeditor.ui;

import com.github.mfl28.boundingboxeditor.controller.Controller;
import com.github.mfl28.boundingboxeditor.controller.KeyCombinations;
import com.github.mfl28.boundingboxeditor.utils.UiUtils;
import javafx.beans.binding.Bindings;
import javafx.geometry.Pos;
Expand Down Expand Up @@ -309,11 +310,11 @@ private ToggleButton createDrawModeButton(String text, String iconCssId) {
private void setUpButtonsAndLabels() {
nextButton.setId(NEXT_BUTTON_ID);
nextButton.setTooltip(UiUtils.createTooltip(NEXT_BUTTON_TOOLTIP_TEXT,
Controller.KeyCombinations.navigateNext));
KeyCombinations.navigateNext));

previousButton.setId(PREVIOUS_BUTTON_ID);
previousButton.setTooltip(UiUtils.createTooltip(PREVIOUS_BUTTON_TOOLTIP_TEXT,
Controller.KeyCombinations.navigatePrevious));
KeyCombinations.navigatePrevious));

brightnessLabel.setId(BRIGHTNESS_LABEL_ID);
brightnessLabel.setTooltip(UiUtils.createTooltip(BRIGHTNESS_LABEL_TOOLTIP));
Expand All @@ -328,23 +329,23 @@ private void setUpButtonsAndLabels() {
imageSettingsToolBox.setId(BOUNDING_SHAPE_EDITOR_TOOLBOX_ID);

showBoundingShapesButton.setTooltip(UiUtils.createTooltip(SHOW_BOUNDING_BOXES_BUTTON_TOOLTIP_TEXT,
Controller.KeyCombinations.showAllBoundingShapes));
KeyCombinations.showAllBoundingShapes));
hideBoundingShapesButton.setTooltip(UiUtils.createTooltip(HIDE_BOUNDING_BOXES_BUTTON_TOOLTIP,
Controller.KeyCombinations.hideAllBoundingShapes));
KeyCombinations.hideAllBoundingShapes));
resetSizeAndCenterImageButton.setTooltip(UiUtils.createTooltip(RESET_IMAGE_SIZE_BUTTON_TOOLTIP,
Controller.KeyCombinations.resetSizeAndCenterImage));
KeyCombinations.resetSizeAndCenterImage));

rectangleModeButton.setToggleGroup(modeToggleGroup);
polygonModeButton.setToggleGroup(modeToggleGroup);
freehandModeButton.setToggleGroup(modeToggleGroup);

rectangleModeButton.setTooltip(UiUtils.createTooltip(RECTANGLE_DRAWING_MODE_TOOLTIP_TEXT,
Controller.KeyCombinations.selectRectangleDrawingMode));
KeyCombinations.selectRectangleDrawingMode));
polygonModeButton.setTooltip(UiUtils.createTooltip(POLYGON_DRAWING_MODE_TOOLTIP_TEXT,
Controller.KeyCombinations.selectPolygonDrawingMode));
KeyCombinations.selectPolygonDrawingMode));

freehandModeButton.setTooltip(UiUtils.createTooltip(FREEHAND_DRAWING_MODE_TOOLTIP_TEXT,
Controller.KeyCombinations.selectFreehandDrawingMode));
KeyCombinations.selectFreehandDrawingMode));

modeToggleGroup.selectToggle(rectangleModeButton);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.mfl28.boundingboxeditor.ui;

import com.github.mfl28.boundingboxeditor.controller.Controller;
import com.github.mfl28.boundingboxeditor.controller.KeyCombinations;
import com.github.mfl28.boundingboxeditor.utils.ColorUtils;
import com.github.mfl28.boundingboxeditor.utils.UiUtils;
import javafx.geometry.Orientation;
Expand Down Expand Up @@ -249,7 +250,7 @@ private VBox createTagBox() {
private void setUpButtonsAndTextFields() {
categoryNameTextField.setId(CATEGORY_INPUT_FIELD_ID);
categoryNameTextField
.setTooltip(UiUtils.createFocusTooltip(Controller.KeyCombinations.focusCategoryNameTextField));
.setTooltip(UiUtils.createFocusTooltip(KeyCombinations.focusCategoryNameTextField));

categoryColorPicker.getStyleClass().add(OBJECT_CATEGORY_COLOR_PICKER_STYLE);
categoryColorPicker.setValue(ColorUtils.createRandomColor());
Expand All @@ -258,7 +259,7 @@ private void setUpButtonsAndTextFields() {
addCategoryButton.setId(ADD_BUTTON_ID);
addCategoryButton.setTooltip(UiUtils.createTooltip(ADD_CATEGORY_BUTTON_TOOLTIP));

categorySearchField.setTooltip(UiUtils.createFocusTooltip(Controller.KeyCombinations.focusCategorySearchField));
categorySearchField.setTooltip(UiUtils.createFocusTooltip(KeyCombinations.focusCategorySearchField));

collapseTreeItemsButton.setTooltip(UiUtils.createTooltip(COLLAPSE_TREE_ITEMS_BUTTON_TOOLTIP));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package com.github.mfl28.boundingboxeditor.ui;

import com.github.mfl28.boundingboxeditor.controller.Controller;
import com.github.mfl28.boundingboxeditor.controller.KeyCombinations;
import com.github.mfl28.boundingboxeditor.model.data.ImageMetaData;
import com.github.mfl28.boundingboxeditor.utils.UiUtils;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -104,7 +104,7 @@ private HBox createImageFileSearchBox() {

imageFileSearchField.setPromptText(IMAGE_FILE_SEARCH_PROMPT_TEXT);
imageFileSearchField.setFocusTraversable(false);
imageFileSearchField.setTooltip(UiUtils.createFocusTooltip(Controller.KeyCombinations.focusFileSearchField));
imageFileSearchField.setTooltip(UiUtils.createFocusTooltip(KeyCombinations.focusFileSearchField));

Region searchIcon = new Region();
searchIcon.setId(IMAGE_FILE_SEARCH_ICON_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package com.github.mfl28.boundingboxeditor.ui;

import com.github.mfl28.boundingboxeditor.controller.Controller;
import com.github.mfl28.boundingboxeditor.controller.KeyCombinations;
import com.github.mfl28.boundingboxeditor.model.data.ObjectCategory;
import com.github.mfl28.boundingboxeditor.utils.UiUtils;
import javafx.beans.binding.Bindings;
Expand Down Expand Up @@ -299,7 +299,7 @@ private MenuItem createShowAllBoundingShapesMenuItem() {
showAllMenuItem.setId(SHOW_ALL_CONTEXT_MENU_ID);
Tooltip.install(showAllMenuItem.getContent(),
UiUtils.createTooltip("",
Controller.KeyCombinations.showAllBoundingShapes));
KeyCombinations.showAllBoundingShapes));
return showAllMenuItem;
}

Expand All @@ -308,7 +308,7 @@ private MenuItem createShowBoundingShapeMenuItem() {
showMenuItem.setId(SHOW_CONTEXT_MENU_ITEM_ID);
Tooltip.install(showMenuItem.getContent(),
UiUtils.createTooltip("",
Controller.KeyCombinations.showSelectedBoundingShape));
KeyCombinations.showSelectedBoundingShape));
return showMenuItem;
}

Expand All @@ -317,7 +317,7 @@ private MenuItem createHideAllBoundingShapesMenuItem() {
hideAllMenuItem.setId(HIDE_ALL_CONTEXT_MENU_ITEM_ID);
Tooltip.install(hideAllMenuItem.getContent(),
UiUtils.createTooltip("",
Controller.KeyCombinations.hideAllBoundingShapes));
KeyCombinations.hideAllBoundingShapes));
return hideAllMenuItem;
}

Expand All @@ -326,7 +326,7 @@ private MenuItem createHideOtherBoundingShapesMenuItem() {
hideOthersMenuItem.setId(HIDE_OTHERS_CONTEXT_MENU_ITEM_ID);
Tooltip.install(hideOthersMenuItem.getContent(),
UiUtils.createTooltip("",
Controller.KeyCombinations.hideNonSelectedBoundingShapes));
KeyCombinations.hideNonSelectedBoundingShapes));
return hideOthersMenuItem;
}

Expand Down Expand Up @@ -401,7 +401,7 @@ private MenuItem createDeleteBoundingShapeMenuItem() {
deleteMenuItem.setId(DELETE_CONTEXT_MENU_ITEM_ID);
Tooltip.install(deleteMenuItem.getContent(),
UiUtils.createTooltip("",
Controller.KeyCombinations.deleteSelectedBoundingShape));
KeyCombinations.deleteSelectedBoundingShape));
return deleteMenuItem;
}

Expand All @@ -410,7 +410,7 @@ private MenuItem createHideBoundingShapeMenuItem() {
hideMenuItem.setId(HIDE_BOUNDING_SHAPE_CONTEXT_MENU_ITEM_ID);
Tooltip.install(hideMenuItem.getContent(),
UiUtils.createTooltip("",
Controller.KeyCombinations.hideSelectedBoundingShape));
KeyCombinations.hideSelectedBoundingShape));
return hideMenuItem;
}

Expand All @@ -420,7 +420,7 @@ private MenuItem createRefineMenuItem() {

Tooltip.install(menuItem.getContent(),
UiUtils.createTooltip(REFINE_MENU_ITEM_TOOLTIP_TEXT,
Controller.KeyCombinations.addVerticesToPolygon));
KeyCombinations.addVerticesToPolygon));
return menuItem;
}

Expand All @@ -430,7 +430,7 @@ private MenuItem createDeleteVerticesMenuItem() {

Tooltip.install(menuItem.getContent(),
UiUtils.createTooltip(DELETE_VERTICES_MENU_ITEM_TOOLTIP_TEXT,
Controller.KeyCombinations.removeEditingVerticesWhenBoundingPolygonSelected));
KeyCombinations.removeEditingVerticesWhenBoundingPolygonSelected));
return menuItem;
}

Expand All @@ -439,7 +439,7 @@ private MenuItem createSimplifyMenuItem() {
menuItem.setId(SIMPLIFY_CONTEXT_MENU_ITEM_ID);

Tooltip.install(menuItem.getContent(), UiUtils.createTooltip(SIMPLIFY_POLYGON_MENU_ITEM_TOOLTIP_TEXT,
Controller.KeyCombinations.simplifyPolygon));
KeyCombinations.simplifyPolygon));

return menuItem;
}
Expand All @@ -449,7 +449,7 @@ private MenuItem createChangeObjectCategoryMenuItem() {
menuItem.setId(CHANGE_CATEGORY_CONTEXT_MENU_ITEM_ID);

Tooltip.install(menuItem.getContent(),
UiUtils.createTooltip("", Controller.KeyCombinations.changeSelectedBoundingShapeCategory));
UiUtils.createTooltip("", KeyCombinations.changeSelectedBoundingShapeCategory));
return menuItem;
}

Expand All @@ -458,7 +458,7 @@ private MenuItem createSaveAsImageMenuItem() {
menuItem.setId(SAVE_AS_IMAGE_MENU_ITEM_ID);

Tooltip.install(menuItem.getContent(),
UiUtils.createTooltip("", Controller.KeyCombinations.saveBoundingShapeAsImage));
UiUtils.createTooltip("", KeyCombinations.saveBoundingShapeAsImage));

return menuItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package com.github.mfl28.boundingboxeditor.ui;

import com.github.mfl28.boundingboxeditor.controller.Controller;
import com.github.mfl28.boundingboxeditor.controller.KeyCombinations;
import com.github.mfl28.boundingboxeditor.utils.UiUtils;
import javafx.application.Platform;
import javafx.beans.property.SimpleListProperty;
Expand Down Expand Up @@ -143,7 +143,7 @@ private TextField createTagInputField() {
TextField textField = new TextField();
textField.setId(TAG_INPUT_FIELD_ID);
textField.setPromptText(TEXT_FIELD_PROMPT_TEXT);
textField.setTooltip(UiUtils.createFocusTooltip(Controller.KeyCombinations.focusTagTextField));
textField.setTooltip(UiUtils.createFocusTooltip(KeyCombinations.focusTagTextField));
// Will be enabled if a tag-list is registered with the tagLists-property.
textField.setDisable(true);

Expand Down
Loading