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

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


   * 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

      child.setLayoutData(hasMargins);
    } else {
      hasMargins = (HasMargins) data;
    }
   
    Margins m = hasMargins.getMargins();
   
    if (m == null) {
      m = new Margins();
      hasMargins.setMargins(m);
    }
   
    if (verticalSpacing != -1) {
      int vs = (int) Math.round(verticalSpacing / 2d);
      m.setTop(vs);
      m.setBottom(vs);
    }
   
    if (horizontalSpacing != -1) {
      int hs = (int) Math.round(horizontalSpacing / 2d);
      m.setLeft(hs);
      m.setRight(hs);
    }
   
  }
View Full Code Here

        layoutData = (BoxLayoutData) d;
      } else {
        layoutData = new BoxLayoutData();
      }

      Margins cm = layoutData.getMargins();
      if (cm == null) {
        cm = new Margins(0);
      }
     
      // TODO strange issue where getOffsetWidth call in 2nd loop is returning smaller number than acutal offset
      // when packing CENTER or END so we cache the offsetWidth for use in 2nd loop
      int ww = widget.getOffsetWidth();
      loopWidthMap.put(widget, ww);

      totalFlex += layoutData.getFlex();
      totalWidth += (ww + cm.getLeft() + cm.getRight());
      maxHeight = Math.max(maxHeight, widget.getOffsetHeight() + cm.getTop() + cm.getBottom());
    }

    int innerCtHeight = maxHeight + pt + pb;

    if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) {
      getContainerTarget().setSize(w, h, true);
    } else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE) || hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) {
      getContainerTarget().setSize(w, h = Math.max(h, innerCtHeight), true);
    } else {
      getContainerTarget().setSize(w, innerCtHeight, true);
    }

    int extraWidth = w - totalWidth - pl - pr;
    int allocated = 0;
    int cw, ch, ct;
    int availableHeight = h - pt - pb;

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

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

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

      BoxLayoutData layoutData = null;
      Object d = widget.getLayoutData();
      if (d instanceof BoxLayoutData) {
        layoutData = (BoxLayoutData) d;
      } else {
        layoutData = new BoxLayoutData();
      }
      Margins cm = layoutData.getMargins();
      if (cm == null) {
        cm = new Margins(0);
      }

      cw = loopWidthMap.remove(widget);
      ch = widget.getOffsetHeight();
      pl += cm.getLeft();

      pl = Math.max(0, pl);
      if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE)) {
        int diff = availableHeight - (ch + cm.getTop() + cm.getBottom());
        if (diff == 0) {
          ct = pt + cm.getTop();
        } else {
          ct = pt + cm.getTop() + (diff / 2);
        }
      } else {
        if (hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) {
          ct = h - (pb + cm.getBottom() + ch);
        } else {
          ct = pt + cm.getTop();
        }

      }

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

      int width = -1;
      if (component) {
        c.setPosition(pl, ct);
      } else {
        XElement.as(widget.getElement()).setLeftTop(pl, ct);
      }

      if (getPack().equals(BoxLayoutPack.START) && layoutData.getFlex() > 0) {
        int add = (int) Math.floor(extraWidth * (layoutData.getFlex() / totalFlex));
        allocated += add;
        if (isAdjustForFlexRemainder() && i == getWidgetCount() - 1) {
          add += (extraWidth - allocated);
        }

        cw += add;
        width = cw;
      }
      if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) {
        applyLayout(
            widget,
            width,
            Util.constrain(stretchHeight - cm.getTop() - cm.getBottom(), layoutData.getMinSize(),
                layoutData.getMaxSize()));
      } else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCHMAX)) {
        applyLayout(widget, width,
            Util.constrain(maxHeight - cm.getTop() - cm.getBottom(), layoutData.getMinSize(), layoutData.getMaxSize()));
      } else if (width > 0) {
        applyLayout(widget, width, -1);
      }
      pl += cw + cm.getRight();
    }

    // do we need overflow
    if (enableOverflow) {
      int runningWidth = 0;
      for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget widget = getWidget(i);

        if (widget == more) {
          continue;
        }

        BoxLayoutData layoutData = null;
        Object d = widget.getLayoutData();
        if (d instanceof BoxLayoutData) {
          layoutData = (BoxLayoutData) d;
        } else {
          layoutData = new BoxLayoutData();
        }
        Margins cm = layoutData.getMargins();
        if (cm == null) {
          cm = new Margins(0);
        }
        runningWidth += getWidgetWidth(widget);
        runningWidth += cm.getLeft();
        runningWidth += cm.getRight();
      }

      if (runningWidth > w) {
        hasOverflow = true;
        onOverflow();
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

  }

  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

      if (d != null && d instanceof BoxLayoutData) {
        layoutData = (BoxLayoutData) d;
      } else {
        layoutData = new BoxLayoutData();
      }
      Margins cm = layoutData.getMargins();
      if (cm == null) {
        cm = new Margins(0);
      }
      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 = null;
      Object d = widget.getLayoutData();
      if (d != null && d instanceof BoxLayoutData) {
        layoutData = (BoxLayoutData) d;
      } else {
        layoutData = new BoxLayoutData();
      }
      Margins cm = layoutData.getMargins();
      if (cm == null) {
        cm = new Margins(0);
      }
      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

      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

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.