Example usage for javafx.scene.control ScrollBar increment

List of usage examples for javafx.scene.control ScrollBar increment

Introduction

In this page you can find the example usage for javafx.scene.control ScrollBar increment.

Prototype

public void increment() 

Source Link

Document

Increments the value of the ScrollBar by the #unitIncrementProperty unitIncrement

Usage

From source file:org.sleuthkit.autopsy.imageanalyzer.gui.GroupPane.java

@ThreadConfined(type = ThreadType.UI)
private void scrollToFileID(final Long newFileID) {
    if (newFileID == null) {
        //scrolling to no file doesn't make sense, so abort.
        return;// www .ja v a 2  s.  c o  m
    }

    int selectedIndex = grouping.get().fileIds().indexOf(newFileID);

    if (selectedIndex == -1) {
        //somehow we got passed a file id that isn't in the curent group.
        //this should never happen, but if it does everything is going to fail, so abort.
        return;
    }

    Optional<ScrollBar> scrollBarOptional = getScrollBar();
    scrollBarOptional.ifPresent((ScrollBar scrollBar) -> {
        DrawableCell cell = cellMap.get(newFileID);

        //while there is no tile/cell for the given id, scroll based on index in group
        while (cell == null) {
            Integer minIndex = cellMap.keySet().stream().map(grouping.get().fileIds()::indexOf)
                    .min(Integer::compare).get();
            Integer maxIndex = cellMap.keySet().stream().map(grouping.get().fileIds()::indexOf)
                    .max(Integer::compare).get();

            if (selectedIndex < minIndex) {
                scrollBar.decrement();
            } else if (selectedIndex > maxIndex) {
                scrollBar.increment();
            } else {
                //sometimes the cellMap isn't up to date, so move the position arbitrarily to update the cellMap
                //TODO: this is clunky and slow, find a better way to do this
                scrollBar.adjustValue(.5);
            }
            cell = cellMap.get(newFileID);

        }

        final Bounds gridViewBounds = gridView.localToScene(gridView.getBoundsInLocal());

        Bounds tileBounds = cell.localToScene(cell.getBoundsInLocal());

        //while the cell is not within the visisble bounds of the gridview, scroll based on screen coordinates
        int i = 0;

        while (gridViewBounds.contains(tileBounds) == false && (i++ < 100)) {

            if (tileBounds.getMinY() < gridViewBounds.getMinY()) {
                scrollBar.decrement();
            } else if (tileBounds.getMaxY() > gridViewBounds.getMaxY()) {
                scrollBar.increment();
            }
            tileBounds = cell.localToScene(cell.getBoundsInLocal());
        }
    });
}