17 import javax.swing.border.{BevelBorder, SoftBevelBorder} |
17 import javax.swing.border.{BevelBorder, SoftBevelBorder} |
18 |
18 |
19 import org.gjt.sp.jedit.{View, jEdit} |
19 import org.gjt.sp.jedit.{View, jEdit} |
20 |
20 |
21 |
21 |
22 class Timing_Dockable(view: View, position: String) extends Dockable(view, position) |
22 class Timing_Dockable(view: View, position: String) extends Dockable(view, position) { |
23 { |
|
24 /* entry */ |
23 /* entry */ |
25 |
24 |
26 private object Entry |
25 private object Entry { |
27 { |
26 object Ordering extends scala.math.Ordering[Entry] { |
28 object Ordering extends scala.math.Ordering[Entry] |
|
29 { |
|
30 def compare(entry1: Entry, entry2: Entry): Int = |
27 def compare(entry1: Entry, entry2: Entry): Int = |
31 entry2.timing compare entry1.timing |
28 entry2.timing compare entry1.timing |
32 } |
29 } |
33 |
30 |
34 object Renderer_Component extends Label |
31 object Renderer_Component extends Label { |
35 { |
|
36 opaque = false |
32 opaque = false |
37 xAlignment = Alignment.Leading |
33 xAlignment = Alignment.Leading |
38 border = BorderFactory.createEmptyBorder(2, 2, 2, 2) |
34 border = BorderFactory.createEmptyBorder(2, 2, 2, 2) |
39 |
35 |
40 var entry: Entry = null |
36 var entry: Entry = null |
41 override def paintComponent(gfx: Graphics2D): Unit = |
37 override def paintComponent(gfx: Graphics2D): Unit = { |
42 { |
38 def paint_rectangle(color: Color): Unit = { |
43 def paint_rectangle(color: Color): Unit = |
|
44 { |
|
45 val size = peer.getSize() |
39 val size = peer.getSize() |
46 val insets = border.getBorderInsets(peer) |
40 val insets = border.getBorderInsets(peer) |
47 val x = insets.left |
41 val x = insets.left |
48 val y = insets.top |
42 val y = insets.top |
49 val w = size.width - x - insets.right |
43 val w = size.width - x - insets.right |
61 } |
55 } |
62 super.paintComponent(gfx) |
56 super.paintComponent(gfx) |
63 } |
57 } |
64 } |
58 } |
65 |
59 |
66 class Renderer extends ListView.Renderer[Entry] |
60 class Renderer extends ListView.Renderer[Entry] { |
67 { |
61 def componentFor( |
68 def componentFor(list: ListView[_ <: Timing_Dockable.this.Entry], |
62 list: ListView[_ <: Timing_Dockable.this.Entry], |
69 isSelected: Boolean, focused: Boolean, entry: Entry, index: Int): Component = |
63 isSelected: Boolean, |
70 { |
64 focused: Boolean, |
|
65 entry: Entry, index: Int |
|
66 ): Component = { |
71 val component = Renderer_Component |
67 val component = Renderer_Component |
72 component.entry = entry |
68 component.entry = entry |
73 component.text = entry.print |
69 component.text = entry.print |
74 component |
70 component |
75 } |
71 } |
76 } |
72 } |
77 } |
73 } |
78 |
74 |
79 private abstract class Entry |
75 private abstract class Entry { |
80 { |
|
81 def timing: Double |
76 def timing: Double |
82 def print: String |
77 def print: String |
83 def follow(snapshot: Document.Snapshot): Unit |
78 def follow(snapshot: Document.Snapshot): Unit |
84 } |
79 } |
85 |
80 |
86 private case class Theory_Entry(name: Document.Node.Name, timing: Double, current: Boolean) |
81 private case class Theory_Entry(name: Document.Node.Name, timing: Double, current: Boolean) |
87 extends Entry |
82 extends Entry { |
88 { |
|
89 def print: String = |
83 def print: String = |
90 Time.print_seconds(timing) + "s theory " + quote(name.theory) |
84 Time.print_seconds(timing) + "s theory " + quote(name.theory) |
91 def follow(snapshot: Document.Snapshot): Unit = |
85 def follow(snapshot: Document.Snapshot): Unit = |
92 PIDE.editor.goto_file(true, view, name.node) |
86 PIDE.editor.goto_file(true, view, name.node) |
93 } |
87 } |
94 |
88 |
95 private case class Command_Entry(command: Command, timing: Double) extends Entry |
89 private case class Command_Entry(command: Command, timing: Double) |
96 { |
90 extends Entry { |
97 def print: String = |
91 def print: String = |
98 " " + Time.print_seconds(timing) + "s command " + quote(command.span.name) |
92 " " + Time.print_seconds(timing) + "s command " + quote(command.span.name) |
99 def follow(snapshot: Document.Snapshot): Unit = |
93 def follow(snapshot: Document.Snapshot): Unit = |
100 PIDE.editor.hyperlink_command(true, snapshot, command.id).foreach(_.follow(view)) |
94 PIDE.editor.hyperlink_command(true, snapshot, command.id).foreach(_.follow(view)) |
101 } |
95 } |
150 |
144 |
151 /* component state -- owned by GUI thread */ |
145 /* component state -- owned by GUI thread */ |
152 |
146 |
153 private var nodes_timing = Map.empty[Document.Node.Name, Document_Status.Overall_Timing] |
147 private var nodes_timing = Map.empty[Document.Node.Name, Document_Status.Overall_Timing] |
154 |
148 |
155 private def make_entries(): List[Entry] = |
149 private def make_entries(): List[Entry] = { |
156 { |
|
157 GUI_Thread.require {} |
150 GUI_Thread.require {} |
158 |
151 |
159 val name = |
152 val name = |
160 Document_View.get(view.getTextArea) match { |
153 Document_View.get(view.getTextArea) match { |
161 case None => Document.Node.Name.empty |
154 case None => Document.Node.Name.empty |
173 theories.flatMap(entry => |
166 theories.flatMap(entry => |
174 if (entry.name == name) entry.copy(current = true) :: commands |
167 if (entry.name == name) entry.copy(current = true) :: commands |
175 else List(entry)) |
168 else List(entry)) |
176 } |
169 } |
177 |
170 |
178 private def handle_update(restriction: Option[Set[Document.Node.Name]] = None): Unit = |
171 private def handle_update(restriction: Option[Set[Document.Node.Name]] = None): Unit = { |
179 { |
|
180 GUI_Thread.require {} |
172 GUI_Thread.require {} |
181 |
173 |
182 val snapshot = PIDE.session.snapshot() |
174 val snapshot = PIDE.session.snapshot() |
183 |
175 |
184 val nodes_timing1 = |
176 val nodes_timing1 = |
208 Session.Consumer[Session.Commands_Changed](getClass.getName) { |
200 Session.Consumer[Session.Commands_Changed](getClass.getName) { |
209 case changed => |
201 case changed => |
210 GUI_Thread.later { handle_update(Some(changed.nodes)) } |
202 GUI_Thread.later { handle_update(Some(changed.nodes)) } |
211 } |
203 } |
212 |
204 |
213 override def init(): Unit = |
205 override def init(): Unit = { |
214 { |
|
215 PIDE.session.commands_changed += main |
206 PIDE.session.commands_changed += main |
216 handle_update() |
207 handle_update() |
217 } |
208 } |
218 |
209 |
219 override def exit(): Unit = |
210 override def exit(): Unit = { |
220 { |
|
221 PIDE.session.commands_changed -= main |
211 PIDE.session.commands_changed -= main |
222 } |
212 } |
223 } |
213 } |