author | wenzelm |
Sun, 29 Aug 2010 15:09:11 +0200 | |
changeset 38845 | a9e37daf5bd0 |
parent 38843 | d95522496593 |
child 38855 | 35b2d91e88d7 |
permissions | -rw-r--r-- |
36760 | 1 |
/* Title: Tools/jEdit/src/jedit/document_view.scala |
2 |
Author: Fabian Immler, TU Munich |
|
3 |
Author: Makarius |
|
4 |
||
5 |
Document view connected to jEdit text area. |
|
6 |
*/ |
|
34408 | 7 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
8 |
package isabelle.jedit |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
9 |
|
34760 | 10 |
|
36015 | 11 |
import isabelle._ |
12 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
13 |
import scala.actors.Actor._ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
14 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
15 |
import java.awt.event.{MouseAdapter, MouseEvent} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
16 |
import java.awt.{BorderLayout, Graphics, Dimension, Color, Graphics2D} |
34734 | 17 |
import javax.swing.{JPanel, ToolTipManager} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
18 |
import javax.swing.event.{CaretListener, CaretEvent} |
34734 | 19 |
|
34709 | 20 |
import org.gjt.sp.jedit.gui.RolloverButton |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
21 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter} |
37241
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
22 |
import org.gjt.sp.jedit.syntax.SyntaxStyle |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
23 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
24 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
25 |
object Document_View |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
26 |
{ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38223
diff
changeset
|
27 |
def choose_color(snapshot: Document.Snapshot, command: Command): Color = |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
28 |
{ |
38356
443fb83a21e8
consider command state as part of Snapshot, not Document;
wenzelm
parents:
38227
diff
changeset
|
29 |
val state = snapshot.state(command) |
38151 | 30 |
if (snapshot.is_outdated) new Color(240, 240, 240) |
37186
349e9223c685
explicit markup for forked goals, as indicated by Goal.fork;
wenzelm
parents:
37132
diff
changeset
|
31 |
else |
38567
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38429
diff
changeset
|
32 |
Isar_Document.command_status(state.status) match { |
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38429
diff
changeset
|
33 |
case Isar_Document.Forked(i) if i > 0 => new Color(255, 228, 225) |
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38429
diff
changeset
|
34 |
case Isar_Document.Finished => new Color(234, 248, 255) |
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38429
diff
changeset
|
35 |
case Isar_Document.Failed => new Color(255, 193, 193) |
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38429
diff
changeset
|
36 |
case Isar_Document.Unprocessed => new Color(255, 228, 225) |
38429
9951852fae91
simplified command status: interpret stacked markup on demand;
wenzelm
parents:
38426
diff
changeset
|
37 |
case _ => Color.red |
37186
349e9223c685
explicit markup for forked goals, as indicated by Goal.fork;
wenzelm
parents:
37132
diff
changeset
|
38 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
39 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
40 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
41 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
42 |
/* document view of text area */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
43 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
44 |
private val key = new Object |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
45 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
46 |
def init(model: Document_Model, text_area: TextArea): Document_View = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
47 |
{ |
38223 | 48 |
Swing_Thread.require() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
49 |
val doc_view = new Document_View(model, text_area) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
50 |
text_area.putClientProperty(key, doc_view) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
51 |
doc_view.activate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
52 |
doc_view |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
53 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
54 |
|
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
55 |
def apply(text_area: TextArea): Option[Document_View] = |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
56 |
{ |
38223 | 57 |
Swing_Thread.require() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
58 |
text_area.getClientProperty(key) match { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
59 |
case doc_view: Document_View => Some(doc_view) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
60 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
61 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
62 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
63 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
64 |
def exit(text_area: TextArea) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
65 |
{ |
38223 | 66 |
Swing_Thread.require() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
67 |
apply(text_area) match { |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
68 |
case None => error("No document view for text area: " + text_area) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
69 |
case Some(doc_view) => |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
70 |
doc_view.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
71 |
text_area.putClientProperty(key, null) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
72 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
73 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
74 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
75 |
|
34733 | 76 |
|
37129 | 77 |
class Document_View(val model: Document_Model, text_area: TextArea) |
34654 | 78 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
79 |
private val session = model.session |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
80 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
81 |
|
37241
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
82 |
/* extended token styles */ |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
83 |
|
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
84 |
private var styles: Array[SyntaxStyle] = null // owned by Swing thread |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
85 |
|
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
86 |
def extend_styles() |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
87 |
{ |
38223 | 88 |
Swing_Thread.require() |
38158 | 89 |
styles = Document_Model.Token_Markup.extend_styles(text_area.getPainter.getStyles) |
37241
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
90 |
} |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
91 |
extend_styles() |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
92 |
|
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
93 |
def set_styles() |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
94 |
{ |
38223 | 95 |
Swing_Thread.require() |
37241
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
96 |
text_area.getPainter.setStyles(styles) |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
97 |
} |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
98 |
|
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
99 |
|
37129 | 100 |
/* commands_changed_actor */ |
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
101 |
|
37129 | 102 |
private val commands_changed_actor = actor { |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
103 |
loop { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
104 |
react { |
38360 | 105 |
case Session.Commands_Changed(changed) => |
38843 | 106 |
val buffer = model.buffer |
107 |
Isabelle.swing_buffer_lock(buffer) { |
|
38151 | 108 |
val snapshot = model.snapshot() |
38843 | 109 |
if (changed.exists(snapshot.node.commands.contains)) { |
110 |
var visible_change = false |
|
111 |
for ((command, start) <- snapshot.node.command_starts) { |
|
112 |
if (changed(command)) { |
|
113 |
val stop = start + command.length |
|
114 |
val line1 = buffer.getLineOfOffset(snapshot.convert(start)) |
|
115 |
val line2 = buffer.getLineOfOffset(snapshot.convert(stop)) |
|
116 |
if (line2 >= text_area.getFirstLine && |
|
117 |
line1 <= text_area.getFirstLine + text_area.getVisibleLines) |
|
118 |
visible_change = true |
|
119 |
text_area.invalidateLineRange(line1, line2) |
|
120 |
} |
|
121 |
} |
|
122 |
// FIXME danger of deadlock!? |
|
123 |
if (visible_change) model.buffer.propertiesChanged() |
|
38640 | 124 |
|
38843 | 125 |
overview.repaint() // FIXME really paint here!? |
38640 | 126 |
} |
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
127 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
128 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
129 |
case bad => System.err.println("command_change_actor: ignoring bad message " + bad) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
130 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
131 |
} |
34678 | 132 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
133 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
134 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
135 |
/* text_area_extension */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
136 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
137 |
private val text_area_extension = new TextAreaExtension |
34678 | 138 |
{ |
37685
305c326db33b
more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents:
37555
diff
changeset
|
139 |
override def paintScreenLineRange(gfx: Graphics2D, |
305c326db33b
more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents:
37555
diff
changeset
|
140 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
305c326db33b
more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents:
37555
diff
changeset
|
141 |
start: Array[Int], end: Array[Int], y0: Int, line_height: Int) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
142 |
{ |
38843 | 143 |
Isabelle.swing_buffer_lock(model.buffer) { |
144 |
val snapshot = model.snapshot() |
|
38223 | 145 |
|
38843 | 146 |
val command_range: Iterable[(Command, Text.Offset)] = |
147 |
{ |
|
148 |
val range = snapshot.node.command_range(snapshot.revert(start(0))) |
|
149 |
if (range.hasNext) { |
|
150 |
val (cmd0, start0) = range.next |
|
151 |
new Iterable[(Command, Text.Offset)] { |
|
152 |
def iterator = |
|
153 |
Document.Node.command_starts(snapshot.node.commands.iterator(cmd0), start0) |
|
154 |
} |
|
155 |
} |
|
156 |
else Iterable.empty |
|
157 |
} |
|
38223 | 158 |
|
38843 | 159 |
val saved_color = gfx.getColor |
160 |
try { |
|
161 |
var y = y0 |
|
162 |
for (i <- 0 until physical_lines.length) { |
|
163 |
if (physical_lines(i) != -1) { |
|
164 |
val line_start = start(i) |
|
165 |
val line_end = model.visible_line_end(line_start, end(i)) |
|
166 |
||
167 |
val a = snapshot.revert(line_start) |
|
168 |
val b = snapshot.revert(line_end) |
|
169 |
val cmds = command_range.iterator. |
|
170 |
dropWhile { case (cmd, c) => c + cmd.length <= a } . |
|
171 |
takeWhile { case (_, c) => c < b } |
|
172 |
||
173 |
for ((command, command_start) <- cmds if !command.is_ignored) { |
|
174 |
val p = |
|
175 |
text_area.offsetToXY(line_start max snapshot.convert(command_start)) |
|
176 |
val q = |
|
177 |
text_area.offsetToXY(line_end min snapshot.convert(command_start + command.length)) |
|
178 |
assert(p.y == q.y) |
|
179 |
gfx.setColor(Document_View.choose_color(snapshot, command)) |
|
180 |
gfx.fillRect(p.x, y, q.x - p.x, line_height) |
|
181 |
} |
|
182 |
} |
|
183 |
y += line_height |
|
38223 | 184 |
} |
185 |
} |
|
38843 | 186 |
finally { gfx.setColor(saved_color) } |
38223 | 187 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
188 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
189 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
190 |
override def getToolTipText(x: Int, y: Int): String = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
191 |
{ |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
192 |
Isabelle.swing_buffer_lock(model.buffer) { |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
193 |
val snapshot = model.snapshot() |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
194 |
val offset = text_area.xyToOffset(x, y) |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
195 |
val markup = |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
196 |
snapshot.select_markup(Text.Range(offset, offset + 1)) { |
38580
881c362d48e4
proper range for hyperlinks and tooltips, using original markup information;
wenzelm
parents:
38577
diff
changeset
|
197 |
case Text.Info(range, XML.Elem(Markup(Markup.ML_TYPING, _), body)) => |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
198 |
Isabelle.tooltip(Pretty.string_of(List(Pretty.block(body)), margin = 40)) |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
199 |
} { null } |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
200 |
if (markup.hasNext) markup.next.info else null |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
201 |
} |
34734 | 202 |
} |
34678 | 203 |
} |
34513 | 204 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
205 |
|
37129 | 206 |
/* caret handling */ |
34810 | 207 |
|
37849 | 208 |
def selected_command(): Option[Command] = |
38223 | 209 |
{ |
210 |
Swing_Thread.require() |
|
38151 | 211 |
model.snapshot().node.proper_command_at(text_area.getCaretPosition) |
38223 | 212 |
} |
34810 | 213 |
|
37849 | 214 |
private val caret_listener = new CaretListener { |
215 |
private val delay = Swing_Thread.delay_last(session.input_delay) { |
|
216 |
session.perspective.event(Session.Perspective) |
|
34810 | 217 |
} |
37849 | 218 |
override def caretUpdate(e: CaretEvent) { delay() } |
34810 | 219 |
} |
220 |
||
221 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
222 |
/* overview of command status left of scrollbar */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
223 |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
224 |
private val overview = new JPanel(new BorderLayout) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
225 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
226 |
private val WIDTH = 10 |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
227 |
private val HEIGHT = 2 |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
228 |
|
34806 | 229 |
setPreferredSize(new Dimension(WIDTH, 0)) |
230 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
231 |
setRequestFocusEnabled(false) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
232 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
233 |
addMouseListener(new MouseAdapter { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
234 |
override def mousePressed(event: MouseEvent) { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
235 |
val line = y_to_line(event.getY) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
236 |
if (line >= 0 && line < text_area.getLineCount) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
237 |
text_area.setCaretPosition(text_area.getLineStartOffset(line)) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
238 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
239 |
}) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
240 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
241 |
override def addNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
242 |
super.addNotify() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
243 |
ToolTipManager.sharedInstance.registerComponent(this) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
244 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
245 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
246 |
override def removeNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
247 |
ToolTipManager.sharedInstance.unregisterComponent(this) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
248 |
super.removeNotify |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
249 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
250 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
251 |
override def getToolTipText(event: MouseEvent): String = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
252 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
253 |
val line = y_to_line(event.getY()) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
254 |
if (line >= 0 && line < text_area.getLineCount) "<html><b>TODO:</b><br>Tooltip</html>" |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
255 |
else "" |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
256 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
257 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
258 |
override def paintComponent(gfx: Graphics) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
259 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
260 |
super.paintComponent(gfx) |
38640 | 261 |
Swing_Thread.assert() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
262 |
val buffer = model.buffer |
38843 | 263 |
Isabelle.buffer_lock(buffer) { |
38640 | 264 |
val snapshot = model.snapshot() |
265 |
val saved_color = gfx.getColor // FIXME needed!? |
|
266 |
try { |
|
267 |
for ((command, start) <- snapshot.node.command_starts if !command.is_ignored) { |
|
268 |
val line1 = buffer.getLineOfOffset(snapshot.convert(start)) |
|
269 |
val line2 = buffer.getLineOfOffset(snapshot.convert(start + command.length)) + 1 |
|
270 |
val y = line_to_y(line1) |
|
271 |
val height = HEIGHT * (line2 - line1) |
|
272 |
gfx.setColor(Document_View.choose_color(snapshot, command)) |
|
273 |
gfx.fillRect(0, y, getWidth - 1, height) |
|
274 |
} |
|
37188 | 275 |
} |
38640 | 276 |
finally { gfx.setColor(saved_color) } |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
277 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
278 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
279 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
280 |
private def line_to_y(line: Int): Int = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
281 |
(line * getHeight) / (text_area.getBuffer.getLineCount max text_area.getVisibleLines) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
282 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
283 |
private def y_to_line(y: Int): Int = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
284 |
(y * (text_area.getBuffer.getLineCount max text_area.getVisibleLines)) / getHeight |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
285 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
286 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
287 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
288 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
289 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
290 |
private def activate() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
291 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
292 |
text_area.getPainter. |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
293 |
addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, text_area_extension) |
34810 | 294 |
text_area.addCaretListener(caret_listener) |
295 |
text_area.addLeftOfScrollBar(overview) |
|
37129 | 296 |
session.commands_changed += commands_changed_actor |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
297 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
298 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
299 |
private def deactivate() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
300 |
{ |
37129 | 301 |
session.commands_changed -= commands_changed_actor |
34810 | 302 |
text_area.removeLeftOfScrollBar(overview) |
303 |
text_area.removeCaretListener(caret_listener) |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
304 |
text_area.getPainter.removeExtension(text_area_extension) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
305 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
306 |
} |