Search in sources :

Example 1 with PercentLayoutAnimator

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());
    }
}
Also used : ActionListener(java.awt.event.ActionListener) PercentLayoutAnimator(com.l2fprod.common.swing.PercentLayoutAnimator) PercentLayout(com.l2fprod.common.swing.PercentLayout) ActionEvent(java.awt.event.ActionEvent) JComponent(javax.swing.JComponent) Component(java.awt.Component) JOutlookBar(com.l2fprod.common.swing.JOutlookBar)

Aggregations

JOutlookBar (com.l2fprod.common.swing.JOutlookBar)1 PercentLayout (com.l2fprod.common.swing.PercentLayout)1 PercentLayoutAnimator (com.l2fprod.common.swing.PercentLayoutAnimator)1 Component (java.awt.Component)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JComponent (javax.swing.JComponent)1