this.alignment = alignment;
}
public void positionHorizontally(double currentLocation,
double allocatedSpace, double marginRight) {
Style style = wrapper.getStyle();
double availableWidth = allocatedSpace;
VCaption caption = getCaption();
Style captionStyle = caption != null ? caption.getElement().getStyle()
: null;
int captionWidth = getCaptionWidth();
boolean captionAboveCompnent;
if (caption == null) {
captionAboveCompnent = false;
style.clearPaddingRight();
} else {
captionAboveCompnent = !caption.shouldBePlacedAfterComponent();
if (!captionAboveCompnent) {
availableWidth -= captionWidth;
if (availableWidth < 0) {
availableWidth = 0;
}
captionStyle.clearLeft();
captionStyle.setRight(0, Unit.PX);
style.setPaddingRight(captionWidth, Unit.PX);
} else {
captionStyle.setLeft(0, Unit.PX);
captionStyle.clearRight();
style.clearPaddingRight();
}
}
if (marginRight > 0) {
style.setMarginRight(marginRight, 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()) {
usedWidth = allocatedContentWidth;
} else {
usedWidth = getWidgetWidth();
}
if (alignment.isHorizontalCenter()) {
currentLocation += (allocatedSpace - usedWidth) / 2d;
if (captionAboveCompnent) {
captionStyle.setLeft(
Math.round(usedWidth - captionWidth) / 2, Unit.PX);
}
} else {
currentLocation += (allocatedSpace - usedWidth);
if (captionAboveCompnent) {
captionStyle.setLeft(Math.round(usedWidth - captionWidth),
Unit.PX);
}
}
} else {
if (captionAboveCompnent) {
captionStyle.setLeft(0, Unit.PX);
}
}
style.setLeft(Math.round(currentLocation), Unit.PX);
}