if (sizeToSelection) {
if (selectionChangeTransition == null) {
Component selectedCard = cardPane.getSelectedCard();
if (selectedCard != null) {
Dimensions cardSize = selectedCard.getPreferredSize();
preferredWidth = cardSize.width;
preferredHeight = cardSize.height;
}
} else {
float percentComplete = selectionChangeTransition.getPercentComplete();
int previousWidth;
int previousHeight;
if (selectionChangeTransition.fromCard == null) {
previousWidth = 0;
previousHeight = 0;
} else {
Dimensions fromSize = selectionChangeTransition.fromCard.getPreferredSize();
previousWidth = fromSize.width;
previousHeight = fromSize.height;
}
int width;
int height;
if (selectionChangeTransition.toCard == null) {
width = 0;
height = 0;
} else {
Dimensions toSize = selectionChangeTransition.toCard.getPreferredSize();
width = toSize.width;
height = toSize.height;
}
preferredWidth = previousWidth + (int)((width - previousWidth) * percentComplete);
preferredHeight = previousHeight + (int)((height - previousHeight) * percentComplete);
}
} else {
for (Component card : cardPane) {
Dimensions cardSize = card.getPreferredSize();
preferredWidth = Math.max(cardSize.width, preferredWidth);
preferredHeight = Math.max(cardSize.height, preferredHeight);
}
}
preferredWidth += (padding.left + padding.right);
preferredHeight += (padding.top + padding.bottom);
return new Dimensions(preferredWidth, preferredHeight);
}