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