public void addSnapshotComponent(final JComponent parent,
                                   final JComponent child,
                                   final RadContainer container,
                                   final RadComponent component) {
    Dimension gridBagSize = getGridBagSize(parent);

    // logic copied from GridBagLayout.java

    GridBagLayout gridBag = (GridBagLayout)parent.getLayout();
    final GridBagConstraints constraints = gridBag.getConstraints(child);

    int curX = constraints.gridx;
    int curY = constraints.gridy;
    int curWidth = constraints.gridwidth;
    int curHeight = constraints.gridheight;
    int px;
    int py;

    /* If x or y is negative, then use relative positioning: */
    if (curX < 0 && curY < 0) {
      if (myLastSnapshotRow >= 0) {
        curY = myLastSnapshotRow;
      }
      else if (myLastSnapshotCol >= 0) {
        curX = myLastSnapshotCol;
      }
      else {
        curY = 0;
      }
    }

    if (curX < 0) {
      if (curHeight <= 0) {
        curHeight += gridBagSize.height - curY;
        if (curHeight < 1) {
          curHeight = 1;
        }
      }

      px = 0;
      for (int i = curY; i < (curY + curHeight); i++) {
        px = Math.max(px, mySnapshotXMax[i]);
      }

      curX = px - curX - 1;
      if (curX < 0) {
        curX = 0;
      }
    }
    else if (curY < 0) {
      if (curWidth <= 0) {
        curWidth += gridBagSize.width - curX;
        if (curWidth < 1) {
          curWidth = 1;
        }
      }

      py = 0;
      for (int i = curX; i < (curX + curWidth); i++) {
        py = Math.max(py, mySnapshotYMax[i]);
      }

      curY = py - curY - 1;
      if (curY < 0) {
        curY = 0;
      }
    }

    if (curWidth <= 0) {
      curWidth += gridBagSize.width - curX;
      if (curWidth < 1) {
        curWidth = 1;
      }
    }

    if (curHeight <= 0) {
      curHeight += gridBagSize.height - curY;
      if (curHeight < 1) {
        curHeight = 1;
      }
    }

    /* Adjust xMax and yMax */
    for (int i = curX; i < (curX + curWidth); i++) {
      mySnapshotYMax[i] = curY + curHeight;
    }
    for (int i = curY; i < (curY + curHeight); i++) {
      mySnapshotXMax[i] = curX + curWidth;
    }

    /* Make negative sizes start a new row/column */
    if (constraints.gridheight == 0 && constraints.gridwidth == 0) {
      myLastSnapshotRow = myLastSnapshotCol = -1;
    }
    if (constraints.gridheight == 0 && myLastSnapshotRow < 0) {
      myLastSnapshotCol = curX + curWidth;
    }
    else if (constraints.gridwidth == 0 && myLastSnapshotCol < 0) {
      myLastSnapshotRow = curY + curHeight;
    }

    component.getConstraints().setColumn(curX);
    component.getConstraints().setRow(curY);
    component.getConstraints().setColSpan(curWidth);
    component.getConstraints().setRowSpan(curHeight);

    if (constraints.weightx >= 1.0) {
      component.getConstraints().setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW);
    }
    else {
      component.getConstraints().setHSizePolicy(0);
    }
    if (constraints.weighty >= 1.0) {
      component.getConstraints().setVSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW);
    }
    else {
      component.getConstraints().setVSizePolicy(0);
    }
    if (constraints.insets.right == 0 && constraints.insets.top == 0 && constraints.insets.bottom == 0) {
      component.getConstraints().setIndent(constraints.insets.left / Util.DEFAULT_INDENT);
    }

    component.getConstraints().setAnchor(convertAnchor(constraints));
    component.getConstraints().setFill(convertFill(constraints));
    component.setCustomLayoutConstraints(constraints.clone());
    container.addComponent(component);
  }
public void addSnapshotComponent(final JComponent parent,
                                   final JComponent child,
                                   final RadContainer container,
                                   final RadComponent component)