Skip to content

Commit 47e3279

Browse files
committed
Added an animation.
1 parent f7018cf commit 47e3279

File tree

1 file changed

+77
-5
lines changed

1 file changed

+77
-5
lines changed

ui/src/main/java/edu/wpi/grip/ui/pipeline/StepController.java

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
import java.util.Collection;
2222
import java.util.List;
2323

24+
import javafx.animation.KeyFrame;
25+
import javafx.animation.KeyValue;
26+
import javafx.animation.Timeline;
27+
import javafx.animation.TimelineBuilder;
28+
import javafx.beans.property.DoubleProperty;
29+
import javafx.event.ActionEvent;
30+
import javafx.event.EventHandler;
2431
import javafx.fxml.FXML;
2532
import javafx.scene.Node;
2633
import javafx.scene.control.Button;
@@ -29,7 +36,7 @@
2936
import javafx.scene.image.ImageView;
3037
import javafx.scene.layout.HBox;
3138
import javafx.scene.layout.VBox;
32-
39+
import javafx.util.Duration;
3340
import javax.inject.Inject;
3441

3542
/**
@@ -169,24 +176,89 @@ private void moveStepRight() {
169176
private void expand() {
170177
if (expanded) {
171178
for (InputSocketController input : inputSockets) {
179+
inputs.setMaxHeight(inputs.getHeight());
180+
inputs.setPrefHeight(inputs.getHeight());
172181
if (input.getSocket().getConnections().isEmpty()) {
173-
input.getRoot().setVisible(false);
174-
input.getRoot().setManaged(false);
182+
fadeOut(input);
175183
}
176184
}
185+
closeUp();
177186
expandIcon.setImage(new Image("/edu/wpi/grip/ui/icons/down.png"));
178187
expanded = false;
179188
} else {
180189
for (InputSocketController input : inputSockets) {
181-
input.getRoot().setManaged(true);
182-
input.getRoot().setVisible(true);
190+
fadeIn(input);
183191
}
192+
reopen();
184193
expandIcon.setImage(new Image("/edu/wpi/grip/ui/icons/up.png"));
185194
expanded = true;
186195
}
187196

188197
}
189198

199+
/**
200+
* Makes an animation to make an input socket fade out over 0.1 seconds.
201+
*
202+
* @param input the input socket controller that will be faded out.
203+
*/
204+
private void fadeOut(InputSocketController input) {
205+
DoubleProperty opacity = input.getRoot().opacityProperty();
206+
Timeline fadeOut = new Timeline(
207+
new KeyFrame(Duration.ZERO, new KeyValue(opacity, 1.0)),
208+
new KeyFrame(new Duration(100), new KeyValue(opacity, 0.0)));
209+
fadeOut.setOnFinished(new EventHandler<ActionEvent>() {
210+
@Override
211+
public void handle(ActionEvent event) {
212+
for (InputSocketController input : inputSockets) {
213+
input.getRoot().setVisible(false);
214+
input.getRoot().setManaged(false);
215+
}
216+
}
217+
});
218+
fadeOut.play();
219+
}
220+
221+
/**
222+
* Makes an animation to make an input socket fade in over 0.25 seconds.
223+
*
224+
* @param input the input socket controller that will be faded out.
225+
*/
226+
private void fadeIn(InputSocketController input) {
227+
input.getRoot().setVisible(true);
228+
DoubleProperty opacity = input.getRoot().opacityProperty();
229+
Timeline fadeIn = new Timeline(
230+
new KeyFrame(new Duration(250), new KeyValue(opacity, 1.0)));
231+
fadeIn.setOnFinished(new EventHandler<ActionEvent>() {
232+
@Override
233+
public void handle(ActionEvent event) {
234+
for (InputSocketController input : inputSockets) {
235+
input.getRoot().setManaged(true);
236+
}
237+
}
238+
});
239+
fadeIn.play();
240+
}
241+
242+
/**
243+
* Makes an animation to make the input vbox slide closed over .25 seconds
244+
*/
245+
private void closeUp() {
246+
Timeline animation = TimelineBuilder.create().cycleCount(1).keyFrames(
247+
new KeyFrame(Duration.seconds(0.25),
248+
new KeyValue(inputs.prefHeightProperty(), 0))).build();
249+
animation.play();
250+
}
251+
252+
/**
253+
* Makes an animation to make the input vbox slide open over .1 seconds
254+
*/
255+
private void reopen() {
256+
Timeline animation = TimelineBuilder.create().cycleCount(1).keyFrames(
257+
new KeyFrame(Duration.seconds(0.1),
258+
new KeyValue(inputs.prefHeightProperty(), inputs.getMaxHeight()))).build();
259+
animation.play();
260+
}
261+
190262
/**
191263
* Used for assisted injects. Guice will automatically create an instance of this interface so we
192264
* can create step controllers. This lets us use injection with StepController even though it

0 commit comments

Comments
 (0)