author | wenzelm |
Sat, 12 Nov 2011 11:45:49 +0100 | |
changeset 45467 | 3f290b6288cf |
parent 45460 | dcd02d1a25d7 |
child 45665 | 129db1416717 |
permissions | -rw-r--r-- |
43282
5d294220ca43
moved sources -- eliminated Netbeans artifact of jedit package directory;
wenzelm
parents:
42839
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/document_view.scala |
36760 | 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 |
||
44379 | 13 |
import scala.collection.mutable |
45460 | 14 |
import scala.collection.immutable.SortedMap |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
15 |
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
|
16 |
|
43520
cec9b95fa35d
explicit import java.lang.System to prevent odd scope problems;
wenzelm
parents:
43510
diff
changeset
|
17 |
import java.lang.System |
39740 | 18 |
import java.awt.{BorderLayout, Graphics, Color, Dimension, Graphics2D, Point} |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
19 |
import java.awt.event.{MouseAdapter, MouseMotionAdapter, MouseEvent, |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
20 |
FocusAdapter, FocusEvent, WindowEvent, WindowAdapter} |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
21 |
import javax.swing.{JPanel, ToolTipManager, Popup, PopupFactory, SwingUtilities, BorderFactory} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
22 |
import javax.swing.event.{CaretListener, CaretEvent} |
34734 | 23 |
|
43404 | 24 |
import org.gjt.sp.util.Log |
25 |
||
42839
19df8385f38d
basic support for overpainting of text, imitating jEdit internals;
wenzelm
parents:
42838
diff
changeset
|
26 |
import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug} |
34709 | 27 |
import org.gjt.sp.jedit.gui.RolloverButton |
39176
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
28 |
import org.gjt.sp.jedit.options.GutterOptionPane |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44379
diff
changeset
|
29 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter, |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44379
diff
changeset
|
30 |
ScrollListener} |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
43282
diff
changeset
|
31 |
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
|
32 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
33 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
34 |
object Document_View |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
35 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
36 |
/* 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
|
37 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
38 |
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
|
39 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
40 |
def apply(text_area: JEditTextArea): 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
|
41 |
{ |
38223 | 42 |
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
|
43 |
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
|
44 |
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
|
45 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
46 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
47 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
48 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
49 |
def exit(text_area: JEditTextArea) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
50 |
{ |
38223 | 51 |
Swing_Thread.require() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
52 |
apply(text_area) match { |
39636 | 53 |
case None => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
54 |
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
|
55 |
doc_view.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
56 |
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
|
57 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
58 |
} |
43397 | 59 |
|
60 |
def init(model: Document_Model, text_area: JEditTextArea): Document_View = |
|
61 |
{ |
|
62 |
exit(text_area) |
|
63 |
val doc_view = new Document_View(model, text_area) |
|
64 |
text_area.putClientProperty(key, doc_view) |
|
65 |
doc_view.activate() |
|
66 |
doc_view |
|
67 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
68 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
69 |
|
34733 | 70 |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43369
diff
changeset
|
71 |
class Document_View(val model: Document_Model, val text_area: JEditTextArea) |
34654 | 72 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
73 |
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
|
74 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
75 |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
76 |
/* robust extension body */ |
43404 | 77 |
|
78 |
def robust_body[A](default: A)(body: => A): A = |
|
43417
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
79 |
{ |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
80 |
try { |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
81 |
Swing_Thread.require() |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
82 |
if (model.buffer == text_area.getBuffer) body |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
83 |
else { |
43650 | 84 |
Log.log(Log.ERROR, this, ERROR("Inconsistent document model")) |
43417
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
85 |
default |
43404 | 86 |
} |
87 |
} |
|
43417
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
88 |
catch { case t: Throwable => Log.log(Log.ERROR, this, t); default } |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
89 |
} |
43404 | 90 |
|
91 |
||
44378 | 92 |
/* visible text range */ |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
93 |
|
38883
0998a635684a
refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents:
38881
diff
changeset
|
94 |
// simplify slightly odd result of TextArea.getScreenLineEndOffset etc. |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
95 |
// NB: jEdit already normalizes \r\n and \r to \n |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
96 |
def proper_line_range(start: Text.Offset, end: Text.Offset): Text.Range = |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
97 |
{ |
38883
0998a635684a
refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents:
38881
diff
changeset
|
98 |
val stop = if (start < end) end - 1 else end min model.buffer.getLength |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
99 |
Text.Range(start, stop) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
100 |
} |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
101 |
|
44378 | 102 |
def visible_range(): Text.Range = |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
103 |
{ |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
104 |
val start = text_area.getScreenLineStartOffset(0) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
105 |
val raw_end = text_area.getScreenLineEndOffset(text_area.getVisibleLines - 1 max 0) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
106 |
proper_line_range(start, if (raw_end >= 0) raw_end else model.buffer.getLength) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
107 |
} |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
108 |
|
44378 | 109 |
def invalidate_range(range: Text.Range) |
39132 | 110 |
{ |
111 |
text_area.invalidateLineRange( |
|
112 |
model.buffer.getLineOfOffset(range.start), |
|
113 |
model.buffer.getLineOfOffset(range.stop)) |
|
114 |
} |
|
115 |
||
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
116 |
|
44379 | 117 |
/* perspective */ |
118 |
||
119 |
def perspective(): Text.Perspective = |
|
120 |
{ |
|
121 |
Swing_Thread.require() |
|
44776
47e8c8daccae
added "check" button: adhoc change to full buffer perspective;
wenzelm
parents:
44615
diff
changeset
|
122 |
val buffer_range = model.buffer_range() |
44473 | 123 |
Text.Perspective( |
44379 | 124 |
for { |
125 |
i <- 0 until text_area.getVisibleLines |
|
126 |
val start = text_area.getScreenLineStartOffset(i) |
|
127 |
val stop = text_area.getScreenLineEndOffset(i) |
|
128 |
if start >= 0 && stop >= 0 |
|
44583
022509c908fb
restrict perspective to actual buffer_range, to avoid spurious edits due to faulty last_exec_offset (NB: jEdit screenlines may be silently extended by trailing newline);
wenzelm
parents:
44473
diff
changeset
|
129 |
val range <- buffer_range.try_restrict(Text.Range(start, stop)) |
022509c908fb
restrict perspective to actual buffer_range, to avoid spurious edits due to faulty last_exec_offset (NB: jEdit screenlines may be silently extended by trailing newline);
wenzelm
parents:
44473
diff
changeset
|
130 |
if !range.is_singularity |
44379 | 131 |
} |
44583
022509c908fb
restrict perspective to actual buffer_range, to avoid spurious edits due to faulty last_exec_offset (NB: jEdit screenlines may be silently extended by trailing newline);
wenzelm
parents:
44473
diff
changeset
|
132 |
yield range) |
44379 | 133 |
} |
134 |
||
44437
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
135 |
private def update_perspective = new TextAreaExtension |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
136 |
{ |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
137 |
override def paintScreenLineRange(gfx: Graphics2D, |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
138 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
139 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
140 |
{ |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
141 |
model.update_perspective() |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
142 |
} |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
143 |
} |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
144 |
|
44379 | 145 |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
146 |
/* snapshot */ |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
147 |
|
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
148 |
// owned by Swing thread |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
149 |
@volatile private var was_outdated = false |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
150 |
@volatile private var was_updated = false |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
151 |
|
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
152 |
def update_snapshot(): Document.Snapshot = |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
153 |
{ |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
154 |
Swing_Thread.require() |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
155 |
val snapshot = model.snapshot() |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
156 |
was_updated = was_outdated && !snapshot.is_outdated |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
157 |
was_outdated = was_outdated || snapshot.is_outdated |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
158 |
snapshot |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
159 |
} |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
160 |
|
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
161 |
def flush_snapshot(): (Boolean, Document.Snapshot) = |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
162 |
{ |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
163 |
Swing_Thread.require() |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
164 |
val snapshot = update_snapshot() |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
165 |
val updated = was_updated |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
166 |
if (updated) { was_outdated = false; was_updated = false } |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
167 |
(updated, snapshot) |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
168 |
} |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
169 |
|
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
170 |
|
39740 | 171 |
/* HTML popups */ |
172 |
||
173 |
private var html_popup: Option[Popup] = None |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
174 |
|
39740 | 175 |
private def exit_popup() { html_popup.map(_.hide) } |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
176 |
|
39740 | 177 |
private val html_panel = |
43661
39fdbd814c7f
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents:
43650
diff
changeset
|
178 |
new HTML_Panel(Isabelle.font_family(), scala.math.round(Isabelle.font_size())) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
179 |
html_panel.setBorder(BorderFactory.createLineBorder(Color.black)) |
38884
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
180 |
|
39740 | 181 |
private def html_panel_resize() |
182 |
{ |
|
183 |
Swing_Thread.now { |
|
184 |
html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size())) |
|
185 |
} |
|
186 |
} |
|
38884
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
187 |
|
39740 | 188 |
private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int) |
189 |
{ |
|
190 |
exit_popup() |
|
40154 | 191 |
/* FIXME broken |
39740 | 192 |
val offset = text_area.xyToOffset(x, y) |
193 |
val p = new Point(x, y); SwingUtilities.convertPointToScreen(p, text_area.getPainter) |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
194 |
|
39740 | 195 |
// FIXME snapshot.cumulate |
196 |
snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match { |
|
197 |
case Text.Info(_, Some(msg)) #:: _ => |
|
198 |
val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60) |
|
199 |
html_panel.render_sync(List(msg)) |
|
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
200 |
Thread.sleep(10) // FIXME !? |
39740 | 201 |
popup.show |
202 |
html_popup = Some(popup) |
|
203 |
case _ => |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
204 |
} |
40154 | 205 |
*/ |
34678 | 206 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
207 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
208 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
209 |
/* subexpression highlighting */ |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
210 |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
211 |
private def subexp_range(snapshot: Document.Snapshot, x: Int, y: Int) |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
212 |
: Option[(Text.Range, Color)] = |
39132 | 213 |
{ |
214 |
val offset = text_area.xyToOffset(x, y) |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
215 |
snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.subexp) match { |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
216 |
case Text.Info(_, Some((range, color))) #:: _ => Some((snapshot.convert(range), color)) |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
217 |
case _ => None |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
218 |
} |
39132 | 219 |
} |
220 |
||
43381 | 221 |
@volatile private var _highlight_range: Option[(Text.Range, Color)] = None |
222 |
def highlight_range(): Option[(Text.Range, Color)] = _highlight_range |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
223 |
|
39740 | 224 |
|
225 |
/* CONTROL-mouse management */ |
|
226 |
||
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
227 |
private var control: Boolean = false |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
228 |
|
39740 | 229 |
private def exit_control() |
230 |
{ |
|
231 |
exit_popup() |
|
43381 | 232 |
_highlight_range = None |
39740 | 233 |
} |
234 |
||
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
235 |
private val focus_listener = new FocusAdapter { |
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
236 |
override def focusLost(e: FocusEvent) { |
43381 | 237 |
_highlight_range = None // FIXME exit_control !? |
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
238 |
} |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
239 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
240 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
241 |
private val window_listener = new WindowAdapter { |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
242 |
override def windowIconified(e: WindowEvent) { exit_control() } |
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
243 |
override def windowDeactivated(e: WindowEvent) { exit_control() } |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
244 |
} |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
245 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
246 |
private val mouse_motion_listener = new MouseMotionAdapter { |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
247 |
override def mouseMoved(e: MouseEvent) { |
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
248 |
control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown |
39740 | 249 |
val x = e.getX() |
250 |
val y = e.getY() |
|
251 |
||
252 |
if (!model.buffer.isLoaded) exit_control() |
|
39132 | 253 |
else |
254 |
Isabelle.swing_buffer_lock(model.buffer) { |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
255 |
val snapshot = update_snapshot() |
39740 | 256 |
|
257 |
if (control) init_popup(snapshot, x, y) |
|
258 |
||
44378 | 259 |
_highlight_range map { case (range, _) => invalidate_range(range) } |
43381 | 260 |
_highlight_range = if (control) subexp_range(snapshot, x, y) else None |
44378 | 261 |
_highlight_range map { case (range, _) => invalidate_range(range) } |
39132 | 262 |
} |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
263 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
264 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
265 |
|
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
266 |
|
43381 | 267 |
/* text area painting */ |
39044 | 268 |
|
43381 | 269 |
private val text_area_painter = new Text_Area_Painter(this) |
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
270 |
|
43381 | 271 |
private val tooltip_painter = new TextAreaExtension |
272 |
{ |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
273 |
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
|
274 |
{ |
43404 | 275 |
robust_body(null: String) { |
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
276 |
val snapshot = update_snapshot() |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
277 |
val offset = text_area.xyToOffset(x, y) |
45460 | 278 |
val range = Text.Range(offset, offset + 1) |
279 |
||
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
280 |
if (control) { |
45460 | 281 |
val tooltips = |
282 |
(snapshot.select_markup(range)(Isabelle_Markup.tooltip1) match |
|
283 |
{ |
|
284 |
case Text.Info(_, Some(text)) #:: _ => List(text) |
|
285 |
case _ => Nil |
|
286 |
}) ::: |
|
287 |
(snapshot.select_markup(range)(Isabelle_Markup.tooltip2) match |
|
288 |
{ |
|
289 |
case Text.Info(_, Some(text)) #:: _ => List(text) |
|
290 |
case _ => Nil |
|
291 |
}) |
|
292 |
if (tooltips.isEmpty) null |
|
293 |
else Isabelle.tooltip(tooltips.mkString("\n")) |
|
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
294 |
} |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
295 |
else { |
45467 | 296 |
snapshot.cumulate_markup(range)(Isabelle_Markup.tooltip_message) match |
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
297 |
{ |
45460 | 298 |
case Text.Info(_, msgs) #:: _ if !msgs.isEmpty => |
299 |
Isabelle.tooltip(msgs.iterator.map(_._2).mkString("\n")) |
|
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
300 |
case _ => null |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
301 |
} |
39174
b95cf3892483
Document_View: some markup for main inner syntax categories;
wenzelm
parents:
39171
diff
changeset
|
302 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
303 |
} |
34734 | 304 |
} |
34678 | 305 |
} |
34513 | 306 |
|
42825 | 307 |
private val gutter_painter = new TextAreaExtension |
39175 | 308 |
{ |
309 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
310 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
311 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
312 |
{ |
|
43404 | 313 |
robust_body(()) { |
314 |
val gutter = text_area.getGutter |
|
315 |
val width = GutterOptionPane.getSelectionAreaWidth |
|
316 |
val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3) |
|
317 |
val FOLD_MARKER_SIZE = 12 |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
318 |
|
43404 | 319 |
if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) { |
320 |
Isabelle.swing_buffer_lock(model.buffer) { |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
321 |
val snapshot = update_snapshot() |
43404 | 322 |
for (i <- 0 until physical_lines.length) { |
323 |
if (physical_lines(i) != -1) { |
|
324 |
val line_range = proper_line_range(start(i), end(i)) |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
325 |
|
43404 | 326 |
// gutter icons |
327 |
val icons = |
|
328 |
(for (Text.Info(_, Some(icon)) <- // FIXME snapshot.cumulate |
|
329 |
snapshot.select_markup(line_range)(Isabelle_Markup.gutter_message).iterator) |
|
330 |
yield icon).toList.sortWith(_ >= _) |
|
331 |
icons match { |
|
332 |
case icon :: _ => |
|
333 |
val icn = icon.icon |
|
334 |
val x0 = (FOLD_MARKER_SIZE + width - border_width - icn.getIconWidth) max 10 |
|
335 |
val y0 = y + i * line_height + (((line_height - icn.getIconHeight) / 2) max 0) |
|
336 |
icn.paintIcon(gutter, gfx, x0, y0) |
|
337 |
case Nil => |
|
338 |
} |
|
39175 | 339 |
} |
340 |
} |
|
341 |
} |
|
342 |
} |
|
343 |
} |
|
344 |
} |
|
345 |
} |
|
346 |
||
347 |
||
43448
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
348 |
/* caret range */ |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
349 |
|
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
350 |
def caret_range(): Text.Range = |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
351 |
Isabelle.buffer_lock(model.buffer) { |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
352 |
def text(i: Text.Offset): Char = model.buffer.getText(i, 1).charAt(0) |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
353 |
val caret = text_area.getCaretPosition |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
354 |
try { |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
355 |
val c = text(caret) |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
356 |
if (Character.isHighSurrogate(c) && Character.isLowSurrogate(text(caret + 1))) |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
357 |
Text.Range(caret, caret + 2) |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
358 |
else if (Character.isLowSurrogate(c) && Character.isHighSurrogate(text(caret - 1))) |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
359 |
Text.Range(caret - 1, caret + 1) |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
360 |
else Text.Range(caret, caret + 1) |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
361 |
} |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
362 |
catch { case _: ArrayIndexOutOfBoundsException => Text.Range(caret, caret + 1) } |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
363 |
} |
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
364 |
|
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43419
diff
changeset
|
365 |
|
37129 | 366 |
/* caret handling */ |
34810 | 367 |
|
37849 | 368 |
def selected_command(): Option[Command] = |
38223 | 369 |
{ |
370 |
Swing_Thread.require() |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
371 |
update_snapshot().node.proper_command_at(text_area.getCaretPosition) |
38223 | 372 |
} |
34810 | 373 |
|
37849 | 374 |
private val caret_listener = new CaretListener { |
375 |
private val delay = Swing_Thread.delay_last(session.input_delay) { |
|
44805 | 376 |
session.caret_focus.event(Session.Caret_Focus) |
34810 | 377 |
} |
37849 | 378 |
override def caretUpdate(e: CaretEvent) { delay() } |
34810 | 379 |
} |
380 |
||
381 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
382 |
/* 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
|
383 |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
384 |
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
|
385 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
|
34806 | 389 |
setPreferredSize(new Dimension(WIDTH, 0)) |
390 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
391 |
setRequestFocusEnabled(false) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
392 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
393 |
addMouseListener(new MouseAdapter { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
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
|
398 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
399 |
}) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
400 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
401 |
override def addNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
402 |
super.addNotify() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
403 |
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
|
404 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
405 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
406 |
override def removeNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
407 |
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
|
408 |
super.removeNotify |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
409 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
410 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
411 |
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
|
412 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
413 |
super.paintComponent(gfx) |
38640 | 414 |
Swing_Thread.assert() |
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
415 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
416 |
val buffer = model.buffer |
38843 | 417 |
Isabelle.buffer_lock(buffer) { |
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
418 |
val snapshot = update_snapshot() |
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
419 |
|
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
420 |
def line_range(command: Command, start: Text.Offset): Option[(Int, Int)] = |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
421 |
{ |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
422 |
try { |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
423 |
val line1 = buffer.getLineOfOffset(snapshot.convert(start)) |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
424 |
val line2 = buffer.getLineOfOffset(snapshot.convert(start + command.length)) + 1 |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
425 |
Some((line1, line2)) |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
426 |
} |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
427 |
catch { case e: ArrayIndexOutOfBoundsException => None } |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
428 |
} |
39182 | 429 |
for { |
430 |
(command, start) <- snapshot.node.command_starts |
|
431 |
if !command.is_ignored |
|
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
432 |
(line1, line2) <- line_range(command, start) |
39182 | 433 |
val y = line_to_y(line1) |
434 |
val height = HEIGHT * (line2 - line1) |
|
435 |
color <- Isabelle_Markup.overview_color(snapshot, command) |
|
436 |
} { |
|
437 |
gfx.setColor(color) |
|
438 |
gfx.fillRect(0, y, getWidth - 1, height) |
|
37188 | 439 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
440 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
441 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
442 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
443 |
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
|
444 |
(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
|
445 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
446 |
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
|
447 |
(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
|
448 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
449 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
450 |
|
39740 | 451 |
/* main actor */ |
452 |
||
453 |
private val main_actor = actor { |
|
454 |
loop { |
|
455 |
react { |
|
44608 | 456 |
case changed: Session.Commands_Changed => |
39740 | 457 |
val buffer = model.buffer |
458 |
Isabelle.swing_buffer_lock(buffer) { |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
459 |
val (updated, snapshot) = flush_snapshot() |
44378 | 460 |
val visible = visible_range() |
39740 | 461 |
|
44608 | 462 |
if (updated || |
44615 | 463 |
(changed.nodes.contains(model.name) && |
44608 | 464 |
changed.commands.exists(snapshot.node.commands.contains))) |
39740 | 465 |
overview.repaint() |
466 |
||
44378 | 467 |
if (updated) invalidate_range(visible) |
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
468 |
else { |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
469 |
val visible_cmds = |
44378 | 470 |
snapshot.node.command_range(snapshot.revert(visible)).map(_._1) |
44608 | 471 |
if (visible_cmds.exists(changed.commands)) { |
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
472 |
for { |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
473 |
line <- 0 until text_area.getVisibleLines |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
474 |
val start = text_area.getScreenLineStartOffset(line) if start >= 0 |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
475 |
val end = text_area.getScreenLineEndOffset(line) if end >= 0 |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
476 |
val range = proper_line_range(start, end) |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
477 |
val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1) |
44608 | 478 |
if line_cmds.exists(changed.commands) |
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
479 |
} text_area.invalidateScreenLineRange(line, line) |
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
480 |
} |
39740 | 481 |
} |
482 |
} |
|
483 |
||
484 |
case Session.Global_Settings => html_panel_resize() |
|
485 |
||
486 |
case bad => System.err.println("command_change_actor: ignoring bad message " + bad) |
|
487 |
} |
|
488 |
} |
|
489 |
} |
|
490 |
||
491 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
492 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
493 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
494 |
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
|
495 |
{ |
42825 | 496 |
val painter = text_area.getPainter |
44437
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
497 |
painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_perspective) |
43387
a59ae768249e
recovered tooltip Entity content (odd effect of layer change!? cf. 806878ae2219);
wenzelm
parents:
43381
diff
changeset
|
498 |
painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter) |
43381 | 499 |
text_area_painter.activate() |
42825 | 500 |
text_area.getGutter.addExtension(gutter_painter) |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
501 |
text_area.addFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
502 |
text_area.getView.addWindowListener(window_listener) |
42825 | 503 |
painter.addMouseMotionListener(mouse_motion_listener) |
34810 | 504 |
text_area.addCaretListener(caret_listener) |
505 |
text_area.addLeftOfScrollBar(overview) |
|
39740 | 506 |
session.commands_changed += main_actor |
507 |
session.global_settings += main_actor |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
508 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
509 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
510 |
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
|
511 |
{ |
42825 | 512 |
val painter = text_area.getPainter |
39740 | 513 |
session.commands_changed -= main_actor |
514 |
session.global_settings -= main_actor |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
515 |
text_area.removeFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
516 |
text_area.getView.removeWindowListener(window_listener) |
42825 | 517 |
painter.removeMouseMotionListener(mouse_motion_listener) |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
518 |
text_area.removeCaretListener(caret_listener) |
34810 | 519 |
text_area.removeLeftOfScrollBar(overview) |
42825 | 520 |
text_area.getGutter.removeExtension(gutter_painter) |
43381 | 521 |
text_area_painter.deactivate() |
522 |
painter.removeExtension(tooltip_painter) |
|
44437
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
523 |
painter.removeExtension(update_perspective) |
39740 | 524 |
exit_popup() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
525 |
} |
42825 | 526 |
} |