Ejemplo n.º 1
0
  // Return true if bounds of point extend beyond point
  public boolean getLineEndBounds(MiPart obj, MiBounds b, boolean start) {
    if (!(obj instanceof MiMultiPointShape)) return (false);

    MiAttributes attributes = obj.getAttributes();
    boolean changed = false;
    boolean styleExtendsBeyondEndOfLine = false;

    MiDistance size = 0;
    if (start) {
      int style = attributes.getLineStartStyle();
      if (style != Mi_NONE) {
        size = attributes.getLineStartSize();
        if (attributes.getLineEndsSizeFnOfLineWidth()) size += attributes.getLineWidth();

        styleExtendsBeyondEndOfLine |= stylesExtendsBeyondEndOfLine[style];
        changed = true;
        obj.getPoint(0, tmpPoint);
        b.setBounds(tmpPoint);
      }
    } else {
      int style = attributes.getLineEndStyle();
      if (style != Mi_NONE) {
        size = attributes.getLineEndSize();
        if (attributes.getLineEndsSizeFnOfLineWidth()) size += attributes.getLineWidth();

        styleExtendsBeyondEndOfLine |= stylesExtendsBeyondEndOfLine[style];
        changed = true;
        obj.getPoint(-1, tmpPoint);
        b.setBounds(tmpPoint);
      }
    }
    if (changed) {
      MiMultiPointShape shape = (MiMultiPointShape) obj;

      if (styleExtendsBeyondEndOfLine) {
        b.addMargins(size);
      } else if (shape.isVertical()) {
        b.setXmin(b.getXmin() - size);
        b.setXmax(b.getXmax() + size);
      } else if (shape.isHorizontal()) {
        b.setYmin(b.getYmin() - size);
        b.setYmax(b.getYmax() + size);
      } else {
        b.addMargins(size);
      }
    }

    return (changed);
  }
Ejemplo n.º 2
0
  /**
   * ------------------------------------------------------ Lays out the container's parts and it's
   * background shape.
   *
   * @overrides MiLayout.doLayout ------------------------------------------------------
   */
  protected void doLayout() {
    if (!autoLayoutEnabled) return;

    MiBounds contents = MiBounds.newBounds();
    MiBounds oldContents = MiBounds.newBounds();
    MiBounds containerBounds = MiBounds.newBounds();
    MiBounds tmp = MiBounds.newBounds();
    MiSize size = MiSize.newSize();
    // -------------------------------------------------------
    // Iterate through all parts of this container... set their
    // size to their preferredSize if this container does not
    // have a layout which has already done so. Also collect
    // the union of their bounds into 'contents'.
    // -------------------------------------------------------
    for (int i = 0; i < getNumberOfParts(); ++i) {
      if (getPart(i).isVisible()) {
        // -------------------------------------------------------
        // If contents have not already been laid out...
        // -------------------------------------------------------
        if ((getLayout() == null) || (!getLayout().determinesPreferredAndMinimumSizes())) {
          getPart(i).getPreferredSize(size);
          getPart(i).setSize(size);
        }
        getPart(i).getBounds(tmp);
        contents.union(tmp);
      }
    }

    // -------------------------------------------------------
    // Set 'oldContents' to this current bounds of all of this
    // container's parts. This will be used later to see it
    // we have changed the size of this container. 'contents'
    // will be modified by this layout routine as per the layout
    // constraints applied to this container.
    // -------------------------------------------------------
    oldContents.copy(contents);

    // -------------------------------------------------------
    // Get the inner bounds of this container into 'container'.
    // -------------------------------------------------------
    MiBounds container = getInnerBounds(containerBounds);
    if (container.isReversed()) {
      getPreferredSize(size);
      replaceBounds(new MiBounds(size));
      container = getInnerBounds(containerBounds);
    }

    // -------------------------------------------------------
    // Set the bounds to the center of the inner bounds.
    // -------------------------------------------------------
    contents.setCenterX(container.getCenterX());
    contents.setCenterY(container.getCenterY());

    // -------------------------------------------------------
    // Expand the bounds to the size of the inner bounds, if
    // so specified by the elementSizing contraints.
    // -------------------------------------------------------
    if (getElementHSizing() == Mi_EXPAND_TO_FILL) contents.setWidth(container.getWidth());
    else if (getElementVSizing() == Mi_EXPAND_TO_FILL) contents.setHeight(container.getHeight());

    // -------------------------------------------------------
    // Translate the bounds in a horizontal direction if so
    // specified by the elementHJustification contraint.
    // -------------------------------------------------------
    int elementHJustification = getElementHJustification();
    if (elementHJustification == Mi_LEFT_JUSTIFIED) contents.translateXminTo(container.getXmin());
    else if (elementHJustification == Mi_RIGHT_JUSTIFIED)
      contents.translateXmaxTo(container.getXmax());
    else if (elementHJustification == Mi_CENTER_JUSTIFIED)
      contents.setCenterX(container.getCenterX());
    else if (elementHJustification == Mi_JUSTIFIED) contents.setCenterX(container.getCenterX());

    // -------------------------------------------------------
    // Modify the bounds to stay within the inner bounds as
    // held in the 'container' variable.
    // -------------------------------------------------------
    if (contents.getXmin() < container.getXmin()) contents.translateXminTo(container.getXmin());
    if (contents.getXmax() > container.getXmax()) contents.translateXmaxTo(container.getXmax());
    if (contents.getXmin() < container.getXmin()) contents.setXmin(container.getXmin());

    // -------------------------------------------------------
    // Translate the bounds in a vertical direction if so
    // specified by the elementVJustification contraint.
    // -------------------------------------------------------
    int elementVJustification = getElementVJustification();
    if (elementVJustification == Mi_BOTTOM_JUSTIFIED) contents.translateYminTo(container.getYmin());
    else if (elementVJustification == Mi_TOP_JUSTIFIED)
      contents.translateYmaxTo(container.getYmax());
    else if (elementVJustification == Mi_CENTER_JUSTIFIED)
      contents.setCenterY(container.getCenterY());
    else if (elementVJustification == Mi_JUSTIFIED) contents.setCenterY(container.getCenterY());

    // -------------------------------------------------------
    // Modify the bounds to stay within the inner bounds as
    // held in the 'container' variable.
    // -------------------------------------------------------
    if (container.getYmin() > contents.getYmin()) contents.translateYminTo(container.getYmin());
    if (container.getYmax() < contents.getYmax()) contents.translateYmaxTo(container.getYmax());
    if (container.getYmin() > contents.getYmin()) contents.setYmin(container.getYmin());

    // -------------------------------------------------------
    // If we have changed the bounds in some way...
    // -------------------------------------------------------
    if (!oldContents.equals(contents)) {
      // -------------------------------------------------------
      // Calculate how much we have to translate the parts...
      // -------------------------------------------------------
      MiDistance tx = contents.getCenterX() - oldContents.getCenterX();
      MiDistance ty = contents.getCenterY() - oldContents.getCenterY();
      // -------------------------------------------------------
      // If there are no expand-to-fill contraints...
      // -------------------------------------------------------
      if ((getElementHSizing() != Mi_EXPAND_TO_FILL)
          && (getElementVSizing() != Mi_EXPAND_TO_FILL)) {
        // -------------------------------------------------------
        // Just translate all of the parts and we are done...
        // -------------------------------------------------------
        for (int i = 0; i < getNumberOfParts(); ++i) {
          getPart(i).translate(tx, ty);
        }
      } else {
        // -------------------------------------------------------
        // There is an expand-to-fill contraint, we need to scale
        // the parts... calculate the scale factor for each dimension.
        // -------------------------------------------------------
        MiPoint center = contents.getCenter();
        MiScale scale =
            new MiScale(
                contents.getWidth() / oldContents.getWidth(),
                contents.getHeight() / oldContents.getHeight());
        if (getElementHSizing() != Mi_EXPAND_TO_FILL) scale.x = 1;
        if (getElementVSizing() != Mi_EXPAND_TO_FILL) scale.y = 1;
        // -------------------------------------------------------
        // Iterate through the parts, translating and scaling
        // -------------------------------------------------------
        for (int i = 0; i < getNumberOfParts(); ++i) {
          getPart(i).translate(tx, ty);
          getPart(i).scale(center, scale);
        }
      }
    }
    // -------------------------------------------------------
    // Release all the bounds we allocated above
    // -------------------------------------------------------
    MiBounds.freeBounds(contents);
    MiBounds.freeBounds(oldContents);
    MiBounds.freeBounds(containerBounds);
    MiBounds.freeBounds(tmp);
    MiSize.freeSize(size);
  }
Ejemplo n.º 3
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);
  }