Example usage for com.google.common.collect TreeRangeMap get

List of usage examples for com.google.common.collect TreeRangeMap get

Introduction

In this page you can find the example usage for com.google.common.collect TreeRangeMap get.

Prototype

@Override
    @Nullable
    public V get(K key) 

Source Link

Usage

From source file:org.sleuthkit.autopsy.timeline.ui.detailview.DetailsChartLane.java

/**
 * Given information about the current layout pass so far and about a
 * particular node, compute the y position of that node.
 *
 *
 * @param yMin    the smallest (towards the top of the screen) y position to
 *                consider/*from   w w w . j av a 2  s  .co m*/
 * @param h       the height of the node we are trying to position
 * @param maxXatY a map from y ranges to the max x within that range. NOTE:
 *                This map will be updated to include the node in question.
 * @param xLeft   the left x-cord of the node to position
 * @param xRight  the left x-cord of the node to position
 *
 * @return the y position for the node in question.
 *
 *
 */
double computeYTop(double yMin, double h, TreeRangeMap<Double, Double> maxXatY, double xLeft, double xRight) {
    double yTop = yMin;
    double yBottom = yTop + h;
    //until the node is not overlapping any others try moving it down.
    boolean overlapping = true;
    while (overlapping) {
        overlapping = false;
        //check each pixel from bottom to top.
        for (double y = yBottom; y >= yTop; y -= MINIMUM_ROW_HEIGHT) {
            final Double maxX = maxXatY.get(y);
            if (maxX != null && maxX >= xLeft - MINIMUM_EVENT_NODE_GAP) {
                //if that pixel is already used
                //jump top to this y value and repeat until free slot is found.
                overlapping = true;
                yTop = y + MINIMUM_EVENT_NODE_GAP;
                yBottom = yTop + h;
                break;
            }
        }
    }
    maxXatY.put(Range.closed(yTop, yBottom), xRight);
    return yTop;
}

From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventDetailsChart.java

/**
 * layout the nodes in the given list, starting form the given minimum y
 * coordinate.//from   w w w .  j  a v  a  2s.  c  o m
 *
 * Layout the nodes representing events via the following algorithm.
 *
 * we start with a list of nodes (each representing an event) - sort the
 * list of nodes by span start time of the underlying event - initialize
 * empty map (maxXatY) from y-position to max used x-value - for each node:
 *
 * -- size the node based on its children (recursively)
 *
 * -- get the event's start position from the dateaxis
 *
 * -- to position node (1)check if maxXatY is to the left of the left x
 * coord: if maxXatY is less than the left x coord, good, put the current
 * node here, mark right x coord as maxXatY, go to next node ; if maxXatY
 * greater than start position, increment y position, do check(1) again
 * until maxXatY less than start position
 *
 * @param nodes collection of nodes to layout
 * @param minY  the minimum y coordinate to position the nodes at.
 */
double layoutEventBundleNodes(final Collection<? extends EventBundleNodeBase<?, ?, ?>> nodes,
        final double minY) {

    TreeRangeMap<Double, Double> treeRangeMap = TreeRangeMap.create();
    // maximum y values occupied by any of the given nodes,  updated as nodes are layed out.
    double localMax = minY;

    Set<String> activeQuickHidefilters = getController().getQuickHideFilters().stream()
            .filter(AbstractFilter::isActive).map(DescriptionFilter::getDescription)
            .collect(Collectors.toSet());
    //for each node do a recursive layout to size it and then position it in first available slot
    for (EventBundleNodeBase<?, ?, ?> bundleNode : nodes) {
        //is the node hiden by a quick hide filter?
        boolean quickHide = activeQuickHidefilters.contains(bundleNode.getDescription());
        if (quickHide) {
            //hide it and skip layout
            bundleNode.setVisible(false);
            bundleNode.setManaged(false);
        } else {
            bundleLayoutHelper(bundleNode);
            //get computed height and width
            double h = bundleNode.getBoundsInLocal().getHeight();
            double w = bundleNode.getBoundsInLocal().getWidth();
            //get left and right x coords from axis plus computed width
            double xLeft = getXForEpochMillis(bundleNode.getStartMillis())
                    - bundleNode.getLayoutXCompensation();
            double xRight = xLeft + w + MINIMUM_EVENT_NODE_GAP;

            //initial test position
            double yTop = minY;

            if (oneEventPerRow.get()) {
                // if onePerRow, just put it at end
                yTop = (localMax + MINIMUM_EVENT_NODE_GAP);
            } else {
                double yBottom = yTop + h;

                //until the node is not overlapping any others try moving it down.
                boolean overlapping = true;
                while (overlapping) {
                    overlapping = false;
                    //check each pixel from bottom to top.
                    for (double y = yBottom; y >= yTop; y--) {
                        final Double maxX = treeRangeMap.get(y);
                        if (maxX != null && maxX >= xLeft - MINIMUM_EVENT_NODE_GAP) {
                            //if that pixel is already used
                            //jump top to this y value and repeat until free slot is found.
                            overlapping = true;
                            yTop = y + MINIMUM_EVENT_NODE_GAP;
                            yBottom = yTop + h;
                            break;
                        }
                    }
                }
                treeRangeMap.put(Range.closed(yTop, yBottom), xRight);
            }

            localMax = Math.max(yTop + h, localMax);

            if ((xLeft != bundleNode.getLayoutX()) || (yTop != bundleNode.getLayoutY())) {

                //animate node to new position
                Timeline timeline = new Timeline(
                        new KeyFrame(Duration.millis(100), new KeyValue(bundleNode.layoutXProperty(), xLeft),
                                new KeyValue(bundleNode.layoutYProperty(), yTop)));
                timeline.setOnFinished((ActionEvent event) -> {
                    requestChartLayout();
                });
                timeline.play();
            }
        }
    }
    return localMax; //return new max
}