Example usage for javafx.collections.transformation SortedList get

List of usage examples for javafx.collections.transformation SortedList get

Introduction

In this page you can find the example usage for javafx.collections.transformation SortedList get.

Prototype

@Override
public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractTimelineChart.java

/**
 * Iterate through the list of tick-marks building a two level structure of
 * replacement tick mark labels. (Visually) upper level has most
 * detailed/highest frequency part of date/time (specific label). Second
 * level has rest of date/time grouped by unchanging part (contextual
 * label).//  w  ww .  ja  va  2  s  .c o  m
 *
 * eg:
 *
 * October-October-31_September-01_September-02_September-03
 *
 * becomes:
 *
 * _________30_________31___________01___________02___________03
 *
 * _________October___________|_____________September___________
 *
 */
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
protected synchronized void layoutDateLabels() {
    //clear old labels
    contextLabelPane.getChildren().clear();
    specificLabelPane.getChildren().clear();
    //since the tickmarks aren't necessarily in value/position order,
    //make a copy of the list sorted by position along axis
    SortedList<Axis.TickMark<X>> tickMarks = getXAxis().getTickMarks()
            .sorted(Comparator.comparing(Axis.TickMark::getPosition));

    if (tickMarks.isEmpty()) {
        /*
         * Since StackedBarChart does some funky animation/background thread
         * stuff, sometimes there are no tick marks even though there is
         * data. Dispatching another call to layoutDateLables() allows that
         * stuff time to run before we check a gain.
         */
        Platform.runLater(this::layoutDateLabels);
    } else {
        //get the spacing between ticks in the underlying axis
        double spacing = getTickSpacing();

        //initialize values from first tick
        TwoPartDateTime dateTime = new TwoPartDateTime(getTickMarkLabel(tickMarks.get(0).getValue()));
        String lastSeenContextLabel = dateTime.context;

        //x-positions (pixels) of the current branch and leaf labels
        double specificLabelX = 0;

        if (dateTime.context.isEmpty()) {
            //if there is only one part to the date (ie only year), just add a label for each tick
            for (Axis.TickMark<X> t : tickMarks) {
                addSpecificLabel(new TwoPartDateTime(getTickMarkLabel(t.getValue())).specifics, spacing,
                        specificLabelX, isTickBold(t.getValue()));
                specificLabelX += spacing; //increment x
            }
        } else {
            //there are two parts so ...
            //initialize additional state
            double contextLabelX = 0;
            double contextLabelWidth = 0;

            for (Axis.TickMark<X> t : tickMarks) {
                //split the label into a TwoPartDateTime
                dateTime = new TwoPartDateTime(getTickMarkLabel(t.getValue()));

                //if we are still in the same context
                if (lastSeenContextLabel.equals(dateTime.context)) {
                    //increment context width
                    contextLabelWidth += spacing;
                } else {// we are on to a new context, so ...
                    addContextLabel(lastSeenContextLabel, contextLabelWidth, contextLabelX);
                    //and then update label, x-pos, and width
                    lastSeenContextLabel = dateTime.context;
                    contextLabelX += contextLabelWidth;
                    contextLabelWidth = spacing;
                }
                //add the specific label (highest frequency part)
                addSpecificLabel(dateTime.specifics, spacing, specificLabelX, isTickBold(t.getValue()));

                //increment specific position
                specificLabelX += spacing;
            }
            //we have reached end so add label for current context
            addContextLabel(lastSeenContextLabel, contextLabelWidth, contextLabelX);
        }
    }
    //request layout since we have modified scene graph structure
    requestParentLayout();
}