From a9ac77317aaab4b3529fb702ad170cb575776fc5 Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Wed, 20 Sep 2023 01:58:12 +0300 Subject: [PATCH] Drop minimum supported Java version to 11 --- .github/workflows/build.yml | 2 +- build.gradle.kts | 2 +- src/main/java/ee/ut/dendroloj/GraphGUI.java | 54 ++++++++----------- .../ee/ut/dendroloj/SimpleTreeLayout.java | 16 ++++-- src/test/java/OhtlikAsi.java | 10 +++- 5 files changed, 44 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e3bce2e..89e5e89 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: temurin - java-version: 16 + java-version: 11 - uses: gradle/wrapper-validation-action@v1 - uses: gradle/gradle-build-action@v2 - run: ./gradlew check shadowJar diff --git a/build.gradle.kts b/build.gradle.kts index 0e28a01..afb4422 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + languageVersion.set(JavaLanguageVersion.of(11)) } } diff --git a/src/main/java/ee/ut/dendroloj/GraphGUI.java b/src/main/java/ee/ut/dendroloj/GraphGUI.java index 448b4ce..73e1a15 100644 --- a/src/main/java/ee/ut/dendroloj/GraphGUI.java +++ b/src/main/java/ee/ut/dendroloj/GraphGUI.java @@ -25,39 +25,27 @@ public static void init(double uiScale) { Graph graph = new SingleGraph("DendroloJ"); graph.setAttribute("ui.quality"); graph.setAttribute("ui.antialias"); - graph.setAttribute("ui.stylesheet", String.format(Locale.ROOT, """ - edge { - size: %fpx; - text-size: %f; - text-alignment: center; - text-background-mode: plain; - text-background-color: rgba(255, 255, 255, 180); - text-padding: %f; - text-offset: 5, 0; - } - - edge .returned { - fill-color: gray; - } - - node { - size: %fpx; - text-size: %f; - text-alignment: at-right; - text-background-mode: plain; - text-background-color: rgba(255, 255, 255, 180); - text-padding: %f; - text-offset: 5, 0; - } - - node.error { - fill-color: #fa4c29; - } - - node:selected { - fill-color: #0096ff; - } - """, Math.sqrt(uiScale), uiScale * 12, uiScale + 1, Math.sqrt(uiScale) * 10, uiScale * 12, uiScale + 1)); + graph.setAttribute("ui.stylesheet", String.format(Locale.ROOT, + "edge {" + + " size: %fpx; text-size: %f; text-alignment: center;" + + " text-background-mode: plain; text-background-color: rgba(255, 255, 255, 180);" + + " text-padding: %f; text-offset: 5, 0;" + + "}" + + "edge .returned {" + + " fill-color: gray;" + + "}" + + "node {" + + " size: %fpx; text-size: %f; text-alignment: at-right;" + + " text-background-mode: plain; text-background-color: rgba(255, 255, 255, 180);" + + " text-padding: %f; text-offset: 5, 0;" + + "}" + + "node.error {" + + " fill-color: #fa4c29;" + + "}" + + "node:selected {" + + " fill-color: #0096ff;" + + "}", + Math.sqrt(uiScale), uiScale * 12, uiScale + 1, Math.sqrt(uiScale) * 10, uiScale * 12, uiScale + 1)); JSlider stepSlider = new JSlider(); stepSlider.setPaintTicks(true); diff --git a/src/main/java/ee/ut/dendroloj/SimpleTreeLayout.java b/src/main/java/ee/ut/dendroloj/SimpleTreeLayout.java index 0af0e50..725a832 100644 --- a/src/main/java/ee/ut/dendroloj/SimpleTreeLayout.java +++ b/src/main/java/ee/ut/dendroloj/SimpleTreeLayout.java @@ -9,6 +9,7 @@ import javax.swing.*; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; class SimpleTreeLayout { @@ -83,11 +84,20 @@ private static void setActiveStep(int newActiveStep) { activeStep = newActiveStep; } - private record NodeMetaWrapper(CallTreeNode node, List children, double reservedWidth) { + private static class NodeMetaWrapper { + public final CallTreeNode node; + public final List children; + public final double reservedWidth; + + public NodeMetaWrapper(CallTreeNode node, List children, double reservedWidth) { + this.node = node; + this.children = children; + this.reservedWidth = reservedWidth; + } } private static NodeMetaWrapper wrap(CallTreeNode node) { - List children = node.childStream().map(SimpleTreeLayout::wrap).toList(); + List children = node.childStream().map(SimpleTreeLayout::wrap).collect(Collectors.toList()); double sum = children.stream().mapToDouble(c -> c.reservedWidth).sum(); return new NodeMetaWrapper(node, children, Math.max(1d, sum)); @@ -118,7 +128,7 @@ private static void updateGraph(NodeMetaWrapper meta, boolean hideNewElements, L double reserve = meta.reservedWidth / meta.children.size(); double padding = reserve / 2; for (int i = 0; i < meta.children.size(); i++) { - updateGraph(meta.children().get(i), hideNewElements, newElements, + updateGraph(meta.children.get(i), hideNewElements, newElements, leftBoundary + padding + (reserve * i), y - layerHeight, layerHeight, current); } diff --git a/src/test/java/OhtlikAsi.java b/src/test/java/OhtlikAsi.java index 52ec824..d704936 100644 --- a/src/test/java/OhtlikAsi.java +++ b/src/test/java/OhtlikAsi.java @@ -1,13 +1,19 @@ import ee.ut.dendroloj.Grow; -public record OhtlikAsi(String tekst) { +public class OhtlikAsi { + public final String tekst; + + public OhtlikAsi(String tekst) { + this.tekst = tekst; + } + @Grow int fib(int n, OhtlikAsi a) { if (n < 2) return n; return fib(n - 2, a) + fib(n - 1, a); } - // @Grow annotatsioon toString meetodil mida kutsutakse puu uuendamise ajal. + // @Grow annotatsioon toString meetodil mida kutsutakse puu uuendamise ajal @Grow @Override public String toString() {