示例#1
0
  private void normalizeRun(final Run run, double runOffset) {
    if (getOrientation() == HORIZONTAL) {
      // horizontal
      ArrayList<Node> rownodes = new ArrayList();
      run.width = (run.rects.size() - 1) * snapSpace(getHgap());
      for (int i = 0, max = run.rects.size(); i < max; i++) {
        LayoutRect lrect = run.rects.get(i);
        rownodes.add(lrect.node);
        run.width += lrect.width;
        lrect.y = runOffset;
      }
      run.height = computeMaxPrefAreaHeight(rownodes, marginAccessor, getRowValignment());
      run.baselineOffset =
          getRowValignment() == VPos.BASELINE
              ? getAreaBaselineOffset(
                  rownodes,
                  marginAccessor,
                  new Callback<Integer, Double>() {

                    public Double call(Integer i) {
                      return run.rects.get(i).width;
                    }
                  },
                  run.height,
                  true)
              : 0;

    } else {
      // vertical
      run.height = (run.rects.size() - 1) * snapSpace(getVgap());
      double maxw = 0;
      for (int i = 0, max = run.rects.size(); i < max; i++) {
        LayoutRect lrect = run.rects.get(i);
        run.height += lrect.height;
        lrect.x = runOffset;
        maxw = Math.max(maxw, lrect.width);
      }

      run.width = maxw;
      run.baselineOffset = run.height;
    }
  }
示例#2
0
  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;
  }