author | immler@in.tum.de |
Fri, 22 May 2009 13:43:34 +0200 | |
changeset 34559 | 2adb23c3e5d1 |
parent 34558 | 668fae39d86d |
child 34560 | 08f0d81c6833 |
permissions | -rw-r--r-- |
34393 | 1 |
/* |
34407 | 2 |
* Document markup nodes, with connection to Swing tree model |
34393 | 3 |
* |
34407 | 4 |
* @author Fabian Immler, TU Munich |
34393 | 5 |
*/ |
6 |
||
7 |
package isabelle.prover |
|
8 |
||
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
9 |
import isabelle.proofdocument.ProofDocument |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
10 |
|
34400
1b61a92f8675
MarkupNode instead of DefaultMutableTreeNode and RelativeAsset
immler@in.tum.de
parents:
34393
diff
changeset
|
11 |
import sidekick.IAsset |
34393 | 12 |
import javax.swing._ |
13 |
import javax.swing.text.Position |
|
34400
1b61a92f8675
MarkupNode instead of DefaultMutableTreeNode and RelativeAsset
immler@in.tum.de
parents:
34393
diff
changeset
|
14 |
import javax.swing.tree._ |
34393 | 15 |
|
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
16 |
object MarkupNode { |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
17 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
18 |
def markup2default_node(node: MarkupNode, cmd: Command, doc: ProofDocument) : DefaultMutableTreeNode = { |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
19 |
|
34480 | 20 |
implicit def int2pos(offset: Int): Position = |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
21 |
new Position { def getOffset = offset; override def toString = offset.toString} |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
22 |
|
34480 | 23 |
object RelativeAsset extends IAsset { |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
24 |
override def getIcon : Icon = null |
34555
7c001369956a
included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents:
34554
diff
changeset
|
25 |
override def getShortString : String = node.content |
34514
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
26 |
override def getLongString : String = node.desc |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
27 |
override def getName : String = node.id |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
28 |
override def setName (name : String) = () |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
29 |
override def setStart(start : Position) = () |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
30 |
override def getStart : Position = node.abs_start(doc) |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
31 |
override def setEnd(end : Position) = () |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
32 |
override def getEnd : Position = node.abs_stop(doc) |
34555
7c001369956a
included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents:
34554
diff
changeset
|
33 |
override def toString = node.id + ": " + node.content + "[" + getStart + " - " + getEnd + "]" |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
34 |
} |
34393 | 35 |
|
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
36 |
new DefaultMutableTreeNode(RelativeAsset) |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
37 |
} |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
38 |
} |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
39 |
|
34514
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
40 |
class MarkupNode (val base : Command, val start : Int, val stop : Int, |
34557 | 41 |
val children: List[MarkupNode], |
42 |
val id : String, val content : String, val desc : String) { |
|
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
43 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
44 |
def swing_node(doc: ProofDocument) : DefaultMutableTreeNode = { |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
45 |
val node = MarkupNode.markup2default_node (this, base, doc) |
34557 | 46 |
children.map(node add _.swing_node(doc)) |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
47 |
node |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
48 |
} |
34557 | 49 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
50 |
def abs_start(doc: ProofDocument) = base.start(doc) + start |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34517
diff
changeset
|
51 |
def abs_stop(doc: ProofDocument) = base.start(doc) + stop |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
52 |
|
34557 | 53 |
def set_children(newchildren: List[MarkupNode]): MarkupNode = |
54 |
new MarkupNode(base, start, stop, newchildren, id, content, desc) |
|
34514
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
55 |
|
34557 | 56 |
def add(child : MarkupNode) = set_children ((child :: children) sort ((a, b) => a.start < b.start)) |
34393 | 57 |
|
34557 | 58 |
def remove(nodes : List[MarkupNode]) = set_children(children diff nodes) |
34393 | 59 |
|
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
60 |
def dfs : List[MarkupNode] = { |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
61 |
var all = Nil : List[MarkupNode] |
34503 | 62 |
for (child <- children) |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
63 |
all = child.dfs ::: all |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
64 |
all = this :: all |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
65 |
all |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
66 |
} |
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
67 |
|
34514
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
68 |
def leafs: List[MarkupNode] = { |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
69 |
if (children == Nil) return List(this) |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
70 |
else return children flatMap (_.leafs) |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
71 |
} |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
72 |
|
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
73 |
def flatten: List[MarkupNode] = { |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
74 |
var next_x = start |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
75 |
if(children.length == 0) List(this) |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
76 |
else { |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
77 |
val filled_gaps = for { |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
78 |
child <- children |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
79 |
markups = if (next_x < child.start) { |
34558 | 80 |
new MarkupNode(base, next_x, child.start, Nil, id, content, desc) :: child.flatten |
34514
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
81 |
} else child.flatten |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
82 |
update = (next_x = child.stop) |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
83 |
markup <- markups |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
84 |
} yield markup |
34558 | 85 |
if (next_x < stop) filled_gaps + new MarkupNode(base, next_x, stop, Nil, id, content, desc) |
34514
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
86 |
else filled_gaps |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
87 |
} |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
88 |
} |
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
89 |
|
34559 | 90 |
def filter(p: (MarkupNode => Boolean)): List[MarkupNode] = { |
91 |
val filtered = children.flatMap(_.filter(p)) |
|
92 |
if (p(this)) List(this set_children(filtered)) |
|
93 |
else filtered |
|
94 |
} |
|
95 |
||
34557 | 96 |
def +(new_child : MarkupNode) : MarkupNode = { |
34503 | 97 |
if (new_child fitting_into this) { |
34557 | 98 |
val new_children = children.map(c => if((new_child fitting_into c)) c + new_child else c) |
99 |
if (new_children == children) { |
|
100 |
// new_child did not fit into children of this -> insert new_child between this and its children |
|
101 |
val (fitting, nonfitting) = children span(_ fitting_into new_child) |
|
102 |
this remove fitting add ((new_child /: fitting) (_ add _)) |
|
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
103 |
} |
34557 | 104 |
else this set_children new_children |
34400
1b61a92f8675
MarkupNode instead of DefaultMutableTreeNode and RelativeAsset
immler@in.tum.de
parents:
34393
diff
changeset
|
105 |
} else { |
34557 | 106 |
error("ignored nonfitting markup " + new_child.id + new_child.content + new_child.desc |
34514
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
107 |
+ "(" +new_child.start + ", "+ new_child.stop + ")") |
34400
1b61a92f8675
MarkupNode instead of DefaultMutableTreeNode and RelativeAsset
immler@in.tum.de
parents:
34393
diff
changeset
|
108 |
} |
1b61a92f8675
MarkupNode instead of DefaultMutableTreeNode and RelativeAsset
immler@in.tum.de
parents:
34393
diff
changeset
|
109 |
} |
34393 | 110 |
|
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34400
diff
changeset
|
111 |
// does this fit into node? |
34557 | 112 |
def fitting_into(node : MarkupNode) = node.start <= this.start && node.stop >= this.stop |
34514
2104a836b415
renamed fields of MarkupNode; implemented flatten and leafs
immler@in.tum.de
parents:
34503
diff
changeset
|
113 |
|
34555
7c001369956a
included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents:
34554
diff
changeset
|
114 |
override def toString = "([" + start + " - " + stop + "] " + id + "( " + content + "): " + desc |
34393 | 115 |
} |