List of usage examples for com.vaadin.client WidgetUtil getRequiredWidth
public static int getRequiredWidth(Widget widget)
From source file:com.haulmont.cuba.web.toolkit.ui.client.caption.CubaCaptionWidget.java
License:Apache License
@Override public int getRenderedWidth() { int width = 0; if (icon != null) { width += WidgetUtil.getRequiredWidth(icon.getElement()); }//w ww . ja va2s . co m if (captionText != null) { width += WidgetUtil.getRequiredWidth(captionText); } if (requiredFieldIndicator != null && requiredFieldIndicator.getParentElement() == getElement()) { width += WidgetUtil.getRequiredWidth(requiredFieldIndicator); } if (errorIndicatorElement != null && errorIndicatorElement.getParentElement() == getElement()) { width += WidgetUtil.getRequiredWidth(errorIndicatorElement); } if (contextHelpIndicatorElement != null && contextHelpIndicatorElement.getParentElement() == getElement()) { width += WidgetUtil.getRequiredWidth(contextHelpIndicatorElement); } return width; }
From source file:com.haulmont.cuba.web.toolkit.ui.client.fieldgrouplayout.CubaFieldGroupLayoutComponentSlot.java
License:Apache License
@Override public void positionHorizontally(double currentLocation, double allocatedSpace, double marginRight) { if (!isCaptionInline()) { super.positionHorizontally(currentLocation, allocatedSpace, marginRight); return;/*w w w . j a v a2 s. c o m*/ } // CAUTION copied from VLayoutSlot.positionHorizontally(~) Style style = wrapper.getStyle(); double availableWidth = allocatedSpace; VCaption caption = getCaption(); Style captionStyle = caption != null ? caption.getElement().getStyle() : null; int captionWidth = getCaptionWidth(); boolean clearCaptionRight = false; boolean captionAboveCompnent; if (caption == null) { captionAboveCompnent = false; style.clearPaddingLeft(); clearCaptionRight = true; } else { captionAboveCompnent = !caption.shouldBePlacedAfterComponent(); if (!captionAboveCompnent) { availableWidth -= captionWidth; if (availableWidth < 0) { availableWidth = 0; } captionStyle.clearLeft(); captionStyle.setRight(0, Style.Unit.PX); style.setPaddingRight(captionWidth, Style.Unit.PX); } else { availableWidth -= captionWidth; if (availableWidth < 0) { availableWidth = 0; } style.setPaddingLeft(captionWidth, Style.Unit.PX); captionStyle.setLeft(0, Style.Unit.PX); captionStyle.clearRight(); clearCaptionRight = true; } } // Take into account right indicators double indicatorsWidth = 0; if (rightCaption != null) { indicatorsWidth = WidgetUtil.getRequiredWidth(rightCaption); availableWidth -= indicatorsWidth; if (availableWidth < 0) { availableWidth = 0; } style.setPaddingRight(indicatorsWidth, Style.Unit.PX); } else if (clearCaptionRight) { style.clearPaddingRight(); } if (marginRight > 0) { style.setMarginRight(marginRight, Style.Unit.PX); } else { style.clearMarginRight(); } if (isRelativeWidth()) { style.setPropertyPx("width", (int) availableWidth); } else { style.clearProperty("width"); } double allocatedContentWidth = 0; if (isRelativeWidth()) { String percentWidth = getWidget().getElement().getStyle().getWidth(); double percentage = parsePercent(percentWidth); allocatedContentWidth = availableWidth * (percentage / 100); reportActualRelativeWidth(Math.round((float) allocatedContentWidth)); } AlignmentInfo alignment = getAlignment(); if (!alignment.isLeft()) { double usedWidth; if (isRelativeWidth()) { if (isCaptionInline()) { usedWidth = allocatedContentWidth + indicatorsWidth + captionWidth; } else { usedWidth = allocatedContentWidth + indicatorsWidth; } } else { usedWidth = getWidgetWidth() + indicatorsWidth; } if (alignment.isHorizontalCenter()) { currentLocation += (allocatedSpace - usedWidth) / 2d; if (captionAboveCompnent) { captionStyle.setLeft(Math.round(usedWidth - captionWidth) / 2, Style.Unit.PX); } } else { currentLocation += (allocatedSpace - usedWidth); if (captionAboveCompnent) { captionStyle.setLeft(Math.round(usedWidth - captionWidth), Style.Unit.PX); } } } else { if (captionAboveCompnent) { captionStyle.setLeft(0, Style.Unit.PX); } } style.setLeft(Math.round(currentLocation), Style.Unit.PX); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.fieldgrouplayout.CubaFieldGroupLayoutComponentSlot.java
License:Apache License
@Override public int getUsedWidth() { if (!isCaptionInline()) { return super.getUsedWidth(); }/* w ww .j a v a2 s . c o m*/ int widgetWidth = getWidgetWidth(); if (getCaption() == null) { return widgetWidth; } else if (getCaption().shouldBePlacedAfterComponent() || isCaptionInline()) { widgetWidth += getCaptionWidth(); if (rightCaption != null) { widgetWidth += WidgetUtil.getRequiredWidth(rightCaption); } return widgetWidth; } else { if (rightCaption != null) { widgetWidth += WidgetUtil.getRequiredWidth(rightCaption); } return Math.max(widgetWidth, getCaptionWidth()); } }
From source file:com.haulmont.cuba.web.toolkit.ui.client.fieldgrouplayout.CubaFieldGroupLayoutComponentSlot.java
License:Apache License
public int getIndicatorsWidth() { if (rightCaption != null) { return WidgetUtil.getRequiredWidth(rightCaption); } else {/*from w w w. j a v a 2 s . co m*/ return 0; } }
From source file:org.vaadin.overlay.widgetset.client.CustomOverlayWidget.java
License:Apache License
protected void updateOverlayPosition() { if (refCompEl != null) { // Calculate the position based on reference component size and the // align point. refY = refCompEl.getAbsoluteTop(); refX = refCompEl.getAbsoluteLeft(); if (align.isBottom()) { refY += refCompEl.getOffsetHeight(); } else if (align.isVerticalCenter()) { refY += refCompEl.getOffsetHeight() / 2; }/*from w ww. j a v a 2 s.co m*/ if (align.isRight()) { refX += refCompEl.getOffsetWidth(); } else if (align.isHorizontalCenter()) { refX += refCompEl.getOffsetWidth() / 2; } // Show popup overlay.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { // Calculate the position based on over component size and // the alignment point. Widget wgt = getOverlayWidget(); int w = WidgetUtil.getRequiredWidth(wgt); int h = WidgetUtil.getRequiredHeight(wgt); log.info("POSITION: w=" + w + "h=" + h); int top = refY + y; int left = refX + x; if (overlayAlign.isBottom()) { top -= h; } else if (overlayAlign.isVerticalCenter()) { top -= h / 2; } if (overlayAlign.isRight()) { left -= w; } else if (overlayAlign.isHorizontalCenter()) { left -= w / 2; } log.info("top=" + top + "left=" + left); overlay.setPopupPosition(left, top); } }); } }