author | wenzelm |
Sat, 13 Aug 2022 22:41:45 +0200 | |
changeset 75852 | fcc25bb49def |
parent 75839 | 29441f2bfe81 |
child 75853 | f981111768ec |
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} |
73037 | 10 |
import java.awt.{Component, Container, Font, Image, Insets, KeyboardFocusManager, Window, Point, |
73117 | 11 |
Rectangle, Dimension, GraphicsEnvironment, MouseInfo, Toolkit} |
72974 | 12 |
import java.awt.font.{FontRenderContext, LineMetrics, TextAttribute, TransformAttribute} |
53785 | 13 |
import java.awt.geom.AffineTransform |
72974 | 14 |
import javax.swing.{ImageIcon, JButton, JDialog, JFrame, JLabel, JLayeredPane, JOptionPane, |
15 |
JTextField, JWindow, LookAndFeel, UIManager, SwingUtilities} |
|
75852 | 16 |
import scala.swing.{CheckBox, ComboBox, ScrollPane, TextArea} |
17 |
import scala.swing.event.{ButtonClicked, SelectionChanged} |
|
51619 | 18 |
|
19 |
||
75393 | 20 |
object GUI { |
73116
b84887a67cc6
clarified default L&F of Isabelle/Scala (not Isabelle/jEdit);
wenzelm
parents:
73111
diff
changeset
|
21 |
/* Swing look-and-feel */ |
59201
702e0971d617
added system property isabelle.laf, notably for initial system dialog;
wenzelm
parents:
59183
diff
changeset
|
22 |
|
73878 | 23 |
def init_laf(): Unit = com.formdev.flatlaf.FlatLightLaf.setup() |
51619 | 24 |
|
73367 | 25 |
def current_laf: String = UIManager.getLookAndFeel.getClass.getName() |
72975 | 26 |
|
73367 | 27 |
def is_macos_laf: Boolean = |
28 |
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
|
29 |
|
75393 | 30 |
class Look_And_Feel(laf: LookAndFeel) extends Isabelle_System.Service { |
73117 | 31 |
def info: UIManager.LookAndFeelInfo = |
32 |
new UIManager.LookAndFeelInfo(laf.getName, laf.getClass.getName) |
|
73111 | 33 |
} |
34 |
||
35 |
lazy val look_and_feels: List[Look_And_Feel] = |
|
36 |
Isabelle_System.make_services(classOf[Look_And_Feel]) |
|
37 |
||
75393 | 38 |
def init_lafs(): Unit = { |
73117 | 39 |
val old_lafs = |
40 |
Set( |
|
41 |
"com.sun.java.swing.plaf.motif.MotifLookAndFeel", |
|
42 |
"com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel") |
|
43 |
val lafs = |
|
44 |
UIManager.getInstalledLookAndFeels().toList |
|
45 |
.filterNot(info => old_lafs(info.getClassName)) |
|
46 |
val more_lafs = look_and_feels.map(_.info) |
|
47 |
UIManager.setInstalledLookAndFeels((more_lafs ::: lafs).toArray) |
|
48 |
} |
|
73111 | 49 |
|
50 |
||
73116
b84887a67cc6
clarified default L&F of Isabelle/Scala (not Isabelle/jEdit);
wenzelm
parents:
73111
diff
changeset
|
51 |
/* additional look-and-feels */ |
b84887a67cc6
clarified default L&F of Isabelle/Scala (not Isabelle/jEdit);
wenzelm
parents:
73111
diff
changeset
|
52 |
|
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
|
53 |
/* 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
|
54 |
|
75393 | 55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
} |
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
|
62 |
|
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
|
63 |
|
51619 | 64 |
/* simple dialogs */ |
65 |
||
75393 | 66 |
def scrollable_text( |
67 |
raw_txt: String, |
|
68 |
width: Int = 60, |
|
69 |
height: Int = 20, |
|
70 |
editable: Boolean = false |
|
71 |
) : ScrollPane = { |
|
59671
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
wenzelm
parents:
59286
diff
changeset
|
72 |
val txt = Output.clean_yxml(raw_txt) |
51619 | 73 |
val text = new TextArea(txt) |
74 |
if (width > 0) text.columns = width |
|
53714 | 75 |
if (height > 0 && split_lines(txt).length > height) text.rows = height |
51619 | 76 |
text.editable = editable |
77 |
new ScrollPane(text) |
|
78 |
} |
|
79 |
||
75393 | 80 |
private def simple_dialog( |
81 |
kind: Int, |
|
82 |
default_title: String, |
|
83 |
parent: Component, |
|
84 |
title: String, |
|
85 |
message: Iterable[Any] |
|
86 |
): Unit = { |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
87 |
GUI_Thread.now { |
65370 | 88 |
val java_message = |
89 |
message.iterator.map({ case x: scala.swing.Component => x.peer case x => x }). |
|
90 |
toArray.asInstanceOf[Array[AnyRef]] |
|
91 |
JOptionPane.showMessageDialog(parent, java_message, |
|
51619 | 92 |
if (title == null) default_title else title, kind) |
93 |
} |
|
94 |
} |
|
95 |
||
57639 | 96 |
def dialog(parent: Component, title: String, message: Any*): Unit = |
51619 | 97 |
simple_dialog(JOptionPane.PLAIN_MESSAGE, null, parent, title, message) |
98 |
||
57639 | 99 |
def warning_dialog(parent: Component, title: String, message: Any*): Unit = |
51619 | 100 |
simple_dialog(JOptionPane.WARNING_MESSAGE, "Warning", parent, title, message) |
101 |
||
57639 | 102 |
def error_dialog(parent: Component, title: String, message: Any*): Unit = |
51619 | 103 |
simple_dialog(JOptionPane.ERROR_MESSAGE, "Error", parent, title, message) |
104 |
||
105 |
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
|
106 |
GUI_Thread.now { |
51619 | 107 |
val java_message = message map { case x: scala.swing.Component => x.peer case x => x } |
108 |
JOptionPane.showConfirmDialog(parent, |
|
109 |
java_message.toArray.asInstanceOf[Array[AnyRef]], title, |
|
110 |
option_type, JOptionPane.QUESTION_MESSAGE) |
|
111 |
} |
|
112 |
||
113 |
||
75852 | 114 |
/* basic GUI components */ |
115 |
||
116 |
class Bool(label: String, init: Boolean = false) extends CheckBox(label) { |
|
117 |
def clicked(state: Boolean): Unit = {} |
|
118 |
def clicked(): Unit = {} |
|
119 |
||
120 |
selected = init |
|
121 |
reactions += { case ButtonClicked(_) => clicked(selected); clicked() } |
|
122 |
} |
|
75839 | 123 |
|
124 |
class Selector[A](val entries: List[A]) extends ComboBox[A](entries) { |
|
125 |
def changed(): Unit = {} |
|
126 |
||
127 |
listenTo(selection) |
|
128 |
reactions += { case SelectionChanged(_) => changed() } |
|
129 |
} |
|
51619 | 130 |
|
75852 | 131 |
|
132 |
/* zoom factor */ |
|
133 |
||
57044 | 134 |
private val Zoom_Factor = "([0-9]+)%?".r |
135 |
||
75839 | 136 |
class Zoom extends Selector[String]( |
75393 | 137 |
List("50%", "70%", "85%", "100%", "125%", "150%", "175%", "200%", "300%", "400%") |
138 |
) { |
|
57044 | 139 |
def factor: Int = parse(selection.item) |
140 |
||
141 |
private def parse(text: String): Int = |
|
51619 | 142 |
text match { |
57044 | 143 |
case Zoom_Factor(s) => |
51619 | 144 |
val i = Integer.parseInt(s) |
56874 | 145 |
if (10 <= i && i < 1000) i else 100 |
51619 | 146 |
case _ => 100 |
147 |
} |
|
148 |
||
57044 | 149 |
private def print(i: Int): String = i.toString + "%" |
51619 | 150 |
|
75393 | 151 |
def set_item(i: Int): Unit = { |
51619 | 152 |
peer.getEditor match { |
153 |
case null => |
|
154 |
case editor => editor.setItem(print(i)) |
|
155 |
} |
|
156 |
} |
|
157 |
||
158 |
makeEditable()(c => new ComboBox.BuiltInEditor(c)(text => print(parse(text)), x => x)) |
|
56874 | 159 |
peer.getEditor.getEditorComponent match { |
56888 | 160 |
case text: JTextField => text.setColumns(4) |
56874 | 161 |
case _ => |
162 |
} |
|
163 |
||
57044 | 164 |
selection.index = 3 |
51619 | 165 |
} |
166 |
||
167 |
||
53786 | 168 |
/* tooltip with multi-line support */ |
169 |
||
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
54965
diff
changeset
|
170 |
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
|
171 |
if (text == null || text == "") null |
62113 | 172 |
else "<html>" + HTML.output(text) + "</html>" |
53786 | 173 |
|
174 |
||
51619 | 175 |
/* icon */ |
176 |
||
177 |
def isabelle_icon(): ImageIcon = |
|
54676
6b2ca4850b71
uniform use of transparent icons, as for main "apps";
wenzelm
parents:
54659
diff
changeset
|
178 |
new ImageIcon(getClass.getClassLoader.getResource("isabelle/isabelle_transparent-32.gif")) |
51619 | 179 |
|
54709 | 180 |
def isabelle_icons(): List[ImageIcon] = |
181 |
for (icon <- List("isabelle/isabelle_transparent-32.gif", "isabelle/isabelle_transparent.gif")) |
|
182 |
yield new ImageIcon(getClass.getClassLoader.getResource(icon)) |
|
183 |
||
51619 | 184 |
def isabelle_image(): Image = isabelle_icon().getImage |
53712 | 185 |
|
186 |
||
72974 | 187 |
/* location within multi-screen environment */ |
188 |
||
75393 | 189 |
final case class Screen_Location(point: Point, bounds: Rectangle) { |
190 |
def relative(parent: Component, size: Dimension): Point = { |
|
72974 | 191 |
val w = size.width |
192 |
val h = size.height |
|
193 |
||
194 |
val x0 = parent.getLocationOnScreen.x |
|
195 |
val y0 = parent.getLocationOnScreen.y |
|
196 |
val x1 = x0 + parent.getWidth - w |
|
197 |
val y1 = y0 + parent.getHeight - h |
|
198 |
val x2 = point.x min (bounds.x + bounds.width - w) |
|
199 |
val y2 = point.y min (bounds.y + bounds.height - h) |
|
200 |
||
201 |
val location = new Point((x2 min x1) max x0, (y2 min y1) max y0) |
|
202 |
SwingUtilities.convertPointFromScreen(location, parent) |
|
203 |
location |
|
204 |
} |
|
205 |
} |
|
206 |
||
75393 | 207 |
def screen_location(component: Component, point: Point): Screen_Location = { |
72974 | 208 |
val screen_point = new Point(point.x, point.y) |
209 |
if (component != null) SwingUtilities.convertPointToScreen(screen_point, component) |
|
210 |
||
211 |
val ge = GraphicsEnvironment.getLocalGraphicsEnvironment |
|
212 |
val screen_bounds = |
|
213 |
(for { |
|
214 |
device <- ge.getScreenDevices.iterator |
|
215 |
config <- device.getConfigurations.iterator |
|
216 |
bounds = config.getBounds |
|
217 |
} yield bounds).find(_.contains(screen_point)) getOrElse ge.getMaximumWindowBounds |
|
218 |
||
219 |
Screen_Location(screen_point, screen_bounds) |
|
220 |
} |
|
221 |
||
222 |
def mouse_location(): Screen_Location = |
|
223 |
screen_location(null, MouseInfo.getPointerInfo.getLocation) |
|
224 |
||
225 |
||
73037 | 226 |
/* screen size */ |
227 |
||
75393 | 228 |
sealed case class Screen_Size(bounds: Rectangle, insets: Insets) { |
73038
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
229 |
def full_screen_bounds: Rectangle = |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
230 |
if (Platform.is_linux) { |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
231 |
// avoid menu bar and docking areas |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
232 |
new Rectangle( |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
233 |
bounds.x + insets.left, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
234 |
bounds.y + insets.top, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
235 |
bounds.width - insets.left - insets.right, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
236 |
bounds.height - insets.top - insets.bottom) |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
237 |
} |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
238 |
else if (Platform.is_macos) { |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
239 |
// avoid menu bar, but ignore docking areas |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
240 |
new Rectangle( |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
241 |
bounds.x, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
242 |
bounds.y + insets.top, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
243 |
bounds.width, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
244 |
bounds.height - insets.top) |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
245 |
} |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
246 |
else bounds |
73037 | 247 |
} |
248 |
||
75393 | 249 |
def screen_size(component: Component): Screen_Size = { |
73037 | 250 |
val config = component.getGraphicsConfiguration |
251 |
val bounds = config.getBounds |
|
252 |
val insets = Toolkit.getDefaultToolkit.getScreenInsets(config) |
|
253 |
Screen_Size(bounds, insets) |
|
254 |
} |
|
255 |
||
256 |
||
53712 | 257 |
/* component hierachy */ |
258 |
||
259 |
def get_parent(component: Component): Option[Container] = |
|
260 |
component.getParent match { |
|
261 |
case null => None |
|
262 |
case parent => Some(parent) |
|
263 |
} |
|
264 |
||
265 |
def ancestors(component: Component): Iterator[Container] = new Iterator[Container] { |
|
266 |
private var next_elem = get_parent(component) |
|
73337 | 267 |
def hasNext: Boolean = next_elem.isDefined |
53712 | 268 |
def next(): Container = |
269 |
next_elem match { |
|
270 |
case Some(parent) => |
|
271 |
next_elem = get_parent(parent) |
|
272 |
parent |
|
273 |
case None => Iterator.empty.next() |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
def parent_window(component: Component): Option[Window] = |
|
278 |
ancestors(component).collectFirst({ case x: Window => x }) |
|
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
|
279 |
|
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
|
280 |
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
|
281 |
parent_window(component) match { |
57879
91e188508bc9
proper layered_pane for JDialog, e.g. relevant for floating dockables in jEdit, for completion popup in text field;
wenzelm
parents:
57639
diff
changeset
|
282 |
case Some(w: JWindow) => Some(w.getLayeredPane) |
91e188508bc9
proper layered_pane for JDialog, e.g. relevant for floating dockables in jEdit, for completion popup in text field;
wenzelm
parents:
57639
diff
changeset
|
283 |
case Some(w: JFrame) => Some(w.getLayeredPane) |
91e188508bc9
proper layered_pane for JDialog, e.g. relevant for floating dockables in jEdit, for completion popup in text field;
wenzelm
parents:
57639
diff
changeset
|
284 |
case Some(w: JDialog) => Some(w.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
|
285 |
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
|
286 |
} |
53785 | 287 |
|
75393 | 288 |
def traverse_components(component: Component, apply: Component => Unit): Unit = { |
289 |
def traverse(comp: Component): Unit = { |
|
63874 | 290 |
apply(comp) |
291 |
comp match { |
|
292 |
case cont: Container => |
|
293 |
for (i <- 0 until cont.getComponentCount) |
|
294 |
traverse(cont.getComponent(i)) |
|
295 |
case _ => |
|
296 |
} |
|
297 |
} |
|
298 |
traverse(component) |
|
299 |
} |
|
300 |
||
53785 | 301 |
|
302 |
/* font operations */ |
|
303 |
||
61742
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
304 |
def copy_font(font: Font): Font = |
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
305 |
if (font == null) null |
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
306 |
else new Font(font.getFamily, font.getStyle, font.getSize) |
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
307 |
|
59230 | 308 |
def line_metrics(font: Font): LineMetrics = |
53785 | 309 |
font.getLineMetrics("", new FontRenderContext(null, false, false)) |
310 |
||
69376 | 311 |
def transform_font(font: Font, transform: AffineTransform): Font = |
73909 | 312 |
font.deriveFont(JMap.of(TextAttribute.TRANSFORM, new TransformAttribute(transform))) |
69376 | 313 |
|
314 |
def font(family: String = Isabelle_Fonts.sans, size: Int = 1, bold: Boolean = false): Font = |
|
315 |
new Font(family, if (bold) Font.BOLD else Font.PLAIN, size) |
|
316 |
||
69377 | 317 |
def label_font(): Font = (new JLabel).getFont |
318 |
||
69376 | 319 |
|
320 |
/* Isabelle fonts */ |
|
321 |
||
75393 | 322 |
def imitate_font( |
323 |
font: Font, |
|
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
69357
diff
changeset
|
324 |
family: String = Isabelle_Fonts.sans, |
75393 | 325 |
scale: Double = 1.0 |
326 |
): Font = { |
|
53785 | 327 |
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
|
328 |
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
|
329 |
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
|
330 |
} |
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59080
diff
changeset
|
331 |
|
75393 | 332 |
def imitate_font_css( |
333 |
font: Font, |
|
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
69357
diff
changeset
|
334 |
family: String = Isabelle_Fonts.sans, |
75393 | 335 |
scale: Double = 1.0 |
336 |
): String = { |
|
59183
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59080
diff
changeset
|
337 |
val font1 = new Font(family, font.getStyle, font.getSize) |
59230 | 338 |
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
|
339 |
"font-family: " + family + "; font-size: " + (scale * rel_size * 100).toInt + "%;" |
53785 | 340 |
} |
69377 | 341 |
|
75393 | 342 |
def use_isabelle_fonts(): Unit = { |
69377 | 343 |
val default_font = label_font() |
344 |
val ui = UIManager.getDefaults |
|
75393 | 345 |
for (prop <- |
346 |
List( |
|
347 |
"ToggleButton.font", |
|
348 |
"CheckBoxMenuItem.font", |
|
349 |
"Label.font", |
|
350 |
"Menu.font", |
|
351 |
"MenuItem.font", |
|
352 |
"PopupMenu.font", |
|
353 |
"Table.font", |
|
354 |
"TableHeader.font", |
|
355 |
"TextArea.font", |
|
356 |
"TextField.font", |
|
357 |
"TextPane.font", |
|
358 |
"ToolTip.font", |
|
359 |
"Tree.font")) { |
|
69377 | 360 |
val font = ui.get(prop) match { case font: Font => font case _ => default_font } |
361 |
ui.put(prop, GUI.imitate_font(font)) |
|
362 |
} |
|
363 |
} |
|
51619 | 364 |
} |
73111 | 365 |
|
366 |
class FlatLightLaf extends GUI.Look_And_Feel(new com.formdev.flatlaf.FlatLightLaf) |
|
367 |
class FlatDarkLaf extends GUI.Look_And_Feel(new com.formdev.flatlaf.FlatDarkLaf) |