
import java.awt.*;
import java.io.*;
import java.util.*;
import cnp.ew.scrolling.*;
import cnp.ew.diagram.*;
import cnp.ew.button.*;
import cnp.ew.grid.*;
import cnp.ew.layout.*;
import cnp.ew.lightweight.*;
import cnp.ew.charts.*;
import java.applet.*;
import cnp.ew.misc.*;
import cnp.ew.notebook.*;
import cnp.ew.text.*;
import cnp.ew.displayer.*;
import cnp.ew.list.*;
import cnp.ew.util.*;

public class CpNotebookDemo extends CpLcApplet
{
    CpPanelLc panelLc;
    CpAbstractNotebookLc currentNotebook;
    CpAttachmentsLayout layout;
    CpDropDownListLc typeChoice;

	public void init () {

        CpAttachments attachments;

        super.init();

        panelLc = new CpPanelLc();
        panelLc.setBorderStyle(CpAbstractLc.BORDER_NONE);
        setLc(panelLc);
        panelLc.setDrawOffscreen(true);
        layout = new CpAttachmentsLayout();
        panelLc.setLayout(layout);

        typeChoice = new CpDropDownListLc();
        typeChoice.addItem("Flat Tabs");
        typeChoice.addItem("3D Tabs");
        typeChoice.addObserver(this);
        typeChoice.setIsTabStop(true);
        attachments = new CpAttachments(-1, 10, -1, -1);
        attachments.setHorizontalCentering();
        layout.setAttachments(typeChoice, attachments);
        panelLc.add(typeChoice);


        addNotebook(new CpBeveledNotebookLc());

        setBackground(Color.lightGray);
		layout();
	}

    void addNotebook(CpAbstractNotebookLc notebook)
    {
        Font font = new Font("Times Roman", Font.BOLD, 26);
        if (currentNotebook != null) {
            currentNotebook.remove();
        }
        notebook.setIsTabStop(true);
        CpAttachments attachments = new CpAttachments(10, -1, 10, 10);
        attachments.setTopAttachment(15, typeChoice);
        layout.setAttachments(notebook, attachments);
        panelLc.add(notebook);

        CpReadOnlyTextAreaLc label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("One");
        notebook.addPage("Page One", label);

        label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("Two");
        notebook.addPage("Page Two", label);

        label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("Three");
        notebook.addPage("Page Three", label);

        label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("Four");
        notebook.addPage("Page Four", label);

        label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("Five");
        notebook.addPage("Page Five", label);

        label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("Six");
        notebook.addPage("Page Six", label);

        label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("Seven");
        notebook.addPage("Page Seven", label);

        label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("Eight");
        notebook.addPage("Page Eight", label);

        label = new CpReadOnlyTextAreaLc();
        label.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);
        label.setVerticalAlignment(CpAlignable.ALIGN_CENTER);
        label.setFont(font);
        label.setText("Nine");
        notebook.addPage("Page Nine", label);
        currentNotebook = notebook;
        panelLc.layout();
        // TBD: This seems suspect; the layouts, and all the removes and adds should have
        // caused damages to be executed.
        panelLc.repaint();
    }

    public void update(CpObservable o, int facet, Object arg)
    {
        if (o == typeChoice && facet == OBJECT_CHANGED) {
            switch (typeChoice.getSelectedIndex()) {
            case 0:
                addNotebook(new CpBeveledNotebookLc());
                break;
            case 1:
                addNotebook(new Cp3DNotebookLc());
                break;
            }
        }
    }
}

