9
9
import edu .wpi .grip .ui .annotations .ParametrizedController ;
10
10
import edu .wpi .grip .ui .components .ExceptionWitnessResponderButton ;
11
11
import edu .wpi .grip .ui .dragging .StepDragService ;
12
+ import edu .wpi .grip .ui .events .SetStepsExpandedEvent ;
12
13
import edu .wpi .grip .ui .pipeline .input .InputSocketController ;
13
14
import edu .wpi .grip .ui .pipeline .input .InputSocketControllerFactory ;
14
15
import edu .wpi .grip .ui .util .ControllerMap ;
15
16
import edu .wpi .grip .ui .util .StyleClassNameUtility ;
16
17
18
+ import com .google .common .eventbus .EventBus ;
19
+ import com .google .common .eventbus .Subscribe ;
17
20
import com .google .inject .assistedinject .Assisted ;
18
21
19
22
import java .io .InputStream ;
22
25
import javafx .animation .KeyFrame ;
23
26
import javafx .animation .KeyValue ;
24
27
import javafx .animation .Timeline ;
28
+ import javafx .beans .property .BooleanProperty ;
25
29
import javafx .beans .property .DoubleProperty ;
30
+ import javafx .beans .property .SimpleBooleanProperty ;
26
31
import javafx .fxml .FXML ;
27
32
import javafx .scene .Node ;
28
33
import javafx .scene .control .Button ;
29
34
import javafx .scene .control .Labeled ;
30
35
import javafx .scene .image .Image ;
31
36
import javafx .scene .image .ImageView ;
37
+ import javafx .scene .input .MouseEvent ;
32
38
import javafx .scene .layout .HBox ;
33
39
import javafx .scene .layout .VBox ;
34
40
import javafx .util .Duration ;
@@ -46,8 +52,9 @@ public class StepController implements Controller {
46
52
private final OutputSocketController .Factory outputSocketControllerFactory ;
47
53
private final ExceptionWitnessResponderButton .Factory exceptionWitnessResponderButtonFactory ;
48
54
private final StepDragService stepDragService ;
55
+ private final EventBus eventBus ;
49
56
private final Step step ;
50
- private boolean expanded = true ;
57
+ private final BooleanProperty expanded = new SimpleBooleanProperty ( true ) ;
51
58
@ FXML
52
59
private VBox root ;
53
60
@ FXML
@@ -78,12 +85,14 @@ public class StepController implements Controller {
78
85
OutputSocketController .Factory outputSocketControllerFactory ,
79
86
ExceptionWitnessResponderButton .Factory exceptionWitnessResponderButtonFactory ,
80
87
StepDragService stepDragService ,
88
+ EventBus eventBus ,
81
89
@ Assisted Step step ) {
82
90
this .pipeline = pipeline ;
83
91
this .inputSocketControllerFactory = inputSocketControllerFactory ;
84
92
this .outputSocketControllerFactory = outputSocketControllerFactory ;
85
93
this .exceptionWitnessResponderButtonFactory = exceptionWitnessResponderButtonFactory ;
86
94
this .stepDragService = stepDragService ;
95
+ this .eventBus = eventBus ;
87
96
this .step = step ;
88
97
}
89
98
@@ -104,6 +113,22 @@ private void initialize() {
104
113
expand .setManaged (false );
105
114
} else {
106
115
expandIcon .setImage (UP_ARROW );
116
+ expanded .addListener (((observable , oldValue , newValue ) -> {
117
+ if (newValue ) {
118
+ inputSocketMapManager .keySet ().stream ()
119
+ .filter (interactiveInputSocketFilter )
120
+ .forEach (this ::fadeIn );
121
+ reopen ();
122
+ expandIcon .setImage (UP_ARROW );
123
+ } else {
124
+ inputSocketMapManager .keySet ().stream ()
125
+ .filter (interactiveInputSocketFilter )
126
+ .filter (i -> i .getSocket ().getConnections ().isEmpty ())
127
+ .forEach (this ::fadeOut );
128
+ closeUp ();
129
+ expandIcon .setImage (DOWN_ARROW );
130
+ }
131
+ }));
107
132
}
108
133
109
134
// Add a SocketControlView for each input socket and output socket
@@ -166,25 +191,23 @@ private void moveStepRight() {
166
191
pipeline .moveStep (step , +1 );
167
192
}
168
193
194
+ /**
195
+ * Clicking the arrow at the top of the step will cause the step to either expand or retract.
196
+ * Double clicking the arrow at the top of the step will cause all steps to either expand or
197
+ * retract.
198
+ */
169
199
@ FXML
170
- private void expand () {
171
- if (expanded ) {
172
- inputSocketMapManager .keySet ().stream ()
173
- .filter (interactiveInputSocketFilter )
174
- .filter (i -> i .getSocket ().getConnections ().isEmpty ())
175
- .forEach (this ::fadeOut );
176
- closeUp ();
177
- expandIcon .setImage (DOWN_ARROW );
178
- expanded = false ;
179
- } else {
180
- inputSocketMapManager .keySet ().stream ()
181
- .filter (interactiveInputSocketFilter )
182
- .forEach (this ::fadeIn );
183
- reopen ();
184
- expandIcon .setImage (UP_ARROW );
185
- expanded = true ;
200
+ private void toggleExpand (MouseEvent event ) {
201
+ if (event .getClickCount () == 1 ) {
202
+ expanded .set (!expanded .get ());
203
+ } else if (event .getClickCount () == 2 ) {
204
+ eventBus .post (new SetStepsExpandedEvent (expanded .get ()));
186
205
}
206
+ }
187
207
208
+ @ Subscribe
209
+ public void setExpanded (SetStepsExpandedEvent event ) {
210
+ expanded .set (event .isExpanded ());
188
211
}
189
212
190
213
/**
0 commit comments