| author | wenzelm |
| Thu, 21 Aug 2025 19:55:30 +0200 | |
| changeset 83022 | 5fe1d566794e |
| parent 82893 | d6a14ed060fb |
| permissions | -rw-r--r-- |
|
53783
f5e9d182f645
clarified location of GUI modules (which depend on Swing of JFX);
wenzelm
parents:
53778
diff
changeset
|
1 |
/* Title: Pure/GUI/gui.scala |
| 51619 | 2 |
Author: Makarius |
3 |
||
| 53712 | 4 |
Basic GUI tools (for AWT/Swing). |
| 51619 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
| 73909 | 9 |
import java.util.{Map => JMap}
|
| 82626 | 10 |
import java.awt.{Color, Component, Container, Font, Image, Insets, KeyboardFocusManager, Window,
|
11 |
Point, Rectangle, Dimension, GraphicsEnvironment, MouseInfo, Toolkit} |
|
| 82142 | 12 |
import java.awt.event.{KeyAdapter, KeyEvent}
|
| 72974 | 13 |
import java.awt.font.{FontRenderContext, LineMetrics, TextAttribute, TransformAttribute}
|
| 53785 | 14 |
import java.awt.geom.AffineTransform |
|
83022
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
15 |
import javax.swing.{Icon, ImageIcon, JButton, JLabel, JLayeredPane, JOptionPane,
|
| 82142 | 16 |
RootPaneContainer, JTextField, JComboBox, LookAndFeel, UIManager, SwingUtilities} |
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
17 |
|
|
83022
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
18 |
import scala.swing.{Alignment, CheckBox, ComboBox, ScrollPane, TextArea, ListView, Separator}
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
19 |
import scala.swing.Swing.EmptyIcon |
| 75852 | 20 |
import scala.swing.event.{ButtonClicked, SelectionChanged}
|
| 51619 | 21 |
|
| 82556 | 22 |
import com.formdev.flatlaf |
23 |
import com.formdev.flatlaf.FlatLaf |
|
24 |
||
| 51619 | 25 |
|
| 75393 | 26 |
object GUI {
|
|
73116
b84887a67cc6
clarified default L&F of Isabelle/Scala (not Isabelle/jEdit);
wenzelm
parents:
73111
diff
changeset
|
27 |
/* Swing look-and-feel */ |
|
59201
702e0971d617
added system property isabelle.laf, notably for initial system dialog;
wenzelm
parents:
59183
diff
changeset
|
28 |
|
| 81335 | 29 |
def current_laf(): String = UIManager.getLookAndFeel.getClass.getName() |
| 72975 | 30 |
|
| 82554 | 31 |
def is_macos_laf(): Boolean = |
| 81335 | 32 |
Platform.is_macos && UIManager.getSystemLookAndFeelClassName() == current_laf() |
|
53848
8d7029eb0c31
disable standard behaviour of Mac OS X text field (i.e. select-all after focus gain) in order to make completion work more smoothly;
wenzelm
parents:
53786
diff
changeset
|
33 |
|
| 82556 | 34 |
def is_dark_laf(): Boolean = FlatLaf.isLafDark() |
| 82555 | 35 |
|
|
82893
d6a14ed060fb
proper default colors (amending e840461d5370): e.g. relevant for session_graph.pdf;
wenzelm
parents:
82626
diff
changeset
|
36 |
def default_foreground_color(): Color = if (is_dark_laf()) Color.WHITE else Color.BLACK |
|
d6a14ed060fb
proper default colors (amending e840461d5370): e.g. relevant for session_graph.pdf;
wenzelm
parents:
82626
diff
changeset
|
37 |
def default_background_color(): Color = if (is_dark_laf()) Color.BLACK else Color.WHITE |
| 82626 | 38 |
def default_intermediate_color(): Color = if (is_dark_laf()) Color.LIGHT_GRAY else Color.GRAY |
39 |
||
| 75393 | 40 |
class Look_And_Feel(laf: LookAndFeel) extends Isabelle_System.Service {
|
| 73117 | 41 |
def info: UIManager.LookAndFeelInfo = |
42 |
new UIManager.LookAndFeelInfo(laf.getName, laf.getClass.getName) |
|
| 73111 | 43 |
} |
44 |
||
45 |
lazy val look_and_feels: List[Look_And_Feel] = |
|
46 |
Isabelle_System.make_services(classOf[Look_And_Feel]) |
|
47 |
||
| 75393 | 48 |
def init_lafs(): Unit = {
|
| 73117 | 49 |
val old_lafs = |
50 |
Set( |
|
51 |
"com.sun.java.swing.plaf.motif.MotifLookAndFeel", |
|
52 |
"com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel") |
|
53 |
val lafs = |
|
54 |
UIManager.getInstalledLookAndFeels().toList |
|
55 |
.filterNot(info => old_lafs(info.getClassName)) |
|
56 |
val more_lafs = look_and_feels.map(_.info) |
|
57 |
UIManager.setInstalledLookAndFeels((more_lafs ::: lafs).toArray) |
|
| 81322 | 58 |
|
59 |
// see https://www.formdev.com/flatlaf/customizing |
|
60 |
UIManager.put("Component.arrowType", "triangle")
|
|
| 73117 | 61 |
} |
| 73111 | 62 |
|
| 82568 | 63 |
def init_laf(): Unit = {
|
64 |
init_lafs() |
|
65 |
flatlaf.FlatLightLaf.setup() |
|
66 |
} |
|
67 |
||
| 73111 | 68 |
|
|
73116
b84887a67cc6
clarified default L&F of Isabelle/Scala (not Isabelle/jEdit);
wenzelm
parents:
73111
diff
changeset
|
69 |
/* additional look-and-feels */ |
|
b84887a67cc6
clarified default L&F of Isabelle/Scala (not Isabelle/jEdit);
wenzelm
parents:
73111
diff
changeset
|
70 |
|
|
56752
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
71 |
/* plain focus traversal, notably for text fields */ |
|
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
72 |
|
| 75393 | 73 |
def plain_focus_traversal(component: Component): Unit = {
|
|
56752
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
74 |
val dummy_button = new JButton |
|
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
75 |
def apply(id: Int): Unit = |
|
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
76 |
component.setFocusTraversalKeys(id, dummy_button.getFocusTraversalKeys(id)) |
|
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
77 |
apply(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) |
|
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
78 |
apply(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS) |
|
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
79 |
} |
|
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
80 |
|
|
72b4205f4de9
uniform focus traversal via TAB / Shift-TAB for all fields, in contrast to Java defaults, but in accordance to occasional jEdit practice;
wenzelm
parents:
56622
diff
changeset
|
81 |
|
| 81655 | 82 |
/* style */ |
| 81648 | 83 |
|
| 81655 | 84 |
class Style {
|
85 |
def enclose(body: String): String = body |
|
86 |
def make_text(str: String): String = str |
|
87 |
def make_bold(str: String): String = str |
|
| 81657 | 88 |
def enclose_text(str: String): String = enclose(make_text(str)) |
89 |
def enclose_bold(str: String): String = enclose(make_bold(str)) |
|
| 81659 | 90 |
def spaces(n: Int): String = Symbol.spaces(n) |
| 81655 | 91 |
} |
| 81649 | 92 |
|
| 81655 | 93 |
class Style_HTML extends Style {
|
| 81670 | 94 |
override def enclose(body: String): String = enclose_style("", body)
|
| 81655 | 95 |
override def make_text(str: String): String = HTML.output(str) |
96 |
override def make_bold(str: String): String = "<b>" + make_text(str) + "</b>" |
|
| 81659 | 97 |
override def spaces(n: Int): String = HTML.spaces(n) |
| 81665 | 98 |
|
| 81666 | 99 |
def enclose_style(style: String, body: String): String = |
| 81670 | 100 |
if (style.isEmpty) {
|
101 |
Library.string_builder(body.length + 13) { s =>
|
|
102 |
s ++= "<html>" |
|
103 |
s ++= body |
|
104 |
s ++= "</html>" |
|
105 |
} |
|
106 |
} |
|
| 81666 | 107 |
else {
|
108 |
Library.string_builder(style.length + body.length + 35) { s =>
|
|
109 |
s ++= "<html><span style=\"" |
|
110 |
s ++= style |
|
111 |
s ++= "\">" |
|
112 |
s ++= body |
|
113 |
s ++= "</span></html>" |
|
114 |
} |
|
115 |
} |
|
116 |
||
|
81674
70d2f72098df
proper bullet symbols for GUI text -- in contrast to Isabelle \<bullet> 0x002219;
wenzelm
parents:
81670
diff
changeset
|
117 |
def regular_bullet: String = "\u2022" |
|
70d2f72098df
proper bullet symbols for GUI text -- in contrast to Isabelle \<bullet> 0x002219;
wenzelm
parents:
81670
diff
changeset
|
118 |
def triangular_bullet: String = "\u2023" |
| 81655 | 119 |
} |
| 81654 | 120 |
|
| 81655 | 121 |
abstract class Style_Symbol extends Style {
|
122 |
def bold: String |
|
123 |
override def make_bold(str: String): String = |
|
124 |
Symbol.iterator(str) |
|
125 |
.flatMap(s => if (Symbol.is_controllable(s)) List(bold, s) else List(s)) |
|
126 |
.mkString |
|
127 |
} |
|
128 |
||
129 |
object Style_Plain extends Style { override def toString: String = "plain" }
|
|
130 |
||
| 81665 | 131 |
object Style_HTML extends Style_HTML { override def toString: String = "html" }
|
| 81655 | 132 |
|
133 |
object Style_Symbol_Encoded extends Style_Symbol {
|
|
134 |
override def toString: String = "symbol_encoded" |
|
135 |
override def bold: String = Symbol.bold |
|
136 |
} |
|
137 |
||
138 |
object Style_Symbol_Decoded extends Style_Symbol {
|
|
139 |
override def toString: String = "symbol_decoded" |
|
140 |
override def bold: String = Symbol.bold_decoded |
|
141 |
} |
|
142 |
||
143 |
||
144 |
/* named items */ |
|
| 81649 | 145 |
|
146 |
sealed case class Name( |
|
147 |
name: String, |
|
148 |
kind: String = "", |
|
149 |
prefix: String = "", |
|
| 81655 | 150 |
style: Style = Style_Plain |
| 81649 | 151 |
) {
|
| 81661 | 152 |
def set_style(new_style: Style): Name = copy(style = new_style) |
153 |
||
| 81648 | 154 |
override def toString: String = {
|
155 |
val a = kind.nonEmpty |
|
156 |
val b = name.nonEmpty |
|
| 81655 | 157 |
style.make_text(prefix) + |
| 81654 | 158 |
if_proper(a || b, |
|
82183
a519b9d1e1c1
refrain from fancy GUI style (in contrast to 904b2144e9c5), which looks bad in Isabelle/VSCode;
wenzelm
parents:
82142
diff
changeset
|
159 |
if_proper(prefix, ": ") + if_proper(kind, style.make_text(kind)) + |
| 81655 | 160 |
if_proper(a && b, " ") + if_proper(b, style.make_text(quote(name)))) |
| 81648 | 161 |
} |
162 |
} |
|
163 |
||
164 |
||
| 51619 | 165 |
/* simple dialogs */ |
166 |
||
| 75393 | 167 |
def scrollable_text( |
168 |
raw_txt: String, |
|
169 |
width: Int = 60, |
|
170 |
height: Int = 20, |
|
171 |
editable: Boolean = false |
|
172 |
) : ScrollPane = {
|
|
| 80817 | 173 |
val txt = Protocol_Message.clean_output(raw_txt) |
| 51619 | 174 |
val text = new TextArea(txt) |
175 |
if (width > 0) text.columns = width |
|
| 53714 | 176 |
if (height > 0 && split_lines(txt).length > height) text.rows = height |
| 51619 | 177 |
text.editable = editable |
178 |
new ScrollPane(text) |
|
179 |
} |
|
180 |
||
| 75393 | 181 |
private def simple_dialog( |
182 |
kind: Int, |
|
183 |
default_title: String, |
|
184 |
parent: Component, |
|
185 |
title: String, |
|
186 |
message: Iterable[Any] |
|
187 |
): Unit = {
|
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
188 |
GUI_Thread.now {
|
| 65370 | 189 |
val java_message = |
190 |
message.iterator.map({ case x: scala.swing.Component => x.peer case x => x }).
|
|
191 |
toArray.asInstanceOf[Array[AnyRef]] |
|
192 |
JOptionPane.showMessageDialog(parent, java_message, |
|
| 51619 | 193 |
if (title == null) default_title else title, kind) |
194 |
} |
|
195 |
} |
|
196 |
||
| 57639 | 197 |
def dialog(parent: Component, title: String, message: Any*): Unit = |
| 51619 | 198 |
simple_dialog(JOptionPane.PLAIN_MESSAGE, null, parent, title, message) |
199 |
||
| 57639 | 200 |
def warning_dialog(parent: Component, title: String, message: Any*): Unit = |
| 51619 | 201 |
simple_dialog(JOptionPane.WARNING_MESSAGE, "Warning", parent, title, message) |
202 |
||
| 57639 | 203 |
def error_dialog(parent: Component, title: String, message: Any*): Unit = |
| 51619 | 204 |
simple_dialog(JOptionPane.ERROR_MESSAGE, "Error", parent, title, message) |
205 |
||
206 |
def confirm_dialog(parent: Component, title: String, option_type: Int, message: Any*): Int = |
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
207 |
GUI_Thread.now {
|
| 51619 | 208 |
val java_message = message map { case x: scala.swing.Component => x.peer case x => x }
|
209 |
JOptionPane.showConfirmDialog(parent, |
|
210 |
java_message.toArray.asInstanceOf[Array[AnyRef]], title, |
|
211 |
option_type, JOptionPane.QUESTION_MESSAGE) |
|
212 |
} |
|
213 |
||
214 |
||
| 75852 | 215 |
/* basic GUI components */ |
216 |
||
| 75853 | 217 |
class Button(label: String) extends scala.swing.Button(label) {
|
218 |
def clicked(): Unit = {}
|
|
219 |
||
220 |
reactions += { case ButtonClicked(_) => clicked() }
|
|
221 |
} |
|
222 |
||
| 75854 | 223 |
class Check(label: String, init: Boolean = false) extends CheckBox(label) {
|
| 75852 | 224 |
def clicked(state: Boolean): Unit = {}
|
225 |
def clicked(): Unit = {}
|
|
226 |
||
227 |
selected = init |
|
228 |
reactions += { case ButtonClicked(_) => clicked(selected); clicked() }
|
|
229 |
} |
|
| 75839 | 230 |
|
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
231 |
|
|
83022
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
232 |
/* label for other component */ |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
233 |
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
234 |
class Label( |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
235 |
label_text: String, |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
236 |
label_icon: Icon, |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
237 |
label_align: Alignment.Value, |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
238 |
label_for: java.awt.Component |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
239 |
) extends scala.swing.Label(label_text, label_icon, label_align) {
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
240 |
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
241 |
override lazy val peer: JLabel = |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
242 |
new JLabel(label_text, if (label_icon == EmptyIcon) null else label_icon, label_align.id) |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
243 |
with SuperMixin { labelFor = label_for }
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
244 |
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
245 |
override def this(label_text: String, label_icon: Icon, label_align: Alignment.Value) = |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
246 |
this(label_text, label_icon, label_align, null) |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
247 |
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
248 |
def this(label_text: String, label_for: java.awt.Component) = |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
249 |
this(label_text, EmptyIcon, Alignment.Center, label_for) |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
250 |
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
251 |
def this(label_text: String, label_for: scala.swing.Component) = |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
252 |
this(label_text, EmptyIcon, Alignment.Center, label_for.peer) |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
253 |
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
254 |
def this(label_text: String) = |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
255 |
this(label_text, EmptyIcon, Alignment.Center) |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
256 |
} |
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
257 |
|
|
5fe1d566794e
support for javax.swing.JLabel.labelFor following the Java Swing Tutorial on Assistive Technologies, although it has no immediate impact on NVDA;
wenzelm
parents:
82893
diff
changeset
|
258 |
|
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
259 |
/* list selector */ |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
260 |
|
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
261 |
object Selector {
|
| 76505 | 262 |
sealed abstract class Entry[A] { def get_value: Option[A] = Value.unapply(this) }
|
|
76504
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
263 |
object Value {
|
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
264 |
def unapply[A](entry: Entry[A]): Option[A] = |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
265 |
entry match {
|
| 76502 | 266 |
case item: Item[_] => Some(item.value) |
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
267 |
case _ => None |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
268 |
} |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
269 |
} |
| 76505 | 270 |
def item[A](value: A): Entry[A] = Item(value, "", 0) |
271 |
def item_description[A](value: A, description: String): Entry[A] = Item(value, description, 0) |
|
272 |
||
|
76504
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
273 |
private case class Item[A](value: A, description: String, batch: Int) extends Entry[A] {
|
| 76502 | 274 |
override def toString: String = proper_string(description) getOrElse value.toString |
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
275 |
} |
|
76504
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
276 |
private case class Separator[A](batch: Int) extends Entry[A] {
|
|
76503
5944f9e70d98
clarified signature: only support nameless separator;
wenzelm
parents:
76502
diff
changeset
|
277 |
override def toString: String = "---" |
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
278 |
} |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
279 |
|
| 76505 | 280 |
private def make_entries[A](batches: List[List[Entry[A]]]): List[Entry[A]] = {
|
| 76789 | 281 |
val item_batches = batches.map(_.flatMap(Library.as_subclass(classOf[Item[A]]))) |
|
76504
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
282 |
val sep_entries: List[Entry[A]] = |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
283 |
item_batches.filter(_.nonEmpty).zipWithIndex.flatMap({ case (batch, i) =>
|
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
284 |
Separator[A](i) :: batch.map(_.copy(batch = i)) |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
285 |
}) |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
286 |
sep_entries.tail |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
287 |
} |
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
288 |
} |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
289 |
|
|
76504
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
290 |
class Selector[A](batches: List[Selector.Entry[A]]*) |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
291 |
extends ComboBox[Selector.Entry[A]](Selector.make_entries(batches.toList)) {
|
| 75839 | 292 |
def changed(): Unit = {}
|
293 |
||
|
76504
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
294 |
lazy val entries: List[Selector.Entry[A]] = Selector.make_entries(batches.toList) |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
295 |
|
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
296 |
def find_value(pred: A => Boolean): Option[Selector.Entry[A]] = |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
297 |
entries.find({ case item: Selector.Item[A] => pred(item.value) case _ => false })
|
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
298 |
|
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
299 |
def selection_value: Option[A] = selection.item.get_value |
|
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
300 |
|
|
76494
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
301 |
override lazy val peer: JComboBox[Selector.Entry[A]] = |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
302 |
new JComboBox[Selector.Entry[A]](ComboBox.newConstantModel(entries)) with SuperMixin {
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
303 |
private var key_released = false |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
304 |
private var sep_selected = false |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
305 |
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
306 |
addKeyListener(new KeyAdapter {
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
307 |
override def keyPressed(e: KeyEvent): Unit = { key_released = false }
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
308 |
override def keyReleased(e: KeyEvent): Unit = { key_released = true }
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
309 |
}) |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
310 |
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
311 |
override def setSelectedIndex(i: Int): Unit = {
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
312 |
getItemAt(i) match {
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
313 |
case _: Selector.Separator[_] => |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
314 |
if (key_released) { sep_selected = true }
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
315 |
else {
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
316 |
val k = getSelectedIndex() |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
317 |
val j = if (i > k) i + 1 else i - 1 |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
318 |
if (0 <= j && j < dataModel.getSize()) super.setSelectedIndex(j) |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
319 |
} |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
320 |
case _ => super.setSelectedIndex(i) |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
321 |
} |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
322 |
} |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
323 |
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
324 |
override def setPopupVisible(visible: Boolean): Unit = {
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
325 |
if (sep_selected) { sep_selected = false}
|
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
326 |
else super.setPopupVisible(visible) |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
327 |
} |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
328 |
} |
|
9686049ce988
more robust selection: avoid duplicates via "batch" number;
wenzelm
parents:
76492
diff
changeset
|
329 |
|
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
330 |
private val default_renderer = renderer |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
331 |
private val render_separator = new Separator |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
332 |
renderer = |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
333 |
(list: ListView[_ <: Selector.Entry[A]], selected: Boolean, focus: Boolean, entry: Selector.Entry[A], i: Int) => {
|
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
334 |
entry match {
|
|
76503
5944f9e70d98
clarified signature: only support nameless separator;
wenzelm
parents:
76502
diff
changeset
|
335 |
case _: Selector.Separator[_] => render_separator |
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
336 |
case _ => default_renderer.componentFor(list, selected, focus, entry, i) |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
337 |
} |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
338 |
} |
|
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
339 |
|
| 75839 | 340 |
listenTo(selection) |
341 |
reactions += { case SelectionChanged(_) => changed() }
|
|
342 |
} |
|
| 51619 | 343 |
|
| 75852 | 344 |
|
345 |
/* zoom factor */ |
|
346 |
||
| 81382 | 347 |
private val Percent = "([0-9]+)%?".r |
| 57044 | 348 |
|
| 75839 | 349 |
class Zoom extends Selector[String]( |
| 75393 | 350 |
List("50%", "70%", "85%", "100%", "125%", "150%", "175%", "200%", "300%", "400%")
|
|
76504
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
351 |
.map(GUI.Selector.item) |
| 75393 | 352 |
) {
|
| 81382 | 353 |
def percent: Int = parse(selection.item.toString) |
354 |
def scale: Double = 0.01 * percent |
|
| 57044 | 355 |
|
356 |
private def parse(text: String): Int = |
|
| 51619 | 357 |
text match {
|
| 81382 | 358 |
case Percent(s) => |
| 51619 | 359 |
val i = Integer.parseInt(s) |
| 56874 | 360 |
if (10 <= i && i < 1000) i else 100 |
| 51619 | 361 |
case _ => 100 |
362 |
} |
|
363 |
||
| 57044 | 364 |
private def print(i: Int): String = i.toString + "%" |
| 51619 | 365 |
|
| 75393 | 366 |
def set_item(i: Int): Unit = {
|
| 51619 | 367 |
peer.getEditor match {
|
368 |
case null => |
|
369 |
case editor => editor.setItem(print(i)) |
|
370 |
} |
|
371 |
} |
|
372 |
||
|
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75854
diff
changeset
|
373 |
makeEditable()(c => |
|
76504
15b058bb2416
clarified signature: ensure that entries are well-formed --- no consecutive separators, no separators at start/end;
wenzelm
parents:
76503
diff
changeset
|
374 |
new ComboBox.BuiltInEditor(c)(text => Selector.item(print(parse(text))), _.toString)) |
| 56874 | 375 |
peer.getEditor.getEditorComponent match {
|
| 56888 | 376 |
case text: JTextField => text.setColumns(4) |
| 56874 | 377 |
case _ => |
378 |
} |
|
379 |
||
| 57044 | 380 |
selection.index = 3 |
| 51619 | 381 |
} |
382 |
||
383 |
||
| 53786 | 384 |
/* tooltip with multi-line support */ |
385 |
||
|
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
54965
diff
changeset
|
386 |
def tooltip_lines(text: String): String = |
|
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
54965
diff
changeset
|
387 |
if (text == null || text == "") null |
| 81657 | 388 |
else Style_HTML.enclose_text(text) |
| 53786 | 389 |
|
390 |
||
| 51619 | 391 |
/* icon */ |
392 |
||
393 |
def isabelle_icon(): ImageIcon = |
|
|
54676
6b2ca4850b71
uniform use of transparent icons, as for main "apps";
wenzelm
parents:
54659
diff
changeset
|
394 |
new ImageIcon(getClass.getClassLoader.getResource("isabelle/isabelle_transparent-32.gif"))
|
| 51619 | 395 |
|
| 54709 | 396 |
def isabelle_icons(): List[ImageIcon] = |
397 |
for (icon <- List("isabelle/isabelle_transparent-32.gif", "isabelle/isabelle_transparent.gif"))
|
|
398 |
yield new ImageIcon(getClass.getClassLoader.getResource(icon)) |
|
399 |
||
| 51619 | 400 |
def isabelle_image(): Image = isabelle_icon().getImage |
| 53712 | 401 |
|
402 |
||
| 72974 | 403 |
/* location within multi-screen environment */ |
404 |
||
| 75393 | 405 |
final case class Screen_Location(point: Point, bounds: Rectangle) {
|
406 |
def relative(parent: Component, size: Dimension): Point = {
|
|
| 72974 | 407 |
val w = size.width |
408 |
val h = size.height |
|
409 |
||
410 |
val x0 = parent.getLocationOnScreen.x |
|
411 |
val y0 = parent.getLocationOnScreen.y |
|
412 |
val x1 = x0 + parent.getWidth - w |
|
413 |
val y1 = y0 + parent.getHeight - h |
|
414 |
val x2 = point.x min (bounds.x + bounds.width - w) |
|
415 |
val y2 = point.y min (bounds.y + bounds.height - h) |
|
416 |
||
417 |
val location = new Point((x2 min x1) max x0, (y2 min y1) max y0) |
|
418 |
SwingUtilities.convertPointFromScreen(location, parent) |
|
419 |
location |
|
420 |
} |
|
421 |
} |
|
422 |
||
| 75393 | 423 |
def screen_location(component: Component, point: Point): Screen_Location = {
|
| 72974 | 424 |
val screen_point = new Point(point.x, point.y) |
425 |
if (component != null) SwingUtilities.convertPointToScreen(screen_point, component) |
|
426 |
||
427 |
val ge = GraphicsEnvironment.getLocalGraphicsEnvironment |
|
428 |
val screen_bounds = |
|
429 |
(for {
|
|
430 |
device <- ge.getScreenDevices.iterator |
|
431 |
config <- device.getConfigurations.iterator |
|
432 |
bounds = config.getBounds |
|
433 |
} yield bounds).find(_.contains(screen_point)) getOrElse ge.getMaximumWindowBounds |
|
434 |
||
435 |
Screen_Location(screen_point, screen_bounds) |
|
436 |
} |
|
437 |
||
438 |
def mouse_location(): Screen_Location = |
|
439 |
screen_location(null, MouseInfo.getPointerInfo.getLocation) |
|
440 |
||
441 |
||
| 73037 | 442 |
/* screen size */ |
443 |
||
| 75393 | 444 |
sealed case class Screen_Size(bounds: Rectangle, insets: Insets) {
|
|
73038
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
445 |
def full_screen_bounds: Rectangle = |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
446 |
if (Platform.is_linux) {
|
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
447 |
// avoid menu bar and docking areas |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
448 |
new Rectangle( |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
449 |
bounds.x + insets.left, |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
450 |
bounds.y + insets.top, |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
451 |
bounds.width - insets.left - insets.right, |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
452 |
bounds.height - insets.top - insets.bottom) |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
453 |
} |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
454 |
else if (Platform.is_macos) {
|
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
455 |
// avoid menu bar, but ignore docking areas |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
456 |
new Rectangle( |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
457 |
bounds.x, |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
458 |
bounds.y + insets.top, |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
459 |
bounds.width, |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
460 |
bounds.height - insets.top) |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
461 |
} |
|
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
462 |
else bounds |
| 73037 | 463 |
} |
464 |
||
| 75393 | 465 |
def screen_size(component: Component): Screen_Size = {
|
| 73037 | 466 |
val config = component.getGraphicsConfiguration |
467 |
val bounds = config.getBounds |
|
468 |
val insets = Toolkit.getDefaultToolkit.getScreenInsets(config) |
|
469 |
Screen_Size(bounds, insets) |
|
470 |
} |
|
471 |
||
472 |
||
| 53712 | 473 |
/* component hierachy */ |
474 |
||
475 |
def get_parent(component: Component): Option[Container] = |
|
476 |
component.getParent match {
|
|
477 |
case null => None |
|
478 |
case parent => Some(parent) |
|
479 |
} |
|
480 |
||
481 |
def ancestors(component: Component): Iterator[Container] = new Iterator[Container] {
|
|
482 |
private var next_elem = get_parent(component) |
|
| 73337 | 483 |
def hasNext: Boolean = next_elem.isDefined |
| 53712 | 484 |
def next(): Container = |
485 |
next_elem match {
|
|
486 |
case Some(parent) => |
|
487 |
next_elem = get_parent(parent) |
|
488 |
parent |
|
489 |
case None => Iterator.empty.next() |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
def parent_window(component: Component): Option[Window] = |
|
| 80553 | 494 |
ancestors(component).collectFirst({ case c: Window => c })
|
|
53778
29eaacff4078
proper layered pane at root of parent component, not global view (e.g. relevant for tooltips for detached info windows);
wenzelm
parents:
53714
diff
changeset
|
495 |
|
|
29eaacff4078
proper layered pane at root of parent component, not global view (e.g. relevant for tooltips for detached info windows);
wenzelm
parents:
53714
diff
changeset
|
496 |
def layered_pane(component: Component): Option[JLayeredPane] = |
|
29eaacff4078
proper layered pane at root of parent component, not global view (e.g. relevant for tooltips for detached info windows);
wenzelm
parents:
53714
diff
changeset
|
497 |
parent_window(component) match {
|
| 80553 | 498 |
case Some(c: RootPaneContainer) => Some(c.getLayeredPane) |
|
53778
29eaacff4078
proper layered pane at root of parent component, not global view (e.g. relevant for tooltips for detached info windows);
wenzelm
parents:
53714
diff
changeset
|
499 |
case _ => None |
|
29eaacff4078
proper layered pane at root of parent component, not global view (e.g. relevant for tooltips for detached info windows);
wenzelm
parents:
53714
diff
changeset
|
500 |
} |
| 53785 | 501 |
|
| 75393 | 502 |
def traverse_components(component: Component, apply: Component => Unit): Unit = {
|
503 |
def traverse(comp: Component): Unit = {
|
|
| 63874 | 504 |
apply(comp) |
505 |
comp match {
|
|
506 |
case cont: Container => |
|
507 |
for (i <- 0 until cont.getComponentCount) |
|
508 |
traverse(cont.getComponent(i)) |
|
509 |
case _ => |
|
510 |
} |
|
511 |
} |
|
512 |
traverse(component) |
|
513 |
} |
|
514 |
||
| 53785 | 515 |
|
516 |
/* font operations */ |
|
517 |
||
|
61742
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
518 |
def copy_font(font: Font): Font = |
|
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
519 |
if (font == null) null |
|
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
520 |
else new Font(font.getFamily, font.getStyle, font.getSize) |
|
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
521 |
|
| 59230 | 522 |
def line_metrics(font: Font): LineMetrics = |
| 53785 | 523 |
font.getLineMetrics("", new FontRenderContext(null, false, false))
|
524 |
||
| 69376 | 525 |
def transform_font(font: Font, transform: AffineTransform): Font = |
| 73909 | 526 |
font.deriveFont(JMap.of(TextAttribute.TRANSFORM, new TransformAttribute(transform))) |
| 69376 | 527 |
|
528 |
def font(family: String = Isabelle_Fonts.sans, size: Int = 1, bold: Boolean = false): Font = |
|
529 |
new Font(family, if (bold) Font.BOLD else Font.PLAIN, size) |
|
530 |
||
| 69377 | 531 |
def label_font(): Font = (new JLabel).getFont |
532 |
||
| 69376 | 533 |
|
534 |
/* Isabelle fonts */ |
|
535 |
||
| 75393 | 536 |
def imitate_font( |
537 |
font: Font, |
|
|
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
69357
diff
changeset
|
538 |
family: String = Isabelle_Fonts.sans, |
| 75393 | 539 |
scale: Double = 1.0 |
540 |
): Font = {
|
|
| 53785 | 541 |
val font1 = new Font(family, font.getStyle, font.getSize) |
|
59286
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
wenzelm
parents:
59230
diff
changeset
|
542 |
val rel_size = line_metrics(font).getHeight.toDouble / line_metrics(font1).getHeight |
|
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
wenzelm
parents:
59230
diff
changeset
|
543 |
new Font(family, font.getStyle, (scale * rel_size * font.getSize).toInt) |
|
59183
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59080
diff
changeset
|
544 |
} |
|
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59080
diff
changeset
|
545 |
|
| 75393 | 546 |
def imitate_font_css( |
547 |
font: Font, |
|
|
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
69357
diff
changeset
|
548 |
family: String = Isabelle_Fonts.sans, |
| 75393 | 549 |
scale: Double = 1.0 |
550 |
): String = {
|
|
|
59183
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59080
diff
changeset
|
551 |
val font1 = new Font(family, font.getStyle, font.getSize) |
| 59230 | 552 |
val rel_size = line_metrics(font).getHeight.toDouble / line_metrics(font1).getHeight |
|
59183
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59080
diff
changeset
|
553 |
"font-family: " + family + "; font-size: " + (scale * rel_size * 100).toInt + "%;" |
| 53785 | 554 |
} |
| 69377 | 555 |
|
| 75393 | 556 |
def use_isabelle_fonts(): Unit = {
|
| 69377 | 557 |
val default_font = label_font() |
558 |
val ui = UIManager.getDefaults |
|
| 75393 | 559 |
for (prop <- |
560 |
List( |
|
561 |
"ToggleButton.font", |
|
562 |
"CheckBoxMenuItem.font", |
|
563 |
"Label.font", |
|
564 |
"Menu.font", |
|
565 |
"MenuItem.font", |
|
566 |
"PopupMenu.font", |
|
567 |
"Table.font", |
|
568 |
"TableHeader.font", |
|
569 |
"TextArea.font", |
|
570 |
"TextField.font", |
|
571 |
"TextPane.font", |
|
572 |
"ToolTip.font", |
|
573 |
"Tree.font")) {
|
|
| 69377 | 574 |
val font = ui.get(prop) match { case font: Font => font case _ => default_font }
|
575 |
ui.put(prop, GUI.imitate_font(font)) |
|
576 |
} |
|
577 |
} |
|
| 51619 | 578 |
} |
| 73111 | 579 |
|
| 82556 | 580 |
class FlatLightLaf extends GUI.Look_And_Feel(new flatlaf.FlatLightLaf) |
581 |
class FlatDarkLaf extends GUI.Look_And_Feel(new flatlaf.FlatDarkLaf) |
|
| 82557 | 582 |
class FlatMacLightLaf extends GUI.Look_And_Feel(new flatlaf.themes.FlatMacLightLaf) |
583 |
class FlatMacDarkLaf extends GUI.Look_And_Feel(new flatlaf.themes.FlatMacDarkLaf) |