Skip to content

Commit eedf0c1

Browse files
committed
Fix preview order
1 parent f880ec2 commit eedf0c1

1 file changed

Lines changed: 9 additions & 29 deletions

File tree

ui/src/main/java/edu/wpi/grip/ui/preview/PreviewsController.java

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22

33
import com.google.common.eventbus.EventBus;
44
import com.google.common.eventbus.Subscribe;
5+
import com.google.common.math.IntMath;
56
import edu.wpi.grip.core.OutputSocket;
67
import edu.wpi.grip.core.Pipeline;
78
import edu.wpi.grip.core.Source;
89
import edu.wpi.grip.core.Step;
910
import edu.wpi.grip.core.events.SocketPreviewChangedEvent;
1011
import edu.wpi.grip.core.events.StepMovedEvent;
1112
import edu.wpi.grip.ui.pipeline.PipelineController;
12-
import edu.wpi.grip.ui.pipeline.StepController;
1313
import edu.wpi.grip.ui.pipeline.source.SourceController;
1414
import edu.wpi.grip.ui.util.GRIPPlatform;
1515
import javafx.fxml.FXML;
1616
import javafx.scene.layout.HBox;
1717

1818
import javax.inject.Inject;
1919
import javax.inject.Singleton;
20-
import java.util.*;
21-
import java.util.stream.Collectors;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import java.util.Stack;
2223

2324
/**
2425
* Controller for a container that automatically shows previews of all sockets marked as "previewed".
@@ -43,23 +44,6 @@ public class PreviewsController {
4344

4445
private final List<OutputSocket<?>> previewedSockets = new ArrayList<>();
4546

46-
private Collection<SocketPreviewView<?>> getPreviewsForStep(Step step) {
47-
return previewBox.getChildren()
48-
.stream()
49-
.map(p -> (SocketPreviewView<?>) p)
50-
.filter(p -> Arrays.asList(step.getOutputSockets())
51-
.stream()
52-
.anyMatch(outputSocket -> outputSocket.equals(p.getSocket())))
53-
.collect(Collectors.toList());
54-
}
55-
56-
private OptionalInt getFirstPreviewOf(Step step) {
57-
return getPreviewsForStep(step).stream()
58-
.mapToInt(previewView -> previewBox.getChildren().indexOf(previewView))
59-
.filter(i -> i != -1)
60-
.min();
61-
}
62-
6347
/**
6448
* This function is called when a step moves in the pipeline to adjust the positions of any open previews it has
6549
* to reflect the new order of the pipeline.
@@ -230,17 +214,13 @@ private int getIndexInPreviewsOfAStepSocket(OutputSocket<?> socket) {
230214
int numbOfSourcePreviews = getNumbOfSourcePreviews();//Count how many *source* previews (not *step* previews) are currently displayed
231215

232216
final Step socketStep = socket.getStep().get();//The pipeline step associated with the socket whose preview has changed
233-
final StepController stepView = this.pipelineController.findStepController(socketStep);//The gui object that displays the socketStep
234-
int indexOfStep = this.pipeline.getSteps().indexOf(stepView); //The index of the step that has the socket in the pipeline
217+
int indexOfStep = this.pipeline.getSteps().indexOf(socketStep); //The index of the step that has the socket in the pipeline
235218

236219
//Start at the first non-source socket in the list of previewed sockets
237-
int indexInPreviews = numbOfSourcePreviews;
238-
239-
while ((this.previewedSockets.size() > indexInPreviews)//While there are sockets in the list of previewed sockets yet to be examined
240-
&& ((this.pipeline.getSteps().indexOf(this.pipelineController.findStepController(this.previewedSockets.get(indexInPreviews).getStep().get()))) < indexOfStep)) {//...AND the socket at this index in the list of displayed sockets has an index in the pipeline less than the socket passed in as "socket"
241-
indexInPreviews++;
242-
}
243-
return indexInPreviews;
220+
long indexInPreviews =
221+
// The socket at this index in the list of displayed sockets has an index in the pipeline less than the socket passed in as "socket"
222+
this.previewedSockets.stream().filter(outSocket -> this.pipeline.getSteps().indexOf(outSocket.getStep().get()) < indexOfStep).count();
223+
return IntMath.checkedAdd(Math.toIntExact(indexInPreviews), numbOfSourcePreviews);
244224
}
245225

246226
/**

0 commit comments

Comments
 (0)