author | wenzelm |
Tue, 14 Jun 2011 14:55:22 +0200 | |
changeset 43387 | a59ae768249e |
parent 43381 | 806878ae2219 |
child 43390 | 7ee98a3802af |
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 |
||
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 |
|
39740 | 15 |
import java.awt.{BorderLayout, Graphics, Color, Dimension, Graphics2D, Point} |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
16 |
import java.awt.event.{MouseAdapter, MouseMotionAdapter, MouseEvent, |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
17 |
FocusAdapter, FocusEvent, WindowEvent, WindowAdapter} |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
18 |
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
|
19 |
import javax.swing.event.{CaretListener, CaretEvent} |
34734 | 20 |
|
42839
19df8385f38d
basic support for overpainting of text, imitating jEdit internals;
wenzelm
parents:
42838
diff
changeset
|
21 |
import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug} |
34709 | 22 |
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
|
23 |
import org.gjt.sp.jedit.options.GutterOptionPane |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
24 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter} |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
43282
diff
changeset
|
25 |
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
|
26 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
27 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
28 |
object Document_View |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
29 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
30 |
/* 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
|
31 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
32 |
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
|
33 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
34 |
def init(model: Document_Model, text_area: JEditTextArea): Document_View = |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
35 |
{ |
38223 | 36 |
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
|
37 |
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
|
38 |
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
|
39 |
doc_view.activate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
40 |
doc_view |
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 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
43 |
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
|
44 |
{ |
38223 | 45 |
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
|
46 |
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
|
47 |
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
|
48 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
49 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
50 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
51 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
52 |
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
|
53 |
{ |
38223 | 54 |
Swing_Thread.require() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
55 |
apply(text_area) match { |
39636 | 56 |
case None => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
57 |
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
|
58 |
doc_view.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
59 |
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
|
60 |
} |
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 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
63 |
|
34733 | 64 |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43369
diff
changeset
|
65 |
class Document_View(val model: Document_Model, val text_area: JEditTextArea) |
34654 | 66 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
67 |
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
|
68 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
69 |
|
42838
15727655bee2
some support for token/chunk handling, imitating jEdit internals;
wenzelm
parents:
42825
diff
changeset
|
70 |
/** token handling **/ |
15727655bee2
some support for token/chunk handling, imitating jEdit internals;
wenzelm
parents:
42825
diff
changeset
|
71 |
|
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
|
72 |
/* 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
|
73 |
|
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
|
74 |
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
|
75 |
|
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
|
76 |
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
|
77 |
{ |
38223 | 78 |
Swing_Thread.require() |
38158 | 79 |
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
|
80 |
} |
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
|
81 |
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
|
82 |
|
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 |
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
|
84 |
{ |
38223 | 85 |
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
|
86 |
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
|
87 |
} |
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
|
88 |
|
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
|
89 |
|
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
90 |
/* visible line ranges */ |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
91 |
|
38883
0998a635684a
refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents:
38881
diff
changeset
|
92 |
// 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
|
93 |
// 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
|
94 |
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
|
95 |
{ |
38883
0998a635684a
refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents:
38881
diff
changeset
|
96 |
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
|
97 |
Text.Range(start, stop) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
98 |
} |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
99 |
|
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
100 |
def screen_lines_range(): Text.Range = |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
101 |
{ |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
102 |
val start = text_area.getScreenLineStartOffset(0) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
} |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
106 |
|
39132 | 107 |
def invalidate_line_range(range: Text.Range) |
108 |
{ |
|
109 |
text_area.invalidateLineRange( |
|
110 |
model.buffer.getLineOfOffset(range.start), |
|
111 |
model.buffer.getLineOfOffset(range.stop)) |
|
112 |
} |
|
113 |
||
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
114 |
|
39740 | 115 |
/* HTML popups */ |
116 |
||
117 |
private var html_popup: Option[Popup] = None |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
118 |
|
39740 | 119 |
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
|
120 |
|
39740 | 121 |
private val html_panel = |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
122 |
new HTML_Panel(Isabelle.system, Isabelle.font_family(), scala.math.round(Isabelle.font_size())) |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
123 |
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
|
124 |
|
39740 | 125 |
private def html_panel_resize() |
126 |
{ |
|
127 |
Swing_Thread.now { |
|
128 |
html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size())) |
|
129 |
} |
|
130 |
} |
|
38884
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
131 |
|
39740 | 132 |
private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int) |
133 |
{ |
|
134 |
exit_popup() |
|
40154 | 135 |
/* FIXME broken |
39740 | 136 |
val offset = text_area.xyToOffset(x, y) |
137 |
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
|
138 |
|
39740 | 139 |
// FIXME snapshot.cumulate |
140 |
snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match { |
|
141 |
case Text.Info(_, Some(msg)) #:: _ => |
|
142 |
val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60) |
|
143 |
html_panel.render_sync(List(msg)) |
|
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
144 |
Thread.sleep(10) // FIXME !? |
39740 | 145 |
popup.show |
146 |
html_popup = Some(popup) |
|
147 |
case _ => |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
148 |
} |
40154 | 149 |
*/ |
34678 | 150 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
151 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
152 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
153 |
/* subexpression highlighting */ |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
154 |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
155 |
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
|
156 |
: Option[(Text.Range, Color)] = |
39132 | 157 |
{ |
158 |
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
|
159 |
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
|
160 |
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
|
161 |
case _ => None |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
162 |
} |
39132 | 163 |
} |
164 |
||
43381 | 165 |
@volatile private var _highlight_range: Option[(Text.Range, Color)] = None |
166 |
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
|
167 |
|
39740 | 168 |
|
169 |
/* CONTROL-mouse management */ |
|
170 |
||
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
171 |
private var control: Boolean = false |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
172 |
|
39740 | 173 |
private def exit_control() |
174 |
{ |
|
175 |
exit_popup() |
|
43381 | 176 |
_highlight_range = None |
39740 | 177 |
} |
178 |
||
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
179 |
private val focus_listener = new FocusAdapter { |
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
180 |
override def focusLost(e: FocusEvent) { |
43381 | 181 |
_highlight_range = None // FIXME exit_control !? |
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
182 |
} |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
183 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
184 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
185 |
private val window_listener = new WindowAdapter { |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
186 |
override def windowIconified(e: WindowEvent) { exit_control() } |
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
187 |
override def windowDeactivated(e: WindowEvent) { exit_control() } |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
188 |
} |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
189 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
190 |
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
|
191 |
override def mouseMoved(e: MouseEvent) { |
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
192 |
control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown |
39740 | 193 |
val x = e.getX() |
194 |
val y = e.getY() |
|
195 |
||
196 |
if (!model.buffer.isLoaded) exit_control() |
|
39132 | 197 |
else |
198 |
Isabelle.swing_buffer_lock(model.buffer) { |
|
39740 | 199 |
val snapshot = model.snapshot |
200 |
||
201 |
if (control) init_popup(snapshot, x, y) |
|
202 |
||
43381 | 203 |
_highlight_range map { case (range, _) => invalidate_line_range(range) } |
204 |
_highlight_range = if (control) subexp_range(snapshot, x, y) else None |
|
205 |
_highlight_range map { case (range, _) => invalidate_line_range(range) } |
|
39132 | 206 |
} |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
207 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
208 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
209 |
|
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
210 |
|
43381 | 211 |
/* text area painting */ |
39044 | 212 |
|
43381 | 213 |
private val text_area_painter = new Text_Area_Painter(this) |
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
214 |
|
43381 | 215 |
private val tooltip_painter = new TextAreaExtension |
216 |
{ |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
217 |
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
|
218 |
{ |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
219 |
Isabelle.swing_buffer_lock(model.buffer) { |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
220 |
val snapshot = model.snapshot() |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
221 |
val offset = text_area.xyToOffset(x, y) |
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
222 |
if (control) { |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
223 |
snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.tooltip) match |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
224 |
{ |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
225 |
case Text.Info(_, Some(text)) #:: _ => Isabelle.tooltip(text) |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
226 |
case _ => null |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
227 |
} |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
228 |
} |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
229 |
else { |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
230 |
// FIXME snapshot.cumulate |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
231 |
snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
232 |
{ |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
233 |
case Text.Info(_, Some(text)) #:: _ => Isabelle.tooltip(text) |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
234 |
case _ => null |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
235 |
} |
39174
b95cf3892483
Document_View: some markup for main inner syntax categories;
wenzelm
parents:
39171
diff
changeset
|
236 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
237 |
} |
34734 | 238 |
} |
34678 | 239 |
} |
34513 | 240 |
|
42825 | 241 |
private val gutter_painter = new TextAreaExtension |
39175 | 242 |
{ |
243 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
244 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
245 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
246 |
{ |
|
39176
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
247 |
val gutter = text_area.getGutter |
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
248 |
val width = GutterOptionPane.getSelectionAreaWidth |
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
249 |
val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3) |
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
250 |
val FOLD_MARKER_SIZE = 12 |
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
251 |
|
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
252 |
if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) { |
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
253 |
Isabelle.swing_buffer_lock(model.buffer) { |
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
254 |
val snapshot = model.snapshot() |
39175 | 255 |
for (i <- 0 until physical_lines.length) { |
256 |
if (physical_lines(i) != -1) { |
|
257 |
val line_range = proper_line_range(start(i), end(i)) |
|
258 |
||
259 |
// gutter icons |
|
39181
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
260 |
val icons = |
39740 | 261 |
(for (Text.Info(_, Some(icon)) <- // FIXME snapshot.cumulate |
39181
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
262 |
snapshot.select_markup(line_range)(Isabelle_Markup.gutter_message).iterator) |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
263 |
yield icon).toList.sortWith(_ >= _) |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
264 |
icons match { |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
265 |
case icon :: _ => |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
266 |
val icn = icon.icon |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
267 |
val x0 = (FOLD_MARKER_SIZE + width - border_width - icn.getIconWidth) max 10 |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
268 |
val y0 = y + i * line_height + (((line_height - icn.getIconHeight) / 2) max 0) |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
269 |
icn.paintIcon(gutter, gfx, x0, y0) |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
270 |
case Nil => |
39175 | 271 |
} |
272 |
} |
|
273 |
} |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
||
37129 | 280 |
/* caret handling */ |
34810 | 281 |
|
37849 | 282 |
def selected_command(): Option[Command] = |
38223 | 283 |
{ |
284 |
Swing_Thread.require() |
|
38151 | 285 |
model.snapshot().node.proper_command_at(text_area.getCaretPosition) |
38223 | 286 |
} |
34810 | 287 |
|
37849 | 288 |
private val caret_listener = new CaretListener { |
289 |
private val delay = Swing_Thread.delay_last(session.input_delay) { |
|
290 |
session.perspective.event(Session.Perspective) |
|
34810 | 291 |
} |
37849 | 292 |
override def caretUpdate(e: CaretEvent) { delay() } |
34810 | 293 |
} |
294 |
||
295 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
296 |
/* 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
|
297 |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
298 |
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
|
299 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
|
34806 | 303 |
setPreferredSize(new Dimension(WIDTH, 0)) |
304 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
305 |
setRequestFocusEnabled(false) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
306 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
307 |
addMouseListener(new MouseAdapter { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
313 |
}) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
314 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
315 |
override def addNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
316 |
super.addNotify() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
317 |
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
|
318 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
319 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
320 |
override def removeNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
321 |
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
|
322 |
super.removeNotify |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
323 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
324 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
325 |
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
|
326 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
327 |
super.paintComponent(gfx) |
38640 | 328 |
Swing_Thread.assert() |
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
329 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
330 |
val buffer = model.buffer |
38843 | 331 |
Isabelle.buffer_lock(buffer) { |
38640 | 332 |
val snapshot = model.snapshot() |
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
333 |
|
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
334 |
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
|
335 |
{ |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
336 |
try { |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
337 |
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
|
338 |
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
|
339 |
Some((line1, line2)) |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
340 |
} |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
341 |
catch { case e: ArrayIndexOutOfBoundsException => None } |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
342 |
} |
39182 | 343 |
for { |
344 |
(command, start) <- snapshot.node.command_starts |
|
345 |
if !command.is_ignored |
|
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
346 |
(line1, line2) <- line_range(command, start) |
39182 | 347 |
val y = line_to_y(line1) |
348 |
val height = HEIGHT * (line2 - line1) |
|
349 |
color <- Isabelle_Markup.overview_color(snapshot, command) |
|
350 |
} { |
|
351 |
gfx.setColor(color) |
|
352 |
gfx.fillRect(0, y, getWidth - 1, height) |
|
37188 | 353 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
354 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
355 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
356 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
357 |
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
|
358 |
(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
|
359 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
360 |
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
|
361 |
(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
|
362 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
363 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
364 |
|
39740 | 365 |
/* main actor */ |
366 |
||
367 |
private val main_actor = actor { |
|
368 |
loop { |
|
369 |
react { |
|
370 |
case Session.Commands_Changed(changed) => |
|
371 |
val buffer = model.buffer |
|
372 |
Isabelle.swing_buffer_lock(buffer) { |
|
373 |
val snapshot = model.snapshot() |
|
374 |
||
375 |
if (changed.exists(snapshot.node.commands.contains)) |
|
376 |
overview.repaint() |
|
377 |
||
378 |
val visible_range = screen_lines_range() |
|
379 |
val visible_cmds = snapshot.node.command_range(snapshot.revert(visible_range)).map(_._1) |
|
380 |
if (visible_cmds.exists(changed)) { |
|
381 |
for { |
|
382 |
line <- 0 until text_area.getVisibleLines |
|
383 |
val start = text_area.getScreenLineStartOffset(line) if start >= 0 |
|
384 |
val end = text_area.getScreenLineEndOffset(line) if end >= 0 |
|
385 |
val range = proper_line_range(start, end) |
|
386 |
val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1) |
|
387 |
if line_cmds.exists(changed) |
|
388 |
} text_area.invalidateScreenLineRange(line, line) |
|
389 |
||
390 |
// FIXME danger of deadlock!? |
|
391 |
// FIXME potentially slow!? |
|
392 |
model.buffer.propertiesChanged() |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
case Session.Global_Settings => html_panel_resize() |
|
397 |
||
398 |
case bad => System.err.println("command_change_actor: ignoring bad message " + bad) |
|
399 |
} |
|
400 |
} |
|
401 |
} |
|
402 |
||
403 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
404 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
405 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
406 |
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
|
407 |
{ |
42825 | 408 |
val painter = text_area.getPainter |
43387
a59ae768249e
recovered tooltip Entity content (odd effect of layer change!? cf. 806878ae2219);
wenzelm
parents:
43381
diff
changeset
|
409 |
painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter) |
43381 | 410 |
text_area_painter.activate() |
42825 | 411 |
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
|
412 |
text_area.addFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
413 |
text_area.getView.addWindowListener(window_listener) |
42825 | 414 |
painter.addMouseMotionListener(mouse_motion_listener) |
34810 | 415 |
text_area.addCaretListener(caret_listener) |
416 |
text_area.addLeftOfScrollBar(overview) |
|
39740 | 417 |
session.commands_changed += main_actor |
418 |
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
|
419 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
420 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
421 |
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
|
422 |
{ |
42825 | 423 |
val painter = text_area.getPainter |
39740 | 424 |
session.commands_changed -= main_actor |
425 |
session.global_settings -= main_actor |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
426 |
text_area.removeFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
427 |
text_area.getView.removeWindowListener(window_listener) |
42825 | 428 |
painter.removeMouseMotionListener(mouse_motion_listener) |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
429 |
text_area.removeCaretListener(caret_listener) |
34810 | 430 |
text_area.removeLeftOfScrollBar(overview) |
42825 | 431 |
text_area.getGutter.removeExtension(gutter_painter) |
43381 | 432 |
text_area_painter.deactivate() |
433 |
painter.removeExtension(tooltip_painter) |
|
39740 | 434 |
exit_popup() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
435 |
} |
42825 | 436 |
} |