Prover/ProverApplet.pizza
changeset 96 907b1fff5637
equal deleted inserted replaced
95:345dd18f020e 96:907b1fff5637
       
     1 package G4ip;
       
     2 
       
     3 import java.applet.*;
       
     4 import java.awt.*;
       
     5 import G4ip.Sequent.*;
       
     6 import G4ip.Prover.*;
       
     7 import G4ip.Parser.*;
       
     8 
       
     9 /** The applet for the prover.
       
    10   * @author      Christian Urban
       
    11   */
       
    12 public class ProverApplet extends Applet {
       
    13   Prover prover;
       
    14   Parser parser;
       
    15 
       
    16   Button start;           
       
    17   Button clear;           
       
    18   Button next;            
       
    19   Button stop;           
       
    20   TextField lhs_text;     // place for the program formulae
       
    21   TextField rhs_text;     // place for the goal formula
       
    22   /** A field for various messages (e.g. error messages).
       
    23     */
       
    24   public Label messages;  // to be verbose   
       
    25 
       
    26   public void init() {
       
    27     setLayout(new BorderLayout());
       
    28     // NORTH
       
    29     Panel textfields = new Panel();
       
    30     add("North", textfields);
       
    31        // the parameters LHS_size and RHS_size are given in the html-file
       
    32     int LHS_size = Integer.parseInt(this.getParameter("LHS_size"));
       
    33     int RHS_size = Integer.parseInt(this.getParameter("RHS_size"));
       
    34     lhs_text = new TextField(LHS_size);    // program textfield
       
    35     rhs_text = new TextField(RHS_size);    // goal textfield
       
    36     Label separation = new Label("=>");    // for separation
       
    37 
       
    38     if (LHS_size > 0) {     // if someone prefears only single side sequents 
       
    39     textfields.add(lhs_text);   }         
       
    40     textfields.add(separation);
       
    41     textfields.add(rhs_text);
       
    42 
       
    43     // CENTER
       
    44     Panel buttonfield = new Panel();
       
    45     add("Center", buttonfield);
       
    46     start = new Button("Start");         
       
    47     clear = new Button("Clear");         
       
    48     next  = new Button("Next");          
       
    49     stop  = new Button("Stop");            
       
    50 
       
    51     switch_into_input_mode();   // start in input mode
       
    52     buttonfield.add(start);
       
    53     buttonfield.add(clear);
       
    54     buttonfield.add(next);
       
    55     buttonfield.add(stop);
       
    56 
       
    57     // SOUTH
       
    58     messages = new Label("");   // for any kind of message
       
    59     messages.setAlignment(Label.CENTER);
       
    60     add("South",messages);
       
    61   }
       
    62   
       
    63   /** When start is pressed; 
       
    64     * start and clear button are disabled;
       
    65     * next and stop button are enabled. 
       
    66     */
       
    67   public void switch_into_prove_mode() { 
       
    68       start.disable();    next.enable();
       
    69       clear.disable();    stop.enable();
       
    70       repaint();
       
    71     }
       
    72 
       
    73   /** When start is pressed 
       
    74     * and (hopefully) when prover finishes. 
       
    75     */  
       
    76   public void switch_into_input_mode() { 
       
    77       start.enable();    next.disable(); 
       
    78       clear.enable();    stop.disable();
       
    79       repaint();
       
    80     }
       
    81 
       
    82   /** Initiates the parse and prove process. 
       
    83     */  
       
    84   void initiate_proving() {
       
    85       Sequent sequ;
       
    86       messages.setText(""); 
       
    87       messages.repaint();
       
    88       repaint(); 
       
    89       Parser rhs_parser = new Parser(rhs_text.getText());
       
    90       Parser lhs_parser = new Parser(lhs_text.getText());
       
    91       try {                          // try to parse the input 
       
    92 	sequ = new Sequent(lhs_parser.parseFormulae(),
       
    93 			   rhs_parser.parseFormula());
       
    94       }
       
    95       catch (Exception exc) {        // there was a parser exception 
       
    96 	messages.setText(exc.getMessage()); 
       
    97 	messages.repaint();
       
    98 	repaint(); 
       
    99 	return;                     // in case there was an exception
       
   100       }                             // don't run the following code
       
   101       System.out.println(sequ.G.internalString()); 
       
   102       switch_into_prove_mode();
       
   103       prover = new Prover(sequ,this);
       
   104       prover.start();
       
   105   }
       
   106 
       
   107   /** Forces the prover to dispose all open frames.
       
   108     */
       
   109   public void destroy() {  
       
   110     if (prover != null && prover.isAlive()) { 
       
   111       prover.stop(); 
       
   112       prover.finalize();
       
   113     }
       
   114   }
       
   115 
       
   116 
       
   117   /** The actions for the buttons:
       
   118     * this bit of code would be different in Java 1.1
       
   119     */
       
   120   public boolean action(Event e, Object arg) {
       
   121     // clear button has been pressed
       
   122     if (e.target == clear) {
       
   123       messages.setText(""); 
       
   124       lhs_text.setText("");
       
   125       rhs_text.setText(""); 
       
   126       messages.repaint();
       
   127       repaint(); 
       
   128     }
       
   129     // start button has been pressed
       
   130     if (e.target == start) {
       
   131       initiate_proving();
       
   132       return true; 
       
   133     }
       
   134     // stop button has been pressed
       
   135     if (e.target == stop) {
       
   136       switch_into_input_mode();
       
   137       if (prover != null && prover.isAlive()) { prover.stop();  }
       
   138       return true; 
       
   139     }
       
   140     // next button has been pressed
       
   141     if (e.target == next) {
       
   142       if (prover != null && prover.isAlive()) { prover.resume();} 
       
   143       return true; 
       
   144     }
       
   145     return false;
       
   146   }
       
   147 
       
   148 }
       
   149 
       
   150