Skip to content

Commit 5b1e389

Browse files
committed
Double click
1 parent 323412d commit 5b1e389

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package edu.wpi.grip.ui.events;
2+
3+
/**
4+
* Toggles every steps' visibility.
5+
*/
6+
public class SetStepsExpandedEvent {
7+
8+
private final boolean expanded;
9+
10+
public SetStepsExpandedEvent(boolean expanded) {
11+
this.expanded = expanded;
12+
}
13+
14+
public boolean isExpanded() {
15+
return expanded;
16+
}
17+
}

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

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
import edu.wpi.grip.ui.annotations.ParametrizedController;
1010
import edu.wpi.grip.ui.components.ExceptionWitnessResponderButton;
1111
import edu.wpi.grip.ui.dragging.StepDragService;
12+
import edu.wpi.grip.ui.events.SetStepsExpandedEvent;
1213
import edu.wpi.grip.ui.pipeline.input.InputSocketController;
1314
import edu.wpi.grip.ui.pipeline.input.InputSocketControllerFactory;
1415
import edu.wpi.grip.ui.util.ControllerMap;
1516
import edu.wpi.grip.ui.util.StyleClassNameUtility;
1617

18+
import com.google.common.eventbus.EventBus;
19+
import com.google.common.eventbus.Subscribe;
1720
import com.google.inject.assistedinject.Assisted;
1821

1922
import java.io.InputStream;
@@ -22,13 +25,16 @@
2225
import javafx.animation.KeyFrame;
2326
import javafx.animation.KeyValue;
2427
import javafx.animation.Timeline;
28+
import javafx.beans.property.BooleanProperty;
2529
import javafx.beans.property.DoubleProperty;
30+
import javafx.beans.property.SimpleBooleanProperty;
2631
import javafx.fxml.FXML;
2732
import javafx.scene.Node;
2833
import javafx.scene.control.Button;
2934
import javafx.scene.control.Labeled;
3035
import javafx.scene.image.Image;
3136
import javafx.scene.image.ImageView;
37+
import javafx.scene.input.MouseEvent;
3238
import javafx.scene.layout.HBox;
3339
import javafx.scene.layout.VBox;
3440
import 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
/**

ui/src/main/resources/edu/wpi/grip/ui/pipeline/Step.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
</graphic>
8080
</Label>
8181
<Separator orientation="HORIZONTAL" />
82-
<Button fx:id="expand" onMouseClicked="#expand" styleClass="expand"
82+
<Button fx:id="expand" onMouseClicked="#toggleExpand" styleClass="expand"
8383
maxWidth="Infinity" prefHeight="0" HBox.hgrow="ALWAYS">
8484
<graphic>
8585
<ImageView fx:id="expandIcon">

0 commit comments

Comments
 (0)