author | wenzelm |
Thu, 04 Nov 2010 10:58:03 +0100 | |
changeset 40338 | e2f03de2b3c7 |
parent 40154 | e11da4ec9d74 |
child 42825 | b04436548927 |
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() |
|
40154 | 133 |
/* FIXME broken |
39740 | 134 |
val offset = text_area.xyToOffset(x, y) |
135 |
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
|
136 |
|
39740 | 137 |
// FIXME snapshot.cumulate |
138 |
snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match { |
|
139 |
case Text.Info(_, Some(msg)) #:: _ => |
|
140 |
val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60) |
|
141 |
html_panel.render_sync(List(msg)) |
|
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
142 |
Thread.sleep(10) // FIXME !? |
39740 | 143 |
popup.show |
144 |
html_popup = Some(popup) |
|
145 |
case _ => |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
146 |
} |
40154 | 147 |
*/ |
34678 | 148 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
149 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
150 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
151 |
/* subexpression highlighting */ |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
152 |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
153 |
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
|
154 |
: Option[(Text.Range, Color)] = |
39132 | 155 |
{ |
156 |
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
|
157 |
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
|
158 |
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
|
159 |
case _ => None |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
160 |
} |
39132 | 161 |
} |
162 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
163 |
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
|
164 |
|
39740 | 165 |
|
166 |
/* CONTROL-mouse management */ |
|
167 |
||
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
168 |
private var control: Boolean = false |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
169 |
|
39740 | 170 |
private def exit_control() |
171 |
{ |
|
172 |
exit_popup() |
|
173 |
highlight_range = None |
|
174 |
} |
|
175 |
||
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
176 |
private val focus_listener = new FocusAdapter { |
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
177 |
override def focusLost(e: FocusEvent) { |
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
178 |
highlight_range = None // FIXME exit_control !? |
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
179 |
} |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
180 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
181 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
182 |
private val window_listener = new WindowAdapter { |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
183 |
override def windowIconified(e: WindowEvent) { exit_control() } |
39742
b59e064e32c3
CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents:
39741
diff
changeset
|
184 |
override def windowDeactivated(e: WindowEvent) { exit_control() } |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
185 |
} |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
186 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
187 |
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
|
188 |
override def mouseMoved(e: MouseEvent) { |
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
189 |
control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown |
39740 | 190 |
val x = e.getX() |
191 |
val y = e.getY() |
|
192 |
||
193 |
if (!model.buffer.isLoaded) exit_control() |
|
39132 | 194 |
else |
195 |
Isabelle.swing_buffer_lock(model.buffer) { |
|
39740 | 196 |
val snapshot = model.snapshot |
197 |
||
198 |
if (control) init_popup(snapshot, x, y) |
|
199 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
200 |
highlight_range map { case (range, _) => invalidate_line_range(range) } |
39740 | 201 |
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
|
202 |
highlight_range map { case (range, _) => invalidate_line_range(range) } |
39132 | 203 |
} |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
204 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
205 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
206 |
|
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
207 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
208 |
/* text_area_extension */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
209 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
210 |
private val text_area_extension = new TextAreaExtension |
34678 | 211 |
{ |
37685
305c326db33b
more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents:
37555
diff
changeset
|
212 |
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
|
213 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
38886 | 214 |
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
|
215 |
{ |
38843 | 216 |
Isabelle.swing_buffer_lock(model.buffer) { |
217 |
val snapshot = model.snapshot() |
|
218 |
val saved_color = gfx.getColor |
|
39044 | 219 |
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
|
220 |
|
39182 | 221 |
for (i <- 0 until physical_lines.length) { |
222 |
if (physical_lines(i) != -1) { |
|
223 |
val line_range = proper_line_range(start(i), end(i)) |
|
39044 | 224 |
|
39182 | 225 |
// background color: status |
226 |
val cmds = snapshot.node.command_range(snapshot.revert(line_range)) |
|
227 |
for { |
|
228 |
(command, command_start) <- cmds if !command.is_ignored |
|
229 |
val range = line_range.restrict(snapshot.convert(command.range + command_start)) |
|
230 |
r <- Isabelle.gfx_range(text_area, range) |
|
231 |
color <- Isabelle_Markup.status_color(snapshot, command) |
|
232 |
} { |
|
233 |
gfx.setColor(color) |
|
234 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
235 |
} |
|
39044 | 236 |
|
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
237 |
// background color (1): markup |
39182 | 238 |
for { |
239 |
Text.Info(range, Some(color)) <- |
|
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
240 |
snapshot.select_markup(line_range)(Isabelle_Markup.background1).iterator |
39182 | 241 |
r <- Isabelle.gfx_range(text_area, range) |
242 |
} { |
|
243 |
gfx.setColor(color) |
|
244 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
245 |
} |
|
39171
525a13b9ac74
highlight bad range of nested error (here from inner parsing);
wenzelm
parents:
39169
diff
changeset
|
246 |
|
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
247 |
// background color (2): markup |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
248 |
for { |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
249 |
Text.Info(range, Some(color)) <- |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
250 |
snapshot.select_markup(line_range)(Isabelle_Markup.background2).iterator |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
251 |
r <- Isabelle.gfx_range(text_area, range) |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
252 |
} { |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
253 |
gfx.setColor(color) |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
254 |
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
|
255 |
} |
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
256 |
|
39182 | 257 |
// sub-expression highlighting -- potentially from other snapshot |
258 |
highlight_range match { |
|
259 |
case Some((range, color)) if line_range.overlaps(range) => |
|
260 |
Isabelle.gfx_range(text_area, line_range.restrict(range)) match { |
|
261 |
case None => |
|
262 |
case Some(r) => |
|
263 |
gfx.setColor(color) |
|
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
264 |
gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1) |
39182 | 265 |
} |
266 |
case _ => |
|
267 |
} |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
268 |
|
39182 | 269 |
// squiggly underline |
270 |
for { |
|
271 |
Text.Info(range, Some(color)) <- |
|
272 |
snapshot.select_markup(line_range)(Isabelle_Markup.message).iterator |
|
273 |
r <- Isabelle.gfx_range(text_area, range) |
|
274 |
} { |
|
275 |
gfx.setColor(color) |
|
276 |
val x0 = (r.x / 2) * 2 |
|
277 |
val y0 = r.y + ascent + 1 |
|
278 |
for (x1 <- Range(x0, x0 + r.length, 2)) { |
|
279 |
val y1 = if (x1 % 4 < 2) y0 else y0 + 1 |
|
280 |
gfx.drawLine(x1, y1, x1 + 1, y1) |
|
38843 | 281 |
} |
282 |
} |
|
38223 | 283 |
} |
284 |
} |
|
285 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
286 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
287 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
288 |
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
|
289 |
{ |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
290 |
Isabelle.swing_buffer_lock(model.buffer) { |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
291 |
val snapshot = model.snapshot() |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
292 |
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
|
293 |
if (control) { |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
294 |
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
|
295 |
{ |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
296 |
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
|
297 |
case _ => null |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
298 |
} |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
299 |
} |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
300 |
else { |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
301 |
// FIXME snapshot.cumulate |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
302 |
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
|
303 |
{ |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
304 |
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
|
305 |
case _ => null |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
306 |
} |
39174
b95cf3892483
Document_View: some markup for main inner syntax categories;
wenzelm
parents:
39171
diff
changeset
|
307 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
308 |
} |
34734 | 309 |
} |
34678 | 310 |
} |
34513 | 311 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
312 |
|
39175 | 313 |
/* gutter_extension */ |
314 |
||
315 |
private val gutter_extension = new TextAreaExtension |
|
316 |
{ |
|
317 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
318 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
319 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
320 |
{ |
|
39176
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
|
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
326 |
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
|
327 |
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
|
328 |
val snapshot = model.snapshot() |
39175 | 329 |
for (i <- 0 until physical_lines.length) { |
330 |
if (physical_lines(i) != -1) { |
|
331 |
val line_range = proper_line_range(start(i), end(i)) |
|
332 |
||
333 |
// gutter icons |
|
39181
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
334 |
val icons = |
39740 | 335 |
(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
|
336 |
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
|
337 |
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
|
338 |
icons match { |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
339 |
case icon :: _ => |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
340 |
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
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
case Nil => |
39175 | 345 |
} |
346 |
} |
|
347 |
} |
|
348 |
} |
|
349 |
} |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
||
37129 | 354 |
/* caret handling */ |
34810 | 355 |
|
37849 | 356 |
def selected_command(): Option[Command] = |
38223 | 357 |
{ |
358 |
Swing_Thread.require() |
|
38151 | 359 |
model.snapshot().node.proper_command_at(text_area.getCaretPosition) |
38223 | 360 |
} |
34810 | 361 |
|
37849 | 362 |
private val caret_listener = new CaretListener { |
363 |
private val delay = Swing_Thread.delay_last(session.input_delay) { |
|
364 |
session.perspective.event(Session.Perspective) |
|
34810 | 365 |
} |
37849 | 366 |
override def caretUpdate(e: CaretEvent) { delay() } |
34810 | 367 |
} |
368 |
||
369 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
370 |
/* 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
|
371 |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
372 |
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
|
373 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
374 |
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
|
375 |
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
|
376 |
|
34806 | 377 |
setPreferredSize(new Dimension(WIDTH, 0)) |
378 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
379 |
setRequestFocusEnabled(false) |
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 |
addMouseListener(new MouseAdapter { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
387 |
}) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
388 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
389 |
override def addNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
390 |
super.addNotify() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
391 |
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
|
392 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
393 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
394 |
override def removeNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
395 |
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
|
396 |
super.removeNotify |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
397 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
398 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
399 |
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
|
400 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
401 |
super.paintComponent(gfx) |
38640 | 402 |
Swing_Thread.assert() |
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
403 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
404 |
val buffer = model.buffer |
38843 | 405 |
Isabelle.buffer_lock(buffer) { |
38640 | 406 |
val snapshot = model.snapshot() |
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
407 |
|
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
408 |
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
|
409 |
{ |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
410 |
try { |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
411 |
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
|
412 |
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
|
413 |
Some((line1, line2)) |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
414 |
} |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
415 |
catch { case e: ArrayIndexOutOfBoundsException => None } |
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
416 |
} |
39182 | 417 |
for { |
418 |
(command, start) <- snapshot.node.command_starts |
|
419 |
if !command.is_ignored |
|
39737
8c312f064223
more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents:
39700
diff
changeset
|
420 |
(line1, line2) <- line_range(command, start) |
39182 | 421 |
val y = line_to_y(line1) |
422 |
val height = HEIGHT * (line2 - line1) |
|
423 |
color <- Isabelle_Markup.overview_color(snapshot, command) |
|
424 |
} { |
|
425 |
gfx.setColor(color) |
|
426 |
gfx.fillRect(0, y, getWidth - 1, height) |
|
37188 | 427 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
428 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
429 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
430 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
431 |
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
|
432 |
(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
|
433 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
434 |
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
|
435 |
(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
|
436 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
437 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
438 |
|
39740 | 439 |
/* main actor */ |
440 |
||
441 |
private val main_actor = actor { |
|
442 |
loop { |
|
443 |
react { |
|
444 |
case Session.Commands_Changed(changed) => |
|
445 |
val buffer = model.buffer |
|
446 |
Isabelle.swing_buffer_lock(buffer) { |
|
447 |
val snapshot = model.snapshot() |
|
448 |
||
449 |
if (changed.exists(snapshot.node.commands.contains)) |
|
450 |
overview.repaint() |
|
451 |
||
452 |
val visible_range = screen_lines_range() |
|
453 |
val visible_cmds = snapshot.node.command_range(snapshot.revert(visible_range)).map(_._1) |
|
454 |
if (visible_cmds.exists(changed)) { |
|
455 |
for { |
|
456 |
line <- 0 until text_area.getVisibleLines |
|
457 |
val start = text_area.getScreenLineStartOffset(line) if start >= 0 |
|
458 |
val end = text_area.getScreenLineEndOffset(line) if end >= 0 |
|
459 |
val range = proper_line_range(start, end) |
|
460 |
val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1) |
|
461 |
if line_cmds.exists(changed) |
|
462 |
} text_area.invalidateScreenLineRange(line, line) |
|
463 |
||
464 |
// FIXME danger of deadlock!? |
|
465 |
// FIXME potentially slow!? |
|
466 |
model.buffer.propertiesChanged() |
|
467 |
} |
|
468 |
} |
|
469 |
||
470 |
case Session.Global_Settings => html_panel_resize() |
|
471 |
||
472 |
case bad => System.err.println("command_change_actor: ignoring bad message " + bad) |
|
473 |
} |
|
474 |
} |
|
475 |
} |
|
476 |
||
477 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
478 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
479 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
480 |
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
|
481 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
482 |
text_area.getPainter. |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
483 |
addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, text_area_extension) |
39175 | 484 |
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
|
485 |
text_area.addFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
486 |
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
|
487 |
text_area.getPainter.addMouseMotionListener(mouse_motion_listener) |
34810 | 488 |
text_area.addCaretListener(caret_listener) |
489 |
text_area.addLeftOfScrollBar(overview) |
|
39740 | 490 |
session.commands_changed += main_actor |
491 |
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
|
492 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
493 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
494 |
private def deactivate() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
495 |
{ |
39740 | 496 |
session.commands_changed -= main_actor |
497 |
session.global_settings -= main_actor |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
498 |
text_area.removeFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
499 |
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
|
500 |
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
|
501 |
text_area.removeCaretListener(caret_listener) |
34810 | 502 |
text_area.removeLeftOfScrollBar(overview) |
39175 | 503 |
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
|
504 |
text_area.getPainter.removeExtension(text_area_extension) |
39740 | 505 |
exit_popup() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
506 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
507 |
} |