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