Skip to content

Commit 0a5446b

Browse files
committed
Merge pull request #576 from JLLeitschuh/feat/glowingStartStop
Makes the Start/Stop button flash when stoped
2 parents 7cdb16e + aeebf8c commit 0a5446b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ui/src/main/java/edu/wpi/grip/ui/components/StartStoppableButton.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import edu.wpi.grip.core.util.service.RestartableService;
99
import edu.wpi.grip.core.util.service.SingleActionListener;
1010
import edu.wpi.grip.ui.util.DPIUtility;
11+
import javafx.animation.FadeTransition;
12+
import javafx.animation.Transition;
1113
import javafx.application.Platform;
1214
import javafx.scene.control.ContentDisplay;
1315
import javafx.scene.control.ToggleButton;
@@ -17,6 +19,7 @@
1719
import javafx.scene.input.MouseEvent;
1820
import javafx.scene.layout.HBox;
1921
import javafx.scene.layout.Priority;
22+
import javafx.util.Duration;
2023

2124
import java.util.Arrays;
2225
import java.util.List;
@@ -90,7 +93,7 @@ private List<String> getCurrentStyleClasses() {
9093
}
9194

9295
/**
93-
* Assigns the state of the button from the {@link StartStoppable}
96+
* Assigns the state of the button from the {@link RestartableService}
9497
*/
9598
private void assignState() {
9699
setSelected(service.isRunning());
@@ -104,7 +107,16 @@ private void assignState() {
104107
* @return The graphic to show on the button.
105108
*/
106109
private static ImageView pickGraphic(RestartableService startStoppable) {
107-
final ImageView icon = startStoppable.isRunning() ? new ImageView(stopImage) : new ImageView(startImage);
110+
final boolean running = startStoppable.isRunning();
111+
final ImageView icon = running ? new ImageView(stopImage) : new ImageView(startImage);
112+
if (!running) {
113+
// If we are not running then we want the icon to flash
114+
final FadeTransition ft = new FadeTransition(Duration.millis(750), icon);
115+
ft.setToValue(0.1);
116+
ft.setCycleCount(Transition.INDEFINITE);
117+
ft.setAutoReverse(true);
118+
ft.play();
119+
}
108120
icon.setFitHeight(DPIUtility.MINI_ICON_SIZE);
109121
icon.setFitWidth(DPIUtility.MINI_ICON_SIZE);
110122
return icon;

0 commit comments

Comments
 (0)