-
Notifications
You must be signed in to change notification settings - Fork 18
/
DrawSingleSequentInference.scala
95 lines (79 loc) · 3.08 KB
/
DrawSingleSequentInference.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package gapt.prooftool
import java.awt.Color
import gapt.formats.latex.LatexExporter
import gapt.proofs.SequentProof
import gapt.proofs.lk.rules.ExistsRightRule
import gapt.proofs.lk.rules.ForallLeftRule
import scala.swing._
class DrawSingleSequentInference[F, T <: SequentProof[F, T]](
main: ProofToolViewer[_],
var orientation: Orientation.Value,
sequent_element_renderer: F => String ) extends ScrollPane {
private var _p: Option[SequentProof[F, T]] = None
def p(): Option[SequentProof[F, T]] = _p
def p_=( np: Option[SequentProof[F, T]] ) = {
this._p = np
init()
revalidate()
repaint()
}
val auxiliaries = new BoxPanel( Orientation.Vertical ) {
border = Swing.TitledBorder( Swing.LineBorder( new Color( 0, 0, 0 ), 1 ), " Auxiliary: " )
background = new Color( 255, 255, 255 )
minimumSize = new Dimension( 50, 20 )
xLayoutAlignment = 0
}
val primaries = new BoxPanel( Orientation.Vertical ) {
border = Swing.TitledBorder( Swing.LineBorder( new Color( 0, 0, 0 ), 1 ), " Primary: " )
background = new Color( 255, 255, 255 )
minimumSize = new Dimension( 50, 20 )
xLayoutAlignment = 0
}
val rule = new BoxPanel( Orientation.Vertical ) {
border = Swing.TitledBorder( Swing.LineBorder( new Color( 0, 0, 0 ), 1 ), " Inference: " )
background = new Color( 255, 255, 255 )
minimumSize = new Dimension( 50, 20 )
xLayoutAlignment = 0
}
val substitution = new BoxPanel( Orientation.Vertical ) {
border = Swing.TitledBorder( Swing.LineBorder( new Color( 0, 0, 0 ), 1 ), " Substitution: " )
background = new Color( 255, 255, 255 )
minimumSize = new Dimension( 50, 20 )
xLayoutAlignment = 0
}
def setContents(): Unit = {
contents = new BoxPanel( orientation ) {
contents += rule
contents += auxiliaries
contents += primaries
contents += substitution
}
}
setContents()
def init(): Unit = {
rule.contents.clear()
if ( p() != None ) rule.contents += LatexLabel( main, p().get.name )
rule.contents += Swing.Glue
auxiliaries.contents.clear()
val aux = for ( proof <- p().toList; ( auxIndices, premise ) <- proof.auxIndices zip proof.premises )
yield for ( ( f, i ) <- premise.zipWithIndex if auxIndices contains i ) yield f
for ( x <- aux ) auxiliaries.contents += DrawSequent( main, x, sequent_element_renderer )
auxiliaries.contents += Swing.Glue
primaries.contents.clear()
val primary = for ( proof <- p() ) yield for {
( f, i ) <- proof.conclusion.zipWithIndex
if proof.mainIndices contains i
} yield f
for ( prim <- primary ) primaries.contents += DrawSequent( main, prim, sequent_element_renderer )
primaries.contents += Swing.Glue
substitution.contents.clear()
p() match {
case Some( proof: ForallLeftRule ) =>
substitution.contents += LatexLabel( main, LatexExporter( proof.term ) )
case Some( proof: ExistsRightRule ) =>
substitution.contents += LatexLabel( main, LatexExporter( proof.term ) )
case _ =>
}
substitution.contents += Swing.Glue
}
}