use of com.l2fprod.common.swing.PercentLayoutAnimator in project CodenameOne by codenameone.
the class BasicOutlookBarUI method tabAdded.
protected void tabAdded(final Component newTab) {
TabButton button = (TabButton) tabToButton.get(newTab);
if (button == null) {
button = createTabButton();
// save the button original color,
// later they would be restored if the button colors are not customized on
// the OutlookBar
button.putClientProperty(BUTTON_ORIGINAL_FOREGROUND, button.getForeground());
button.putClientProperty(BUTTON_ORIGINAL_BACKGROUND, button.getBackground());
buttonToTab.put(button, newTab);
tabToButton.put(newTab, button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Component current = getVisibleComponent();
Component target = newTab;
// tabPane allows animation
if (((JOutlookBar) tabPane).isAnimated() && current != target && current != null && target != null) {
if (animator != null) {
animator.stop();
}
animator = new PercentLayoutAnimator(tabPane, (PercentLayout) tabPane.getLayout()) {
protected void complete() {
super.complete();
tabPane.setSelectedComponent(newTab);
nextVisibleComponent = null;
// animation
if (current.getParent() == tabPane) {
((PercentLayout) tabPane.getLayout()).setConstraint(current, "100%");
}
}
};
nextVisibleComponent = newTab;
animator.setTargetPercent(current, 1.0f, 0.0f);
animator.setTargetPercent(newTab, 0.0f, 1.0f);
animator.start();
} else {
nextVisibleComponent = null;
tabPane.setSelectedComponent(newTab);
}
}
});
} else {
// the tab is already in the list, remove the button, it will be
// added again later
tabPane.remove(button);
}
// update the button with the tab information
updateTabButtonAt(tabPane.indexOfComponent(newTab));
int index = indexOfComponent(newTab);
tabPane.add(button, index);
// introduced by J2SE 5
if (JVM.current().isOneDotFive()) {
assureRectsCreated(tabPane.getTabCount());
}
}
Aggregations