author | wenzelm |
Tue, 28 Sep 2010 23:47:45 +0200 | |
changeset 39741 | 62b91eb2d39a |
parent 39740 | 0294948ba962 |
child 39742 | b59e064e32c3 |
permissions | -rw-r--r-- |
36760 | 1 |
/* Title: Tools/jEdit/src/jedit/document_view.scala |
2 |
Author: Fabian Immler, TU Munich |
|
3 |
Author: Makarius |
|
4 |
||
5 |
Document view connected to jEdit text area. |
|
6 |
*/ |
|
34408 | 7 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
8 |
package isabelle.jedit |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
9 |
|
34760 | 10 |
|
36015 | 11 |
import isabelle._ |
12 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
13 |
import scala.actors.Actor._ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
14 |
|
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 |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
21 |
import org.gjt.sp.jedit.{jEdit, OperatingSystem} |
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} |
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
|
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 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
65 |
class Document_View(val model: Document_Model, 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 |
|
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
|
70 |
/* 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
|
71 |
|
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 |
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
|
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 |
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
|
75 |
{ |
38223 | 76 |
Swing_Thread.require() |
38158 | 77 |
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
|
78 |
} |
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
|
79 |
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
|
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 |
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
|
82 |
{ |
38223 | 83 |
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
|
84 |
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
|
85 |
} |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37201
diff
changeset
|
86 |
|
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 |
|
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
88 |
/* visible line ranges */ |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
89 |
|
38883
0998a635684a
refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents:
38881
diff
changeset
|
90 |
// 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
|
91 |
// 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
|
92 |
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
|
93 |
{ |
38883
0998a635684a
refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents:
38881
diff
changeset
|
94 |
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
|
95 |
Text.Range(start, stop) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
96 |
} |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
97 |
|
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
98 |
def screen_lines_range(): Text.Range = |
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 |
val start = text_area.getScreenLineStartOffset(0) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
} |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
104 |
|
39132 | 105 |
def invalidate_line_range(range: Text.Range) |
106 |
{ |
|
107 |
text_area.invalidateLineRange( |
|
108 |
model.buffer.getLineOfOffset(range.start), |
|
109 |
model.buffer.getLineOfOffset(range.stop)) |
|
110 |
} |
|
111 |
||
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
112 |
|
39740 | 113 |
/* HTML popups */ |
114 |
||
115 |
private var html_popup: Option[Popup] = None |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
116 |
|
39740 | 117 |
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
|
118 |
|
39740 | 119 |
private val html_panel = |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
|
39740 | 123 |
private def html_panel_resize() |
124 |
{ |
|
125 |
Swing_Thread.now { |
|
126 |
html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size())) |
|
127 |
} |
|
128 |
} |
|
38884
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
129 |
|
39740 | 130 |
private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int) |
131 |
{ |
|
132 |
exit_popup() |
|
133 |
val offset = text_area.xyToOffset(x, y) |
|
134 |
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
|
135 |
|
39740 | 136 |
// FIXME snapshot.cumulate |
137 |
snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match { |
|
138 |
case Text.Info(_, Some(msg)) #:: _ => |
|
139 |
val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60) |
|
140 |
html_panel.render_sync(List(msg)) |
|
141 |
popup.show |
|
142 |
html_popup = Some(popup) |
|
143 |
case _ => |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
144 |
} |
34678 | 145 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
146 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
147 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
148 |
/* subexpression highlighting */ |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
149 |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
150 |
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
|
151 |
: Option[(Text.Range, Color)] = |
39132 | 152 |
{ |
153 |
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
|
154 |
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
|
155 |
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
|
156 |
case _ => None |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
157 |
} |
39132 | 158 |
} |
159 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
160 |
private var highlight_range: Option[(Text.Range, Color)] = None |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
161 |
|
39740 | 162 |
|
163 |
/* CONTROL-mouse management */ |
|
164 |
||
165 |
private def exit_control() |
|
166 |
{ |
|
167 |
exit_popup() |
|
168 |
highlight_range = None |
|
169 |
} |
|
170 |
||
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
171 |
private val focus_listener = new FocusAdapter { |
39740 | 172 |
override def focusLost(e: FocusEvent) { exit_control() } |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
173 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
174 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
175 |
private val window_listener = new WindowAdapter { |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
176 |
override def windowIconified(e: WindowEvent) { exit_control() } |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
177 |
} |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
178 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
179 |
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
|
180 |
override def mouseMoved(e: MouseEvent) { |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
181 |
val control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown |
39740 | 182 |
val x = e.getX() |
183 |
val y = e.getY() |
|
184 |
||
185 |
if (!model.buffer.isLoaded) exit_control() |
|
39132 | 186 |
else |
187 |
Isabelle.swing_buffer_lock(model.buffer) { |
|
39740 | 188 |
val snapshot = model.snapshot |
189 |
||
190 |
if (control) init_popup(snapshot, x, y) |
|
191 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
192 |
highlight_range map { case (range, _) => invalidate_line_range(range) } |
39740 | 193 |
highlight_range = if (control) subexp_range(snapshot, x, y) else None |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
194 |
highlight_range map { case (range, _) => invalidate_line_range(range) } |
39132 | 195 |
} |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
196 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
197 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
198 |
|
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
199 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
200 |
/* text_area_extension */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
201 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
202 |
private val text_area_extension = new TextAreaExtension |
34678 | 203 |
{ |
37685
305c326db33b
more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents:
37555
diff
changeset
|
204 |
override def paintScreenLineRange(gfx: Graphics2D, |
305c326db33b
more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents:
37555
diff
changeset
|
205 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
38886 | 206 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
207 |
{ |
38843 | 208 |
Isabelle.swing_buffer_lock(model.buffer) { |
209 |
val snapshot = model.snapshot() |
|
210 |
val saved_color = gfx.getColor |
|
39044 | 211 |
val ascent = text_area.getPainter.getFontMetrics.getAscent |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
212 |
|
39182 | 213 |
for (i <- 0 until physical_lines.length) { |
214 |
if (physical_lines(i) != -1) { |
|
215 |
val line_range = proper_line_range(start(i), end(i)) |
|
39044 | 216 |
|
39182 | 217 |
// background color: status |
218 |
val cmds = snapshot.node.command_range(snapshot.revert(line_range)) |
|
219 |
for { |
|
220 |
(command, command_start) <- cmds if !command.is_ignored |
|
221 |
val range = line_range.restrict(snapshot.convert(command.range + command_start)) |
|
222 |
r <- Isabelle.gfx_range(text_area, range) |
|
223 |
color <- Isabelle_Markup.status_color(snapshot, command) |
|
224 |
} { |
|
225 |
gfx.setColor(color) |
|
226 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
227 |
} |
|
39044 | 228 |
|
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
229 |
// background color (1): markup |
39182 | 230 |
for { |
231 |
Text.Info(range, Some(color)) <- |
|
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
232 |
snapshot.select_markup(line_range)(Isabelle_Markup.background1).iterator |
39182 | 233 |
r <- Isabelle.gfx_range(text_area, range) |
234 |
} { |
|
235 |
gfx.setColor(color) |
|
236 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
237 |
} |
|
39171
525a13b9ac74
highlight bad range of nested error (here from inner parsing);
wenzelm
parents:
39169
diff
changeset
|
238 |
|
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
239 |
// background color (2): markup |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
240 |
for { |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
241 |
Text.Info(range, Some(color)) <- |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
242 |
snapshot.select_markup(line_range)(Isabelle_Markup.background2).iterator |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
243 |
r <- Isabelle.gfx_range(text_area, range) |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
244 |
} { |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
245 |
gfx.setColor(color) |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
246 |
gfx.fillRect(r.x + 2, y + i * line_height + 2, r.length - 4, line_height - 4) |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
247 |
} |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
248 |
|
39182 | 249 |
// sub-expression highlighting -- potentially from other snapshot |
250 |
highlight_range match { |
|
251 |
case Some((range, color)) if line_range.overlaps(range) => |
|
252 |
Isabelle.gfx_range(text_area, line_range.restrict(range)) match { |
|
253 |
case None => |
|
254 |
case Some(r) => |
|
255 |
gfx.setColor(color) |
|
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
256 |
gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1) |
39182 | 257 |
} |
258 |
case _ => |
|
259 |
} |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
260 |
|
39182 | 261 |
// squiggly underline |
262 |
for { |
|
263 |
Text.Info(range, Some(color)) <- |
|
264 |
snapshot.select_markup(line_range)(Isabelle_Markup.message).iterator |
|
265 |
r <- Isabelle.gfx_range(text_area, range) |
|
266 |
} { |
|
267 |
gfx.setColor(color) |
|
268 |
val x0 = (r.x / 2) * 2 |
|
269 |
val y0 = r.y + ascent + 1 |
|
270 |
for (x1 <- Range(x0, x0 + r.length, 2)) { |
|
271 |
val y1 = if (x1 % 4 < 2) y0 else y0 + 1 |
|
272 |
gfx.drawLine(x1, y1, x1 + 1, y1) |
|
38843 | 273 |
} |
274 |
} |
|
38223 | 275 |
} |
276 |
} |
|
277 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
278 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
279 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
280 |
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
|
281 |
{ |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
282 |
Isabelle.swing_buffer_lock(model.buffer) { |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
283 |
val snapshot = model.snapshot() |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
284 |
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
|
285 |
snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.tooltip) match |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
286 |
{ |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
287 |
case Text.Info(_, Some(text)) #:: _ => Isabelle.tooltip(text) |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
288 |
case _ => null |
39174
b95cf3892483
Document_View: some markup for main inner syntax categories;
wenzelm
parents:
39171
diff
changeset
|
289 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
290 |
} |
34734 | 291 |
} |
34678 | 292 |
} |
34513 | 293 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
294 |
|
39175 | 295 |
/* gutter_extension */ |
296 |
||
297 |
private val gutter_extension = new TextAreaExtension |
|
298 |
{ |
|
299 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
300 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
301 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
302 |
{ |
|
39176
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
|
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
308 |
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
|
309 |
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
|
310 |
val snapshot = model.snapshot() |
39175 | 311 |
for (i <- 0 until physical_lines.length) { |
312 |
if (physical_lines(i) != -1) { |
|
313 |
val line_range = proper_line_range(start(i), end(i)) |
|
314 |
||
315 |
// gutter icons |
|
39181
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
316 |
val icons = |
39740 | 317 |
(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
|
318 |
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
|
319 |
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
|
320 |
icons match { |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
321 |
case icon :: _ => |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
case Nil => |
39175 | 327 |
} |
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
||
37129 | 336 |
/* caret handling */ |
34810 | 337 |
|
37849 | 338 |
def selected_command(): Option[Command] = |
38223 | 339 |
{ |
340 |
Swing_Thread.require() |
|
38151 | 341 |
model.snapshot().node.proper_command_at(text_area.getCaretPosition) |
38223 | 342 |
} |
34810 | 343 |
|
37849 | 344 |
private val caret_listener = new CaretListener { |
345 |
private val delay = Swing_Thread.delay_last(session.input_delay) { |
|
346 |
session.perspective.event(Session.Perspective) |
|
34810 | 347 |
} |
37849 | 348 |
override def caretUpdate(e: CaretEvent) { delay() } |
34810 | 349 |
} |
350 |
||
351 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
352 |
/* 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
|
353 |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
354 |
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
|
355 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
356 |
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
|
357 |
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
|
358 |
|
34806 | 359 |
setPreferredSize(new Dimension(WIDTH, 0)) |
360 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
361 |
setRequestFocusEnabled(false) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
362 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
363 |
addMouseListener(new MouseAdapter { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
364 |
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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
369 |
}) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
370 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
371 |
override def addNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
372 |
super.addNotify() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
373 |
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
|
374 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
375 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
376 |
override def removeNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
377 |
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
|
378 |
super.removeNotify |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
379 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
380 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
381 |
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
|
382 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
383 |
super.paintComponent(gfx) |
38640 | 384 |
Swing_Thread.assert() |
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
385 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
386 |
val buffer = model.buffer |
38843 | 387 |
Isabelle.buffer_lock(buffer) { |
38640 | 388 |
val snapshot = model.snapshot() |
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
389 |
|
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
390 |
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
|
391 |
{ |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
392 |
try { |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
393 |
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
|
394 |
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
|
395 |
Some((line1, line2)) |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
396 |
} |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
397 |
catch { case e: ArrayIndexOutOfBoundsException => None } |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
398 |
} |
39182 | 399 |
for { |
400 |
(command, start) <- snapshot.node.command_starts |
|
401 |
if !command.is_ignored |
|
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
402 |
(line1, line2) <- line_range(command, start) |
39182 | 403 |
val y = line_to_y(line1) |
404 |
val height = HEIGHT * (line2 - line1) |
|
405 |
color <- Isabelle_Markup.overview_color(snapshot, command) |
|
406 |
} { |
|
407 |
gfx.setColor(color) |
|
408 |
gfx.fillRect(0, y, getWidth - 1, height) |
|
37188 | 409 |
} |
34784
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 |
} |
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 |
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
|
414 |
(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
|
415 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
416 |
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
|
417 |
(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
|
418 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
419 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
420 |
|
39740 | 421 |
/* main actor */ |
422 |
||
423 |
private val main_actor = actor { |
|
424 |
loop { |
|
425 |
react { |
|
426 |
case Session.Commands_Changed(changed) => |
|
427 |
val buffer = model.buffer |
|
428 |
Isabelle.swing_buffer_lock(buffer) { |
|
429 |
val snapshot = model.snapshot() |
|
430 |
||
431 |
if (changed.exists(snapshot.node.commands.contains)) |
|
432 |
overview.repaint() |
|
433 |
||
434 |
val visible_range = screen_lines_range() |
|
435 |
val visible_cmds = snapshot.node.command_range(snapshot.revert(visible_range)).map(_._1) |
|
436 |
if (visible_cmds.exists(changed)) { |
|
437 |
for { |
|
438 |
line <- 0 until text_area.getVisibleLines |
|
439 |
val start = text_area.getScreenLineStartOffset(line) if start >= 0 |
|
440 |
val end = text_area.getScreenLineEndOffset(line) if end >= 0 |
|
441 |
val range = proper_line_range(start, end) |
|
442 |
val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1) |
|
443 |
if line_cmds.exists(changed) |
|
444 |
} text_area.invalidateScreenLineRange(line, line) |
|
445 |
||
446 |
// FIXME danger of deadlock!? |
|
447 |
// FIXME potentially slow!? |
|
448 |
model.buffer.propertiesChanged() |
|
449 |
} |
|
450 |
} |
|
451 |
||
452 |
case Session.Global_Settings => html_panel_resize() |
|
453 |
||
454 |
case bad => System.err.println("command_change_actor: ignoring bad message " + bad) |
|
455 |
} |
|
456 |
} |
|
457 |
} |
|
458 |
||
459 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
460 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
461 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
462 |
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
|
463 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
464 |
text_area.getPainter. |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
465 |
addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, text_area_extension) |
39175 | 466 |
text_area.getGutter.addExtension(gutter_extension) |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
467 |
text_area.addFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
468 |
text_area.getView.addWindowListener(window_listener) |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
469 |
text_area.getPainter.addMouseMotionListener(mouse_motion_listener) |
34810 | 470 |
text_area.addCaretListener(caret_listener) |
471 |
text_area.addLeftOfScrollBar(overview) |
|
39740 | 472 |
session.commands_changed += main_actor |
473 |
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
|
474 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
475 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
476 |
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
|
477 |
{ |
39740 | 478 |
session.commands_changed -= main_actor |
479 |
session.global_settings -= main_actor |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
480 |
text_area.removeFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
481 |
text_area.getView.removeWindowListener(window_listener) |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
482 |
text_area.getPainter.removeMouseMotionListener(mouse_motion_listener) |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
483 |
text_area.removeCaretListener(caret_listener) |
34810 | 484 |
text_area.removeLeftOfScrollBar(overview) |
39175 | 485 |
text_area.getGutter.removeExtension(gutter_extension) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
486 |
text_area.getPainter.removeExtension(text_area_extension) |
39740 | 487 |
exit_popup() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
488 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
489 |
} |