コード例 #1
0
  private static int getMin2(DimensionInfo info, int componentIndex) {
    int s;
    if ((info.getSizePolicy(componentIndex) & 1) != 0) {
      s = info.getMinimumWidth(componentIndex);
    } else {
      s = Math.max(info.getMinimumWidth(componentIndex), info.getPreferredWidth(componentIndex));
    }

    return s;
  }
コード例 #2
0
  private int[] getMinOrPrefSizes(DimensionInfo info, boolean min) {
    int[] widths = new int[info.getCellCount()];

    int toProcess;
    for (toProcess = 0; toProcess < widths.length; ++toProcess) {
      widths[toProcess] = this.myMinCellSize;
    }

    for (toProcess = info.getComponentCount() - 1; toProcess >= 0; --toProcess) {
      if (info.getSpan(toProcess) == 1) {
        int i =
            min
                ? getMin2(info, toProcess)
                : Math.max(info.getMinimumWidth(toProcess), info.getPreferredWidth(toProcess));
        int size = info.getCell(toProcess);
        int span = countGap(info, size, info.getSpan(toProcess));
        i = Math.max(i - span, 0);
        widths[size] = Math.max(widths[size], i);
      }
    }

    updateSizesFromChildren(info, min, widths);
    boolean[] priority = new boolean[info.getCellCount()];
    for (int i = info.getComponentCount() - 1; i >= 0; --i) {
      int size =
          min ? getMin2(info, i) : Math.max(info.getMinimumWidth(i), info.getPreferredWidth(i));
      int span = info.getSpan(i);
      int cell = info.getCell(i);
      int gap = countGap(info, cell, span);
      size = Math.max(size - gap, 0);
      Arrays.fill(priority, false);
      int curSize = 0;

      for (int higherPriorityCells = 0; higherPriorityCells < span; ++higherPriorityCells) {
        curSize += widths[higherPriorityCells + cell];
        priority[higherPriorityCells + cell] = true;
      }

      if (curSize < size) {
        boolean[] higherPriorityCells = new boolean[priority.length];
        this.getCellsWithHigherPriorities(info, priority, higherPriorityCells, false, widths);
        distribute(higherPriorityCells, info, size - curSize, widths);
      }
    }

    return widths;
  }