@Override
protected Rectangle calculateLayout(int contentWidth, int contentHeight, int width, int height) {
if (rotation == 0) {
Rectangle layout = super.calculateLayout(contentWidth, contentHeight, width, height);
rotatedLayout = null;
layout.translate(translationX, translationY);
return layout;
}
rotatedLayout = new RotatedRectangle(0, 0, contentWidth, contentHeight, rotation);
Rectangle bb = rotatedLayout.getBoundingBox();
Rectangle layout = super.calculateLayout(bb.width, bb.height, width, height);
int dx = layout.x - bb.x;
int dy = layout.y - bb.y;
rotatedLayout.translate(dx + translationX, dy + translationY);
layout.translate(translationX, translationY);
return layout;
}