public void setConstraint(LayoutConstraint constraint) {
this.constraint = constraint;
}
private void layoutChild(PrintComponent<?> child, Rectangle box) {
LayoutConstraint layoutConstraint = child.getConstraint();
float bx = box.getLeft();
float by = box.getBottom();
float bw = box.getWidth();
float bh = box.getHeight();
float cw = child.getBounds().getWidth();
float ch = child.getBounds().getHeight();
float marginX = layoutConstraint.getMarginX();
float marginY = layoutConstraint.getMarginY();
float absw = layoutConstraint.getWidth();
float absh = layoutConstraint.getHeight();
float x = 0;
float y = 0;
float w = cw;
float h = ch;
switch (layoutConstraint.getAlignmentX()) {
case LayoutConstraint.LEFT:
x = bx + marginX;
break;
case LayoutConstraint.CENTER:
x = bx + (bw - cw) / 2;
break;
case LayoutConstraint.RIGHT:
x = bx + bw - marginX - cw;
break;
case LayoutConstraint.JUSTIFIED:
x = bx + marginX;
w = bw - 2 * marginX;
break;
case LayoutConstraint.ABSOLUTE:
x = marginX;
w = absw;
break;
}
switch (layoutConstraint.getAlignmentY()) {
case LayoutConstraint.BOTTOM:
y = by + marginY;
break;
case LayoutConstraint.CENTER:
y = by + (bh - ch) / 2;