author | wenzelm |
Wed, 08 Sep 2010 00:17:41 +0200 | |
changeset 39182 | cce0c10ed943 |
parent 39181 | 2257eded8323 |
child 39636 | 610dc743932c |
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 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
15 |
import java.awt.event.{MouseAdapter, MouseMotionAdapter, MouseEvent, FocusAdapter, FocusEvent} |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
16 |
import java.awt.{BorderLayout, Graphics, Color, Dimension, Graphics2D} |
34734 | 17 |
import javax.swing.{JPanel, ToolTipManager} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
18 |
import javax.swing.event.{CaretListener, CaretEvent} |
34734 | 19 |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
20 |
import org.gjt.sp.jedit.{jEdit, OperatingSystem} |
34709 | 21 |
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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
|
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 |
object Document_View |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
28 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
29 |
/* 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
|
30 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
31 |
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
|
32 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
33 |
def init(model: Document_Model, text_area: TextArea): Document_View = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
34 |
{ |
38223 | 35 |
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
|
36 |
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
|
37 |
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
|
38 |
doc_view.activate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
39 |
doc_view |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
40 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
41 |
|
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
42 |
def apply(text_area: TextArea): Option[Document_View] = |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
43 |
{ |
38223 | 44 |
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
|
45 |
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
|
46 |
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
|
47 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
48 |
} |
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 |
def exit(text_area: TextArea) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
52 |
{ |
38223 | 53 |
Swing_Thread.require() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
54 |
apply(text_area) match { |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
55 |
case None => error("No document view for text area: " + text_area) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
56 |
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
|
57 |
doc_view.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
58 |
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
|
59 |
} |
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 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
62 |
|
34733 | 63 |
|
37129 | 64 |
class Document_View(val model: Document_Model, text_area: TextArea) |
34654 | 65 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
66 |
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
|
67 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
68 |
|
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
|
69 |
/* 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
|
70 |
|
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 |
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
|
72 |
|
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 |
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
|
74 |
{ |
38223 | 75 |
Swing_Thread.require() |
38158 | 76 |
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
|
77 |
} |
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 |
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
|
79 |
|
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 |
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
|
81 |
{ |
38223 | 82 |
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
|
83 |
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
|
84 |
} |
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 |
|
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
87 |
/* visible line ranges */ |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
88 |
|
38883
0998a635684a
refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents:
38881
diff
changeset
|
89 |
// 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
|
90 |
// 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
|
91 |
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
|
92 |
{ |
38883
0998a635684a
refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents:
38881
diff
changeset
|
93 |
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
|
94 |
Text.Range(start, stop) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
95 |
} |
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 |
def screen_lines_range(): Text.Range = |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
98 |
{ |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
99 |
val start = text_area.getScreenLineStartOffset(0) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
100 |
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
|
101 |
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
|
102 |
} |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
103 |
|
39132 | 104 |
def invalidate_line_range(range: Text.Range) |
105 |
{ |
|
106 |
text_area.invalidateLineRange( |
|
107 |
model.buffer.getLineOfOffset(range.start), |
|
108 |
model.buffer.getLineOfOffset(range.stop)) |
|
109 |
} |
|
110 |
||
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
111 |
|
37129 | 112 |
/* commands_changed_actor */ |
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
113 |
|
37129 | 114 |
private val commands_changed_actor = actor { |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
115 |
loop { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
116 |
react { |
38360 | 117 |
case Session.Commands_Changed(changed) => |
38843 | 118 |
val buffer = model.buffer |
119 |
Isabelle.swing_buffer_lock(buffer) { |
|
38151 | 120 |
val snapshot = model.snapshot() |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
121 |
|
38884
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
122 |
if (changed.exists(snapshot.node.commands.contains)) |
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
123 |
overview.repaint() |
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
124 |
|
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
125 |
val visible_range = screen_lines_range() |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
126 |
val visible_cmds = snapshot.node.command_range(snapshot.revert(visible_range)).map(_._1) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
127 |
if (visible_cmds.exists(changed)) { |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
128 |
for { |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
129 |
line <- 0 until text_area.getVisibleLines |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
130 |
val start = text_area.getScreenLineStartOffset(line) if start >= 0 |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
131 |
val end = text_area.getScreenLineEndOffset(line) if end >= 0 |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
132 |
val range = proper_line_range(start, end) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
133 |
val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
134 |
if line_cmds.exists(changed) |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
135 |
} text_area.invalidateScreenLineRange(line, line) |
38884
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
136 |
|
38843 | 137 |
// FIXME danger of deadlock!? |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
138 |
// FIXME potentially slow!? |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
139 |
model.buffer.propertiesChanged() |
38640 | 140 |
} |
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
141 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
142 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
143 |
case bad => System.err.println("command_change_actor: ignoring bad message " + bad) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
144 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
145 |
} |
34678 | 146 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
147 |
|
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
148 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
149 |
/* subexpression highlighting */ |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
150 |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
151 |
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
|
152 |
: Option[(Text.Range, Color)] = |
39132 | 153 |
{ |
154 |
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
|
155 |
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
|
156 |
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
|
157 |
case _ => None |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
158 |
} |
39132 | 159 |
} |
160 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
161 |
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
|
162 |
|
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
163 |
private val focus_listener = new FocusAdapter { |
39132 | 164 |
override def focusLost(e: FocusEvent) { highlight_range = None } |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
165 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
166 |
|
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
167 |
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
|
168 |
override def mouseMoved(e: MouseEvent) { |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
169 |
val control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown |
39132 | 170 |
if (!model.buffer.isLoaded) highlight_range = None |
171 |
else |
|
172 |
Isabelle.swing_buffer_lock(model.buffer) { |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
173 |
highlight_range map { case (range, _) => invalidate_line_range(range) } |
39132 | 174 |
highlight_range = |
175 |
if (control) subexp_range(model.snapshot(), e.getX(), e.getY()) else None |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
176 |
highlight_range map { case (range, _) => invalidate_line_range(range) } |
39132 | 177 |
} |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
178 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
179 |
} |
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 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
182 |
/* text_area_extension */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
183 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
184 |
private val text_area_extension = new TextAreaExtension |
34678 | 185 |
{ |
37685
305c326db33b
more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents:
37555
diff
changeset
|
186 |
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
|
187 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
38886 | 188 |
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
|
189 |
{ |
38843 | 190 |
Isabelle.swing_buffer_lock(model.buffer) { |
191 |
val snapshot = model.snapshot() |
|
192 |
val saved_color = gfx.getColor |
|
39044 | 193 |
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
|
194 |
|
39182 | 195 |
for (i <- 0 until physical_lines.length) { |
196 |
if (physical_lines(i) != -1) { |
|
197 |
val line_range = proper_line_range(start(i), end(i)) |
|
39044 | 198 |
|
39182 | 199 |
// background color: status |
200 |
val cmds = snapshot.node.command_range(snapshot.revert(line_range)) |
|
201 |
for { |
|
202 |
(command, command_start) <- cmds if !command.is_ignored |
|
203 |
val range = line_range.restrict(snapshot.convert(command.range + command_start)) |
|
204 |
r <- Isabelle.gfx_range(text_area, range) |
|
205 |
color <- Isabelle_Markup.status_color(snapshot, command) |
|
206 |
} { |
|
207 |
gfx.setColor(color) |
|
208 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
209 |
} |
|
39044 | 210 |
|
39182 | 211 |
// background color: markup |
212 |
for { |
|
213 |
Text.Info(range, Some(color)) <- |
|
214 |
snapshot.select_markup(line_range)(Isabelle_Markup.background).iterator |
|
215 |
r <- Isabelle.gfx_range(text_area, range) |
|
216 |
} { |
|
217 |
gfx.setColor(color) |
|
218 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
219 |
} |
|
39171
525a13b9ac74
highlight bad range of nested error (here from inner parsing);
wenzelm
parents:
39169
diff
changeset
|
220 |
|
39182 | 221 |
// sub-expression highlighting -- potentially from other snapshot |
222 |
highlight_range match { |
|
223 |
case Some((range, color)) if line_range.overlaps(range) => |
|
224 |
Isabelle.gfx_range(text_area, line_range.restrict(range)) match { |
|
225 |
case None => |
|
226 |
case Some(r) => |
|
227 |
gfx.setColor(color) |
|
228 |
gfx.drawRect(r.x, y + i * line_height, r.length, line_height - 1) |
|
229 |
} |
|
230 |
case _ => |
|
231 |
} |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
232 |
|
39182 | 233 |
// boxed text |
234 |
for { |
|
235 |
Text.Info(range, Some(color)) <- |
|
236 |
snapshot.select_markup(line_range)(Isabelle_Markup.box).iterator |
|
237 |
r <- Isabelle.gfx_range(text_area, range) |
|
238 |
} { |
|
239 |
gfx.setColor(color) |
|
240 |
gfx.drawRect(r.x + 1, y + i * line_height + 1, r.length - 2, line_height - 3) |
|
241 |
} |
|
39168
e3ac771235f7
report token range after inner parse error -- often provides important clues about misunderstanding concerning lexical phase;
wenzelm
parents:
39132
diff
changeset
|
242 |
|
39182 | 243 |
// squiggly underline |
244 |
for { |
|
245 |
Text.Info(range, Some(color)) <- |
|
246 |
snapshot.select_markup(line_range)(Isabelle_Markup.message).iterator |
|
247 |
r <- Isabelle.gfx_range(text_area, range) |
|
248 |
} { |
|
249 |
gfx.setColor(color) |
|
250 |
val x0 = (r.x / 2) * 2 |
|
251 |
val y0 = r.y + ascent + 1 |
|
252 |
for (x1 <- Range(x0, x0 + r.length, 2)) { |
|
253 |
val y1 = if (x1 % 4 < 2) y0 else y0 + 1 |
|
254 |
gfx.drawLine(x1, y1, x1 + 1, y1) |
|
38843 | 255 |
} |
256 |
} |
|
38223 | 257 |
} |
258 |
} |
|
259 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
260 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
261 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
262 |
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
|
263 |
{ |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
264 |
Isabelle.swing_buffer_lock(model.buffer) { |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
265 |
val snapshot = model.snapshot() |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
266 |
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
|
267 |
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
|
268 |
{ |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
39176
diff
changeset
|
269 |
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
|
270 |
case _ => null |
39174
b95cf3892483
Document_View: some markup for main inner syntax categories;
wenzelm
parents:
39171
diff
changeset
|
271 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
272 |
} |
34734 | 273 |
} |
34678 | 274 |
} |
34513 | 275 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
276 |
|
39175 | 277 |
/* gutter_extension */ |
278 |
||
279 |
private val gutter_extension = new TextAreaExtension |
|
280 |
{ |
|
281 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
282 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
283 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
284 |
{ |
|
39176
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
|
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
290 |
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
|
291 |
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
|
292 |
val snapshot = model.snapshot() |
39175 | 293 |
for (i <- 0 until physical_lines.length) { |
294 |
if (physical_lines(i) != -1) { |
|
295 |
val line_range = proper_line_range(start(i), end(i)) |
|
296 |
||
297 |
// gutter icons |
|
39181
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
298 |
val icons = |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
299 |
(for (Text.Info(_, Some(icon)) <- |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
icons match { |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
303 |
case icon :: _ => |
2257eded8323
Document_View: select gutter message icons from markup over line range, not full range results;
wenzelm
parents:
39178
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
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
|
308 |
case Nil => |
39175 | 309 |
} |
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
||
37129 | 318 |
/* caret handling */ |
34810 | 319 |
|
37849 | 320 |
def selected_command(): Option[Command] = |
38223 | 321 |
{ |
322 |
Swing_Thread.require() |
|
38151 | 323 |
model.snapshot().node.proper_command_at(text_area.getCaretPosition) |
38223 | 324 |
} |
34810 | 325 |
|
37849 | 326 |
private val caret_listener = new CaretListener { |
327 |
private val delay = Swing_Thread.delay_last(session.input_delay) { |
|
328 |
session.perspective.event(Session.Perspective) |
|
34810 | 329 |
} |
37849 | 330 |
override def caretUpdate(e: CaretEvent) { delay() } |
34810 | 331 |
} |
332 |
||
333 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
334 |
/* 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
|
335 |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
336 |
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
|
337 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
338 |
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
|
339 |
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
|
340 |
|
34806 | 341 |
setPreferredSize(new Dimension(WIDTH, 0)) |
342 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
343 |
setRequestFocusEnabled(false) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
344 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
345 |
addMouseListener(new MouseAdapter { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
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
|
350 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
351 |
}) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
352 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
353 |
override def addNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
354 |
super.addNotify() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
355 |
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
|
356 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
357 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
358 |
override def removeNotify() { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
359 |
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
|
360 |
super.removeNotify |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
361 |
} |
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 |
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
|
364 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
365 |
super.paintComponent(gfx) |
38640 | 366 |
Swing_Thread.assert() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
367 |
val buffer = model.buffer |
38843 | 368 |
Isabelle.buffer_lock(buffer) { |
38640 | 369 |
val snapshot = model.snapshot() |
39182 | 370 |
for { |
371 |
(command, start) <- snapshot.node.command_starts |
|
372 |
if !command.is_ignored |
|
373 |
val line1 = buffer.getLineOfOffset(snapshot.convert(start)) |
|
374 |
val line2 = buffer.getLineOfOffset(snapshot.convert(start + command.length)) + 1 |
|
375 |
val y = line_to_y(line1) |
|
376 |
val height = HEIGHT * (line2 - line1) |
|
377 |
color <- Isabelle_Markup.overview_color(snapshot, command) |
|
378 |
} { |
|
379 |
gfx.setColor(color) |
|
380 |
gfx.fillRect(0, y, getWidth - 1, height) |
|
37188 | 381 |
} |
34784
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 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
384 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
385 |
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
|
386 |
(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
|
387 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
388 |
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
|
389 |
(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
|
390 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
391 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
392 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
393 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
394 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
395 |
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
|
396 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
397 |
text_area.getPainter. |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
398 |
addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, text_area_extension) |
39175 | 399 |
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
|
400 |
text_area.addFocusListener(focus_listener) |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
401 |
text_area.getPainter.addMouseMotionListener(mouse_motion_listener) |
34810 | 402 |
text_area.addCaretListener(caret_listener) |
403 |
text_area.addLeftOfScrollBar(overview) |
|
37129 | 404 |
session.commands_changed += commands_changed_actor |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
405 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
406 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
407 |
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
|
408 |
{ |
37129 | 409 |
session.commands_changed -= commands_changed_actor |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
410 |
text_area.removeFocusListener(focus_listener) |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
411 |
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
|
412 |
text_area.removeCaretListener(caret_listener) |
34810 | 413 |
text_area.removeLeftOfScrollBar(overview) |
39175 | 414 |
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
|
415 |
text_area.getPainter.removeExtension(text_area_extension) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
416 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
417 |
} |