From e2b4f59738b12913b1bd69b85d497aa73b47e14f Mon Sep 17 00:00:00 2001 From: millmanorama Date: Fri, 6 Nov 2015 10:15:04 -0500 Subject: [PATCH] fix scroll speed management simplify scroll speed management, and scroll bounds WIP, cleanup cleanup and comments --- .../ui/detailview/DetailViewPane.java | 156 ++++++++---------- .../ui/detailview/EventDetailsChart.java | 5 +- 2 files changed, 74 insertions(+), 87 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/DetailViewPane.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/DetailViewPane.java index a881b4ff5a..e9f184c0bf 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/DetailViewPane.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/DetailViewPane.java @@ -54,8 +54,6 @@ import static javafx.scene.input.KeyCode.PAGE_DOWN; import static javafx.scene.input.KeyCode.PAGE_UP; import static javafx.scene.input.KeyCode.UP; import javafx.scene.input.KeyEvent; -import javafx.scene.input.MouseEvent; -import javafx.scene.input.ScrollEvent; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.Priority; @@ -93,53 +91,91 @@ public class DetailViewPane extends AbstractVisualizationPane>> treeSelectionModel; + private static final double LINE_SCROLL_PERCENTAGE = .10; + private static final double PAGE_SCROLL_PERCENTAGE = .70; - //these three could be injected from fxml but it was causing npe's private final DateAxis dateAxis = new DateAxis(); - private final Axis verticalAxis = new EventAxis(); + private final ScrollBar vertScrollBar = new ScrollBar(); + private final Region scrollBarSpacer = new Region(); + + private MultipleSelectionModel>> treeSelectionModel; + private final ObservableList> highlightedNodes = FXCollections.synchronizedObservableList(FXCollections.observableArrayList()); //private access to barchart data private final Map> eventTypeToSeriesMap = new ConcurrentHashMap<>(); - private final ScrollBar vertScrollBar = new ScrollBar(); - - private final Region region = new Region(); - - private final ObservableList> highlightedNodes = FXCollections.synchronizedObservableList(FXCollections.observableArrayList()); - public ObservableList> getEventBundles() { return chart.getEventBundles(); } + public DetailViewPane(TimeLineController controller, Pane partPane, Pane contextPane, Region bottomLeftSpacer) { + super(controller, partPane, contextPane, bottomLeftSpacer); + settingsNodes = new ArrayList<>(new DetailViewSettingsPane().getChildrenUnmodifiable()); - public DetailViewPane(TimeLineController controller, Pane partPane, Pane contextPane, Region spacer) { - super(controller, partPane, contextPane, spacer); + //initialize chart; chart = new EventDetailsChart(controller, dateAxis, verticalAxis, selectedNodes); - setChartClickHandler(); + setChartClickHandler(); //can we push this into chart chart.setData(dataSets); setCenter(chart); - - chart.setPrefHeight(USE_COMPUTED_SIZE); - - settingsNodes = new ArrayList<>(new DetailViewSettingsPane().getChildrenUnmodifiable()); - - vertScrollBar.setOrientation(Orientation.VERTICAL); - VBox vBox = new VBox(); - VBox.setVgrow(vertScrollBar, Priority.ALWAYS); - vBox.getChildren().add(vertScrollBar); - vBox.getChildren().add(region); - setRight(vBox); - + //bind layout fo axes and spacers + dateAxis.setTickLabelGap(0); dateAxis.setAutoRanging(false); - region.minHeightProperty().bind(dateAxis.heightProperty()); - vertScrollBar.visibleAmountProperty().bind(chart.heightProperty().multiply(100).divide(chart.maxVScrollProperty())); - requestLayout(); + dateAxis.setTickLabelsVisible(false); + dateAxis.getTickMarks().addListener((Observable observable) -> layoutDateLabels()); + dateAxis.getTickSpacing().addListener(observable -> layoutDateLabels()); + bottomLeftSpacer.minWidthProperty().bind(verticalAxis.widthProperty().add(verticalAxis.tickLengthProperty())); + bottomLeftSpacer.prefWidthProperty().bind(verticalAxis.widthProperty().add(verticalAxis.tickLengthProperty())); + bottomLeftSpacer.maxWidthProperty().bind(verticalAxis.widthProperty().add(verticalAxis.tickLengthProperty())); + + scrollBarSpacer.minHeightProperty().bind(dateAxis.heightProperty()); + + //configure scrollbar + vertScrollBar.setOrientation(Orientation.VERTICAL); + vertScrollBar.maxProperty().bind(chart.maxVScrollProperty().subtract(chart.heightProperty())); + vertScrollBar.visibleAmountProperty().bind(chart.heightProperty()); + vertScrollBar.visibleProperty().bind(vertScrollBar.visibleAmountProperty().greaterThanOrEqualTo(0)); + VBox.setVgrow(vertScrollBar, Priority.ALWAYS); + setRight(new VBox(vertScrollBar, scrollBarSpacer)); + + //interpret scroll events to the scrollBar + this.setOnScroll(scrollEvent -> + vertScrollBar.valueProperty().set(clampScroll(vertScrollBar.getValue() - scrollEvent.getDeltaY()))); + + //request focus for keyboard scrolling + setOnMouseClicked(mouseEvent -> requestFocus()); + + //interpret scroll related keys to scrollBar + this.setOnKeyPressed((KeyEvent t) -> { + switch (t.getCode()) { + case PAGE_UP: + incrementScrollValue(-PAGE_SCROLL_PERCENTAGE); + t.consume(); + break; + case PAGE_DOWN: + incrementScrollValue(PAGE_SCROLL_PERCENTAGE); + t.consume(); + break; + case KP_UP: + case UP: + incrementScrollValue(-LINE_SCROLL_PERCENTAGE); + t.consume(); + break; + case KP_DOWN: + case DOWN: + incrementScrollValue(LINE_SCROLL_PERCENTAGE); + t.consume(); + break; + } + }); + + //scrollbar value change handler. This forwards changes in scroll bar to chart + this.vertScrollBar.valueProperty().addListener(observable -> chart.setVScroll(vertScrollBar.getValue())); + + //maintain highlighted effect on correct nodes highlightedNodes.addListener((ListChangeListener.Change> change) -> { - while (change.next()) { change.getAddedSubList().forEach(node -> { node.applyHighlightEffect(true); @@ -149,71 +185,24 @@ public class DetailViewPane extends AbstractVisualizationPane { - requestFocus(); - }); - - //These scroll related handlers don't affect any other view or the model, so they are handled internally - //mouse wheel scroll handler - this.onScrollProperty().set((ScrollEvent t) -> { - vertScrollBar.valueProperty().set(Math.max(0, Math.min(100, vertScrollBar.getValue() - t.getDeltaY() / 200.0))); - }); - - this.setOnKeyPressed((KeyEvent t) -> { - switch (t.getCode()) { - case PAGE_UP: - incrementScrollValue(-70); - break; - case PAGE_DOWN: - incrementScrollValue(70); - break; - case KP_UP: - case UP: - incrementScrollValue(-10); - break; - case KP_DOWN: - case DOWN: - incrementScrollValue(10); - break; - } - t.consume(); - }); - - //scrollbar handler - this.vertScrollBar.valueProperty().addListener((o, oldValue, newValue) -> { - chart.setVScroll(newValue.doubleValue() / 100.0); - }); - spacer.minWidthProperty().bind(verticalAxis.widthProperty().add(verticalAxis.tickLengthProperty())); - spacer.prefWidthProperty().bind(verticalAxis.widthProperty().add(verticalAxis.tickLengthProperty())); - spacer.maxWidthProperty().bind(verticalAxis.widthProperty().add(verticalAxis.tickLengthProperty())); - - dateAxis.setTickLabelsVisible(false); - - dateAxis.getTickMarks().addListener((Observable observable) -> { - layoutDateLabels(); - }); - dateAxis.getTickSpacing().addListener((Observable observable) -> { - layoutDateLabels(); - }); - - dateAxis.setTickLabelGap(0); selectedNodes.addListener((Observable observable) -> { highlightedNodes.clear(); selectedNodes.stream().forEach((tn) -> { - for (EventBundleNodeBase n : chart.getNodes((EventBundleNodeBase t) -> t.getDescription().equals(tn.getDescription()))) { highlightedNodes.add(n); } }); }); - } - private void incrementScrollValue(int factor) { - vertScrollBar.valueProperty().set(Math.max(0, Math.min(100, vertScrollBar.getValue() + factor * (chart.getHeight() / chart.maxVScrollProperty().get())))); + private void incrementScrollValue(double factor) { + vertScrollBar.valueProperty().set(clampScroll(vertScrollBar.getValue() + factor * chart.getHeight())); + } + + private Double clampScroll(Double value) { + return Math.max(0, Math.min(vertScrollBar.getMax() + 50, value)); } public void setSelectionModel(MultipleSelectionModel>> selectionModel) { @@ -472,5 +461,4 @@ public class DetailViewPane extends AbstractVisualizationPane imp return getNodes(x -> true); } - synchronized void setVScroll(double d) { - final double h = maxY.get() - (getHeight() * .9); - nodeGroup.setTranslateY(-d * h); + synchronized void setVScroll(double vScrollValue) { + nodeGroup.setTranslateY(-vScrollValue); } private void clearGuideLine() {