// FILE. . . . . /home/hak/ilt/src/ilog/rif/applet/Applet.java
// EDIT BY . . . Hassan Ait-Kaci
// ON MACHINE. . 4j4zn71
// STARTED ON. . Fri Apr 04 03:33:29 2008

/**
 * This a quick-&-dirty bare-bone applet with two text areas: one for
 * typing in BLD forms, and one for outputting the parser's output; and
 * two buttons: one to invoke the BLD->XML compiler on submitted input,
 * and one to reset the input and oupt areas.
 *
 * @version     Last modified on Mon May 05 21:57:15 2008 by hak
 * @author      <a href="mailto:hak@ilog.com">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; 2006 <a href="http://www.ilog.com/">ILOG, Inc.</a>
 */

import java.awt.*;
import java.awt.event.*;

import ilog.rif.bld.*;

public class Applet extends java.applet.Applet
{
  final int WIDTH = 600;
  final String GREETINGS = "Enter a BLD form here...";

  // The applet components: these cannot be private because some
  // browsers won't allow an inner class to access private members.

  TextArea input  = new TextArea(GREETINGS,20,100);
  TextArea output = new TextArea("",40,100);
  Button   doit   = new Button("XMLify");
  Button   reset  = new Button("Reset");

  public void init ()
  {
    // Add the text area for entering the input:
    input.setEditable(true);
    add(input);

    // Add the do-it button to invoke the compiler:
    add(doit);

    // Tell the doit button what it should do when clicked:
    doit.addActionListener(new DoitListener());

    // Add the text area for printing the output:
    output.setEditable(false);
    add(output);

    // Add the reset button to clean up both text areas:
    add(reset);

    // Tell the reset button what it should do when clicked:
    reset.addActionListener(new ResetListener());
  }

  /**
   * The DoitListener class.
   */
  class DoitListener implements ActionListener
  {
    public void actionPerformed (ActionEvent event)
    {
      try
	{
	  Parser p = new Parser(new Tokenizer());
	  p.setTreeType("XML");
          p.setQuiet(false);
          p.setApplet(true);
          p.setStartTime();
          p.parseRifDocument(input.getText());
	  output.setText(p.xmlForm());
	}
      catch (Exception e)
        {
	  output.setText("Something weird happened!...\n"
			 +e.getMessage());
        }     
    }
  }

  /**
   * The ResetListener class.
   */
  class ResetListener implements ActionListener
  {
    public void actionPerformed (ActionEvent event)
    {
      input.setText(GREETINGS);
      output.setText("");
    }
  }
}

