Package com.sencha.gxt.core.client.util

Examples of com.sencha.gxt.core.client.util.Margins


      } else {
        layoutData = new BoxLayoutData();
        widget.setLayoutData(layoutData);
      }

      Margins cm = layoutData.getMargins();
      if (cm == null) {
        cm = new Margins(0);
        layoutData.setMargins(cm);
      }
    }
   
    if (findWidth || findHeight) {
      for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget widget = getWidget(i);

        if (!widget.isVisible()) {
          continue;
        }

        BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
        Margins cm = layoutData.getMargins();

        calculateHeight += widget.getOffsetHeight();
        maxWidgetWidth = Math.max(maxWidgetWidth, widget.getOffsetWidth());

        calculateHeight += (cm.getTop() + cm.getBottom());
        maxMarginLeft = Math.max(maxMarginLeft, cm.getLeft());
        maxMarginRight = Math.max(maxMarginRight, cm.getRight());
      }
      maxWidgetWidth += (maxMarginLeft + maxMarginRight);

      if (findHeight) {
        h = calculateHeight;
      }

      if (findWidth) {
        w = maxWidgetWidth;
      }
    }

    int pl = 0;
    int pt = 0;
    int pb = 0;
    int pr = 0;
    if (getPadding() != null) {
      pl = getPadding().getLeft();
      pt = getPadding().getTop();
      pb = getPadding().getBottom();
      pr = getPadding().getRight();
    }
   
    if (findHeight) {
      h += pt + pb;
    }
    if (findWidth) {
      w += pl + pr;
    }


    int stretchWidth = w - pl - pr;
    int totalFlex = 0;
    int totalHeight = 0;
    int maxWidth = 0;
    for (int i = 0, len = getWidgetCount(); i < len; i++) {
      Widget widget = getWidget(i);
      widget.addStyleName(CommonStyles.get().positionable());

      widget.getElement().getStyle().setMargin(0, Unit.PX);

      // callLayout(widget, false);

      BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
      Margins cm = layoutData.getMargins();
     
      totalFlex += layoutData.getFlex();
      totalHeight += widget.getOffsetHeight() + cm.getTop() + cm.getBottom();
      maxWidth = Math.max(maxWidth, widget.getOffsetWidth() + cm.getLeft() + cm.getRight());
    }

    int innerCtWidth = maxWidth + pl + pr;

    if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCH)) {
      getContainerTarget().setSize(w, h, true);
    } else {
      getContainerTarget().setSize(w = Math.max(w, innerCtWidth), h, true);
    }

    int extraHeight = h - totalHeight - pt - pb;
    int allocated = 0;
    int cw, ch, cl;
    int availableWidth = w - pl - pr;

    if (getPack().equals(BoxLayoutPack.CENTER)) {
      pt += extraHeight / 2;
    } else if (getPack().equals(BoxLayoutPack.END)) {
      pt += extraHeight;
    }

    for (int i = 0, len = getWidgetCount(); i < len; i++) {
      Widget widget = getWidget(i);

      BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
      Margins cm = layoutData.getMargins();
     
      cw = widget.getOffsetWidth();
      ch = widget.getOffsetHeight();
      pt += cm.getTop();
      if (vBoxLayoutAlign.equals(VBoxLayoutAlign.CENTER)) {
        int diff = availableWidth - (cw + cm.getLeft() + cm.getRight());
        if (diff == 0) {
          cl = pl + cm.getLeft();
        } else {
          cl = pl + cm.getLeft() + (diff / 2);
        }
      } else {
        if (vBoxLayoutAlign.equals(VBoxLayoutAlign.RIGHT)) {
          cl = w - (pr + cm.getRight() + cw);
        } else {
          cl = pl + cm.getLeft();
        }
      }

      boolean component = widget instanceof Component;
      Component c = null;
      if (component) {
        c = (Component) widget;
      }

      int height = -1;
      if (component) {
        c.setPosition(cl, pt);
      } else {
        XElement.as(widget.getElement()).setLeftTop(cl, pt);
      }

      if (getPack().equals(BoxLayoutPack.START) && layoutData.getFlex() > 0) {
        int add = (int) Math.floor(extraHeight * (layoutData.getFlex() / totalFlex));
        allocated += add;
        if (isAdjustForFlexRemainder() && i == getWidgetCount() - 1) {
          add += extraHeight - allocated;
        }
        ch += add;
        height = ch;
      }
      if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCH)) {
        applyLayout(
            widget,
            Util.constrain(stretchWidth - cm.getLeft() - cm.getRight(), layoutData.getMinSize(), layoutData.getMaxSize()),
            height);
      } else if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCHMAX)) {
        applyLayout(widget,
            Util.constrain(maxWidth - cm.getLeft() - cm.getRight(), layoutData.getMinSize(), layoutData.getMaxSize()),
            height);
      } else if (height > 0) {
        applyLayout(widget, -1, height);
      }
      pt += ch + cm.getBottom();
    }
  }
View Full Code Here


    if (w == null) {
      return 0;
    }
    Object data = w.getLayoutData();
    if (data instanceof HasMargins) {
      Margins margins = ((HasMargins) data).getMargins();
      if (margins == null) {
        return 0;
      }
      int tot = 0;
      if (margins.getLeft() != -1) {
        tot += margins.getLeft();
      }
      if (margins.getRight() != -1) {
        tot += margins.getRight();
      }
      return tot;
    }
    return 0;
  }
View Full Code Here

  protected int getSideMargins(Widget w) {
    if (GXT.isWebKit()) {
      Object data = w.getLayoutData();
      if (data != null && data instanceof MarginData) {
        MarginData m = (MarginData) data;
        Margins margins = m.getMargins();
        if (margins == null) {
          return 0;
        }
        int tot = 0;
        if (margins.getLeft() != -1) {
          tot += margins.getLeft();
        }
        if (margins.getRight() != -1) {
          tot += margins.getRight();
        }
        return tot;
      }
    } else {
      return w.getElement().<XElement> cast().getMargins(Side.LEFT, Side.RIGHT);
View Full Code Here

    if (w == null) {
      return 0;
    }
    Object data = w.getLayoutData();
    if (data instanceof HasMargins) {
      Margins margins = ((HasMargins) data).getMargins();
      if (margins == null) {
        return 0;
      }
      int tot = 0;
      if (margins.getLeft() != -1) {
        tot += margins.getTop();
      }
      if (margins.getRight() != -1) {
        tot += margins.getBottom();
      }
      return tot;
    }

    return 0;
View Full Code Here

    d.setMoveAfterProxyDrag(false);
    d.setSizeProxyToSource(true);
    d.setEnabled(!portlet.isPinned());

    getWidget(column).insert(portlet, index, new VerticalLayoutData(1, -1, new Margins(0, 0, 10, 0)));
    getWidget(column).forceLayout();
  }
View Full Code Here

   * Creates a layout parameter with the specified margins.
   *
   * @param margins the margins
   */
  public MarginData(int margins) {
    this.margins = new Margins(margins);
  }
View Full Code Here

   * @param right the right margin
   * @param bottom the bottom margin
   * @param left the left margin
   */
  public MarginData(int top, int right, int bottom, int left) {
    this.margins = new Margins(top, right, bottom, left);
  }
View Full Code Here

      int tx = x;
      int ty = sTop;
      int tw = (int) Math.floor(width);
      int th = (int) Math.floor(height);

      Margins m = null;
      if (d instanceof HasMargins) {
        m = ((HasMargins) d).getMargins();
        if (m != null) {
          tx += m.getLeft();
          ty += m.getTop();
          if (th != -1) {
            th -= m.getTop();
            th -= m.getBottom();
          }
        }
      }

      applyLayout(c, new Rectangle(tx, ty, tw, th));

      if (tw == -1) {
        tw = c.getOffsetWidth();
      }

      x += tw + (m != null ? (m.getLeft() + m.getRight()) : 0);
    }
  }
View Full Code Here

  }

  protected void onInsert(int index, Widget child) {
    if (child.getLayoutData() instanceof HasMargins) {
      HasMargins m = (HasMargins) child.getLayoutData();
      Margins margins = m.getMargins();
      if (margins != null) {
        child.getElement().getStyle().setMarginTop(margins.getTop(), Unit.PX);
        child.getElement().getStyle().setMarginBottom(margins.getBottom(), Unit.PX);
        child.getElement().getStyle().setMarginLeft(margins.getLeft(), Unit.PX);
        child.getElement().getStyle().setMarginRight(margins.getRight(), Unit.PX);

      }
    }
  }
View Full Code Here

      BorderLayoutData data = getLayoutData(north);
      north.setVisible(!data.isHidden());

      if (north.isVisible()) {
        Rectangle b = new Rectangle();
        Margins m = data.getMargins() != null ? data.getMargins() : new Margins();
        double s = data.getSize() <= 1 ? data.getSize() * size.getHeight() : data.getSize();
        b.setHeight((int) s);
        b.setWidth(w - (m.getLeft() + m.getRight()));
        b.setX(m.getLeft());
        b.setY(m.getTop());
        centerY = b.getHeight() + b.getY() + m.getBottom();
        centerH -= centerY;
        b.setX(b.getX() + sLeft);
        b.setY(b.getY() + sTop);
        applyLayout(north, b);
      }
    }
    if (south != null) {
      BorderLayoutData data = getLayoutData(south);
      south.setVisible(!data.isHidden());
      if (south.isVisible()) {
        Rectangle b = new Rectangle();
        Margins m = data.getMargins() != null ? data.getMargins() : new Margins();
        double s = data.getSize() <= 1 ? data.getSize() * size.getHeight() : data.getSize();
        b.setHeight((int) s);
        b.setWidth(w - (m.getLeft() + m.getRight()));
        b.setX(m.getLeft());
        int totalHeight = (b.getHeight() + m.getTop() + m.getBottom());
        b.setY(h - totalHeight + m.getTop());
        centerH -= totalHeight;
        b.setX(b.getX() + sLeft);
        b.setY(b.getY() + sTop);
        applyLayout(south, b);
      }
    }

    if (west != null) {
      BorderLayoutData data = getLayoutData(west);
      west.setVisible(!data.isHidden());
      if (west.isVisible()) {
        Rectangle box = new Rectangle();
        Margins m = data.getMargins() != null ? data.getMargins() : new Margins();
        double s = data.getSize() <= 1 ? data.getSize() * size.getWidth() : data.getSize();
        box.setWidth((int) s);
        box.setHeight(centerH - (m.getTop() + m.getBottom()));
        box.setX(m.getLeft());
        box.setY(centerY + m.getTop());
        int totalWidth = (box.getWidth() + m.getLeft() + m.getRight());
        centerX += totalWidth;
        centerW -= totalWidth;
        box.setX(box.getX() + sLeft);
        box.setY(box.getY() + sTop);
        applyLayout(west, box);
      }

    }
    if (east != null) {
      BorderLayoutData data = getLayoutData(east);
      east.setVisible(!data.isHidden());
      if (east.isVisible()) {
        Rectangle b = new Rectangle();
        Margins m = data.getMargins() != null ? data.getMargins() : new Margins();
        double s = data.getSize() <= 1 ? data.getSize() * size.getWidth() : data.getSize();
        b.setWidth((int) s);
        b.setHeight(centerH - (m.getTop() + m.getBottom()));
        int totalWidth = (b.getWidth() + m.getLeft() + m.getRight());
        b.setX(w - totalWidth + m.getLeft());
        b.setY(centerY + m.getTop());
        centerW -= totalWidth;
        b.setX(b.getX() + sLeft);
        b.setY(b.getY() + sTop);
        applyLayout(east, b);
      }
    }

    if (widget != null) {
      Object data = widget.getLayoutData();
      Margins m = null;
      if (data instanceof HasMargins) {
        m = ((HasMargins) data).getMargins();
      }
      if (m == null) {
        m = new Margins(0);
      }
      lastCenter = new Rectangle(centerX, centerY, centerW, centerH);
      lastCenter.setX(centerX + (m.getLeft() + sLeft));
      lastCenter.setY(centerY + (m.getTop() + sTop));
      lastCenter.setWidth(centerW - (m.getLeft() + m.getRight()));
      lastCenter.setHeight(centerH - (m.getTop() + m.getBottom()));
      applyLayout(widget, lastCenter);
    }
  }
View Full Code Here

TOP

Related Classes of com.sencha.gxt.core.client.util.Margins

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.