Prover/ProofDisplay.pizza
changeset 96 907b1fff5637
equal deleted inserted replaced
95:345dd18f020e 96:907b1fff5637
       
     1 package G4ip;
       
     2 
       
     3 import pizza.util.Hashtable;
       
     4 import java.awt.*;
       
     5 import G4ip.Form.*;
       
     6 
       
     7 
       
     8 /** A label with a surrounding box.
       
     9   */
       
    10 class MyLabel extends Label {
       
    11   public MyLabel() { super(); }
       
    12   public MyLabel(String s) { super(s); }
       
    13 
       
    14   public void paint(Graphics g) {
       
    15     Dimension d = this.size();
       
    16     g.setColor(Color.gray);
       
    17     g.drawRect(0,0,d.width-1,d.height-1);
       
    18   }
       
    19 }
       
    20 
       
    21 
       
    22 /** Draws a frame on the screen containing a proof.
       
    23   */
       
    24 public class ProofDisplay extends Frame {
       
    25   Button ok;
       
    26   Hashtable<int,Sequent> proof;      // contains the indexed sequents 
       
    27 
       
    28   /** The proof is represented in the hashtable.
       
    29     * @param proof is a hashtable; the structure of the proof (or tree) 
       
    30     * is mapped onto a sequence of integers; each integer is a key for
       
    31     * a sequent stored in the hashtable.
       
    32     */
       
    33   public ProofDisplay(Hashtable<int,Sequent> iproof) {
       
    34     super("Proof");
       
    35     ok = new Button("Close");
       
    36     proof = iproof;
       
    37 
       
    38     setLayout(new BorderLayout());
       
    39     // SOUTH
       
    40     Panel p = new Panel();
       
    41     p.add(ok);
       
    42     add("South",p);
       
    43 
       
    44     //CENTER
       
    45     Panel display = new Panel();
       
    46     printproof(display,1);
       
    47     add("Center", display);
       
    48 
       
    49     pack();
       
    50     show();
       
    51   }
       
    52 
       
    53   /** Recovers the structure of the proofs from the hashtable representation.
       
    54     */
       
    55   public void printproof(Panel p,int index) {
       
    56     MyLabel l = new MyLabel(proof.get(index).toString());
       
    57     l.setAlignment(MyLabel.CENTER);
       
    58     p.setLayout(new BorderLayout());
       
    59     p.add("South",l); 
       
    60     // axiom (do nothing)
       
    61     if ((proof.get(2*index) == null) && (proof.get(2*index+1) == null)) { 
       
    62       return;    
       
    63     }
       
    64     // rule with a single premise
       
    65     if ((proof.get(2*index) != null) && (proof.get(2*index+1) == null)) { 
       
    66       Panel np = new Panel();
       
    67       printproof(np,2*index);
       
    68       p.add("Center",np);
       
    69       return;  
       
    70     }
       
    71     // rule with two premises
       
    72     if ((proof.get(2*index) != null) && (proof.get(2*index+1) != null)) { 
       
    73       Panel np1 = new Panel();
       
    74       Panel np2 = new Panel();
       
    75       printproof(np1,2*index);
       
    76       printproof(np2,2*index+1);
       
    77       p.add("West",np1);
       
    78       p.add("East",np2);
       
    79       return;
       
    80     }
       
    81     
       
    82   }
       
    83 
       
    84   /** If either the "Close" or the "Window-destroy" button
       
    85     * is pressed, then close the window.
       
    86     */
       
    87   public boolean handleEvent(Event e)  {
       
    88     if (e.id == Event.ACTION_EVENT && e.target == ok) {
       
    89       this.finalize(); 
       
    90       return true;
       
    91     }
       
    92     if (e.id == Event.WINDOW_DESTROY) {
       
    93       this.finalize(); 
       
    94       return true;
       
    95     }
       
    96     return false;
       
    97   }
       
    98 
       
    99   /** Closes the window.
       
   100     */
       
   101   public void finalize()
       
   102     { this.dispose();  }
       
   103   
       
   104 }
       
   105 
       
   106