99import edu .wpi .grip .ui .annotations .ParametrizedController ;
1010import edu .wpi .grip .ui .components .ExceptionWitnessResponderButton ;
1111import edu .wpi .grip .ui .dragging .StepDragService ;
12+ import edu .wpi .grip .ui .events .SetStepsExpandedEvent ;
1213import edu .wpi .grip .ui .pipeline .input .InputSocketController ;
1314import edu .wpi .grip .ui .pipeline .input .InputSocketControllerFactory ;
1415import edu .wpi .grip .ui .util .ControllerMap ;
1516import edu .wpi .grip .ui .util .StyleClassNameUtility ;
1617
18+ import com .google .common .eventbus .EventBus ;
19+ import com .google .common .eventbus .Subscribe ;
1720import com .google .inject .assistedinject .Assisted ;
1821
1922import java .io .InputStream ;
2225import javafx .animation .KeyFrame ;
2326import javafx .animation .KeyValue ;
2427import javafx .animation .Timeline ;
28+ import javafx .beans .property .BooleanProperty ;
2529import javafx .beans .property .DoubleProperty ;
30+ import javafx .beans .property .SimpleBooleanProperty ;
2631import javafx .fxml .FXML ;
2732import javafx .scene .Node ;
2833import javafx .scene .control .Button ;
2934import javafx .scene .control .Labeled ;
3035import javafx .scene .image .Image ;
3136import javafx .scene .image .ImageView ;
37+ import javafx .scene .input .MouseEvent ;
3238import javafx .scene .layout .HBox ;
3339import javafx .scene .layout .VBox ;
3440import javafx .util .Duration ;
@@ -46,8 +52,9 @@ public class StepController implements Controller {
4652 private final OutputSocketController .Factory outputSocketControllerFactory ;
4753 private final ExceptionWitnessResponderButton .Factory exceptionWitnessResponderButtonFactory ;
4854 private final StepDragService stepDragService ;
55+ private final EventBus eventBus ;
4956 private final Step step ;
50- private boolean expanded = true ;
57+ private final BooleanProperty expanded = new SimpleBooleanProperty ( true ) ;
5158 @ FXML
5259 private VBox root ;
5360 @ FXML
@@ -78,12 +85,14 @@ public class StepController implements Controller {
7885 OutputSocketController .Factory outputSocketControllerFactory ,
7986 ExceptionWitnessResponderButton .Factory exceptionWitnessResponderButtonFactory ,
8087 StepDragService stepDragService ,
88+ EventBus eventBus ,
8189 @ Assisted Step step ) {
8290 this .pipeline = pipeline ;
8391 this .inputSocketControllerFactory = inputSocketControllerFactory ;
8492 this .outputSocketControllerFactory = outputSocketControllerFactory ;
8593 this .exceptionWitnessResponderButtonFactory = exceptionWitnessResponderButtonFactory ;
8694 this .stepDragService = stepDragService ;
95+ this .eventBus = eventBus ;
8796 this .step = step ;
8897 }
8998
@@ -104,6 +113,22 @@ private void initialize() {
104113 expand .setManaged (false );
105114 } else {
106115 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+ }));
107132 }
108133
109134 // Add a SocketControlView for each input socket and output socket
@@ -166,25 +191,23 @@ private void moveStepRight() {
166191 pipeline .moveStep (step , +1 );
167192 }
168193
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+ */
169199 @ 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 ()));
186205 }
206+ }
187207
208+ @ Subscribe
209+ public void setExpanded (SetStepsExpandedEvent event ) {
210+ expanded .set (event .isExpanded ());
188211 }
189212
190213 /**
0 commit comments