KeyboardShortcuts.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package de.tu_darmstadt.informatik.tk.scopviz.ui.handlers;
  2. import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
  3. import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
  4. import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
  5. import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
  6. import de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController;
  7. import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
  8. import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.MapViewFunctions;
  9. import javafx.event.EventHandler;
  10. import javafx.scene.input.KeyCode;
  11. import javafx.scene.input.KeyCodeCombination;
  12. import javafx.scene.input.KeyCombination;
  13. import javafx.scene.input.KeyEvent;
  14. import javafx.stage.Stage;
  15. /**
  16. * Class for defining keyboard shortcuts for all kind of actions. Shortcuts for
  17. * actions in the menu bar should be defined in the fxml file as accelerators.
  18. *
  19. * @author Julian Ohl (julian.ohl95@web.de)
  20. * @version 1.3
  21. *
  22. */
  23. public final class KeyboardShortcuts {
  24. /**
  25. * Reference to the GUI Controller for Access to various GUI Elements.
  26. */
  27. private static GUIController controller;
  28. // example of keycombinations
  29. final static KeyCombination mShift = new KeyCodeCombination(KeyCode.M, KeyCombination.SHIFT_DOWN);
  30. final static KeyCombination rAltShift = new KeyCodeCombination(KeyCode.R, KeyCombination.ALT_DOWN,
  31. KeyCombination.SHIFT_DOWN);
  32. /**
  33. * Private constructor to prevent Instantiation.
  34. */
  35. private KeyboardShortcuts() {
  36. }
  37. /**
  38. * Initialize the Keyboard Shortcuts, add them to the Stage.
  39. *
  40. * @param primaryStage
  41. * the Stage
  42. */
  43. public static void initialize(Stage primaryStage, GUIController c) {
  44. controller = c;
  45. primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, buttonsPressed);
  46. primaryStage.addEventFilter(KeyEvent.KEY_RELEASED, buttonsReleased);
  47. }
  48. /**
  49. * A general Handler for any Button presses.
  50. */
  51. private static EventHandler<KeyEvent> buttonsPressed = new EventHandler<KeyEvent>() {
  52. @Override
  53. public void handle(KeyEvent event) {
  54. if (event.getCode() == KeyCode.CONTROL) {
  55. // for functionality of holding down ctrl for creating mapping
  56. // edges
  57. if (Main.getInstance().getGraphManager().getGraph().getAttribute("layer") == Layer.MAPPING) {
  58. Main.getInstance().setCreationMode(CreationMode.CREATE_DIRECTED_EDGE);
  59. Debug.out("Ctrl pressed");
  60. }
  61. }
  62. if (event.getCode() == KeyCode.ESCAPE) {
  63. // clears toolbox selection/selectionmode
  64. controller.toolbox.getSelectionModel().clearSelection();
  65. Main.getInstance().getGraphManager().deselectEdgeCreationNodes();
  66. }
  67. }
  68. };
  69. /**
  70. * A general Handler for any Button releases
  71. */
  72. private static EventHandler<KeyEvent> buttonsReleased = new EventHandler<KeyEvent>() {
  73. @Override
  74. public void handle(KeyEvent event) {
  75. if (mShift.match(event)) {
  76. Debug.out("M+Shift released");
  77. }
  78. else if (rAltShift.match(event)) {
  79. Debug.out("Alt+Shift+R released");
  80. }
  81. else if (event.getCode() == KeyCode.CONTROL) {
  82. // for functionality of holding down ctrl for creating mapping
  83. // edges
  84. if (Main.getInstance().getGraphManager().getGraph().getAttribute("layer") == Layer.MAPPING) {
  85. Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);
  86. Main.getInstance().getGraphManager().deselectEdgeCreationNodes();
  87. Debug.out("Ctrl released");
  88. }
  89. }
  90. else if (event.getCode().equals(KeyCode.RIGHT)) {
  91. if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
  92. MapViewFunctions.switchToNextWaypoint();
  93. }
  94. }
  95. else if (event.getCode().equals(KeyCode.LEFT)) {
  96. if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
  97. MapViewFunctions.switchToPreviousWaypoint();
  98. }
  99. }
  100. }
  101. };
  102. }