17
17
import com .google .inject .assistedinject .Assisted ;
18
18
19
19
import java .io .InputStream ;
20
- import java .util .ArrayList ;
21
20
import java .util .Collection ;
22
- import java .util .List ;
23
-
21
+ import java .util .function .Predicate ;
24
22
import javafx .animation .KeyFrame ;
25
23
import javafx .animation .KeyValue ;
26
24
import javafx .animation .Timeline ;
27
- import javafx .animation .TimelineBuilder ;
28
25
import javafx .beans .property .DoubleProperty ;
29
- import javafx .event .ActionEvent ;
30
- import javafx .event .EventHandler ;
31
26
import javafx .fxml .FXML ;
32
27
import javafx .scene .Node ;
33
28
import javafx .scene .control .Button ;
@@ -52,7 +47,6 @@ public class StepController implements Controller {
52
47
private final ExceptionWitnessResponderButton .Factory exceptionWitnessResponderButtonFactory ;
53
48
private final StepDragService stepDragService ;
54
49
private final Step step ;
55
- private final List <InputSocketController > inputSockets ;
56
50
private boolean expanded = true ;
57
51
@ FXML
58
52
private VBox root ;
@@ -75,6 +69,8 @@ public class StepController implements Controller {
75
69
76
70
private static final Image UP_ARROW = new Image ("/edu/wpi/grip/ui/icons/up.png" );
77
71
private static final Image DOWN_ARROW = new Image ("/edu/wpi/grip/ui/icons/down.png" );
72
+ private static final Predicate <InputSocketController > interactiveInputSocketFilter
73
+ = i -> !i .getSocket ().getSocketHint ().getView ().equals (SocketHint .View .NONE );
78
74
79
75
@ Inject
80
76
StepController (Pipeline pipeline ,
@@ -89,7 +85,6 @@ public class StepController implements Controller {
89
85
this .exceptionWitnessResponderButtonFactory = exceptionWitnessResponderButtonFactory ;
90
86
this .stepDragService = stepDragService ;
91
87
this .step = step ;
92
- inputSockets = new ArrayList <>();
93
88
}
94
89
95
90
@ FXML
@@ -113,11 +108,7 @@ private void initialize() {
113
108
114
109
// Add a SocketControlView for each input socket and output socket
115
110
for (InputSocket <?> inputSocket : step .getInputSockets ()) {
116
- InputSocketController tempSocket = inputSocketControllerFactory .create (inputSocket );
117
- inputSocketMapManager .add (tempSocket );
118
- if (!inputSocket .getSocketHint ().getView ().equals (SocketHint .View .NONE )) {
119
- inputSockets .add (tempSocket );
120
- }
111
+ inputSocketMapManager .add (inputSocketControllerFactory .create (inputSocket ));
121
112
}
122
113
123
114
for (OutputSocket <?> outputSocket : step .getOutputSockets ()) {
@@ -178,20 +169,17 @@ private void moveStepRight() {
178
169
@ FXML
179
170
private void expand () {
180
171
if (expanded ) {
181
- for (InputSocketController input : inputSockets ) {
182
- inputs .setMaxHeight (inputs .getHeight ());
183
- inputs .setPrefHeight (inputs .getHeight ());
184
- if (input .getSocket ().getConnections ().isEmpty ()) {
185
- fadeOut (input );
186
- }
187
- }
172
+ inputSocketMapManager .keySet ().stream ()
173
+ .filter (interactiveInputSocketFilter )
174
+ .filter (i -> i .getSocket ().getConnections ().isEmpty ())
175
+ .forEach (this ::fadeOut );
188
176
closeUp ();
189
177
expandIcon .setImage (DOWN_ARROW );
190
178
expanded = false ;
191
179
} else {
192
- for ( InputSocketController input : inputSockets ) {
193
- fadeIn ( input );
194
- }
180
+ inputSocketMapManager . keySet (). stream ()
181
+ . filter ( interactiveInputSocketFilter )
182
+ . forEach ( this :: fadeIn );
195
183
reopen ();
196
184
expandIcon .setImage (UP_ARROW );
197
185
expanded = true ;
@@ -209,12 +197,9 @@ private void fadeOut(InputSocketController input) {
209
197
Timeline fadeOut = new Timeline (
210
198
new KeyFrame (Duration .ZERO , new KeyValue (opacity , 1.0 )),
211
199
new KeyFrame (new Duration (100 ), new KeyValue (opacity , 0.0 )));
212
- fadeOut .setOnFinished (new EventHandler <ActionEvent >() {
213
- @ Override
214
- public void handle (ActionEvent event ) {
215
- input .getRoot ().setVisible (false );
216
- input .getRoot ().setManaged (false );
217
- }
200
+ fadeOut .setOnFinished (event -> {
201
+ input .getRoot ().setVisible (false );
202
+ input .getRoot ().setManaged (false );
218
203
});
219
204
fadeOut .play ();
220
205
}
@@ -229,34 +214,28 @@ private void fadeIn(InputSocketController input) {
229
214
DoubleProperty opacity = input .getRoot ().opacityProperty ();
230
215
Timeline fadeIn = new Timeline (
231
216
new KeyFrame (new Duration (100 ), new KeyValue (opacity , 1.0 )));
232
- fadeIn .setOnFinished (new EventHandler <ActionEvent >() {
233
- @ Override
234
- public void handle (ActionEvent event ) {
235
- for (InputSocketController input : inputSockets ) {
236
- input .getRoot ().setManaged (true );
237
- }
238
- }
239
- });
217
+ fadeIn .setOnFinished (
218
+ event -> inputSocketMapManager .keySet ().forEach (i -> input .getRoot ().setManaged (true )));
240
219
fadeIn .play ();
241
220
}
242
221
243
222
/**
244
223
* Makes an animation to make the input vbox slide closed over .25 seconds
245
224
*/
246
225
private void closeUp () {
247
- Timeline animation = TimelineBuilder . create (). cycleCount ( 1 ). keyFrames (
226
+ Timeline animation = new Timeline (
248
227
new KeyFrame (Duration .seconds (0.25 ),
249
- new KeyValue (inputs .prefHeightProperty (), 0 ))). build () ;
228
+ new KeyValue (inputs .prefHeightProperty (), 0 )));
250
229
animation .play ();
251
230
}
252
231
253
232
/**
254
233
* Makes an animation to make the input vbox slide open over .1 seconds
255
234
*/
256
235
private void reopen () {
257
- Timeline animation = TimelineBuilder . create (). cycleCount ( 1 ). keyFrames (
236
+ Timeline animation = new Timeline (
258
237
new KeyFrame (Duration .seconds (0.1 ),
259
- new KeyValue (inputs .prefHeightProperty (), inputs .getMaxHeight ()))). build () ;
238
+ new KeyValue (inputs .prefHeightProperty (), inputs .getMaxHeight ())));
260
239
animation .play ();
261
240
}
262
241
0 commit comments