Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ScrollingLaneWrapper.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2016 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.timeline.ui.detailview;
20 
21 import javafx.application.Platform;
22 import javafx.beans.Observable;
23 import javafx.geometry.Orientation;
24 import javafx.scene.control.ScrollBar;
25 import javafx.scene.input.KeyEvent;
26 import javafx.scene.layout.BorderPane;
27 import javafx.scene.layout.Priority;
28 import javafx.scene.layout.Region;
29 import javafx.scene.layout.VBox;
30 
34 class ScrollingLaneWrapper extends BorderPane {
35 
36  private static final double LINE_SCROLL_PERCENTAGE = .10;
37  private static final double PAGE_SCROLL_PERCENTAGE = .70;
38  private final ScrollBar vertScrollBar = new ScrollBar();
39  private final Region scrollBarSpacer = new Region();
40  private final DetailsChartLane<?> chart;
41 
42  ScrollingLaneWrapper(DetailsChartLane<?> center) {
43  super(center);
44  this.chart = center;
45 
46  scrollBarSpacer.minHeightProperty().bind(chart.getXAxis().heightProperty());
47 
48  //configure scrollbar
49  vertScrollBar.setOrientation(Orientation.VERTICAL);
50  vertScrollBar.maxProperty().bind(chart.maxVScrollProperty().subtract(chart.heightProperty()));
51  vertScrollBar.visibleAmountProperty().bind(chart.heightProperty());
52  vertScrollBar.visibleProperty().bind(vertScrollBar.visibleAmountProperty().greaterThanOrEqualTo(0));
53  VBox.setVgrow(vertScrollBar, Priority.ALWAYS);
54  setRight(new VBox(vertScrollBar, scrollBarSpacer));
55 
56  //scrollbar value change handler. This forwards changes in scroll bar to chart
57  this.vertScrollBar.valueProperty().addListener((Observable observable) -> {
58  chart.setVScroll(vertScrollBar.getValue());
59  });
60  //request focus for keyboard scrolling
61  setOnMouseClicked(mouseEvent -> requestFocus());
62 
63  //interpret scroll events to the scrollBar
64  this.setOnScroll(scrollEvent ->
65  vertScrollBar.valueProperty().set(clampScroll(vertScrollBar.getValue() - scrollEvent.getDeltaY())));
66 
67  //interpret scroll related keys to scrollBar
68  this.setOnKeyPressed((KeyEvent t) -> {
69  switch (t.getCode()) {
70  case PAGE_UP:
71  incrementScrollValue(-PAGE_SCROLL_PERCENTAGE);
72  t.consume();
73  break;
74  case PAGE_DOWN:
75  incrementScrollValue(PAGE_SCROLL_PERCENTAGE);
76  t.consume();
77  break;
78  case KP_UP:
79  case UP:
80  incrementScrollValue(-LINE_SCROLL_PERCENTAGE);
81  t.consume();
82  break;
83  case KP_DOWN:
84  case DOWN:
85  incrementScrollValue(LINE_SCROLL_PERCENTAGE);
86  t.consume();
87  break;
88  }
89  });
90  }
91 
92  void reset() {
93  Platform.runLater(() -> {
94  vertScrollBar.setValue(0);
95  });
96  }
97 
98  private void incrementScrollValue(double factor) {
99  vertScrollBar.valueProperty().set(clampScroll(vertScrollBar.getValue() + factor * chart.getHeight()));
100  }
101 
102  private Double clampScroll(Double value) {
103  return Math.max(0, Math.min(vertScrollBar.getMax() + 50, value));
104  }
105 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.