Skip to content

Commit 89651fe

Browse files
CopilotbedaHovorka
andauthored
Apply PR review feedback: fix key bindings, tests, and documentation
- Fix VK_PLUS binding: use Shift+VK_EQUALS for '+' key on standard keyboards, add numpad support - Remove unreachable catch block in SpeedPresetAction (setSpeed doesn't throw IllegalStateException) - Remove unused companion object logger in SimulationKeyBindings - Remove headless test skip - tests use lightweight Swing components that don't need display - Fix test setup: block context.run() with CountDownLatch to prevent race conditions - Run all tests and actions on EDT using SwingUtilities.invokeAndWait - Update MenuBar KDoc to reflect global keyboard shortcuts (remove mention of removed accelerators) - Remove commented-out accelerator code in MenuBar - Fix SonarQube workflow condition: include workflow_dispatch to allow manual scans on feature branches Agent-Logs-Url: https://github.com/bedaHovorka/interlockSim/sessions/86ce4646-5290-410d-98d6-86fe02b0300a Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
1 parent 74186c1 commit 89651fe

4 files changed

Lines changed: 212 additions & 141 deletions

File tree

.github/workflows/sonarqube.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
# Requires SONAR_TOKEN and SONAR_ORGANIZATION secrets configured in GitHub
9999
# If secrets are not configured, this step will skip gracefully
100100
- name: SonarCloud Scan
101-
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
101+
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
102102
env:
103103
GITHUB_ACTOR: ${{ github.actor }}
104104
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

desktop-ui/src/main/kotlin/cz/vutbr/fit/interlockSim/gui/MenuBar.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,9 @@ class MenuBar : JMenuBar() {
381381
/**
382382
* Builds the "Simulation" menu with Start/Stop actions and a Speed submenu.
383383
*
384-
* Speed presets (0.1x, 0.5x, 1x, 2x, 10x) have keyboard accelerators (keys 1–5)
385-
* so that the user can change the speed without reaching for the mouse during a run.
384+
* Speed presets (0.1x, 0.5x, 1x, 2x, 10x) are available via menu items.
385+
* Global keyboard shortcuts (keys 1–5, +/-, Space) are handled by [SimulationKeyBindings]
386+
* during simulation mode (Phase 3.1, Issue #193).
386387
*/
387388
private fun simulationMenu(): JMenu {
388389
val menu = JMenu("Simulation")
@@ -399,11 +400,8 @@ class MenuBar : JMenuBar() {
399400
Triple("2x", 2.0, KeyEvent.VK_4),
400401
Triple("10x", 10.0, KeyEvent.VK_5),
401402
)
402-
for ((label, multiplier, keyCode) in speedPresets) {
403+
for ((label, multiplier, _) in speedPresets) {
403404
val item = JMenuItem(SetSpeedAction(label, multiplier))
404-
// Note: Keyboard accelerators removed in Phase 3.1 (Issue #193).
405-
// Global keyboard shortcuts are now handled by SimulationKeyBindings.
406-
// item.accelerator = KeyStroke.getKeyStroke(keyCode, 0)
407405
speedMenu.add(item)
408406
}
409407
menu.add(speedMenu)

desktop-ui/src/main/kotlin/cz/vutbr/fit/interlockSim/gui/SimulationKeyBindings.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ internal class SimulationKeyBindings(
7070
}
7171

7272
// Incremental speed adjustment: + increases by ×1.5, - decreases by ÷1.5
73-
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, 0), ACTION_KEY_SPEED_UP)
74-
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0), ACTION_KEY_SPEED_UP)
73+
// '+' is typically Shift+'=' on most keyboards, so bind both Shift+VK_EQUALS and numpad plus
74+
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.SHIFT_DOWN_MASK), ACTION_KEY_SPEED_UP)
75+
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0), ACTION_KEY_SPEED_UP) // Numpad +
7576
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0), ACTION_KEY_SPEED_DOWN)
77+
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0), ACTION_KEY_SPEED_DOWN) // Numpad -
7678
actionMap.put(ACTION_KEY_SPEED_UP, IncrementalSpeedAction(multiplier = SPEED_INCREMENT))
7779
actionMap.put(ACTION_KEY_SPEED_DOWN, IncrementalSpeedAction(multiplier = 1.0 / SPEED_INCREMENT))
7880

@@ -103,9 +105,10 @@ internal class SimulationKeyBindings(
103105
}
104106

105107
// Remove incremental speed bindings
106-
inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, 0))
107-
inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0))
108+
inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.SHIFT_DOWN_MASK))
109+
inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0))
108110
inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0))
111+
inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0))
109112
actionMap.remove(ACTION_KEY_SPEED_UP)
110113
actionMap.remove(ACTION_KEY_SPEED_DOWN)
111114

@@ -121,7 +124,8 @@ internal class SimulationKeyBindings(
121124
/**
122125
* Action that sets the simulation speed to a fixed preset value.
123126
*
124-
* If no simulation is running, the action is a no-op (graceful degradation).
127+
* If no simulation is running, [SimulationController.setSpeed] updates [SimulationController.desiredSpeed]
128+
* which will be applied when the next simulation starts.
125129
*/
126130
private inner class SpeedPresetAction(private val speed: Double) : AbstractAction() {
127131
override fun actionPerformed(e: ActionEvent) {
@@ -130,9 +134,6 @@ internal class SimulationKeyBindings(
130134
logger.debug { "Speed preset applied: ${speed}×" }
131135
} catch (ex: IllegalArgumentException) {
132136
logger.warn { "Invalid speed preset: $speed${ex.message}" }
133-
} catch (ex: IllegalStateException) {
134-
// No runner active — ignore gracefully
135-
logger.debug { "Speed preset ignored (no simulation running): $speed" }
136137
}
137138
}
138139
}
@@ -194,8 +195,6 @@ internal class SimulationKeyBindings(
194195
}
195196

196197
companion object {
197-
private val logger = KotlinLogging.logger {}
198-
199198
/** Action key for speed-up shortcut. */
200199
private const val ACTION_KEY_SPEED_UP = "simulation_speed_up"
201200

0 commit comments

Comments
 (0)