Exemplo n.º 1
0
 public void addLayoutComponent(Component comp, Object constraints) {
   GridConstraints c = (GridConstraints) constraints;
   int row = c.getRow();
   int rowSpan = c.getRowSpan();
   int rowCount = this.getRowCount();
   if (row >= 0 && row < rowCount) {
     if (row + rowSpan - 1 >= rowCount) {
       throw new IllegalArgumentException(
           "wrong row span: " + rowSpan + "; row=" + row + " rowCount=" + rowCount);
     } else {
       int column = c.getColumn();
       int colSpan = c.getColSpan();
       int columnCount = this.getColumnCount();
       if (column >= 0 && column < columnCount) {
         if (column + colSpan - 1 >= columnCount) {
           throw new IllegalArgumentException(
               "wrong col span: "
                   + colSpan
                   + "; column="
                   + column
                   + " columnCount="
                   + columnCount);
         } else {
           super.addLayoutComponent(comp, constraints);
         }
       } else {
         throw new IllegalArgumentException("wrong column: " + column);
       }
     }
   } else {
     throw new IllegalArgumentException("wrong row: " + row);
   }
 }
Exemplo n.º 2
0
  private int checkSetSizesFromParent(Container container, Insets insets) {
    int skipLayout = 0;
    GridLayoutManager parentGridLayout = null;
    GridConstraints parentGridConstraints = null;
    Container parent = container.getParent();
    if (parent != null) {
      if (parent.getLayout() instanceof GridLayoutManager) {
        parentGridLayout = (GridLayoutManager) parent.getLayout();
        parentGridConstraints = parentGridLayout.getConstraintsForComponent(container);
      } else {
        Container col = parent.getParent();
        if (col != null && col.getLayout() instanceof GridLayoutManager) {
          parentGridLayout = (GridLayoutManager) col.getLayout();
          parentGridConstraints = parentGridLayout.getConstraintsForComponent(parent);
        }
      }
    }

    if (parentGridLayout != null && parentGridConstraints.isUseParentLayout()) {
      int i;
      if (this.myRowStretches.length == parentGridConstraints.getRowSpan()) {
        int row = parentGridConstraints.getRow();
        this.myYs[0] = insets.top + this.myMargin.top;
        this.myHeights[0] = parentGridLayout.myHeights[row] - this.myYs[0];

        for (i = 1; i < this.myRowStretches.length; ++i) {
          this.myYs[i] = parentGridLayout.myYs[i + row] - parentGridLayout.myYs[row];
          this.myHeights[i] = parentGridLayout.myHeights[i + row];
        }

        this.myHeights[this.myRowStretches.length - 1] -= insets.bottom + this.myMargin.bottom;
        skipLayout |= 1;
      }

      if (this.myColumnStretches.length == parentGridConstraints.getColSpan()) {
        int column = parentGridConstraints.getColumn();
        this.myXs[0] = insets.left + this.myMargin.left;
        this.myWidths[0] = parentGridLayout.myWidths[column] - this.myXs[0];

        for (i = 1; i < this.myColumnStretches.length; ++i) {
          this.myXs[i] = parentGridLayout.myXs[i + column] - parentGridLayout.myXs[column];
          this.myWidths[i] = parentGridLayout.myWidths[i + column];
        }

        this.myWidths[this.myColumnStretches.length - 1] -= insets.right + this.myMargin.right;
        skipLayout |= 2;
      }
    }

    return skipLayout;
  }