//import coco.*;
import java.io.*;
import java.awt.*;

/*page designers may write codes such as this*/
class GenerateExampleCocoPage{
  public static void main(String[] argv){
    /*tabula rasa*/
    CocoPage cp=new CocoPage();

    /*add a label showing static text*/
    cp.setLayout(new GridBagLayout());
    cp.add(
      new Label("This is an example coco page."),
      new GridBagConstraints(
        1/*gridx*/,
        1/*gridy*/,
        2/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.CENTER/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    );

    /*add some form components*/
    Checkbox cb=new Checkbox("check this");
    cp.add(
      cb,
      new GridBagConstraints(
        1/*gridx*/,
        2/*gridy*/,
        2/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.CENTER/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    );
    Choice ch=new Choice();
    ch.add("Eenie");
    ch.add("Meenie");
    ch.add("Minie");
    ch.add("Jacob");
    cp.add(
      new Label("Choose one: "),
      new GridBagConstraints(
        1/*gridx*/,
        3/*gridy*/,
        1/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.EAST/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    );
    cp.add(
      ch,
      new GridBagConstraints(
        2/*gridx*/,
        3/*gridy*/,
        1/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.WEST/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    );
    List ls=new List(0,true);
    ls.add("Bill");
    ls.add("Ball");
    ls.add("Bull");
    ls.add("Bell");
    cp.add(
      new Label("Choose zero or more: "),
      new GridBagConstraints(
        1/*gridx*/,
        4/*gridy*/,
        1/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.EAST/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    );
    cp.add(
      ls,
      new GridBagConstraints(
        2/*gridx*/,
        4/*gridy*/,
        1/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.WEST/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    );
    TextField tf=new TextField("default");
    cp.add(
      new Label("Type some text: "),
      new GridBagConstraints(
        1/*gridx*/,
        5/*gridy*/,
        1/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.EAST/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    );
    cp.add(
      tf,
      new GridBagConstraints(
        2/*gridx*/,
        5/*gridy*/,
        1/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.WEST/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    );

    /*add a submit button; actionlistener remains unset until page is
      downloaded*/
    CocoSubmitButton b=new CocoSubmitButton();
    b.setLabel("Submit"); //look
    b.setCocoAddressee("/dev/null"); //addressee
    cp.add(
      b,
      new GridBagConstraints(
        1/*gridx*/,
        6/*gridy*/,
        2/*gridwidth*/,1/*gridheight*/,
        0/*weightx*/,0/*weighty*/,
        GridBagConstraints.CENTER/*anchor*/,
        GridBagConstraints.NONE/*fill*/,
        new Insets(8,8,8,8)/*insets*/,
        0/*ipadx*/,0/*ipady*/
      )
    ); //to the page

    //include the whole form
    b.addParameter(cb);
    b.addParameter(ch);
    b.addParameter(ls);
    b.addParameter(tf);

    /*write the page to a file; designer will upload this file to the
      coco page server*/
    try{
      cp.dump("justdown.cjd");
    }catch(IOException x){
      System.out.println("Error dumping generated page.\n"+x.toString());
    }
  }
}
