author | wenzelm |
Sun, 10 Nov 2024 12:29:32 +0100 | |
changeset 81419 | b242c7603e08 |
parent 81418 | de8dbdadda76 |
child 81420 | d25a241502c1 |
permissions | -rw-r--r-- |
81416 | 1 |
/* Title: Pure/GUI/rich_text.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Support for rendering of rich text, based on individual messages (XML.Elem). |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
10 |
import javax.swing.JComponent |
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
11 |
|
81418 | 12 |
import scala.collection.mutable |
13 |
||
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
14 |
|
81416 | 15 |
object Rich_Text { |
16 |
def command( |
|
17 |
body: XML.Body = Nil, |
|
18 |
id: Document_ID.Command = Document_ID.none, |
|
19 |
results: Command.Results = Command.Results.empty |
|
20 |
): Command = { |
|
21 |
val source = XML.content(body) |
|
22 |
val markups = Command.Markups.init(Markup_Tree.from_XML(body)) |
|
23 |
Command.unparsed(source, id = id, results = results, markups = markups) |
|
24 |
} |
|
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
25 |
|
81418 | 26 |
def format( |
27 |
msgs: List[XML.Elem], |
|
28 |
margin: Double, |
|
29 |
metric: Font_Metric, |
|
30 |
results: Command.Results |
|
31 |
) : List[Command] = { |
|
32 |
val result = new mutable.ListBuffer[Command] |
|
33 |
for (msg <- msgs) { |
|
34 |
if (result.nonEmpty) { |
|
35 |
result += command(body = Pretty.Separator, id = Document_ID.make()) |
|
36 |
} |
|
37 |
val body = Pretty.formatted(List(msg), margin = margin, metric = metric) |
|
81419 | 38 |
result += command(body = body, id = Protocol_Message.get_serial(msg)) |
81418 | 39 |
|
40 |
Exn.Interrupt.expose() |
|
41 |
} |
|
42 |
result.toList |
|
43 |
} |
|
44 |
||
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
45 |
def make_margin(metric: Font_Metric, margin: Int, limit: Int = -1): Int = { |
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
46 |
val m = (margin * metric.average).toInt |
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
47 |
(if (limit < 0) m else m min limit) max 20 |
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
48 |
} |
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
49 |
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
50 |
def component_margin(metric: Font_Metric, component: JComponent): Int = |
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
51 |
make_margin(metric, (component.getWidth.toDouble / metric.average_width).toInt) |
81416 | 52 |
} |