author | wenzelm |
Wed, 15 Jun 2011 13:36:08 +0200 | |
changeset 43393 | f4141da52e92 |
parent 43392 | fe4b8c52b1cc |
child 43396 | 548a68eafaea |
permissions | -rw-r--r-- |
43381 | 1 |
/* Title: Tools/jEdit/src/text_area_painter.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 |
|
43381 | 4 |
Painter setup for main jEdit text area. |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
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 |
package isabelle.jedit |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
8 |
|
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 |
import isabelle._ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
11 |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
12 |
import java.awt.{Graphics2D, Shape} |
43392 | 13 |
import java.awt.font.TextAttribute |
14 |
import java.text.AttributedString |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
15 |
import java.util.ArrayList |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
16 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
17 |
import org.gjt.sp.jedit.Debug |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
18 |
import org.gjt.sp.jedit.syntax.{DisplayTokenHandler, Chunk} |
43392 | 19 |
import org.gjt.sp.jedit.textarea.{TextAreaExtension, TextAreaPainter, JEditTextArea} |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
20 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
21 |
|
43381 | 22 |
class Text_Area_Painter(doc_view: Document_View) |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
23 |
{ |
43381 | 24 |
private val model = doc_view.model |
43382 | 25 |
private val buffer = model.buffer |
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
26 |
private val text_area = doc_view.text_area |
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
27 |
|
43392 | 28 |
|
29 |
/* original painters */ |
|
30 |
||
31 |
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
|
32 |
{ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
33 |
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
|
34 |
match { |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
35 |
case List(x) => x |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
36 |
case _ => error("Expected exactly one " + name) |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
37 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
38 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
39 |
|
43392 | 40 |
private val orig_text_painter = |
41 |
pick_extension("org.gjt.sp.jedit.textarea.TextAreaPainter$PaintText") |
|
42 |
||
43 |
||
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
44 |
/* common painter state */ |
43381 | 45 |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
46 |
@volatile private var painter_snapshot: Document.Snapshot = null |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
47 |
@volatile private var painter_clip: Shape = null |
43381 | 48 |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
49 |
private val set_state = new TextAreaExtension |
43381 | 50 |
{ |
51 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
52 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
53 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
54 |
{ |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
55 |
painter_snapshot = model.snapshot() |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
56 |
painter_clip = gfx.getClip |
43381 | 57 |
} |
58 |
} |
|
59 |
||
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
60 |
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
|
61 |
{ |
43381 | 62 |
override def paintScreenLineRange(gfx: Graphics2D, |
63 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
64 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
65 |
{ |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
66 |
painter_snapshot = null |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
67 |
painter_clip = null |
43381 | 68 |
} |
69 |
} |
|
70 |
||
71 |
||
72 |
/* text background */ |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
73 |
|
43381 | 74 |
private val background_painter = new TextAreaExtension |
75 |
{ |
|
76 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
77 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
78 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
79 |
{ |
|
43382 | 80 |
Isabelle.swing_buffer_lock(buffer) { |
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
81 |
val snapshot = painter_snapshot |
43381 | 82 |
val ascent = text_area.getPainter.getFontMetrics.getAscent |
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
83 |
|
43381 | 84 |
for (i <- 0 until physical_lines.length) { |
85 |
if (physical_lines(i) != -1) { |
|
86 |
val line_range = doc_view.proper_line_range(start(i), end(i)) |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
87 |
|
43381 | 88 |
// background color: status |
89 |
val cmds = snapshot.node.command_range(snapshot.revert(line_range)) |
|
90 |
for { |
|
91 |
(command, command_start) <- cmds if !command.is_ignored |
|
92 |
val range = line_range.restrict(snapshot.convert(command.range + command_start)) |
|
93 |
r <- Isabelle.gfx_range(text_area, range) |
|
94 |
color <- Isabelle_Markup.status_color(snapshot, command) |
|
95 |
} { |
|
96 |
gfx.setColor(color) |
|
97 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
98 |
} |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
99 |
|
43381 | 100 |
// background color (1): markup |
101 |
for { |
|
102 |
Text.Info(range, Some(color)) <- |
|
103 |
snapshot.select_markup(line_range)(Isabelle_Markup.background1).iterator |
|
104 |
r <- Isabelle.gfx_range(text_area, range) |
|
105 |
} { |
|
106 |
gfx.setColor(color) |
|
107 |
gfx.fillRect(r.x, y + i * line_height, r.length, line_height) |
|
108 |
} |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
109 |
|
43381 | 110 |
// background color (2): markup |
111 |
for { |
|
112 |
Text.Info(range, Some(color)) <- |
|
113 |
snapshot.select_markup(line_range)(Isabelle_Markup.background2).iterator |
|
114 |
r <- Isabelle.gfx_range(text_area, range) |
|
115 |
} { |
|
116 |
gfx.setColor(color) |
|
117 |
gfx.fillRect(r.x + 2, y + i * line_height + 2, r.length - 4, line_height - 4) |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
118 |
} |
43381 | 119 |
|
120 |
// sub-expression highlighting -- potentially from other snapshot |
|
121 |
doc_view.highlight_range match { |
|
122 |
case Some((range, color)) if line_range.overlaps(range) => |
|
123 |
Isabelle.gfx_range(text_area, line_range.restrict(range)) match { |
|
124 |
case None => |
|
125 |
case Some(r) => |
|
126 |
gfx.setColor(color) |
|
127 |
gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1) |
|
128 |
} |
|
129 |
case _ => |
|
130 |
} |
|
131 |
||
132 |
// squiggly underline |
|
133 |
for { |
|
134 |
Text.Info(range, Some(color)) <- |
|
135 |
snapshot.select_markup(line_range)(Isabelle_Markup.message).iterator |
|
136 |
r <- Isabelle.gfx_range(text_area, range) |
|
137 |
} { |
|
138 |
gfx.setColor(color) |
|
139 |
val x0 = (r.x / 2) * 2 |
|
140 |
val y0 = r.y + ascent + 1 |
|
141 |
for (x1 <- Range(x0, x0 + r.length, 2)) { |
|
142 |
val y1 = if (x1 % 4 < 2) y0 else y0 + 1 |
|
143 |
gfx.drawLine(x1, y1, x1 + 1, y1) |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
144 |
} |
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
145 |
} |
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
146 |
} |
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
147 |
} |
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43375
diff
changeset
|
148 |
} |
43381 | 149 |
} |
150 |
} |
|
151 |
||
152 |
||
153 |
/* text */ |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
154 |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
155 |
def char_width(): Int = |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
156 |
{ |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
157 |
val painter = text_area.getPainter |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
158 |
val font = painter.getFont |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
159 |
val font_context = painter.getFontRenderContext |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
160 |
font.getStringBounds(" ", font_context).getWidth.round.toInt |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
161 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
162 |
|
43382 | 163 |
private def line_infos(physical_lines: Iterator[Int]): Map[Text.Offset, Chunk] = |
164 |
{ |
|
165 |
val painter = text_area.getPainter |
|
166 |
val font = painter.getFont |
|
167 |
val font_context = painter.getFontRenderContext |
|
168 |
||
169 |
// see org.gjt.sp.jedit.textarea.TextArea.propertiesChanged |
|
170 |
// see org.gjt.sp.jedit.textarea.TextArea.setMaxLineLength |
|
171 |
val margin = |
|
172 |
if (buffer.getStringProperty("wrap") != "soft") 0.0f |
|
173 |
else { |
|
174 |
val max = buffer.getIntegerProperty("maxLineLen", 0) |
|
175 |
if (max > 0) font.getStringBounds(" " * max, font_context).getWidth.toInt |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
176 |
else painter.getWidth - char_width() * 3 |
43382 | 177 |
}.toFloat |
178 |
||
179 |
val out = new ArrayList[Chunk] |
|
180 |
val handler = new DisplayTokenHandler |
|
181 |
||
182 |
var result = Map[Text.Offset, Chunk]() |
|
183 |
for (line <- physical_lines) { |
|
184 |
out.clear |
|
185 |
handler.init(painter.getStyles, font_context, painter, out, margin) |
|
186 |
buffer.markTokens(line, handler) |
|
187 |
||
188 |
val line_start = buffer.getLineStartOffset(line) |
|
189 |
for (i <- 0 until out.size) { |
|
190 |
val chunk = out.get(i) |
|
191 |
result += (line_start + chunk.offset -> chunk) |
|
192 |
} |
|
193 |
} |
|
194 |
result |
|
195 |
} |
|
196 |
||
197 |
private def paint_chunk_list(gfx: Graphics2D, |
|
43392 | 198 |
offset: Text.Offset, caret_offset: Text.Offset, head: Chunk, x: Float, y: Float): Float = |
43382 | 199 |
{ |
200 |
val clip_rect = gfx.getClipBounds |
|
43392 | 201 |
val painter = text_area.getPainter |
202 |
val font_context = painter.getFontRenderContext |
|
43382 | 203 |
|
204 |
var w = 0.0f |
|
205 |
var chunk_offset = offset |
|
206 |
var chunk = head |
|
207 |
while (chunk != null) { |
|
208 |
val chunk_length = if (chunk.str == null) 0 else chunk.str.length |
|
209 |
||
210 |
if (x + w + chunk.width > clip_rect.x && |
|
211 |
x + w < clip_rect.x + clip_rect.width && |
|
212 |
chunk.accessable && chunk.visible) |
|
213 |
{ |
|
214 |
val chunk_range = Text.Range(chunk_offset, chunk_offset + chunk_length) |
|
215 |
val chunk_font = chunk.style.getFont |
|
216 |
val chunk_color = chunk.style.getForegroundColor |
|
217 |
||
218 |
val markup = painter_snapshot.select_markup(chunk_range)(Isabelle_Markup.foreground) |
|
219 |
||
220 |
gfx.setFont(chunk_font) |
|
221 |
if (!Debug.DISABLE_GLYPH_VECTOR && chunk.gv != null && |
|
43392 | 222 |
markup.forall(info => info.info.isEmpty) && |
223 |
!chunk_range.contains(caret_offset)) { |
|
43382 | 224 |
gfx.setColor(chunk_color) |
225 |
gfx.drawGlyphVector(chunk.gv, x + w, y) |
|
226 |
} |
|
227 |
else { |
|
43383 | 228 |
var x1 = x + w |
43382 | 229 |
for (Text.Info(range, info) <- markup) { |
230 |
val str = chunk.str.substring(range.start - chunk_offset, range.stop - chunk_offset) |
|
231 |
gfx.setColor(info.getOrElse(chunk_color)) |
|
43392 | 232 |
if (range.contains(caret_offset)) { |
233 |
val astr = new AttributedString(str) |
|
234 |
val i = caret_offset - range.start |
|
235 |
astr.addAttribute(TextAttribute.FONT, chunk_font) |
|
236 |
astr.addAttribute(TextAttribute.FOREGROUND, painter.getCaretColor, i, i + 1) |
|
237 |
astr.addAttribute(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON, i, i + 1) |
|
238 |
gfx.drawString(astr.getIterator, x1.toInt, y.toInt) |
|
239 |
} |
|
240 |
else { |
|
241 |
gfx.drawString(str, x1.toInt, y.toInt) |
|
242 |
} |
|
43383 | 243 |
x1 += chunk_font.getStringBounds(str, font_context).getWidth.toFloat |
43382 | 244 |
} |
245 |
} |
|
246 |
} |
|
247 |
w += chunk.width |
|
248 |
chunk_offset += chunk_length |
|
249 |
chunk = chunk.next.asInstanceOf[Chunk] |
|
250 |
} |
|
251 |
w |
|
252 |
} |
|
253 |
||
43381 | 254 |
private val text_painter = new TextAreaExtension |
255 |
{ |
|
256 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
257 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
43382 | 258 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
43381 | 259 |
{ |
260 |
Isabelle.swing_buffer_lock(buffer) { |
|
261 |
val clip = gfx.getClip |
|
262 |
val x0 = text_area.getHorizontalOffset |
|
43382 | 263 |
val fm = text_area.getPainter.getFontMetrics |
264 |
var y0 = y + fm.getHeight - (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
|
265 |
|
43392 | 266 |
val caret_offset = |
267 |
if (text_area.hasFocus) text_area.getCaretPosition |
|
268 |
else -1 |
|
269 |
||
43382 | 270 |
val infos = line_infos(physical_lines.iterator.filter(i => i != -1)) |
43381 | 271 |
for (i <- 0 until physical_lines.length) { |
272 |
if (physical_lines(i) != -1) { |
|
43392 | 273 |
val x1 = |
274 |
infos.get(start(i)) match { |
|
275 |
case None => x0 |
|
276 |
case Some(chunk) => |
|
277 |
gfx.clipRect(x0, y + line_height * i, Integer.MAX_VALUE, line_height) |
|
278 |
val w = paint_chunk_list(gfx, start(i), caret_offset, chunk, x0, y0).toInt |
|
279 |
x0 + w.toInt |
|
280 |
} |
|
281 |
gfx.clipRect(x1, 0, Integer.MAX_VALUE, Integer.MAX_VALUE) |
|
282 |
orig_text_painter.paintValidLine(gfx, |
|
283 |
first_line + i, physical_lines(i), start(i), end(i), y + line_height * i) |
|
284 |
gfx.setClip(clip) |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
285 |
} |
43381 | 286 |
y0 += line_height |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
287 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
288 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
289 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
290 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
291 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
292 |
|
43393
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
293 |
/* 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
|
294 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
295 |
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
|
296 |
{ |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
297 |
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
|
298 |
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
|
299 |
{ |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
300 |
if (before) gfx.clipRect(0, 0, 0, 0) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
301 |
else gfx.setClip(painter_clip) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
302 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
303 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
304 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
305 |
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
|
306 |
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
|
307 |
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
|
308 |
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
|
309 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
310 |
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
|
311 |
{ |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
{ |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
315 |
if (text_area.hasFocus) { |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
316 |
val caret = text_area.getCaretPosition |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
317 |
if (start <= caret && caret == end - 1) { |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
318 |
val painter = text_area.getPainter |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
319 |
val fm = painter.getFontMetrics |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
320 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
321 |
val offset = caret - text_area.getLineStartOffset(physical_line) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
322 |
val x = text_area.offsetToXY(physical_line, offset).x |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
323 |
gfx.setColor(painter.getCaretColor) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
324 |
gfx.drawRect(x, y, char_width() - 1, fm.getHeight - 1) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
325 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
326 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
327 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
328 |
} |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
329 |
|
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
330 |
|
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
331 |
/* activation */ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
332 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
333 |
def activate() |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
334 |
{ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
335 |
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
|
336 |
painter.addExtension(TextAreaPainter.LOWEST_LAYER, set_state) |
43381 | 337 |
painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, background_painter) |
338 |
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
|
339 |
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
|
340 |
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
|
341 |
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
|
342 |
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
|
343 |
painter.addExtension(TextAreaPainter.BLOCK_CARET_LAYER + 2, caret_painter) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
344 |
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
|
345 |
painter.removeExtension(orig_text_painter) |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
346 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
347 |
|
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
348 |
def deactivate() |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
349 |
{ |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
350 |
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
|
351 |
painter.removeExtension(reset_state) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
352 |
painter.removeExtension(caret_painter) |
f4141da52e92
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
wenzelm
parents:
43392
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
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
|
356 |
painter.removeExtension(before_caret_painter1) |
43381 | 357 |
painter.removeExtension(text_painter) |
358 |
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
|
359 |
painter.removeExtension(set_state) |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
360 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
361 |
} |
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
diff
changeset
|
362 |