author | wenzelm |
Tue, 20 Dec 2016 21:35:56 +0100 | |
changeset 64621 | 7116f2634e32 |
parent 63044 | 9478f0dff636 |
child 64884 | b2e78c0ce537 |
permissions | -rw-r--r-- |
49411 | 1 |
/* Title: Tools/jEdit/src/rich_text_area.scala |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
3 |
|
49411 | 4 |
Enhanced version of jEdit text area, with rich text rendering, |
5 |
tooltips, hyperlinks etc. |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
6 |
*/ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
7 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle.jedit |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
9 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
10 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
11 |
import isabelle._ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
12 |
|
56322
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
13 |
import java.awt.{Graphics2D, Shape, Color, Point, Toolkit, Cursor, MouseInfo} |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
14 |
import java.awt.event.{MouseMotionAdapter, MouseAdapter, MouseEvent, |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
15 |
FocusAdapter, FocusEvent, WindowEvent, WindowAdapter} |
43392 | 16 |
import java.awt.font.TextAttribute |
56322
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
17 |
import javax.swing.SwingUtilities |
43392 | 18 |
import java.text.AttributedString |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
19 |
import java.util.ArrayList |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
20 |
|
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
21 |
import scala.util.matching.Regex |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
22 |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
23 |
import org.gjt.sp.util.Log |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
24 |
import org.gjt.sp.jedit.{OperatingSystem, Debug, View} |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
25 |
import org.gjt.sp.jedit.syntax.{DisplayTokenHandler, Chunk} |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
26 |
import org.gjt.sp.jedit.textarea.{TextAreaExtension, TextAreaPainter, TextArea} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
27 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
28 |
|
49492 | 29 |
class Rich_Text_Area( |
30 |
view: View, |
|
31 |
text_area: TextArea, |
|
64621 | 32 |
get_rendering: () => JEdit_Rendering, |
50915
12de8ea66f54
close tooltip after Active.action, to make it look more interactive (notably due to lack of dynamic update);
wenzelm
parents:
50849
diff
changeset
|
33 |
close_action: () => Unit, |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
34 |
get_search_pattern: () => Option[Regex], |
63028 | 35 |
caret_update: () => Unit, |
50306 | 36 |
caret_visible: Boolean, |
53179 | 37 |
enable_hovering: Boolean) |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
38 |
{ |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
39 |
private val buffer = text_area.getBuffer |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
40 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
41 |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
42 |
/* robust extension body */ |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
43 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
44 |
def robust_body[A](default: A)(body: => A): A = |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
45 |
{ |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
46 |
try { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56884
diff
changeset
|
47 |
GUI_Thread.require {} |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
48 |
if (buffer == text_area.getBuffer) body |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
49 |
else { |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
50 |
Log.log(Log.ERROR, this, ERROR("Implicit change of text area buffer")) |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
51 |
default |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
52 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
53 |
} |
50641 | 54 |
catch { case exn: Throwable => Log.log(Log.ERROR, this, exn); default } |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
55 |
} |
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
56 |
|
43392 | 57 |
|
58 |
/* original painters */ |
|
59 |
||
60 |
private def pick_extension(name: String): TextAreaExtension = |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
61 |
{ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
62 |
text_area.getPainter.getExtensions.iterator.filter(x => x.getClass.getName == name).toList |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
63 |
match { |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
64 |
case List(x) => x |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
65 |
case _ => error("Expected exactly one " + name) |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
66 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
67 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
68 |
|
43392 | 69 |
private val orig_text_painter = |
70 |
pick_extension("org.gjt.sp.jedit.textarea.TextAreaPainter$PaintText") |
|
71 |
||
72 |
||
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
73 |
/* common painter state */ |
43381 | 74 |
|
64621 | 75 |
@volatile private var painter_rendering: JEdit_Rendering = null |
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
76 |
@volatile private var painter_clip: Shape = null |
62988 | 77 |
@volatile private var caret_focus: Set[Long] = Set.empty |
43381 | 78 |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
79 |
private val set_state = new TextAreaExtension |
43381 | 80 |
{ |
81 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
82 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
83 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
84 |
{ |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
85 |
painter_rendering = get_rendering() |
46220
663251a395c2
more explicit/robust treatment of common snapshot;
wenzelm
parents:
46205
diff
changeset
|
86 |
painter_clip = gfx.getClip |
62988 | 87 |
caret_focus = |
88 |
JEdit_Lib.visible_range(text_area) match { |
|
63044 | 89 |
case Some(visible_range) if caret_enabled && !painter_rendering.snapshot.is_outdated => |
62988 | 90 |
painter_rendering.caret_focus(JEdit_Lib.caret_range(text_area), visible_range) |
91 |
case _ => Set.empty[Long] |
|
92 |
} |
|
43381 | 93 |
} |
94 |
} |
|
95 |
||
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
96 |
private val reset_state = new TextAreaExtension |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
97 |
{ |
43381 | 98 |
override def paintScreenLineRange(gfx: Graphics2D, |
99 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
100 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
101 |
{ |
|
49356 | 102 |
painter_rendering = null |
46220
663251a395c2
more explicit/robust treatment of common snapshot;
wenzelm
parents:
46205
diff
changeset
|
103 |
painter_clip = null |
62988 | 104 |
caret_focus = Set.empty |
43381 | 105 |
} |
106 |
} |
|
107 |
||
64621 | 108 |
def robust_rendering(body: JEdit_Rendering => Unit) |
46220
663251a395c2
more explicit/robust treatment of common snapshot;
wenzelm
parents:
46205
diff
changeset
|
109 |
{ |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
110 |
robust_body(()) { body(painter_rendering) } |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
111 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
112 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
113 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
114 |
/* active areas within the text */ |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
115 |
|
56317
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
116 |
private class Active_Area[A]( |
64621 | 117 |
rendering: JEdit_Rendering => Text.Range => Option[Text.Info[A]], |
56317
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
118 |
cursor: Option[Int]) |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
119 |
{ |
49493
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
120 |
private var the_text_info: Option[(String, Text.Info[A])] = None |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
121 |
|
55688 | 122 |
def is_active: Boolean = the_text_info.isDefined |
49493
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
123 |
def text_info: Option[(String, Text.Info[A])] = the_text_info |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
124 |
def info: Option[Text.Info[A]] = the_text_info.map(_._2) |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
125 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
126 |
def update(new_info: Option[Text.Info[A]]) |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
127 |
{ |
49493
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
128 |
val old_text_info = the_text_info |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
129 |
val new_text_info = |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
130 |
new_info.map(info => (text_area.getText(info.range.start, info.range.length), info)) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
131 |
|
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
132 |
if (new_text_info != old_text_info) { |
63028 | 133 |
caret_update() |
56317
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
134 |
if (cursor.isDefined) { |
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
135 |
if (new_text_info.isDefined) |
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
136 |
text_area.getPainter.setCursor(Cursor.getPredefinedCursor(cursor.get)) |
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
137 |
else |
56406
0e21270952c3
revert ce37fcb30cf2 for the sake of Mac OS X -- let some event listeners of jEdit reset the cursor;
wenzelm
parents:
56373
diff
changeset
|
138 |
text_area.getPainter.resetCursor() |
56317
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
139 |
} |
49493
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
140 |
for { |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
141 |
r0 <- JEdit_Lib.visible_range(text_area) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
142 |
opt <- List(old_text_info, new_text_info) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
143 |
(_, Text.Info(r1, _)) <- opt |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
144 |
r2 <- r1.try_restrict(r0) // FIXME more precise?! |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
145 |
} JEdit_Lib.invalidate_range(text_area, r2) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
146 |
the_text_info = new_text_info |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
147 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
148 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
149 |
|
64621 | 150 |
def update_rendering(r: JEdit_Rendering, range: Text.Range) |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
151 |
{ update(rendering(r)(range)) } |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
152 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
153 |
def reset { update(None) } |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
154 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
155 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56884
diff
changeset
|
156 |
// owned by GUI thread |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
157 |
|
56317
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
158 |
private val highlight_area = |
60892 | 159 |
new Active_Area[Color]( |
64621 | 160 |
(rendering: JEdit_Rendering) => rendering.highlight _, None) |
60892 | 161 |
|
52980 | 162 |
private val hyperlink_area = |
56317
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
163 |
new Active_Area[PIDE.editor.Hyperlink]( |
64621 | 164 |
(rendering: JEdit_Rendering) => rendering.hyperlink _, Some(Cursor.HAND_CURSOR)) |
60892 | 165 |
|
56317
1147854080b4
tuned rendering -- change mouse pointer for active areas;
wenzelm
parents:
56172
diff
changeset
|
166 |
private val active_area = |
60892 | 167 |
new Active_Area[XML.Elem]( |
64621 | 168 |
(rendering: JEdit_Rendering) => rendering.active _, Some(Cursor.DEFAULT_CURSOR)) |
49492 | 169 |
|
170 |
private val active_areas = |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50306
diff
changeset
|
171 |
List((highlight_area, true), (hyperlink_area, true), (active_area, false)) |
50216 | 172 |
def active_reset(): Unit = active_areas.foreach(_._1.reset) |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
173 |
|
62988 | 174 |
private def area_active(): Boolean = |
175 |
active_areas.exists({ case (area, _) => area.is_active }) |
|
176 |
||
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
177 |
private val focus_listener = new FocusAdapter { |
49424 | 178 |
override def focusLost(e: FocusEvent) { robust_body(()) { active_reset() } } |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
179 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
180 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
181 |
private val window_listener = new WindowAdapter { |
49424 | 182 |
override def windowIconified(e: WindowEvent) { robust_body(()) { active_reset() } } |
183 |
override def windowDeactivated(e: WindowEvent) { robust_body(()) { active_reset() } } |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
184 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
185 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
186 |
private val mouse_listener = new MouseAdapter { |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
187 |
override def mouseClicked(e: MouseEvent) { |
49424 | 188 |
robust_body(()) { |
189 |
hyperlink_area.info match { |
|
56433
db69cb14f7ed
prepare "back" position for Navigator, before following hyperlink;
wenzelm
parents:
56406
diff
changeset
|
190 |
case Some(Text.Info(range, link)) => |
56494
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56433
diff
changeset
|
191 |
if (!link.external) { |
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56433
diff
changeset
|
192 |
try { text_area.moveCaretPosition(range.start) } |
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56433
diff
changeset
|
193 |
catch { |
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56433
diff
changeset
|
194 |
case _: ArrayIndexOutOfBoundsException => |
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56433
diff
changeset
|
195 |
case _: IllegalArgumentException => |
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56433
diff
changeset
|
196 |
} |
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56433
diff
changeset
|
197 |
text_area.requestFocus |
56433
db69cb14f7ed
prepare "back" position for Navigator, before following hyperlink;
wenzelm
parents:
56406
diff
changeset
|
198 |
} |
52482
5b7c4fb41511
explicit Pretty_Tooltip.dismiss_all due to slightly changed focus mechanics;
wenzelm
parents:
52480
diff
changeset
|
199 |
link.follow(view) |
49492 | 200 |
case None => |
201 |
} |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50306
diff
changeset
|
202 |
active_area.text_info match { |
50915
12de8ea66f54
close tooltip after Active.action, to make it look more interactive (notably due to lack of dynamic update);
wenzelm
parents:
50849
diff
changeset
|
203 |
case Some((text, Text.Info(_, markup))) => |
12de8ea66f54
close tooltip after Active.action, to make it look more interactive (notably due to lack of dynamic update);
wenzelm
parents:
50849
diff
changeset
|
204 |
Active.action(view, text, markup) |
12de8ea66f54
close tooltip after Active.action, to make it look more interactive (notably due to lack of dynamic update);
wenzelm
parents:
50849
diff
changeset
|
205 |
close_action() |
49424 | 206 |
case None => |
207 |
} |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
208 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
209 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
210 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
211 |
|
56322
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
212 |
private def mouse_inside_painter(): Boolean = |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
213 |
MouseInfo.getPointerInfo match { |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
214 |
case null => false |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
215 |
case info => |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
216 |
val point = info.getLocation |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
217 |
val painter = text_area.getPainter |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
218 |
SwingUtilities.convertPointFromScreen(point, painter) |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
219 |
painter.contains(point) |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
220 |
} |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
221 |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
222 |
private val mouse_motion_listener = new MouseMotionAdapter { |
56321
7e8c11011fdf
dismiss all popups on mouse drags, e.g. to avoid conflict of C-hover of Isabelle/jEdit and C-selection of jEdit;
wenzelm
parents:
56317
diff
changeset
|
223 |
override def mouseDragged(evt: MouseEvent) { |
7e8c11011fdf
dismiss all popups on mouse drags, e.g. to avoid conflict of C-hover of Isabelle/jEdit and C-selection of jEdit;
wenzelm
parents:
56317
diff
changeset
|
224 |
robust_body(()) { |
57857
4d86378e635f
even more thorough reset on mouse drag (see also 0c63f3538639, 7e8c11011fdf);
wenzelm
parents:
57612
diff
changeset
|
225 |
active_reset() |
56497
0c63f3538639
dismiss popups more carefully (amending 7e8c11011fdf), notably allow mouse dragging within some tooltip, e.g. for text selection;
wenzelm
parents:
56496
diff
changeset
|
226 |
Completion_Popup.Text_Area.dismissed(text_area) |
0c63f3538639
dismiss popups more carefully (amending 7e8c11011fdf), notably allow mouse dragging within some tooltip, e.g. for text selection;
wenzelm
parents:
56496
diff
changeset
|
227 |
Pretty_Tooltip.dismiss_descendant(text_area.getPainter) |
56321
7e8c11011fdf
dismiss all popups on mouse drags, e.g. to avoid conflict of C-hover of Isabelle/jEdit and C-selection of jEdit;
wenzelm
parents:
56317
diff
changeset
|
228 |
} |
7e8c11011fdf
dismiss all popups on mouse drags, e.g. to avoid conflict of C-hover of Isabelle/jEdit and C-selection of jEdit;
wenzelm
parents:
56317
diff
changeset
|
229 |
} |
7e8c11011fdf
dismiss all popups on mouse drags, e.g. to avoid conflict of C-hover of Isabelle/jEdit and C-selection of jEdit;
wenzelm
parents:
56317
diff
changeset
|
230 |
|
53182 | 231 |
override def mouseMoved(evt: MouseEvent) { |
49424 | 232 |
robust_body(()) { |
53182 | 233 |
val x = evt.getX |
234 |
val y = evt.getY |
|
235 |
val control = (evt.getModifiers & Toolkit.getDefaultToolkit.getMenuShortcutKeyMask) != 0 |
|
49492 | 236 |
|
53179 | 237 |
if ((control || enable_hovering) && !buffer.isLoading) { |
49424 | 238 |
JEdit_Lib.buffer_lock(buffer) { |
53182 | 239 |
JEdit_Lib.pixel_range(text_area, x, y) match { |
50211 | 240 |
case None => active_reset() |
49941
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
241 |
case Some(range) => |
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
242 |
val rendering = get_rendering() |
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
243 |
for ((area, require_control) <- active_areas) |
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
244 |
{ |
50165
24d47733975f
reset active area for outdated snapshot (again?);
wenzelm
parents:
50164
diff
changeset
|
245 |
if (control == require_control && !rendering.snapshot.is_outdated) |
49941
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
246 |
area.update_rendering(rendering, range) |
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
247 |
else area.reset |
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
248 |
} |
49492 | 249 |
} |
49424 | 250 |
} |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
251 |
} |
49424 | 252 |
else active_reset() |
51441
37f699750430
more elementary tooltips via mouse events (imitating parts of javax.swing.ToolTipManager) -- avoid abuse of getToolTipText to produce window as side-effect;
wenzelm
parents:
50915
diff
changeset
|
253 |
|
53182 | 254 |
if (evt.getSource == text_area.getPainter) { |
52494
a1e09340c0f4
clarified tooltip timing of pending event and active state;
wenzelm
parents:
52483
diff
changeset
|
255 |
Pretty_Tooltip.invoke(() => |
52495 | 256 |
robust_body(()) { |
56322
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
257 |
if (mouse_inside_painter()) { |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
258 |
val rendering = get_rendering() |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
259 |
val snapshot = rendering.snapshot |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
260 |
if (!snapshot.is_outdated) { |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
261 |
JEdit_Lib.pixel_range(text_area, x, y) match { |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
262 |
case None => |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
263 |
case Some(range) => |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
264 |
val result = |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
265 |
if (control) rendering.tooltip(range) |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
266 |
else rendering.tooltip_message(range) |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
267 |
result match { |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
268 |
case None => |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
269 |
case Some(tip) => |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
270 |
val painter = text_area.getPainter |
58767
30766b5fd0e1
proper line height and text base line, like regular TextAreaPainter.PaintText;
wenzelm
parents:
57857
diff
changeset
|
271 |
val loc = new Point(x, y + painter.getLineHeight / 2) |
56496 | 272 |
val results = rendering.command_results(tip.range) |
56322
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
273 |
Pretty_Tooltip(view, painter, loc, rendering, results, tip) |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
274 |
} |
f9ad26836516
check global mouse status before opening tooltip, e.g. relevant when the mouse has moved outside the window and mouse events are no longer seen by this component;
wenzelm
parents:
56321
diff
changeset
|
275 |
} |
52494
a1e09340c0f4
clarified tooltip timing of pending event and active state;
wenzelm
parents:
52483
diff
changeset
|
276 |
} |
a1e09340c0f4
clarified tooltip timing of pending event and active state;
wenzelm
parents:
52483
diff
changeset
|
277 |
} |
52495 | 278 |
}) |
51452
14e6d761ba1c
extra tooltip_delay after window.dismiss operation, to avoid flickering of quick reactivation;
wenzelm
parents:
51449
diff
changeset
|
279 |
} |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
280 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
281 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
282 |
} |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
283 |
|
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
284 |
|
55713
734ac5709fbe
clarified painting of invisible caret, e.g. focus change due to popup;
wenzelm
parents:
55711
diff
changeset
|
285 |
/* text background */ |
734ac5709fbe
clarified painting of invisible caret, e.g. focus change due to popup;
wenzelm
parents:
55711
diff
changeset
|
286 |
|
43381 | 287 |
private val background_painter = new TextAreaExtension |
288 |
{ |
|
289 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
290 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
291 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
292 |
{ |
|
49356 | 293 |
robust_rendering { rendering => |
51581
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
294 |
val fm = text_area.getPainter.getFontMetrics |
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
295 |
|
43381 | 296 |
for (i <- 0 until physical_lines.length) { |
297 |
if (physical_lines(i) != -1) { |
|
56884
7de69b35bdaf
more robust line_range, according to usual jEdit confusion at end of last line (see also 71c5d1f516c0);
wenzelm
parents:
56883
diff
changeset
|
298 |
val line_range = Text.Range(start(i), end(i) min buffer.getLength) |
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
299 |
|
49473 | 300 |
// line background color |
301 |
for { (color, separator) <- rendering.line_background(line_range) } |
|
302 |
{ |
|
303 |
gfx.setColor(color) |
|
60215 | 304 |
val sep = if (separator) 2 min (line_height / 2) else 0 |
49475 | 305 |
gfx.fillRect(0, y + i * line_height, text_area.getWidth, line_height - sep) |
49473 | 306 |
} |
307 |
||
55790
4670f18baba5
simplified rendering -- no need to over-emphasize "token_range";
wenzelm
parents:
55766
diff
changeset
|
308 |
// background color |
43381 | 309 |
for { |
62988 | 310 |
Text.Info(range, color) <- rendering.background(line_range, caret_focus) |
49409 | 311 |
r <- JEdit_Lib.gfx_range(text_area, range) |
43381 | 312 |
} { |
313 |
gfx.setColor(color) |
|
314 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
315 |
} |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
316 |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50306
diff
changeset
|
317 |
// active area -- potentially from other snapshot |
49492 | 318 |
for { |
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50306
diff
changeset
|
319 |
info <- active_area.info |
49492 | 320 |
Text.Info(range, _) <- info.try_restrict(line_range) |
321 |
r <- JEdit_Lib.gfx_range(text_area, range) |
|
322 |
} { |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50306
diff
changeset
|
323 |
gfx.setColor(rendering.active_hover_color) |
49492 | 324 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
325 |
} |
|
326 |
||
43381 | 327 |
// squiggly underline |
328 |
for { |
|
49356 | 329 |
Text.Info(range, color) <- rendering.squiggly_underline(line_range) |
49409 | 330 |
r <- JEdit_Lib.gfx_range(text_area, range) |
43381 | 331 |
} { |
332 |
gfx.setColor(color) |
|
333 |
val x0 = (r.x / 2) * 2 |
|
51574
2b58d7b139d6
ghost bullet via markup, which is painted as bar under text (normally space);
wenzelm
parents:
51496
diff
changeset
|
334 |
val y0 = r.y + fm.getAscent + 1 |
43381 | 335 |
for (x1 <- Range(x0, x0 + r.length, 2)) { |
336 |
val y1 = if (x1 % 4 < 2) y0 else y0 + 1 |
|
337 |
gfx.drawLine(x1, y1, x1 + 1, y1) |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
338 |
} |
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
339 |
} |
56550 | 340 |
|
56560
ac916ea744e4
tuned rendering -- avoid overlap with squiggly underline;
wenzelm
parents:
56558
diff
changeset
|
341 |
// spell checker |
56550 | 342 |
for { |
56558
05c833d402bc
tuned signature -- explicit Spell_Checker_Variable;
wenzelm
parents:
56551
diff
changeset
|
343 |
spell_checker <- PIDE.spell_checker.get |
56565 | 344 |
spell_range <- rendering.spell_checker_ranges(line_range) |
345 |
text <- JEdit_Lib.try_get_text(buffer, spell_range) |
|
346 |
info <- spell_checker.marked_words(spell_range.start, text) |
|
347 |
r <- JEdit_Lib.gfx_range(text_area, info.range) |
|
56550 | 348 |
} { |
349 |
gfx.setColor(rendering.spell_checker_color) |
|
56560
ac916ea744e4
tuned rendering -- avoid overlap with squiggly underline;
wenzelm
parents:
56558
diff
changeset
|
350 |
val y0 = r.y + ((fm.getAscent + 4) min (line_height - 2)) |
56550 | 351 |
gfx.drawLine(r.x, y0, r.x + r.length, y0) |
352 |
} |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
353 |
} |
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
354 |
} |
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
355 |
} |
43381 | 356 |
} |
357 |
} |
|
358 |
||
359 |
||
360 |
/* text */ |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
361 |
|
55766 | 362 |
private def caret_enabled: Boolean = |
363 |
caret_visible && (!text_area.hasFocus || text_area.isCaretVisible) |
|
364 |
||
64621 | 365 |
private def caret_color(rendering: JEdit_Rendering, offset: Text.Offset): Color = |
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
366 |
{ |
61011 | 367 |
if (text_area.isCaretVisible) text_area.getPainter.getCaretColor |
61014 | 368 |
else { |
369 |
val debug_positions = |
|
61017 | 370 |
(for { |
371 |
c <- Debugger.focus().iterator |
|
372 |
pos <- c.debug_position.iterator |
|
373 |
} yield pos).toList |
|
61014 | 374 |
if (debug_positions.exists(PIDE.editor.is_hyperlink_position(rendering.snapshot, offset, _))) |
61011 | 375 |
rendering.caret_debugger_color |
376 |
else rendering.caret_invisible_color |
|
61014 | 377 |
} |
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
378 |
} |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
379 |
|
64621 | 380 |
private def paint_chunk_list(rendering: JEdit_Rendering, |
43505 | 381 |
gfx: Graphics2D, line_start: Text.Offset, head: Chunk, x: Float, y: Float): Float = |
43382 | 382 |
{ |
383 |
val clip_rect = gfx.getClipBounds |
|
43392 | 384 |
val painter = text_area.getPainter |
385 |
val font_context = painter.getFontRenderContext |
|
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
386 |
|
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
387 |
val caret_range = |
56592
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56565
diff
changeset
|
388 |
if (caret_enabled) JEdit_Lib.caret_range(text_area) |
56172 | 389 |
else Text.Range.offside |
43382 | 390 |
|
391 |
var w = 0.0f |
|
392 |
var chunk = head |
|
393 |
while (chunk != null) { |
|
43505 | 394 |
val chunk_offset = line_start + chunk.offset |
43382 | 395 |
if (x + w + chunk.width > clip_rect.x && |
50306 | 396 |
x + w < clip_rect.x + clip_rect.width && chunk.length > 0) |
43382 | 397 |
{ |
43505 | 398 |
val chunk_range = Text.Range(chunk_offset, chunk_offset + chunk.length) |
44662
c8f1d943bfc5
more robust chunk painting wrt. hard tabs, when chunk.str == null;
wenzelm
parents:
44545
diff
changeset
|
399 |
val chunk_str = if (chunk.str == null) " " * chunk.length else chunk.str |
43382 | 400 |
val chunk_font = chunk.style.getFont |
401 |
val chunk_color = chunk.style.getForegroundColor |
|
402 |
||
44056
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
403 |
def string_width(s: String): Float = |
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
404 |
if (s.isEmpty) 0.0f |
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
405 |
else chunk_font.getStringBounds(s, font_context).getWidth.toFloat |
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
406 |
|
43426
24e2e2f0032b
more explicit treatment of ranges after revert/convert, which may well distort the overall start/end positions;
wenzelm
parents:
43419
diff
changeset
|
407 |
val markup = |
43428
b41dea5772c6
more robust treatment of partial range restriction;
wenzelm
parents:
43426
diff
changeset
|
408 |
for { |
49356 | 409 |
r1 <- rendering.text_color(chunk_range, chunk_color) |
43450 | 410 |
r2 <- r1.try_restrict(chunk_range) |
411 |
} yield r2 |
|
43382 | 412 |
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56358
diff
changeset
|
413 |
val padded_markup_iterator = |
43759
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
414 |
if (markup.isEmpty) |
46197
e4da482283ef
tuned text_color: cumulate with explicit default color;
wenzelm
parents:
46178
diff
changeset
|
415 |
Iterator(Text.Info(chunk_range, chunk_color)) |
43759
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
416 |
else |
46197
e4da482283ef
tuned text_color: cumulate with explicit default color;
wenzelm
parents:
46178
diff
changeset
|
417 |
Iterator( |
e4da482283ef
tuned text_color: cumulate with explicit default color;
wenzelm
parents:
46178
diff
changeset
|
418 |
Text.Info(Text.Range(chunk_range.start, markup.head.range.start), chunk_color)) ++ |
43759
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
419 |
markup.iterator ++ |
46197
e4da482283ef
tuned text_color: cumulate with explicit default color;
wenzelm
parents:
46178
diff
changeset
|
420 |
Iterator(Text.Info(Text.Range(markup.last.range.stop, chunk_range.stop), chunk_color)) |
43759
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
421 |
|
43450 | 422 |
var x1 = x + w |
43382 | 423 |
gfx.setFont(chunk_font) |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56358
diff
changeset
|
424 |
for (Text.Info(range, color) <- padded_markup_iterator if !range.is_singularity) { |
44662
c8f1d943bfc5
more robust chunk painting wrt. hard tabs, when chunk.str == null;
wenzelm
parents:
44545
diff
changeset
|
425 |
val str = chunk_str.substring(range.start - chunk_offset, range.stop - chunk_offset) |
46197
e4da482283ef
tuned text_color: cumulate with explicit default color;
wenzelm
parents:
46178
diff
changeset
|
426 |
gfx.setColor(color) |
43448
90aec5043461
more robust caret painting wrt. surrogate characters;
wenzelm
parents:
43435
diff
changeset
|
427 |
|
43759
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
428 |
range.try_restrict(caret_range) match { |
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
429 |
case Some(r) if !r.is_singularity => |
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
430 |
val i = r.start - range.start |
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
431 |
val j = r.stop - range.start |
44056
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
432 |
val s1 = str.substring(0, i) |
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
433 |
val s2 = str.substring(i, j) |
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
434 |
val s3 = str.substring(j) |
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
435 |
|
62812
ce22e5c3d4ce
more robust display of bidirectional Unicode text: enforce left-to-right;
wenzelm
parents:
61017
diff
changeset
|
436 |
if (s1.nonEmpty) gfx.drawString(Word.bidi_override(s1), x1, y) |
44056
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
437 |
|
62812
ce22e5c3d4ce
more robust display of bidirectional Unicode text: enforce left-to-right;
wenzelm
parents:
61017
diff
changeset
|
438 |
val astr = new AttributedString(Word.bidi_override(s2)) |
43759
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
439 |
astr.addAttribute(TextAttribute.FONT, chunk_font) |
61011 | 440 |
astr.addAttribute(TextAttribute.FOREGROUND, caret_color(rendering, r.start)) |
44056
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
441 |
astr.addAttribute(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON) |
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
442 |
gfx.drawString(astr.getIterator, x1 + string_width(s1), y) |
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
443 |
|
59319 | 444 |
if (s3.nonEmpty) |
62812
ce22e5c3d4ce
more robust display of bidirectional Unicode text: enforce left-to-right;
wenzelm
parents:
61017
diff
changeset
|
445 |
gfx.drawString(Word.bidi_override(s3), x1 + string_width(str.substring(0, j)), y) |
44056
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
446 |
|
43759
d93a69672362
more uniform padded_markup, which is important for caret visibility despite absence of markup;
wenzelm
parents:
43506
diff
changeset
|
447 |
case _ => |
62812
ce22e5c3d4ce
more robust display of bidirectional Unicode text: enforce left-to-right;
wenzelm
parents:
61017
diff
changeset
|
448 |
gfx.drawString(Word.bidi_override(str), x1, y) |
43382 | 449 |
} |
44056
be825a69fc67
less ambitious use of AttributedString, for proper caret painting within \<^sup>\<foobar>;
wenzelm
parents:
43759
diff
changeset
|
450 |
x1 += string_width(str) |
43382 | 451 |
} |
452 |
} |
|
453 |
w += chunk.width |
|
454 |
chunk = chunk.next.asInstanceOf[Chunk] |
|
455 |
} |
|
456 |
w |
|
457 |
} |
|
458 |
||
43381 | 459 |
private val text_painter = new TextAreaExtension |
460 |
{ |
|
461 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
462 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
43382 | 463 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
43381 | 464 |
{ |
49356 | 465 |
robust_rendering { rendering => |
51581
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
466 |
val painter = text_area.getPainter |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
467 |
val fm = painter.getFontMetrics |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
468 |
val lm = painter.getFont.getLineMetrics(" ", painter.getFontRenderContext) |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
469 |
|
43381 | 470 |
val clip = gfx.getClip |
471 |
val x0 = text_area.getHorizontalOffset |
|
58767
30766b5fd0e1
proper line height and text base line, like regular TextAreaPainter.PaintText;
wenzelm
parents:
57857
diff
changeset
|
472 |
var y0 = y + painter.getLineHeight - (fm.getLeading + 1) - fm.getDescent |
43372
2df2144b0910
use orig_text_painter for extras outside main text (also required to update internal line infos);
wenzelm
parents:
43371
diff
changeset
|
473 |
|
51581
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
474 |
val (bullet_x, bullet_y, bullet_w, bullet_h) = |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
475 |
{ |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
476 |
val w = fm.charWidth(' ') |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
477 |
val b = (w / 2) max 1 |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
478 |
val c = (lm.getAscent + lm.getStrikethroughOffset).round.toInt |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
479 |
((w - b + 1) / 2, c - b / 2, w - b, line_height - b) |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
480 |
} |
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
481 |
|
43381 | 482 |
for (i <- 0 until physical_lines.length) { |
49097
4e5e48c589ea
more direct access to all-important chunks for text painting;
wenzelm
parents:
48921
diff
changeset
|
483 |
val line = physical_lines(i) |
4e5e48c589ea
more direct access to all-important chunks for text painting;
wenzelm
parents:
48921
diff
changeset
|
484 |
if (line != -1) { |
56884
7de69b35bdaf
more robust line_range, according to usual jEdit confusion at end of last line (see also 71c5d1f516c0);
wenzelm
parents:
56883
diff
changeset
|
485 |
val line_range = Text.Range(start(i), end(i) min buffer.getLength) |
51581
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
486 |
|
587c917e8d36
paint bullet bar within text layer -- thus it remains visible with active selection etc.;
wenzelm
parents:
51577
diff
changeset
|
487 |
// text chunks |
49097
4e5e48c589ea
more direct access to all-important chunks for text painting;
wenzelm
parents:
48921
diff
changeset
|
488 |
val screen_line = first_line + i |
4e5e48c589ea
more direct access to all-important chunks for text painting;
wenzelm
parents:
48921
diff
changeset
|
489 |
val chunks = text_area.getChunksOfScreenLine(screen_line) |
4e5e48c589ea
more direct access to all-important chunks for text painting;
wenzelm
parents:
48921
diff
changeset
|
490 |
if (chunks != null) { |
56358
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
491 |
try { |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
492 |
val line_start = buffer.getLineStartOffset(line) |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
493 |
gfx.clipRect(x0, y + line_height * i, Integer.MAX_VALUE, line_height) |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
494 |
val w = paint_chunk_list(rendering, gfx, line_start, chunks, x0, y0).toInt |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
495 |
gfx.clipRect(x0 + w.toInt, 0, Integer.MAX_VALUE, Integer.MAX_VALUE) |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
496 |
orig_text_painter.paintValidLine(gfx, |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
497 |
screen_line, line, start(i), end(i), y + line_height * i) |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
498 |
} finally { gfx.setClip(clip) } |
49097
4e5e48c589ea
more direct access to all-important chunks for text painting;
wenzelm
parents:
48921
diff
changeset
|
499 |
} |
60913 | 500 |
|
501 |
// bullet bar |
|
502 |
for { |
|
503 |
Text.Info(range, color) <- rendering.bullet(line_range) |
|
504 |
r <- JEdit_Lib.gfx_range(text_area, range) |
|
505 |
} { |
|
506 |
gfx.setColor(color) |
|
507 |
gfx.fillRect(r.x + bullet_x, y + i * line_height + bullet_y, |
|
508 |
r.length - bullet_w, line_height - bullet_h) |
|
509 |
} |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
510 |
} |
43381 | 511 |
y0 += line_height |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
512 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
513 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
514 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
515 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
516 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
517 |
|
43435
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
518 |
/* foreground */ |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
519 |
|
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
520 |
private val foreground_painter = new TextAreaExtension |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
521 |
{ |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
522 |
override def paintScreenLineRange(gfx: Graphics2D, |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
523 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
524 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
525 |
{ |
49356 | 526 |
robust_rendering { rendering => |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
527 |
val search_pattern = get_search_pattern() |
43435
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
528 |
for (i <- 0 until physical_lines.length) { |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
529 |
if (physical_lines(i) != -1) { |
56884
7de69b35bdaf
more robust line_range, according to usual jEdit confusion at end of last line (see also 71c5d1f516c0);
wenzelm
parents:
56883
diff
changeset
|
530 |
val line_range = Text.Range(start(i), end(i) min buffer.getLength) |
43435
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
531 |
|
44545
3c40007aa031
transparent foreground color for quoted entities;
wenzelm
parents:
44056
diff
changeset
|
532 |
// foreground color |
3c40007aa031
transparent foreground color for quoted entities;
wenzelm
parents:
44056
diff
changeset
|
533 |
for { |
49356 | 534 |
Text.Info(range, color) <- rendering.foreground(line_range) |
49409 | 535 |
r <- JEdit_Lib.gfx_range(text_area, range) |
44545
3c40007aa031
transparent foreground color for quoted entities;
wenzelm
parents:
44056
diff
changeset
|
536 |
} { |
3c40007aa031
transparent foreground color for quoted entities;
wenzelm
parents:
44056
diff
changeset
|
537 |
gfx.setColor(color) |
3c40007aa031
transparent foreground color for quoted entities;
wenzelm
parents:
44056
diff
changeset
|
538 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
3c40007aa031
transparent foreground color for quoted entities;
wenzelm
parents:
44056
diff
changeset
|
539 |
} |
3c40007aa031
transparent foreground color for quoted entities;
wenzelm
parents:
44056
diff
changeset
|
540 |
|
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
541 |
// search pattern |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
542 |
for { |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
543 |
regex <- search_pattern |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
544 |
text <- JEdit_Lib.try_get_text(buffer, line_range) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
545 |
m <- regex.findAllMatchIn(text) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
546 |
range = Text.Range(m.start, m.end) + line_range.start |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
547 |
r <- JEdit_Lib.gfx_range(text_area, range) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
548 |
} { |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
549 |
gfx.setColor(rendering.search_color) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
550 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
551 |
} |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56662
diff
changeset
|
552 |
|
49357 | 553 |
// highlight range -- potentially from other snapshot |
46205 | 554 |
for { |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
555 |
info <- highlight_area.info |
46205 | 556 |
Text.Info(range, color) <- info.try_restrict(line_range) |
49409 | 557 |
r <- JEdit_Lib.gfx_range(text_area, range) |
46205 | 558 |
} { |
559 |
gfx.setColor(color) |
|
560 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
43435
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
561 |
} |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47471
diff
changeset
|
562 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47471
diff
changeset
|
563 |
// hyperlink range -- potentially from other snapshot |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47471
diff
changeset
|
564 |
for { |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
565 |
info <- hyperlink_area.info |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47471
diff
changeset
|
566 |
Text.Info(range, _) <- info.try_restrict(line_range) |
49409 | 567 |
r <- JEdit_Lib.gfx_range(text_area, range) |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47471
diff
changeset
|
568 |
} { |
49356 | 569 |
gfx.setColor(rendering.hyperlink_color) |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47471
diff
changeset
|
570 |
gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47471
diff
changeset
|
571 |
} |
55688 | 572 |
|
62988 | 573 |
// entity def range |
574 |
if (!area_active() && caret_visible) { |
|
575 |
for { |
|
62991 | 576 |
Text.Info(range, color) <- rendering.entity_ref(line_range, caret_focus) |
62988 | 577 |
r <- JEdit_Lib.gfx_range(text_area, range) |
578 |
} { |
|
579 |
gfx.setColor(color) |
|
580 |
gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1) |
|
581 |
} |
|
582 |
} |
|
583 |
||
55688 | 584 |
// completion range |
62988 | 585 |
if (!area_active() && caret_visible) { |
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
586 |
for { |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
587 |
completion <- Completion_Popup.Text_Area(text_area) |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
588 |
Text.Info(range, color) <- completion.rendering(rendering, line_range) |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
589 |
r <- JEdit_Lib.gfx_range(text_area, range) |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
590 |
} { |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
591 |
gfx.setColor(color) |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55726
diff
changeset
|
592 |
gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1) |
55711 | 593 |
} |
55688 | 594 |
} |
43435
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
595 |
} |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
596 |
} |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
597 |
} |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
598 |
} |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
599 |
} |
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
600 |
|
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
601 |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
602 |
/* caret -- outside of text range */ |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
603 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
604 |
private class Caret_Painter(before: Boolean) extends TextAreaExtension |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
605 |
{ |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
606 |
override def paintValidLine(gfx: Graphics2D, |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
607 |
screen_line: Int, physical_line: Int, start: Int, end: Int, y: Int) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
608 |
{ |
49356 | 609 |
robust_rendering { _ => |
43404 | 610 |
if (before) gfx.clipRect(0, 0, 0, 0) |
611 |
else gfx.setClip(painter_clip) |
|
612 |
} |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
613 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
614 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
615 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
616 |
private val before_caret_painter1 = new Caret_Painter(true) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
617 |
private val after_caret_painter1 = new Caret_Painter(false) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
618 |
private val before_caret_painter2 = new Caret_Painter(true) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
619 |
private val after_caret_painter2 = new Caret_Painter(false) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
620 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
621 |
private val caret_painter = new TextAreaExtension |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
622 |
{ |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
623 |
override def paintValidLine(gfx: Graphics2D, |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
624 |
screen_line: Int, physical_line: Int, start: Int, end: Int, y: Int) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
625 |
{ |
55713
734ac5709fbe
clarified painting of invisible caret, e.g. focus change due to popup;
wenzelm
parents:
55711
diff
changeset
|
626 |
robust_rendering { rendering => |
734ac5709fbe
clarified painting of invisible caret, e.g. focus change due to popup;
wenzelm
parents:
55711
diff
changeset
|
627 |
if (caret_visible) { |
43398
c3e2a361b418
more robust painter_body wrt. EBP races and spurious exceptions (which causes jEdit to remove the extension);
wenzelm
parents:
43396
diff
changeset
|
628 |
val caret = text_area.getCaretPosition |
55766 | 629 |
if (caret_enabled && start <= caret && caret == end - 1) { |
43398
c3e2a361b418
more robust painter_body wrt. EBP races and spurious exceptions (which causes jEdit to remove the extension);
wenzelm
parents:
43396
diff
changeset
|
630 |
val painter = text_area.getPainter |
c3e2a361b418
more robust painter_body wrt. EBP races and spurious exceptions (which causes jEdit to remove the extension);
wenzelm
parents:
43396
diff
changeset
|
631 |
val fm = painter.getFontMetrics |
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
632 |
|
43398
c3e2a361b418
more robust painter_body wrt. EBP races and spurious exceptions (which causes jEdit to remove the extension);
wenzelm
parents:
43396
diff
changeset
|
633 |
val offset = caret - text_area.getLineStartOffset(physical_line) |
c3e2a361b418
more robust painter_body wrt. EBP races and spurious exceptions (which causes jEdit to remove the extension);
wenzelm
parents:
43396
diff
changeset
|
634 |
val x = text_area.offsetToXY(physical_line, offset).x |
58767
30766b5fd0e1
proper line height and text base line, like regular TextAreaPainter.PaintText;
wenzelm
parents:
57857
diff
changeset
|
635 |
val y1 = y + painter.getLineHeight - (fm.getLeading + 1) - fm.getDescent |
56358
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
636 |
|
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
637 |
val astr = new AttributedString(" ") |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
638 |
astr.addAttribute(TextAttribute.FONT, painter.getFont) |
61011 | 639 |
astr.addAttribute(TextAttribute.FOREGROUND, caret_color(rendering, caret)) |
56358
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
640 |
astr.addAttribute(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON) |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
641 |
|
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
642 |
val clip = gfx.getClip |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
643 |
try { |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
644 |
gfx.clipRect(x, y, Integer.MAX_VALUE, painter.getLineHeight) |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
645 |
gfx.drawString(astr.getIterator, x, y1) |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
646 |
} |
ed09e5f3aedf
more uniform painting of caret, which also improves visibility in invisible state;
wenzelm
parents:
56340
diff
changeset
|
647 |
finally { gfx.setClip(clip) } |
43398
c3e2a361b418
more robust painter_body wrt. EBP races and spurious exceptions (which causes jEdit to remove the extension);
wenzelm
parents:
43396
diff
changeset
|
648 |
} |
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
649 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
650 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
651 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
652 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
653 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
654 |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
655 |
/* activation */ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
656 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
657 |
def activate() |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
658 |
{ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
659 |
val painter = text_area.getPainter |
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
660 |
painter.addExtension(TextAreaPainter.LOWEST_LAYER, set_state) |
43381 | 661 |
painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, background_painter) |
662 |
painter.addExtension(TextAreaPainter.TEXT_LAYER, text_painter) |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
663 |
painter.addExtension(TextAreaPainter.CARET_LAYER - 1, before_caret_painter1) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
664 |
painter.addExtension(TextAreaPainter.CARET_LAYER + 1, after_caret_painter1) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
665 |
painter.addExtension(TextAreaPainter.BLOCK_CARET_LAYER - 1, before_caret_painter2) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
666 |
painter.addExtension(TextAreaPainter.BLOCK_CARET_LAYER + 1, after_caret_painter2) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
667 |
painter.addExtension(TextAreaPainter.BLOCK_CARET_LAYER + 2, caret_painter) |
43435
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
668 |
painter.addExtension(500, foreground_painter) |
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
669 |
painter.addExtension(TextAreaPainter.HIGHEST_LAYER, reset_state) |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
670 |
painter.removeExtension(orig_text_painter) |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
671 |
painter.addMouseListener(mouse_listener) |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
672 |
painter.addMouseMotionListener(mouse_motion_listener) |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
673 |
text_area.addFocusListener(focus_listener) |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
674 |
view.addWindowListener(window_listener) |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
675 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
676 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
677 |
def deactivate() |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
678 |
{ |
56340
af8cb60b55eb
clear active areas (notably mouse pointer) before changing context (e.g. via hyperlink);
wenzelm
parents:
56339
diff
changeset
|
679 |
active_reset() |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
680 |
val painter = text_area.getPainter |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
681 |
view.removeWindowListener(window_listener) |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
682 |
text_area.removeFocusListener(focus_listener) |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
683 |
painter.removeMouseMotionListener(mouse_motion_listener) |
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49409
diff
changeset
|
684 |
painter.removeMouseListener(mouse_listener) |
43396 | 685 |
painter.addExtension(TextAreaPainter.TEXT_LAYER, orig_text_painter) |
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
686 |
painter.removeExtension(reset_state) |
43435
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
687 |
painter.removeExtension(foreground_painter) |
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
688 |
painter.removeExtension(caret_painter) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
689 |
painter.removeExtension(after_caret_painter2) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
690 |
painter.removeExtension(before_caret_painter2) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
691 |
painter.removeExtension(after_caret_painter1) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
692 |
painter.removeExtension(before_caret_painter1) |
43381 | 693 |
painter.removeExtension(text_painter) |
694 |
painter.removeExtension(background_painter) |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
695 |
painter.removeExtension(set_state) |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
696 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
697 |
} |