List of usage examples for javafx.collections ObservableList sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualization.java
/** iterate through the list of tick-marks building a two level structure of * replacement tick marl labels. (Visually) upper level has most * detailed/highest frequency part of date/time. Second level has rest of * date/time grouped by unchanging part. * eg:// ww w . j ava2 s.c o m * * * october-30_october-31_september-01_september-02_september-03 * * becomes * * _________30_________31___________01___________02___________03 * * _________october___________|_____________september___________ * * * NOTE: This method should only be invoked on the JFX thread */ public synchronized void layoutDateLabels() { //clear old labels branchPane.getChildren().clear(); leafPane.getChildren().clear(); //since the tickmarks aren't necessarily in value/position order, //make a clone of the list sorted by position along axis ObservableList<Axis.TickMark<X>> tickMarks = FXCollections.observableArrayList(getXAxis().getTickMarks()); tickMarks.sort( (Axis.TickMark<X> t, Axis.TickMark<X> t1) -> Double.compare(t.getPosition(), t1.getPosition())); if (tickMarks.isEmpty() == false) { //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 lastSeenBranchLabel = dateTime.branch; //cumulative width of the current branch label //x-positions (pixels) of the current branch and leaf labels double leafLabelX = 0; if (dateTime.branch.equals("")) { //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) { assignLeafLabel(new TwoPartDateTime(getTickMarkLabel(t.getValue())).leaf, spacing, leafLabelX, isTickBold(t.getValue())); leafLabelX += spacing; //increment x } } else { //there are two parts so ... //initialize additional state double branchLabelX = 0; double branchLabelWidth = 0; for (Axis.TickMark<X> t : tickMarks) { //for each tick //split the label into a TwoPartDateTime dateTime = new TwoPartDateTime(getTickMarkLabel(t.getValue())); //if we are still on the same branch if (lastSeenBranchLabel.equals(dateTime.branch)) { //increment branch width branchLabelWidth += spacing; } else {// we are on to a new branch, so ... assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX); //and then update label, x-pos, and width lastSeenBranchLabel = dateTime.branch; branchLabelX += branchLabelWidth; branchLabelWidth = spacing; } //add the label for the leaf (highest frequency part) assignLeafLabel(dateTime.leaf, spacing, leafLabelX, isTickBold(t.getValue())); //increment leaf position leafLabelX += spacing; } //we have reached end so add branch label for current branch assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX); } } //request layout since we have modified scene graph structure requestParentLayout(); }
From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualizationPane.java
/** * iterate through the list of tick-marks building a two level structure of * replacement tick marl labels. (Visually) upper level has most * detailed/highest frequency part of date/time. Second level has rest of * date/time grouped by unchanging part. eg: * * * october-30_october-31_september-01_september-02_september-03 * * becomes// w w w . ja va 2 s.c om * * _________30_________31___________01___________02___________03 * * _________october___________|_____________september___________ * * * NOTE: This method should only be invoked on the JFX thread */ public synchronized void layoutDateLabels() { //clear old labels branchPane.getChildren().clear(); leafPane.getChildren().clear(); //since the tickmarks aren't necessarily in value/position order, //make a clone of the list sorted by position along axis ObservableList<Axis.TickMark<X>> tickMarks = FXCollections.observableArrayList(getXAxis().getTickMarks()); tickMarks.sort( (Axis.TickMark<X> t, Axis.TickMark<X> t1) -> Double.compare(t.getPosition(), t1.getPosition())); if (tickMarks.isEmpty() == false) { //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 lastSeenBranchLabel = dateTime.branch; //cumulative width of the current branch label //x-positions (pixels) of the current branch and leaf labels double leafLabelX = 0; if (dateTime.branch.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) { assignLeafLabel(new TwoPartDateTime(getTickMarkLabel(t.getValue())).leaf, spacing, leafLabelX, isTickBold(t.getValue())); leafLabelX += spacing; //increment x } } else { //there are two parts so ... //initialize additional state double branchLabelX = 0; double branchLabelWidth = 0; for (Axis.TickMark<X> t : tickMarks) { //for each tick //split the label into a TwoPartDateTime dateTime = new TwoPartDateTime(getTickMarkLabel(t.getValue())); //if we are still on the same branch if (lastSeenBranchLabel.equals(dateTime.branch)) { //increment branch width branchLabelWidth += spacing; } else {// we are on to a new branch, so ... assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX); //and then update label, x-pos, and width lastSeenBranchLabel = dateTime.branch; branchLabelX += branchLabelWidth; branchLabelWidth = spacing; } //add the label for the leaf (highest frequency part) assignLeafLabel(dateTime.leaf, spacing, leafLabelX, isTickBold(t.getValue())); //increment leaf position leafLabelX += spacing; } //we have reached end so add branch label for current branch assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX); } } //request layout since we have modified scene graph structure requestParentLayout(); }