return preferredSize;
}
public void layout() {
CardPane cardPane = (CardPane)getComponent();
int width = getWidth();
int height = getHeight();
if (selectionChangeTransition == null) {
Component selectedCard = cardPane.getSelectedCard();
for (Component card : cardPane) {
// Set the size of the selected component to the container's size
// and show the card
if (card == selectedCard) {
card.setLocation(0, 0);
card.setSize(width, height);
card.setVisible(true);
} else {
card.setVisible(false);
}
}
} else {
if (matchSelectedCardSize) {
Component previousSelectedCard = selectionChangeTransition.getPreviousSelectedCard();
Component selectedCard = selectionChangeTransition.getSelectedCard();
Orientation orientation = cardPane.getOrientation();
if (selectionChangeTransition.isRunning()) {
for (Component card : cardPane) {
// Center old and new cards and ensure they are visible
if (card == previousSelectedCard
|| card == selectedCard) {
int x = (orientation == Orientation.VERTICAL) ?
0 : Math.round((float)(width - card.getWidth()) / 2);
int y = (orientation == Orientation.HORIZONTAL) ?
0 : Math.round((float)(height - card.getHeight()) / 2);
card.setLocation(x, y);
card.setVisible(true);
} else {
card.setVisible(false);
}
}
} else {
if (previousSelectedCard != null) {
previousSelectedCard.setSize(previousSelectedCard.getPreferredSize());
}
if (selectedCard != null) {
selectedCard.setSize(selectedCard.getPreferredSize());
selectedCard.setVisible(true);
}
}
} else {
if (selectionChangeTransition.isRunning()) {
int previousSelectedIndex = selectionChangeTransition.previousSelectedIndex;
int selectedIndex = selectionChangeTransition.selectedIndex;
if (previousSelectedIndex != -1
&& selectedIndex != -1) {
float percentComplete = selectionChangeTransition.getEasedSlidePercentComplete();
int direction = Integer.signum(previousSelectedIndex - selectedIndex);
int dx = (int)((float)width * percentComplete) * direction;
int dy = (int)((float)height * percentComplete) * direction;
Orientation orientation = cardPane.getOrientation();
for (int i = 0, n = cardPane.getLength(); i < n; i++) {
Component card = cardPane.get(i);
if (i == previousSelectedIndex) {
if (orientation == Orientation.HORIZONTAL) {
card.setLocation(dx, 0);
} else {
card.setLocation(0, dy);
}
card.setVisible(true);
} else if (i == selectedIndex) {
if (orientation == Orientation.HORIZONTAL) {
card.setLocation(-width * direction + dx, 0);
} else {
card.setLocation(0, -height * direction + dy);
}
card.setVisible(true);
} else {
card.setVisible(false);
}
}
}
} else {
Component selectedCard = selectionChangeTransition.getSelectedCard();
Orientation orientation = cardPane.getOrientation();
if (selectedCard != null) {
if (orientation == Orientation.HORIZONTAL) {
for (Component card : cardPane) {
height = Math.max(height, card.getPreferredHeight(width));