package cnp.ew.notebook;

import java.awt.*;
import cnp.ew.displayer.*;
import cnp.ew.lightweight.*;


// TBD: This class needs work.
public class CpStackedNotebookTabsLc extends CpAbstractNotebookTabsLc
{
    Vector tabsByRow;

    void selectedTabChanged(boolean wasClick)
    {
        // TBD: Need to change this from dealing with clicks to dealing
        // with not being valid. Removing this test causes an infinite loop.
        if (wasClick) {
        }
        layout();
    }

    // TBD: THIS IS NOT THE WAY TO DO THIS...
    boolean isValid()
    {
        return bounds().width >=0 && bounds().height >= 0;
    }


    public void layout()
    {
        int startX=0, startY=0;
        boolean firstTime = true;
        int tabHeight=0;
        CpTabLc tab;
        int width;

    // We sometimes get layout messages before we have a valid rectangle (e.g. when
    // the selection changes before we're fully built).  Since we know we'll get a layout
    // when we do have a valid rectangle, we can ignore these.
        if (!isValid()) {
            return;
        }

    }


    public Dimension preferredSize()
    {
        int width=0;
        boolean firstTime=true;
        int maxPreferredHeight=0, extraHeight=0;
        for (int i=0; i < tabs.size(); i++) {
            CpTabLc tab = (CpTabLc)tabs.elementAt(i);

            if (firstTime) {
                Insets maxExpansion = tab.maxExpansion();
                width = maxExpansion.left + maxExpansion.right;
                extraHeight = maxExpansion.top + maxExpansion.bottom;
                firstTime = false;
            }
            width += tab.preferredSize().width - tab.horizontalOverlap();
            maxPreferredHeight = Math.max(maxPreferredHeight, tab.preferredSize().height);
        }
        return new Dimension(width, maxPreferredHeight + extraHeight);
    }

    void tabAdded()
    {
    }
}

