// TODO Optimize
return new Dimensions(getPreferredWidth(-1), getPreferredHeight(-1));
}
public void layout() {
TabPane tabPane = (TabPane)getComponent();
int width = getWidth();
int height = getHeight();
int tabX = 0;
int tabY = 0;
int tabWidth = 0;
int tabHeight = 0;
Component selectedTab = tabPane.getSelectedTab();
Component corner = tabPane.getCorner();
Dimensions buttonPanoramaSize;
if (expandTransition == null) {
buttonPanoramaSize = buttonPanorama.getPreferredSize();
} else {
buttonPanoramaSize = buttonPanorama.getSize();
}
Orientation tabOrientation = tabPane.getTabOrientation();
switch (tabOrientation) {
case HORIZONTAL: {
int buttonPanoramaWidth = Math.min(width,
buttonPanoramaSize.width);
int buttonPanoramaHeight = buttonPanoramaSize.height;
int buttonPanoramaX = 0;
int buttonPanoramaY = 0;
if (corner != null) {
if (corner.isDisplayable()) {
int cornerWidth = width - buttonPanoramaWidth;
int cornerHeight = Math.max(corner.getPreferredHeight(-1), buttonPanoramaSize.height - 1);
int cornerX = buttonPanoramaWidth;
int cornerY = Math.max(buttonPanoramaHeight - cornerHeight - 1, 0);
buttonPanoramaY = Math.max(cornerHeight - buttonPanoramaHeight + 1, 0);
corner.setVisible(true);
corner.setLocation(cornerX, cornerY);
corner.setSize(cornerWidth, cornerHeight);
} else {
corner.setVisible(false);
}
}
buttonPanorama.setLocation(buttonPanoramaX, buttonPanoramaY);
buttonPanorama.setSize(buttonPanoramaWidth, buttonPanoramaHeight);
tabX = padding.left + 1;
tabY = padding.top + buttonPanoramaY + buttonPanoramaHeight;
tabWidth = Math.max(width - (padding.left + padding.right + 2), 0);
tabHeight = Math.max(height - (padding.top + padding.bottom
+ buttonPanoramaY + buttonPanoramaHeight + 1), 0);
break;
}
case VERTICAL: {
int buttonPanoramaWidth = buttonPanoramaSize.width;
int buttonPanoramaHeight = Math.min(height,
buttonPanoramaSize.height);
int buttonPanoramaX = 0;
int buttonPanoramaY = 0;
if (corner != null) {
if (corner.isDisplayable()) {
int cornerWidth = corner.getPreferredWidth(-1);
int cornerHeight = height - buttonPanoramaHeight;
int cornerX = Math.max(buttonPanoramaWidth - cornerWidth - 1, 0);
int cornerY = buttonPanoramaHeight;
buttonPanoramaX = Math.max(cornerWidth - buttonPanoramaWidth + 1, 0);
corner.setVisible(true);
corner.setLocation(cornerX, cornerY);
corner.setSize(cornerWidth, cornerHeight);
} else {
corner.setVisible(false);
}
}
buttonPanorama.setLocation(buttonPanoramaX, buttonPanoramaY);
buttonPanorama.setSize(buttonPanoramaWidth, buttonPanoramaHeight);
tabX = padding.left + buttonPanoramaX + buttonPanoramaWidth;
tabY = padding.top + 1;
tabWidth = Math.max(width - (padding.left + padding.right
+ buttonPanoramaX + buttonPanoramaWidth + 1), 0);
tabHeight = Math.max(height - (padding.top + padding.bottom + 2), 0);
break;
}
}
if (expandTransition == null) {
for (Component tab : tabPane.getTabs()) {
if (tab == selectedTab) {
// Show the selected tab
tab.setVisible(true);
// Set the tab's size and location
tab.setLocation(tabX, tabY);
tab.setSize(tabWidth, tabHeight);
} else {
tab.setVisible(false);
}
}
} else {
if (expandTransition.isRunning()) {
// Update the clip
expandTransition.clipDecorator.setWidth(tabWidth);
expandTransition.clipDecorator.setHeight(tabHeight);
} else {
switch (tabOrientation) {
case HORIZONTAL: {
tabHeight = 0;
for (Component tab : tabPane.getTabs()) {
tabHeight = Math.max(tab.getPreferredHeight(tabWidth), tabHeight);
}
break;
}
case VERTICAL: {
tabWidth = 0;
for (Component tab : tabPane.getTabs()) {
tabWidth = Math.max(tab.getPreferredWidth(tabHeight), tabWidth);
}
break;
}