Ejemplo n.º 1
0
  /**
   * ------------------------------------------------------ Realculates the outer bounds of this
   * container.
   *
   * @param bounds the (returned) outer bounds
   *     ------------------------------------------------------
   */
  protected void reCalcBounds(MiBounds bounds) {
    getBounds(bounds);

    if (!autoLayoutEnabled) {
      return;
    }

    MiBounds contents = MiBounds.newBounds();
    MiMargins insetMargins = getInsetMargins();
    MiMargins cellMargins = getCellMargins();

    super.reCalcBounds(contents);
    if (contents.isReversed()) {
      contents.copy(bounds);
      if (contents.isReversed()) {
        contents.setBounds(0, 0, 0, 0);
        contents.addMargins(insetMargins);
        contents.addMargins(cellMargins);
        contents.addMargins(getMargins(tmpMargins));
      } else if ((contents.getWidth()
              < insetMargins.getWidth()
                  + getMargins(tmpMargins).getWidth()
                  + cellMargins.getWidth())
          || (contents.getHeight()
              < insetMargins.getHeight()
                  + getMargins(tmpMargins).getHeight()
                  + cellMargins.getHeight())) {
        contents.setWidth(
            insetMargins.getWidth() + getMargins(tmpMargins).getWidth() + cellMargins.getWidth());
        contents.setHeight(
            insetMargins.getHeight()
                + getMargins(tmpMargins).getHeight()
                + cellMargins.getHeight());
      }
      bounds.copy(contents);
    } else {
      // SUPER CLASS DOES THIS contents.addMargins(insetMargins);
      contents.addMargins(cellMargins);
      // SUPER CLASS DOES THIS contents.addMargins(getMargins(tmpMargins));
    }

    if ((autoLayoutRule == MAKE_CONTAINER_SAME_SIZE_AS_CONTENTS)) {
      bounds.copy(contents);
    } else if ((autoLayoutRule == MAKE_CONTAINER_SAME_SIZE_OR_BIGGER_THAN_CONTENTS)) {
      if (!contents.isContainedIn(bounds)) bounds.copy(contents);
    } else if ((autoLayoutRule
        == MAKE_CONTAINER_SAME_SIZE_AS_CONTENTS_OR_OVERRIDDEN_PREFERRED_SIZE)) {
      bounds.copy(contents);
      if (hasOverriddenPreferredSize()) {
        bounds.setSize(getPreferredSize(new MiSize()));
      }
    }

    if (hasFixedWidthOrHeight) {
      getBounds(contents);

      if (hasFixedWidth()) {
        bounds.xmin = contents.xmin;
        bounds.xmax = contents.xmax;
      }
      if (hasFixedHeight()) {
        bounds.ymin = contents.ymin;
        bounds.ymax = contents.ymax;
      }
    }
    MiBounds.freeBounds(contents);
  }
Ejemplo n.º 2
0
  protected void layoutParts(int h_sizing, int v_sizing, int h_justification, int v_justification) {
    if (graphics != null) graphics.getPreferredSize(tmpSize);
    else if (strValue != null) attributes.getFont().getSize(strValue, tmpSize);
    else tmpSize.zeroOut();

    MiBounds cellBounds = MiBounds.newBounds();
    cellBounds.setSize(tmpSize);
    MiBounds theInnerBounds = tmpBounds;
    theInnerBounds.copy(innerBounds);
    if (margins != null) theInnerBounds.subtractMargins(margins);
    cellBounds.setCenterX(theInnerBounds.getCenterX());
    cellBounds.setCenterY(theInnerBounds.getCenterY());
    switch (h_sizing) {
      case Mi_EXPAND_TO_FILL:
        cellBounds.setWidth(theInnerBounds.getWidth());
        break;
      case Mi_SAME_SIZE:
        cellBounds.setWidth(theInnerBounds.getWidth());
        break;
      case Mi_NONE:
      default:
        break;
    }

    switch (v_sizing) {
      case Mi_EXPAND_TO_FILL:
        cellBounds.setHeight(theInnerBounds.getHeight());
        break;
      case Mi_SAME_SIZE:
        cellBounds.setHeight(theInnerBounds.getHeight());
        break;
      case Mi_NONE:
      default:
        break;
    }
    switch (h_justification) {
      case Mi_JUSTIFIED:
      case Mi_CENTER_JUSTIFIED:
      case Mi_NONE:
        cellBounds.setCenterX(theInnerBounds.getCenterX());
        break;
      case Mi_LEFT_JUSTIFIED:
        cellBounds.translateXminTo(theInnerBounds.getXmin());
        break;
      case Mi_RIGHT_JUSTIFIED:
        cellBounds.translateXmaxTo(theInnerBounds.getXmax());
        break;
    }

    switch (v_justification) {
      case Mi_JUSTIFIED:
      case Mi_CENTER_JUSTIFIED:
      case Mi_NONE:
        cellBounds.setCenterY(theInnerBounds.getCenterY());
        break;
      case Mi_BOTTOM_JUSTIFIED:
        cellBounds.translateYminTo(theInnerBounds.getYmin());
        break;
      case Mi_TOP_JUSTIFIED:
        cellBounds.translateYmaxTo(theInnerBounds.getYmax());
        break;
    }

    if (graphics != null) {
      graphics.setBounds(cellBounds);
      if (!graphics.hasValidLayout()) {
        graphics.validateLayout();
      }
    } else {
      innerBounds.copy(cellBounds);
    }
    MiBounds.freeBounds(cellBounds);
  }