From 6025ebd4e828b628adb18e289175a2e9c940e33b Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Wed, 13 Oct 2021 20:39:57 +0200 Subject: [PATCH] Documentation: Increase resolution of preview images --- .../core/documentation/CreateUITable.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/core/src/test/java/com/github/weisj/darklaf/core/documentation/CreateUITable.java b/core/src/test/java/com/github/weisj/darklaf/core/documentation/CreateUITable.java index dd212df2..db94c613 100644 --- a/core/src/test/java/com/github/weisj/darklaf/core/documentation/CreateUITable.java +++ b/core/src/test/java/com/github/weisj/darklaf/core/documentation/CreateUITable.java @@ -21,15 +21,16 @@ package com.github.weisj.darklaf.core.documentation; import java.awt.*; -import java.awt.Font; import java.awt.image.BufferedImage; import java.io.*; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.imageio.ImageIO; import javax.swing.*; @@ -71,7 +72,9 @@ public class CreateUITable { workingFolder = FOLDER + theme.getPrefix() + "/"; String os = SystemInfo.getOsName(); String htmlFile = workingFolder + "defaults_" + os + ".html"; - Files.createDirectories(new File(workingFolder).toPath()); + final Path workingPath = new File(workingFolder).toPath(); + deleteDeep(workingPath); + Files.createDirectories(workingPath); File f = new File(htmlFile); if (!f.exists()) Files.createFile(f.toPath()); @@ -87,6 +90,21 @@ public class CreateUITable { } } + private static void deleteDeep(final Path path) { + if (Files.isDirectory(path)) { + try (Stream children = Files.list(path)) { + children.forEach(CreateUITable::deleteDeep); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + Files.deleteIfExists(path); + } catch (IOException e) { + e.printStackTrace(); + } + } + private String getGroup(final Map.Entry entry) { Parser.DebugParseResult value = Types.safeCast(entry.getValue(), Parser.DebugParseResult.class); String s = value != null ? value.originalKey : entry.getKey().toString(); @@ -236,18 +254,20 @@ public class CreateUITable { Dimension size = new Dimension(SAMPLE_WIDTH, SAMPLE_HEIGHT); try { if (!(value instanceof Icon)) { - path = createImage(value, stringRepresentation, size); + path = createImage(value, stringRepresentation, size, 4); } else { - path = createImage(value, keyName, size); + path = createImage(value, keyName, size, 1); } } catch (final IOException ignored) { return StringUtil.repeat(IDENT, ident) + "\n"; } return StringUtil.repeat(IDENT, ident) + String - .format("\"%s\"\n", path, key); + .format("\"%s\"\n", + path, key, SAMPLE_WIDTH, SAMPLE_HEIGHT); } - private String createImage(final Object value, final String name, final Dimension size) throws IOException { + private String createImage(final Object value, final String name, final Dimension size, int scale) + throws IOException { // noinspection ResultOfMethodCallIgnored new File(workingFolder + "img/").mkdirs(); String fileName = "img/" + name + "_" + SystemInfo.getOsName() + ".png"; @@ -259,14 +279,17 @@ public class CreateUITable { } JComponent comp = (JComponent) new SampleRenderer().getTableCellRendererComponent(null, value, false, false, 0, 0); - BufferedImage image = ImageUtil.createCompatibleTranslucentImage(size.width, size.height); + BufferedImage image = ImageUtil.createCompatibleTranslucentImage(scale * size.width, scale * size.height); Graphics g = image.getGraphics(); + ((Graphics2D) g).scale(scale, scale); + if (!(value instanceof Icon) && !(value instanceof DropShadowBorder)) { g.setColor(new JPanel().getBackground()); g.fillRect(0, 0, size.width, size.height); } comp.setBounds(0, 0, size.width, size.height); comp.setOpaque(false); + comp.doLayout(); comp.paint(g); g.dispose(); ImageIO.write(image, "png", imageFile);