//
// test program that demonstrates the ControlListBox
// widget.
//
// Note - we use an (included) 3rd party module, 'waba.ui.Button2',
// because it has a fix for the clipping problem

import waba.ui.*;
import waba.sys.*;
import waba.fx.*;

public class Test extends MainWindow
{
    ControlListBox clb;
    
    Button butUpFully, butUpPage, butUpLine;
    Button butDownFully, butDownPage, butDownLine;
    
    Button butAddOne, butAddTen, butAddHundred;
    
    Button butDel1;
    Button butIns3;
    
    Button butDbg;
    
    int nextN = 0;
    
    public Test()
    {
        super("ControlListBox test", TAB_ONLY_BORDER);
    
        // I'm no fan of the default Superwaba blue background
        setBackColor(Color.WHITE);
    
        // and no fan of CE-like widgets on a Palm
        Settings.setUIStyle(Settings.PalmOS);
    
        // Create the scrolling container widget, size it and place it
        clb = new ControlListBox();
        clb.setRect(5, 20, 100, 120);
        add(clb);
    
        // and set its line scroll to height of text Label
        clb.setScrollLineAmount(11);
    
        // add a few lines
        for (int i=0; i<4; i++)
            clb.add(new Label("Line --------------"+nextN++));
    
    /**/
        // add a plain button
        Button2 b = new Button2("button");
        clb.add(b);
    
        // add a sized button, within a sized container
        Button2 b1 = new Button2("button");
        b1.setRect(5, 3, 70, 15);
        Container c1 = new Container();
        c1.setRect(0, 0, 90, 25);
        //c1.setBackColor(Color.YELLOW);
        c1.add(b1);
        clb.addSized(c1, 90, 25);
    /**/
    
        // add a set of scrolling buttons
        // to demonstrate the widget's scrolling methods
        butUpFully = new Button("|<");
        add(butUpFully, 5, 145);
    
        butUpPage = new Button("<<");
        add(butUpPage, 20, 145);
    
        butUpLine = new Button("<");
        add(butUpLine, 40, 145);
    
        butDownLine = new Button(">");
        add(butDownLine, 60, 145);
    
        butDownPage = new Button(">>");
        add(butDownPage, 75, 145);
    
        butDownFully = new Button(">|");
        add(butDownFully, 95, 145);
    
        // add buttons for adding and removing child controls
        butAddOne = new Button("Add 1 ");
        add(butAddOne, 110, 26);
        
        butAddTen = new Button("Add 10");
        add(butAddTen, 110, 40);
    
        butAddHundred = new Button("Add 100");
        add(butAddHundred, 110, 54);
    
        butDel1 = new Button("Del 1");
        add(butDel1, 110, 68);
    
        butIns3 = new Button("Ins 3");
        add(butIns3, 110, 82);
    
        // and a silly debugging button
        butDbg = new Button("DBG");
        add(butDbg, 110, 145);
    }
    
    public void onStart()
    {
    }
    
    public void onEvent(Event event)
    {
        if (event.type == ControlEvent.PRESSED)
        {
            // handle our scrolling demo buttons
            if (event.target == butUpFully)
                clb.scrollUpFully();
            else if (event.target == butUpPage)
                clb.scrollUpPage();
            else if (event.target == butUpLine)
                clb.scrollUpLine();
            else if (event.target == butDownLine)
                clb.scrollDownLine();
            else if (event.target == butDownPage)
                clb.scrollDownPage();
            else if (event.target == butDownFully)
                clb.scrollDownFully();
    
            // handle buttons for adding/removing content
            else if (event.target == butAddOne)
                clb.add(new Label("Line " + nextN++));
            else if (event.target == butAddTen)
                for (int i=0; i<10; i++)
                    clb.add(new Label("Line " + nextN++));
            else if (event.target == butAddHundred)
                for (int i=0; i<100; i++)
                    clb.add(new Label("Line " + nextN++));
            else if (event.target == butDel1)
                clb.remove(1);
            else if (event.target == butIns3)
                clb.insert(3, new Label("Line " + nextN++));
    
            else if (event.target == butDbg)
                clb.debugPopup();
    
        }
    
    //    else if (event.type == PenEvent.PEN_DOWN)
    //        exit(0);
    }
    
}

