author | wenzelm |
Mon, 29 Jul 2013 15:01:44 +0200 | |
changeset 52769 | 0827b6f5de44 |
parent 52763 | 3b5f4f2ff108 |
child 52779 | 82707f95a783 |
permissions | -rw-r--r-- |
50299 | 1 |
/* Title: Tools/jEdit/src/theories_dockable.scala |
39515 | 2 |
Author: Makarius |
3 |
||
50299 | 4 |
Dockable window for theories managed by prover. |
39515 | 5 |
*/ |
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
import scala.actors.Actor._ |
|
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
13 |
import scala.swing.{FlowPanel, Button, TextArea, Label, ListView, Alignment, ScrollPane, Component, |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
14 |
BoxPanel, Orientation, RadioButton, ButtonGroup} |
49246 | 15 |
import scala.swing.event.{ButtonClicked, MouseClicked} |
39593 | 16 |
|
43520
cec9b95fa35d
explicit import java.lang.System to prevent odd scope problems;
wenzelm
parents:
43282
diff
changeset
|
17 |
import java.lang.System |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
18 |
import java.awt.{BorderLayout, Graphics2D, Insets, Color} |
47588 | 19 |
import javax.swing.{JList, BorderFactory} |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
20 |
import javax.swing.border.{BevelBorder, SoftBevelBorder, LineBorder} |
39515 | 21 |
|
44865 | 22 |
import org.gjt.sp.jedit.{View, jEdit} |
39515 | 23 |
|
24 |
||
50299 | 25 |
class Theories_Dockable(view: View, position: String) extends Dockable(view, position) |
39515 | 26 |
{ |
48021
d899be1cfe6d
separate syslog dockable -- discontinued tendency of sub-window management via tabs;
wenzelm
parents:
48018
diff
changeset
|
27 |
/* status */ |
39591 | 28 |
|
48021
d899be1cfe6d
separate syslog dockable -- discontinued tendency of sub-window management via tabs;
wenzelm
parents:
48018
diff
changeset
|
29 |
private val status = new ListView(Nil: List[Document.Node.Name]) { |
44991 | 30 |
listenTo(mouse.clicks) |
31 |
reactions += { |
|
32 |
case MouseClicked(_, point, _, clicks, _) if clicks == 2 => |
|
33 |
val index = peer.locationToIndex(point) |
|
51534 | 34 |
if (index >= 0) Hyperlink(listData(index).node).follow(view) |
44991 | 35 |
} |
36 |
} |
|
50250 | 37 |
status.peer.setLayoutOrientation(JList.HORIZONTAL_WRAP) |
38 |
status.peer.setVisibleRowCount(0) |
|
44609 | 39 |
status.selection.intervalMode = ListView.IntervalMode.Single |
40 |
||
49038 | 41 |
set_content(new ScrollPane(status)) |
39515 | 42 |
|
43 |
||
39593 | 44 |
/* controls */ |
45 |
||
50299 | 46 |
def phase_text(phase: Session.Phase): String = |
47 |
"Prover: " + Library.lowercase(phase.toString) |
|
48 |
||
49 |
private val session_phase = new Label(phase_text(PIDE.session.phase)) |
|
39697 | 50 |
session_phase.border = new SoftBevelBorder(BevelBorder.LOWERED) |
50299 | 51 |
session_phase.tooltip = "Status of prover session" |
39635 | 52 |
|
48018
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
53 |
private def handle_phase(phase: Session.Phase) |
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
54 |
{ |
50299 | 55 |
Swing_Thread.later { session_phase.text = " " + phase_text(phase) + " " } |
48018
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
56 |
} |
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
57 |
|
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
58 |
private val execution_range = new BoxPanel(Orientation.Horizontal) { |
52769 | 59 |
private def button(range: PIDE.Execution_Range.Value, tip: String): RadioButton = |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
60 |
new RadioButton(range.toString) { |
52769 | 61 |
tooltip = tip |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
62 |
reactions += { case ButtonClicked(_) => PIDE.update_execution_range(range) } |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
63 |
} |
52769 | 64 |
private val label = |
65 |
new Label("Range:") { tooltip = "Execution range of continuous document processing" } |
|
66 |
private val b1 = button(PIDE.Execution_Range.ALL, "Check all theories") |
|
67 |
private val b2 = button(PIDE.Execution_Range.NONE, "Check nothing") |
|
68 |
private val b3 = button(PIDE.Execution_Range.VISIBLE, "Check visible parts of theories") |
|
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
69 |
private val group = new ButtonGroup(b1, b2, b3) |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
70 |
contents ++= List(label, b1, b2, b3) |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
71 |
border = new LineBorder(Color.GRAY) |
44775
27930cf6f0f7
added "cancel" button based on cancel_execution, not interrupt (cf. 156be0e43336);
wenzelm
parents:
44734
diff
changeset
|
72 |
|
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
73 |
def load() |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
74 |
{ |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
75 |
PIDE.execution_range() match { |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
76 |
case PIDE.Execution_Range.ALL => group.select(b1) |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
77 |
case PIDE.Execution_Range.NONE => group.select(b2) |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
78 |
case PIDE.Execution_Range.VISIBLE => group.select(b3) |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
79 |
} |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
80 |
} |
52763 | 81 |
load() |
44776
47e8c8daccae
added "check" button: adhoc change to full buffer perspective;
wenzelm
parents:
44775
diff
changeset
|
82 |
} |
47e8c8daccae
added "check" button: adhoc change to full buffer perspective;
wenzelm
parents:
44775
diff
changeset
|
83 |
|
49246 | 84 |
private val logic = Isabelle_Logic.logic_selector(true) |
39702 | 85 |
|
44775
27930cf6f0f7
added "cancel" button based on cancel_execution, not interrupt (cf. 156be0e43336);
wenzelm
parents:
44734
diff
changeset
|
86 |
private val controls = |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
87 |
new FlowPanel(FlowPanel.Alignment.Right)(execution_range, session_phase, logic) |
39593 | 88 |
add(controls.peer, BorderLayout.NORTH) |
89 |
||
90 |
||
44609 | 91 |
/* component state -- owned by Swing thread */ |
92 |
||
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
93 |
private var nodes_status: Map[Document.Node.Name, Protocol.Node_Status] = Map.empty |
44866 | 94 |
|
44990 | 95 |
private object Node_Renderer_Component extends Label |
44866 | 96 |
{ |
44990 | 97 |
opaque = false |
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
98 |
xAlignment = Alignment.Leading |
44989
5450ab3c677e
explicit border independent of UI (cf. ad5883642a83, 2bec3b7514cf);
wenzelm
parents:
44981
diff
changeset
|
99 |
border = BorderFactory.createEmptyBorder(2, 2, 2, 2) |
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
100 |
|
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
101 |
var node_name = Document.Node.Name.empty |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
102 |
override def paintComponent(gfx: Graphics2D) |
44866 | 103 |
{ |
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
104 |
nodes_status.get(node_name) match { |
44866 | 105 |
case Some(st) if st.total > 0 => |
50900
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
106 |
val colors = List( |
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
107 |
(st.unprocessed, PIDE.options.color_value("unprocessed1_color")), |
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
108 |
(st.running, PIDE.options.color_value("running_color")), |
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
109 |
(st.warned, PIDE.options.color_value("warning_color")), |
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
110 |
(st.failed, PIDE.options.color_value("error_color"))) |
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
111 |
|
44958 | 112 |
val size = peer.getSize() |
51535 | 113 |
val insets = border.getBorderInsets(peer) |
44958 | 114 |
val w = size.width - insets.left - insets.right |
115 |
val h = size.height - insets.top - insets.bottom |
|
116 |
var end = size.width - insets.right |
|
50900
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
117 |
|
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
118 |
for { (n, color) <- colors } |
44866 | 119 |
{ |
120 |
gfx.setColor(color) |
|
50900
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
121 |
val v = (n * (w - colors.length) / st.total) max (if (n > 0) 4 else 0) |
44958 | 122 |
gfx.fillRect(end - v, insets.top, v, h) |
50900
6d80709ab862
separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents:
50895
diff
changeset
|
123 |
end = end - v - 1 |
44866 | 124 |
} |
125 |
case _ => |
|
126 |
} |
|
44867 | 127 |
super.paintComponent(gfx) |
44866 | 128 |
} |
129 |
} |
|
130 |
||
44990 | 131 |
private class Node_Renderer extends ListView.Renderer[Document.Node.Name] |
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
132 |
{ |
44990 | 133 |
def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, |
134 |
name: Document.Node.Name, index: Int): Component = |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
135 |
{ |
44990 | 136 |
val component = Node_Renderer_Component |
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
137 |
component.node_name = name |
44989
5450ab3c677e
explicit border independent of UI (cf. ad5883642a83, 2bec3b7514cf);
wenzelm
parents:
44981
diff
changeset
|
138 |
component.text = name.theory |
44990 | 139 |
component |
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
140 |
} |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
141 |
} |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44867
diff
changeset
|
142 |
status.renderer = new Node_Renderer |
44609 | 143 |
|
45011
436ea69d5d37
more careful treatment of initial update, similar to output panel;
wenzelm
parents:
44991
diff
changeset
|
144 |
private def handle_update(restriction: Option[Set[Document.Node.Name]] = None) |
44609 | 145 |
{ |
146 |
Swing_Thread.now { |
|
50205 | 147 |
val snapshot = PIDE.session.snapshot() |
44613 | 148 |
|
46723 | 149 |
val iterator = |
150 |
restriction match { |
|
151 |
case Some(names) => names.iterator.map(name => (name, snapshot.version.nodes(name))) |
|
152 |
case None => snapshot.version.nodes.entries |
|
153 |
} |
|
46681 | 154 |
val nodes_status1 = |
46723 | 155 |
(nodes_status /: iterator)({ case (status, (name, node)) => |
50205 | 156 |
if (PIDE.thy_load.loaded_theories(name.theory)) status |
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46723
diff
changeset
|
157 |
else status + (name -> Protocol.node_status(snapshot.state, snapshot.version, node)) }) |
44672 | 158 |
|
159 |
if (nodes_status != nodes_status1) { |
|
160 |
nodes_status = nodes_status1 |
|
44866 | 161 |
status.listData = |
46723 | 162 |
snapshot.version.nodes.topological_order.filter( |
44960 | 163 |
(name: Document.Node.Name) => nodes_status.isDefinedAt(name)) |
44609 | 164 |
} |
165 |
} |
|
166 |
} |
|
167 |
||
168 |
||
39515 | 169 |
/* main actor */ |
170 |
||
171 |
private val main_actor = actor { |
|
172 |
loop { |
|
173 |
react { |
|
48018
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
174 |
case phase: Session.Phase => handle_phase(phase) |
39635 | 175 |
|
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
176 |
case _: Session.Global_Options => |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
177 |
Swing_Thread.later { |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
178 |
execution_range.load() |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
179 |
logic.load () |
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
51535
diff
changeset
|
180 |
} |
49247 | 181 |
|
45011
436ea69d5d37
more careful treatment of initial update, similar to output panel;
wenzelm
parents:
44991
diff
changeset
|
182 |
case changed: Session.Commands_Changed => handle_update(Some(changed.nodes)) |
44609 | 183 |
|
50299 | 184 |
case bad => System.err.println("Theories_Dockable: ignoring bad message " + bad) |
39515 | 185 |
} |
186 |
} |
|
187 |
} |
|
188 |
||
48018
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
189 |
override def init() |
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
190 |
{ |
50205 | 191 |
PIDE.session.phase_changed += main_actor; handle_phase(PIDE.session.phase) |
192 |
PIDE.session.global_options += main_actor |
|
193 |
PIDE.session.commands_changed += main_actor; handle_update() |
|
39635 | 194 |
} |
195 |
||
48018
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
196 |
override def exit() |
b941dd7df92a
make double sure that GUI components are up-to-date after init;
wenzelm
parents:
48014
diff
changeset
|
197 |
{ |
50205 | 198 |
PIDE.session.phase_changed -= main_actor |
199 |
PIDE.session.global_options -= main_actor |
|
200 |
PIDE.session.commands_changed -= main_actor |
|
39635 | 201 |
} |
39515 | 202 |
} |