}
private void command_ANCHOR_horizontal(WidgetInfo widget, Anchor anchor) throws Exception {
MethodInvocation invocation;
Rectangle bounds = widget.getBounds();
AstEditor editor = getEditor();
if ((invocation = getWidgetInvocation(widget, "setWidgetLeftWidth")) != null) {
if (anchor == Anchor.NONE) {
editor.removeEnclosingStatement(invocation);
}
if (anchor == Anchor.TRAILING) {
int right = getBounds().width - bounds.right();
editor.replaceInvocationName(invocation, "setWidgetRightWidth");
setInvocationArgument(invocation, 1, right, true);
}
if (anchor == Anchor.BOTH) {
int right = getBounds().width - bounds.right();
editor.replaceInvocationName(invocation, "setWidgetLeftRight");
setInvocationArgument(invocation, 3, right, true);
}
return;
}
if ((invocation = getWidgetInvocation(widget, "setWidgetRightWidth")) != null) {
if (anchor == Anchor.NONE) {
editor.removeEnclosingStatement(invocation);
}
if (anchor == Anchor.LEADING) {
int left = bounds.left();
editor.replaceInvocationName(invocation, "setWidgetLeftWidth");
setInvocationArgument(invocation, 1, left, true);
}
if (anchor == Anchor.BOTH) {
editor.replaceInvocationName(invocation, "setWidgetLeftRight");
{
Expression rightExpression = DomGenerics.arguments(invocation).get(1);
editor.replaceInvocationArgument(invocation, 3, editor.getSource(rightExpression));
}
setInvocationArgument(invocation, 1, bounds.left(), true);
}
return;
}
if ((invocation = getWidgetInvocation(widget, "setWidgetLeftRight")) != null) {
if (anchor == Anchor.NONE) {
editor.removeEnclosingStatement(invocation);
}
if (anchor == Anchor.LEADING) {
editor.replaceInvocationName(invocation, "setWidgetLeftWidth");
// use same unit for left/width
Object unit = getUnit(invocation, 2);
setInvocationUnit(invocation, 4, unit);
// set width
setInvocationArgument(invocation, 3, bounds.width, true);
}
if (anchor == Anchor.TRAILING) {
editor.replaceInvocationName(invocation, "setWidgetRightWidth");
// use same unit for right/width
Object unit = getUnit(invocation, 4);
setInvocationUnit(invocation, 2, unit);
// set right/width
{
Expression rightExpression = DomGenerics.arguments(invocation).get(3);
editor.replaceInvocationArgument(invocation, 1, editor.getSource(rightExpression));
}
// set width
setInvocationArgument(invocation, 3, bounds.width, true);
}
return;