List of usage examples for com.google.gwt.user.client.ui Widget getOffsetWidth
@Override public int getOffsetWidth()
From source file:com.preferanser.client.geom.Point.java
License:Open Source License
public static Point FromWidgetRightBottom(Widget widget) { return new Point(widget.getAbsoluteLeft() + widget.getOffsetWidth(), widget.getAbsoluteTop() + widget.getOffsetHeight()); }
From source file:com.sciencegadgets.client.algebra.WrapDragController.java
License:Open Source License
@Override protected Widget newDragProxy(DragContext context) { Widget drag = context.draggable; Element selectedElement = drag.getElement(); Node dragEl = selectedElement.cloneNode(true); double pxPerEm = EquationHTML.getPxPerEm(selectedElement); proxy = new SimplePanel(); proxy.getElement().getStyle().setWidth(drag.getOffsetWidth(), Unit.PX); proxy.getElement().getStyle().setHeight(drag.getOffsetHeight(), Unit.PX); proxy.addStyleName(DragClientBundle.INSTANCE.css().movablePanel()); proxy.getElement().getStyle().setFontSize(pxPerEm, Unit.PX); proxy.getElement().appendChild(dragEl); return proxy; }
From source file:com.seanchenxi.gwt.serenity.client.widget.PopupLabelBox.java
License:Apache License
public void showRelativeTo(Widget w) { show();/*from w w w . ja va 2s. c o m*/ int top = w.getAbsoluteTop() - 20; int left = w.getAbsoluteLeft() + w.getOffsetWidth(); setPopupPosition(left, top); }
From source file:com.sencha.gxt.desktop.client.widget.DesktopLayoutContainer.java
License:sencha.com license
@Override protected void doLayout() { int widgetCount = getWidgetCount(); if (widgetCount == 0) { return;/*w w w . j a v a 2 s . c o m*/ } int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < widgetCount; i++) { Widget widget = getWidget(i); Margins margins = getMargins(widget); maxWidth = Math.max(maxWidth, widget.getOffsetWidth() + margins.getLeft() + margins.getRight()); maxHeight = Math.max(maxHeight, widget.getOffsetHeight() + margins.getTop() + margins.getBottom()); } XElement element = getElement(); Size size = XElement.as(element).getStyleSize(); int availableHeight = size.getHeight() - XDOM.getScrollBarWidth(); int rowCount = availableHeight / maxHeight; int columnCount = (widgetCount + (rowCount - 1)) / rowCount; int requiredWidth = columnCount * maxWidth; getContainerTarget().setSize(requiredWidth, availableHeight); for (int i = 0; i < widgetCount; i++) { Widget widget = getWidget(i); Margins margins = getMargins(widget); int row = i % rowCount; int column = i / rowCount; int left = column * maxWidth; int top = row * maxHeight; int widgetWidth = widget.getOffsetWidth(); int widgetHeight = widget.getOffsetHeight(); int marginWidth = margins.getLeft() + margins.getRight(); int marginHeight = margins.getTop() + margins.getBottom(); int excessWidth = maxWidth - widgetWidth - marginWidth; int excessHeight = maxHeight - widgetHeight - marginHeight; boolean isSizeChange = false; switch (vBoxLayoutAlign) { case CENTER: left += excessWidth / 2; break; case LEFT: // no action required break; case RIGHT: left += excessWidth; break; case STRETCH: case STRETCHMAX: default: widgetWidth = maxWidth - marginWidth; isSizeChange = true; break; } switch (hBoxLayoutAlign) { case TOP: // no action required break; case MIDDLE: top += excessHeight / 2; break; case BOTTOM: top += excessHeight; break; case STRETCH: case STRETCHMAX: default: widgetHeight = maxHeight - marginHeight; isSizeChange = true; break; } XElement.as(widget.getElement()).makePositionable(true); XElement.as(widget.getElement()).setLeftTop(left, top); if (isSizeChange) { applyLayout(widget, widgetWidth, widgetHeight); } } }
From source file:com.sencha.gxt.widget.core.client.container.CssFloatLayoutContainer.java
License:sencha.com license
@Override protected void doLayout() { Size size = getContainerTarget().getStyleSize(); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " doLayout size: " + size); }//from www.ja va 2 s .com int w = size.getWidth() - (adjustForScroll ? XDOM.getScrollBarWidth() : 0); w -= getContainerTarget().getFrameWidth(Side.LEFT, Side.RIGHT); int count = getWidgetCount(); // some columns can be percentages while others are fixed // so we need to make 2 passes double linePercentageRemaining = 1.0; double lineRemainingFixed = w; List<Widget> line = new ArrayList<Widget>(); for (int i = 0; i < count; i++) { Widget widget = getWidget(i); Object d = widget.getLayoutData(); CssFloatData layoutData; if (d instanceof CssFloatData) { layoutData = (CssFloatData) d; } else { layoutData = new CssFloatData(); } if (layoutData.isClear()) { appendLine(line, (int) lineRemainingFixed); lineRemainingFixed = w; linePercentageRemaining = 1.0; widget.getElement().getStyle().setClear(Clear.BOTH); } else { widget.getElement().getStyle().clearClear(); } if (layoutData.getSize() > 1) { if (lineRemainingFixed < layoutData.getSize() + getLeftRightMargins(widget)) { appendLine(line, (int) lineRemainingFixed); lineRemainingFixed = w; linePercentageRemaining = 1.0; } lineRemainingFixed -= layoutData.getSize() + getLeftRightMargins(widget); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " child " + i + " consuming " + layoutData.getSize() + "px"); } } else if (layoutData.getSize() > 0) { if (linePercentageRemaining < layoutData.getSize()) { appendLine(line, (int) (lineRemainingFixed)); lineRemainingFixed = w; linePercentageRemaining = 1.0; } linePercentageRemaining -= layoutData.getSize(); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " child " + i + " consuming " + layoutData.getSize() * 100 + "%"); } } else { //assume layoutData.getSize() == -1, measure the child to see where we put it int width = widget.getOffsetWidth(); if (lineRemainingFixed < width + getLeftRightMargins(widget)) { appendLine(line, (int) lineRemainingFixed); lineRemainingFixed = w; linePercentageRemaining = 1.0; } lineRemainingFixed -= width + getLeftRightMargins(widget); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " child " + i + " consuming " + width + "px (as -1)"); } } line.add(widget); } appendLine(line, (int) (lineRemainingFixed)); }
From source file:com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.java
License:sencha.com license
@Override protected void doLayout() { Size size = getElement().getStyleSize(); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " doLayout size: " + size); }//from w w w. j a va 2s. c om if ((size.getHeight() == 0 && size.getWidth() == 0) || size.getWidth() == 0) { return; } int w = size.getWidth() - getScrollOffset(); int h = size.getHeight(); int styleHeight = Util.parseInt(getElement().getStyle().getProperty("height"), Style.DEFAULT); int styleWidth = Util.parseInt(getElement().getStyle().getProperty("width"), Style.DEFAULT); boolean findWidth = styleWidth == -1; boolean findHeight = styleHeight == -1; if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " findWidth: " + findWidth + " findHeight: " + findHeight); } int calculateWidth = 0; int maxWidgetHeight = 0; int maxMarginTop = 0; int maxMarginBottom = 0; for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); BoxLayoutData layoutData = null; Object d = widget.getLayoutData(); if (d instanceof BoxLayoutData) { layoutData = (BoxLayoutData) d; } 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(); calculateWidth += widget.getOffsetWidth(); maxWidgetHeight = Math.max(maxWidgetHeight, widget.getOffsetHeight()); calculateWidth += (cm.getLeft() + cm.getRight()); maxMarginTop = Math.max(maxMarginTop, cm.getTop()); maxMarginBottom = Math.max(maxMarginBottom, cm.getBottom()); } maxWidgetHeight += (maxMarginTop + maxMarginBottom); if (findWidth) { w = calculateWidth; } if (findHeight) { h = maxWidgetHeight; } } 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 stretchHeight = h - pt - pb; int totalFlex = 0; int totalWidth = 0; int maxHeight = 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); if (!widget.isVisible()) { continue; } if (widget == more) { triggerWidth = widget.getOffsetWidth() + 10; } BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData(); Margins cm = layoutData.getMargins(); // TODO strange issue where getOffsetWidth call in 2nd loop is returning smaller number than actual offset // when packing CENTER or END so we cache the offsetWidth for use in 2nd loop // with buttons, the button is word wrapping causing the button to be narrower and taller int ww = widget.getOffsetWidth(); loopWidthMap.put(widget, ww); loopHeightMap.put(widget, widget.getOffsetHeight()); 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 componentWidth, componentHeight, componentTop; 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 = (BoxLayoutData) widget.getLayoutData(); Margins cm = layoutData.getMargins(); componentWidth = loopWidthMap.remove(widget); componentHeight = loopHeightMap.remove(widget); pl += cm.getLeft(); pl = Math.max(0, pl); if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE)) { int diff = availableHeight - (componentHeight + cm.getTop() + cm.getBottom()); if (diff == 0) { componentTop = pt + cm.getTop(); } else { componentTop = pt + cm.getTop() + (diff / 2); } } else { if (hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) { componentTop = h - (pb + cm.getBottom() + componentHeight); } else { componentTop = pt + cm.getTop(); } } boolean component = widget instanceof Component; Component c = null; if (component) { c = (Component) widget; } int width = -1; if (component) { c.setPosition(pl, componentTop); } else { XElement.as(widget.getElement()).setLeftTop(pl, componentTop); } 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); } componentWidth += add; width = componentWidth; } 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 += componentWidth + 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(); } else { hasOverflow = false; if (more != null && more.getParent() == this) { onUnoverflow(); } } } }
From source file:com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.java
License:sencha.com license
protected int getWidgetWidth(Widget widget) { Integer w = widthMap.get(widget); if (w != null) { return w; } else {/*from w w w .java 2 s . co m*/ return widget.getOffsetWidth(); } }
From source file:com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.java
License:sencha.com license
protected void hideComponent(Widget w) { widthMap.put(w, w.getOffsetWidth()); hiddens.add(w); w.setVisible(false); }
From source file:com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer.java
License:sencha.com license
@Override protected void doLayout() { Size size = getContainerTarget().getStyleSize(); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " doLayout size: " + size); }/*from w w w . j a va 2 s.c o m*/ int w = size.getWidth() - (adjustForScroll ? XDOM.getScrollBarWidth() : 0); int h = size.getHeight(); int pw = w; int count = getWidgetCount(); // some columns can be percentages while others are fixed // so we need to make 2 passes for (int i = 0; i < count; i++) { Widget c = getWidget(i); if (!c.isVisible()) { continue; } c.getElement().getStyle().setPosition(Position.ABSOLUTE); double width = -1; Object d = c.getLayoutData(); if (d instanceof HasWidth) { width = ((HasWidth) d).getWidth(); } if (width > 1) { pw -= width; } else if (width == -1) { if ((c instanceof HasWidgets || c instanceof IndexedPanel) && !secondPassRequired) { secondPassRequired = true; Scheduler.get().scheduleDeferred(layoutCommand); return; } pw -= c.getOffsetWidth(); pw -= getLeftRightMargins(c); } else if (width < -1) { pw -= (w + width); pw -= getLeftRightMargins(c); } } secondPassRequired = false; pw = pw < 0 ? 0 : pw; int x = getContainerTarget().getPadding(Side.LEFT); int sTop = getContainerTarget().getPadding(Side.TOP); for (int i = 0; i < count; i++) { Widget c = getWidget(i); if (!c.isVisible()) { continue; } c.getElement().getStyle().setMargin(0, Unit.PX); double width = -1; double height = -1; Object d = c.getLayoutData(); if (d instanceof HasWidth) { width = ((HasWidth) d).getWidth(); } if (d instanceof HasHeight) { height = ((HasHeight) d).getHeight(); } if (height >= 0 && height <= 1) { height = height * h; } else if (height < -1) { height = h + height; } if (width >= 0 && width <= 1) { width = width * pw; } else if (width < -1) { width = w + width; } 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() + m.getBottom(); } if (tw != -1) { tw -= m.getLeft() + m.getRight(); } } } applyLayout(c, new Rectangle(tx, ty, tw, th)); if (tw == -1) { tw = c.getOffsetWidth(); } x += tw + (m != null ? (m.getLeft() + m.getRight()) : 0); } }
From source file:com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.java
License:sencha.com license
@Override protected void doLayout() { Size size = getElement().getStyleSize(); if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " doLayout size: " + size); }/*from w w w.java 2 s .c o m*/ int w = size.getWidth() - getScrollOffset(); int h = size.getHeight(); int styleHeight = Util.parseInt(getElement().getStyle().getProperty("height"), Style.DEFAULT); int styleWidth = Util.parseInt(getElement().getStyle().getProperty("width"), Style.DEFAULT); boolean findWidth = styleWidth == -1; boolean findHeight = styleHeight == -1; if (GXTLogConfiguration.loggingIsEnabled()) { logger.finest(getId() + " findWidth: " + findWidth + " findHeight: " + findHeight); } int calculateHeight = 0; int maxWidgetWidth = 0; int maxMarginLeft = 0; int maxMarginRight = 0; for (int i = 0, len = getWidgetCount(); i < len; i++) { Widget widget = getWidget(i); BoxLayoutData layoutData = null; Object d = widget.getLayoutData(); if (d instanceof BoxLayoutData) { layoutData = (BoxLayoutData) d; } 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(); } }