author | wenzelm |
Fri, 01 Apr 2022 17:06:10 +0200 | |
changeset 75393 | 87ebf5a50283 |
parent 73909 | 1d0d9772fff0 |
child 75809 | 1dd5d4f4b69e |
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} |
|
16 |
import scala.swing.{ComboBox, ScrollPane, TextArea} |
|
51619 | 17 |
import scala.swing.event.SelectionChanged |
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 |
||
114 |
/* zoom box */ |
|
115 |
||
57044 | 116 |
private val Zoom_Factor = "([0-9]+)%?".r |
117 |
||
118 |
abstract class Zoom_Box extends ComboBox[String]( |
|
75393 | 119 |
List("50%", "70%", "85%", "100%", "125%", "150%", "175%", "200%", "300%", "400%") |
120 |
) { |
|
57044 | 121 |
def changed: Unit |
122 |
def factor: Int = parse(selection.item) |
|
123 |
||
124 |
private def parse(text: String): Int = |
|
51619 | 125 |
text match { |
57044 | 126 |
case Zoom_Factor(s) => |
51619 | 127 |
val i = Integer.parseInt(s) |
56874 | 128 |
if (10 <= i && i < 1000) i else 100 |
51619 | 129 |
case _ => 100 |
130 |
} |
|
131 |
||
57044 | 132 |
private def print(i: Int): String = i.toString + "%" |
51619 | 133 |
|
75393 | 134 |
def set_item(i: Int): Unit = { |
51619 | 135 |
peer.getEditor match { |
136 |
case null => |
|
137 |
case editor => editor.setItem(print(i)) |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
makeEditable()(c => new ComboBox.BuiltInEditor(c)(text => print(parse(text)), x => x)) |
|
56874 | 142 |
peer.getEditor.getEditorComponent match { |
56888 | 143 |
case text: JTextField => text.setColumns(4) |
56874 | 144 |
case _ => |
145 |
} |
|
146 |
||
57044 | 147 |
selection.index = 3 |
148 |
||
51619 | 149 |
listenTo(selection) |
57044 | 150 |
reactions += { case SelectionChanged(_) => changed } |
51619 | 151 |
} |
152 |
||
153 |
||
53786 | 154 |
/* tooltip with multi-line support */ |
155 |
||
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
54965
diff
changeset
|
156 |
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
|
157 |
if (text == null || text == "") null |
62113 | 158 |
else "<html>" + HTML.output(text) + "</html>" |
53786 | 159 |
|
160 |
||
51619 | 161 |
/* icon */ |
162 |
||
163 |
def isabelle_icon(): ImageIcon = |
|
54676
6b2ca4850b71
uniform use of transparent icons, as for main "apps";
wenzelm
parents:
54659
diff
changeset
|
164 |
new ImageIcon(getClass.getClassLoader.getResource("isabelle/isabelle_transparent-32.gif")) |
51619 | 165 |
|
54709 | 166 |
def isabelle_icons(): List[ImageIcon] = |
167 |
for (icon <- List("isabelle/isabelle_transparent-32.gif", "isabelle/isabelle_transparent.gif")) |
|
168 |
yield new ImageIcon(getClass.getClassLoader.getResource(icon)) |
|
169 |
||
51619 | 170 |
def isabelle_image(): Image = isabelle_icon().getImage |
53712 | 171 |
|
172 |
||
72974 | 173 |
/* location within multi-screen environment */ |
174 |
||
75393 | 175 |
final case class Screen_Location(point: Point, bounds: Rectangle) { |
176 |
def relative(parent: Component, size: Dimension): Point = { |
|
72974 | 177 |
val w = size.width |
178 |
val h = size.height |
|
179 |
||
180 |
val x0 = parent.getLocationOnScreen.x |
|
181 |
val y0 = parent.getLocationOnScreen.y |
|
182 |
val x1 = x0 + parent.getWidth - w |
|
183 |
val y1 = y0 + parent.getHeight - h |
|
184 |
val x2 = point.x min (bounds.x + bounds.width - w) |
|
185 |
val y2 = point.y min (bounds.y + bounds.height - h) |
|
186 |
||
187 |
val location = new Point((x2 min x1) max x0, (y2 min y1) max y0) |
|
188 |
SwingUtilities.convertPointFromScreen(location, parent) |
|
189 |
location |
|
190 |
} |
|
191 |
} |
|
192 |
||
75393 | 193 |
def screen_location(component: Component, point: Point): Screen_Location = { |
72974 | 194 |
val screen_point = new Point(point.x, point.y) |
195 |
if (component != null) SwingUtilities.convertPointToScreen(screen_point, component) |
|
196 |
||
197 |
val ge = GraphicsEnvironment.getLocalGraphicsEnvironment |
|
198 |
val screen_bounds = |
|
199 |
(for { |
|
200 |
device <- ge.getScreenDevices.iterator |
|
201 |
config <- device.getConfigurations.iterator |
|
202 |
bounds = config.getBounds |
|
203 |
} yield bounds).find(_.contains(screen_point)) getOrElse ge.getMaximumWindowBounds |
|
204 |
||
205 |
Screen_Location(screen_point, screen_bounds) |
|
206 |
} |
|
207 |
||
208 |
def mouse_location(): Screen_Location = |
|
209 |
screen_location(null, MouseInfo.getPointerInfo.getLocation) |
|
210 |
||
211 |
||
73037 | 212 |
/* screen size */ |
213 |
||
75393 | 214 |
sealed case class Screen_Size(bounds: Rectangle, insets: Insets) { |
73038
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
215 |
def full_screen_bounds: Rectangle = |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
216 |
if (Platform.is_linux) { |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
217 |
// avoid menu bar and docking areas |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
218 |
new Rectangle( |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
219 |
bounds.x + insets.left, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
220 |
bounds.y + insets.top, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
221 |
bounds.width - insets.left - insets.right, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
222 |
bounds.height - insets.top - insets.bottom) |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
223 |
} |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
224 |
else if (Platform.is_macos) { |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
225 |
// avoid menu bar, but ignore docking areas |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
226 |
new Rectangle( |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
227 |
bounds.x, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
228 |
bounds.y + insets.top, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
229 |
bounds.width, |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
230 |
bounds.height - insets.top) |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
231 |
} |
3b14f7315dd2
some attempts at multi-platform full-screen mode;
wenzelm
parents:
73037
diff
changeset
|
232 |
else bounds |
73037 | 233 |
} |
234 |
||
75393 | 235 |
def screen_size(component: Component): Screen_Size = { |
73037 | 236 |
val config = component.getGraphicsConfiguration |
237 |
val bounds = config.getBounds |
|
238 |
val insets = Toolkit.getDefaultToolkit.getScreenInsets(config) |
|
239 |
Screen_Size(bounds, insets) |
|
240 |
} |
|
241 |
||
242 |
||
53712 | 243 |
/* component hierachy */ |
244 |
||
245 |
def get_parent(component: Component): Option[Container] = |
|
246 |
component.getParent match { |
|
247 |
case null => None |
|
248 |
case parent => Some(parent) |
|
249 |
} |
|
250 |
||
251 |
def ancestors(component: Component): Iterator[Container] = new Iterator[Container] { |
|
252 |
private var next_elem = get_parent(component) |
|
73337 | 253 |
def hasNext: Boolean = next_elem.isDefined |
53712 | 254 |
def next(): Container = |
255 |
next_elem match { |
|
256 |
case Some(parent) => |
|
257 |
next_elem = get_parent(parent) |
|
258 |
parent |
|
259 |
case None => Iterator.empty.next() |
|
260 |
} |
|
261 |
} |
|
262 |
||
263 |
def parent_window(component: Component): Option[Window] = |
|
264 |
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
|
265 |
|
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
} |
53785 | 273 |
|
75393 | 274 |
def traverse_components(component: Component, apply: Component => Unit): Unit = { |
275 |
def traverse(comp: Component): Unit = { |
|
63874 | 276 |
apply(comp) |
277 |
comp match { |
|
278 |
case cont: Container => |
|
279 |
for (i <- 0 until cont.getComponentCount) |
|
280 |
traverse(cont.getComponent(i)) |
|
281 |
case _ => |
|
282 |
} |
|
283 |
} |
|
284 |
traverse(component) |
|
285 |
} |
|
286 |
||
53785 | 287 |
|
288 |
/* font operations */ |
|
289 |
||
61742
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
290 |
def copy_font(font: Font): Font = |
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
291 |
if (font == null) null |
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
292 |
else new Font(font.getFamily, font.getStyle, font.getSize) |
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61529
diff
changeset
|
293 |
|
59230 | 294 |
def line_metrics(font: Font): LineMetrics = |
53785 | 295 |
font.getLineMetrics("", new FontRenderContext(null, false, false)) |
296 |
||
69376 | 297 |
def transform_font(font: Font, transform: AffineTransform): Font = |
73909 | 298 |
font.deriveFont(JMap.of(TextAttribute.TRANSFORM, new TransformAttribute(transform))) |
69376 | 299 |
|
300 |
def font(family: String = Isabelle_Fonts.sans, size: Int = 1, bold: Boolean = false): Font = |
|
301 |
new Font(family, if (bold) Font.BOLD else Font.PLAIN, size) |
|
302 |
||
69377 | 303 |
def label_font(): Font = (new JLabel).getFont |
304 |
||
69376 | 305 |
|
306 |
/* Isabelle fonts */ |
|
307 |
||
75393 | 308 |
def imitate_font( |
309 |
font: Font, |
|
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
69357
diff
changeset
|
310 |
family: String = Isabelle_Fonts.sans, |
75393 | 311 |
scale: Double = 1.0 |
312 |
): Font = { |
|
53785 | 313 |
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
|
314 |
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
|
315 |
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
|
316 |
} |
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59080
diff
changeset
|
317 |
|
75393 | 318 |
def imitate_font_css( |
319 |
font: Font, |
|
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
69357
diff
changeset
|
320 |
family: String = Isabelle_Fonts.sans, |
75393 | 321 |
scale: Double = 1.0 |
322 |
): String = { |
|
59183
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59080
diff
changeset
|
323 |
val font1 = new Font(family, font.getStyle, font.getSize) |
59230 | 324 |
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
|
325 |
"font-family: " + family + "; font-size: " + (scale * rel_size * 100).toInt + "%;" |
53785 | 326 |
} |
69377 | 327 |
|
75393 | 328 |
def use_isabelle_fonts(): Unit = { |
69377 | 329 |
val default_font = label_font() |
330 |
val ui = UIManager.getDefaults |
|
75393 | 331 |
for (prop <- |
332 |
List( |
|
333 |
"ToggleButton.font", |
|
334 |
"CheckBoxMenuItem.font", |
|
335 |
"Label.font", |
|
336 |
"Menu.font", |
|
337 |
"MenuItem.font", |
|
338 |
"PopupMenu.font", |
|
339 |
"Table.font", |
|
340 |
"TableHeader.font", |
|
341 |
"TextArea.font", |
|
342 |
"TextField.font", |
|
343 |
"TextPane.font", |
|
344 |
"ToolTip.font", |
|
345 |
"Tree.font")) { |
|
69377 | 346 |
val font = ui.get(prop) match { case font: Font => font case _ => default_font } |
347 |
ui.put(prop, GUI.imitate_font(font)) |
|
348 |
} |
|
349 |
} |
|
51619 | 350 |
} |
73111 | 351 |
|
352 |
class FlatLightLaf extends GUI.Look_And_Feel(new com.formdev.flatlaf.FlatLightLaf) |
|
353 |
class FlatDarkLaf extends GUI.Look_And_Feel(new com.formdev.flatlaf.FlatDarkLaf) |