From efece00e05c50daa45657e0774b8ca6170093de4 Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Wed, 27 Mar 2024 19:43:47 +0200 Subject: [PATCH] Fix issue with OS UI scaling --- .../java/ee/ut/dendroloj/AgentTracer.java | 4 ++- .../java/ee/ut/dendroloj/CallTreeLayout.java | 8 ++++-- src/main/java/ee/ut/dendroloj/GraphGUI.java | 28 ++++++++++++++----- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/ee/ut/dendroloj/AgentTracer.java b/src/main/java/ee/ut/dendroloj/AgentTracer.java index fd62ffe..9844cfb 100644 --- a/src/main/java/ee/ut/dendroloj/AgentTracer.java +++ b/src/main/java/ee/ut/dendroloj/AgentTracer.java @@ -11,7 +11,8 @@ import java.lang.instrument.Instrumentation; class AgentTracer { - static void init() { + + public static void init() { Instrumentation inst = ByteBuddyAgent.install(); // TraceProcessor is originally private to ensure that users cannot access it. It is marked public here, because generated code needs to access it from outside. @@ -34,5 +35,6 @@ static void init() { ) .installOn(inst); } + } diff --git a/src/main/java/ee/ut/dendroloj/CallTreeLayout.java b/src/main/java/ee/ut/dendroloj/CallTreeLayout.java index 247d540..3770527 100644 --- a/src/main/java/ee/ut/dendroloj/CallTreeLayout.java +++ b/src/main/java/ee/ut/dendroloj/CallTreeLayout.java @@ -16,6 +16,10 @@ class CallTreeLayout { + static { + GraphGUI.initProperties(); + } + public static final MetaTreeNode root = new MetaTreeNode(); private static TreeNode currentNode = root; @@ -106,7 +110,7 @@ private static void setActiveStep(int newActiveStep) { } private static LayoutResult updateGraph(CallTreeNode current, boolean hideNewElements, List newElements, - double x, double y, double minWidth, CallTreeNode parent) { + double x, double y, double minWidth, CallTreeNode parent) { // Currently mutable arguments and return values show the value they had when they were first added to the graph. // TODO: Show old values of mutable values when scrolling through history? @@ -201,5 +205,3 @@ private static LayoutResult updateGraph(CallTreeNode current, boolean hideNewEle } } - - diff --git a/src/main/java/ee/ut/dendroloj/GraphGUI.java b/src/main/java/ee/ut/dendroloj/GraphGUI.java index 28597e7..b9b59ca 100644 --- a/src/main/java/ee/ut/dendroloj/GraphGUI.java +++ b/src/main/java/ee/ut/dendroloj/GraphGUI.java @@ -9,7 +9,6 @@ import org.graphstream.ui.swing_viewer.SwingViewer; import org.graphstream.ui.swing_viewer.util.DefaultMouseManager; import org.graphstream.ui.view.View; -import org.graphstream.ui.view.Viewer; import org.graphstream.ui.view.camera.Camera; import org.graphstream.ui.view.util.MouseManager; import org.graphstream.ui.view.util.ShortcutManager; @@ -20,6 +19,23 @@ import java.util.Locale; class GraphGUI { + + static { + System.setProperty("org.graphstream.ui", "swing"); + System.setProperty("sun.java2d.uiScale", "1"); + } + + /** + * Initializes global Swing and GraphStream properties. + * This will be called automatically when the GUI is initialized. + * You should call this manually before creating Swing objects + * if you create Swing objects before GUI is initialized. + */ + public static void initProperties() { + // The actual initialization happens inside the static block above + // Calling this method ensures that the static block has been executed + } + public static boolean isHeadless() { return GraphicsEnvironment.isHeadless(); } @@ -60,7 +76,7 @@ public static void initGenericGUI(double uiScale, Graph graph, Layout layout) { uiScale * 14, uiScale + 1, uiScale * 28, uiScale * 14, uiScale * 3)); - init(graph, layout, null); + initGUI(graph, layout, null); } public static void initCallTreeGUI(double uiScale) { @@ -91,13 +107,10 @@ public static void initCallTreeGUI(double uiScale) { "}", Math.max(0.8, Math.sqrt(uiScale)), uiScale * 12, uiScale + 1, Math.sqrt(uiScale) * 10, uiScale * 12, uiScale + 1)); - init(CallTreeLayout.graph, null, CallTreeLayout.stepSlider); + initGUI(CallTreeLayout.graph, null, CallTreeLayout.stepSlider); } - private static void init(Graph graph, Layout layout, JComponent toolbar) { - System.setProperty("org.graphstream.ui", "swing"); - System.setProperty("sun.java2d.uiScale", "1"); - + private static void initGUI(Graph graph, Layout layout, JComponent toolbar) { graph.setAttribute("ui.quality"); graph.setAttribute("ui.antialias"); @@ -246,4 +259,5 @@ public void actionPerformed(ActionEvent event) { root.setVisible(true); } + }