Skip to content

Commit 4b63ed5

Browse files
CopilotbedaHovorka
andauthored
fix: handle stopped runner detachment and initial speed callback
Agent-Logs-Url: https://github.com/bedaHovorka/interlockSim/sessions/e88ff78a-7a85-4ecd-9542-da0b8e356164 Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
1 parent c8c849e commit 4b63ed5

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class Frame : JFrame(PROGRAM_FULL_NAME) {
127127

128128
SimulationController.SimulationStatus.STOPPED -> {
129129
toolBar.hideSimulationControls()
130+
simulationControlPanel.runner = null
130131
controlPanel.setStopEnabled(false)
131132
controlPanel.updateStatus(ControlPanel.SimulationStatus.STOPPED)
132133
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ internal class SimulationController(
112112
}
113113
speedListener = listener
114114
newRunner.addPropertyChangeListener(SimulationRunner.PROP_SPEED_MULTIPLIER, listener)
115+
onSpeedChanged(newRunner.speedMultiplier)
115116

116117
onStateChanged(SimulationStatus.RUNNING)
117118

desktop-ui/src/test/kotlin/cz/vutbr/fit/interlockSim/gui/SimulationControllerTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,33 @@ class SimulationControllerTest {
519519
controller.stop()
520520
}
521521

522+
@Test
523+
@Timeout(value = 10, unit = TimeUnit.SECONDS)
524+
@DisplayName("preselected speed is propagated to StatusBar when start() begins")
525+
fun preselectedSpeedPropagatesOnStart() {
526+
val started = CountDownLatch(1)
527+
val blockSim = CountDownLatch(1)
528+
every { context.run() } answers {
529+
started.countDown()
530+
blockSim.await(10, TimeUnit.SECONDS)
531+
}
532+
533+
val statusBar = StatusBar()
534+
val controller = createController(statusBar = statusBar)
535+
controller.setSpeed(2.5)
536+
controller.start(context)
537+
assertThat(started.await(5, TimeUnit.SECONDS)).isTrue()
538+
flushEDT()
539+
540+
SwingUtilities.invokeAndWait {
541+
assertThat(statusBar.speedIndicatorText()).isEqualTo("Speed: 2.5x")
542+
assertThat(statusBar.isSpeedIndicatorVisible()).isTrue()
543+
}
544+
545+
blockSim.countDown()
546+
controller.stop()
547+
}
548+
522549
// ── helpers ───────────────────────────────────────────────────────────────
523550

524551
// ── toolBar / statusBar wiring ────────────────────────────────────────────

0 commit comments

Comments
 (0)