int heightNorth = 0;
int heightSouth = 0;
final List<Spatial> content = container.getChildren();
// Go through each component in the given container and determine the width and height of our edges.
final Rectangle2 store = new Rectangle2();
for (final Spatial s : content) {
if (!(s instanceof UIComponent)) {
continue;
}
final UIComponent comp = (UIComponent) s;
comp.getRelativeMinComponentBounds(store);
final BorderLayoutData data = (BorderLayoutData) comp.getLayoutData();
if (data != null) {
switch (data) {
case NORTH:
heightNorth = store.getHeight();
break;
case SOUTH:
heightSouth = store.getHeight();
break;
case EAST:
widthEast = store.getWidth();
break;
case WEST:
widthWest = store.getWidth();
break;
case CENTER:
// nothing to do
break;
}
}
}
// Using the information from the last pass, set the position and size of each component in the container.
for (final Spatial s : content) {
if (!(s instanceof UIComponent)) {
continue;
}
final UIComponent comp = (UIComponent) s;
comp.getRelativeMinComponentBounds(store);
final BorderLayoutData data = (BorderLayoutData) comp.getLayoutData();
if (data != null) {
switch (data) {
case NORTH:
comp.fitComponentIn(container.getContentWidth(), store.getHeight());
comp.getRelativeComponentBounds(store);
comp.setLocalXY(-store.getX(), container.getContentHeight() - heightNorth - store.getY());
break;
case SOUTH:
comp.fitComponentIn(container.getContentWidth(), store.getHeight());
comp.getRelativeComponentBounds(store);
comp.setLocalXY(-store.getX(), -store.getY());
break;
case EAST:
comp.fitComponentIn(store.getWidth(), container.getContentHeight() - heightNorth - heightSouth);
comp.getRelativeComponentBounds(store);
comp.setLocalXY(container.getContentWidth() - store.getWidth() - 1 - store.getX(), heightSouth
- store.getY());
break;
case WEST:
comp.fitComponentIn(store.getWidth(), container.getContentHeight() - heightNorth - heightSouth);
comp.getRelativeComponentBounds(store);
comp.setLocalXY(-store.getX(), heightSouth - store.getY());
break;
case CENTER:
comp.fitComponentIn(container.getContentWidth() - widthEast - widthWest, container
.getContentHeight()
- heightSouth - heightNorth);
comp.getRelativeComponentBounds(store);
comp.setLocalXY(widthWest - store.getX(), heightSouth - store.getY());
}
}
}
}