int left = target.getStyle().getPadding(Component.LEFT);
int right = target.getLayoutWidth() - target.getSideGap() - target.getStyle().getPadding(Component.RIGHT);
int targetWidth = target.getWidth();
int targetHeight = target.getHeight();
Component c = null;
if (north != null) {
c = north;
c.setWidth(right - left - c.getStyle().getMargin(Component.LEFT) - c.getStyle().getMargin(Component.RIGHT));
c.setHeight(Math.min(targetHeight, c.getPreferredSize().getHeight())); //verify I want to use tge prefered size
c.setX(left + c.getStyle().getMargin(Component.LEFT));
c.setY(top + c.getStyle().getMargin(Component.TOP));
top += (c.getHeight() + c.getStyle().getMargin(Component.TOP) + c.getStyle().getMargin(Component.BOTTOM));
}
if (south != null) {
c = south;
c.setWidth(right - left - c.getStyle().getMargin(Component.LEFT) - c.getStyle().getMargin(Component.RIGHT));
c.setHeight(Math.min(targetHeight, c.getPreferredSize().getHeight())); //verify I want to use tge prefered size
c.setX(left + c.getStyle().getMargin(Component.LEFT));
c.setY(bottom - c.getHeight() - c.getStyle().getMargin(Component.TOP));
bottom -= (c.getHeight() + c.getStyle().getMargin(Component.TOP) + c.getStyle().getMargin(Component.BOTTOM));
}
if (east != null) {
c = east;
c.setWidth(Math.min(targetWidth, c.getPreferredSize().getWidth()));
c.setHeight(bottom - top - c.getStyle().getMargin(Component.TOP) - c.getStyle().getMargin(Component.BOTTOM)); //verify I want to use tge prefered size
c.setX(right - c.getWidth() - c.getStyle().getMargin(Component.LEFT));
c.setY(top + c.getStyle().getMargin(Component.TOP));
right -= (c.getWidth() + c.getStyle().getMargin(Component.LEFT) + c.getStyle().getMargin(Component.RIGHT));
}
if (west != null) {
c = west;
c.setWidth(Math.min(targetWidth, c.getPreferredSize().getWidth()));
c.setHeight(bottom - top - c.getStyle().getMargin(Component.TOP) - c.getStyle().getMargin(Component.BOTTOM)); //verify I want to use tge prefered size
c.setX(left + c.getStyle().getMargin(Component.LEFT));
c.setY(top + c.getStyle().getMargin(Component.TOP));
left += (c.getWidth() + c.getStyle().getMargin(Component.LEFT) + c.getStyle().getMargin(Component.RIGHT));
}
if (center != null) {
c = center;
c.setWidth(right - left - c.getStyle().getMargin(Component.LEFT) - c.getStyle().getMargin(Component.RIGHT));
c.setHeight(bottom - top - c.getStyle().getMargin(Component.TOP) - c.getStyle().getMargin(Component.BOTTOM)); //verify I want to use the remaining size
c.setX(left + c.getStyle().getMargin(Component.LEFT));
c.setY(top + c.getStyle().getMargin(Component.TOP));
// if(c instanceof Container) {
// ((Container)c).layoutContainer();
// }
}
}