import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
import java.io.ByteArrayOutputStream;
import JavaAgent.resource.fopl.*;

public class ToClauses extends Applet {

  TextArea
    inTA = new TextArea(7, 50),
    outTA = new TextArea(30, 50);
  Button tb = new Button("Translate");

  public void init() {
    setLayout(new BorderLayout());
    tb.addActionListener(new tbL());
    add(inTA, BorderLayout.NORTH);
    add(outTA, BorderLayout.SOUTH);
    outTA.setEditable(false);
    add(new Label("                          "), BorderLayout.WEST);
    add(new Label("                          "), BorderLayout.EAST);
    add(tb, BorderLayout.CENTER);
  }

  class tbL implements ActionListener {
    public void actionPerformed(ActionEvent ae) {
      outTA.setText("");
      try {
	Formula iForm = Formula.parse(inTA.getText());
	ClauseSet cs = new ClauseSet(iForm);
	ByteArrayOutputStream bOut = new ByteArrayOutputStream(2000);
	cs.writeToStream(bOut);
	outTA.setText(bOut.toString());
      } catch (Exception e) {
	outTA.setText(e.getMessage());
      }
    }
  }

}
