Skip to content

Commit

Permalink
Fix issue with OS UI scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
FeldrinH committed Mar 27, 2024
1 parent d696642 commit efece00
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/main/java/ee/ut/dendroloj/AgentTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -34,5 +35,6 @@ static void init() {
)
.installOn(inst);
}

}

8 changes: 5 additions & 3 deletions src/main/java/ee/ut/dendroloj/CallTreeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

class CallTreeLayout {

static {
GraphGUI.initProperties();
}

public static final MetaTreeNode root = new MetaTreeNode();
private static TreeNode currentNode = root;

Expand Down Expand Up @@ -106,7 +110,7 @@ private static void setActiveStep(int newActiveStep) {
}

private static LayoutResult updateGraph(CallTreeNode current, boolean hideNewElements, List<Element> 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?

Expand Down Expand Up @@ -201,5 +205,3 @@ private static LayoutResult updateGraph(CallTreeNode current, boolean hideNewEle
}

}


28 changes: 21 additions & 7 deletions src/main/java/ee/ut/dendroloj/GraphGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -246,4 +259,5 @@ public void actionPerformed(ActionEvent event) {

root.setVisible(true);
}

}

0 comments on commit efece00

Please sign in to comment.