private List<Run> getRuns(double maxRunLength) { if (runs == null || maxRunLength != lastMaxRunLength) { computingRuns = true; lastMaxRunLength = maxRunLength; runs = new ArrayList(); double runLength = 0; double runOffset = 0; Run run = new Run(); double vgap = snapSpace(this.getVgap()); double hgap = snapSpace(this.getHgap()); final List<Node> children = getChildren(); for (int i = 0, size = children.size(); i < size; i++) { Node child = children.get(i); if (child.isManaged()) { LayoutRect nodeRect = new LayoutRect(); nodeRect.node = child; Insets margin = getMargin(child); nodeRect.width = computeChildPrefAreaWidth(child, margin); nodeRect.height = computeChildPrefAreaHeight(child, margin); double nodeLength = getOrientation() == HORIZONTAL ? nodeRect.width : nodeRect.height; if (runLength + nodeLength > maxRunLength && runLength > 0) { // wrap to next run *unless* its the only node in the run normalizeRun(run, runOffset); if (getOrientation() == HORIZONTAL) { // horizontal runOffset += run.height + vgap; } else { // vertical runOffset += run.width + hgap; } runs.add(run); runLength = 0; run = new Run(); } if (getOrientation() == HORIZONTAL) { // horizontal nodeRect.x = runLength; runLength += nodeRect.width + hgap; } else { // vertical nodeRect.y = runLength; runLength += nodeRect.height + vgap; } run.rects.add(nodeRect); } } // insert last run normalizeRun(run, runOffset); runs.add(run); computingRuns = false; } return runs; }