Browse Source

Documentation: Increase resolution of preview images

pull/295/head
weisj 3 years ago committed by Jannis Weis
parent
commit
6025ebd4e8
  1. 37
      core/src/test/java/com/github/weisj/darklaf/core/documentation/CreateUITable.java

37
core/src/test/java/com/github/weisj/darklaf/core/documentation/CreateUITable.java

@ -21,15 +21,16 @@
package com.github.weisj.darklaf.core.documentation; package com.github.weisj.darklaf.core.documentation;
import java.awt.*; import java.awt.*;
import java.awt.Font;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
@ -71,7 +72,9 @@ public class CreateUITable {
workingFolder = FOLDER + theme.getPrefix() + "/"; workingFolder = FOLDER + theme.getPrefix() + "/";
String os = SystemInfo.getOsName(); String os = SystemInfo.getOsName();
String htmlFile = workingFolder + "defaults_" + os + ".html"; 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); File f = new File(htmlFile);
if (!f.exists()) Files.createFile(f.toPath()); 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<Path> 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<Object, Object> entry) { private String getGroup(final Map.Entry<Object, Object> entry) {
Parser.DebugParseResult value = Types.safeCast(entry.getValue(), Parser.DebugParseResult.class); Parser.DebugParseResult value = Types.safeCast(entry.getValue(), Parser.DebugParseResult.class);
String s = value != null ? value.originalKey : entry.getKey().toString(); String s = value != null ? value.originalKey : entry.getKey().toString();
@ -236,18 +254,20 @@ public class CreateUITable {
Dimension size = new Dimension(SAMPLE_WIDTH, SAMPLE_HEIGHT); Dimension size = new Dimension(SAMPLE_WIDTH, SAMPLE_HEIGHT);
try { try {
if (!(value instanceof Icon)) { if (!(value instanceof Icon)) {
path = createImage(value, stringRepresentation, size); path = createImage(value, stringRepresentation, size, 4);
} else { } else {
path = createImage(value, keyName, size); path = createImage(value, keyName, size, 1);
} }
} catch (final IOException ignored) { } catch (final IOException ignored) {
return StringUtil.repeat(IDENT, ident) + "<td></td>\n"; return StringUtil.repeat(IDENT, ident) + "<td></td>\n";
} }
return StringUtil.repeat(IDENT, ident) + String return StringUtil.repeat(IDENT, ident) + String
.format("<td style=\"padding:0\" align=\"center\"><img src=\"%s\" alt=\"%s\"></td>\n", path, key); .format("<td style=\"padding:0\" align=\"center\"><img src=\"%s\" alt=\"%s\" width=\"%d\" height=\"%d\"></td>\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 // noinspection ResultOfMethodCallIgnored
new File(workingFolder + "img/").mkdirs(); new File(workingFolder + "img/").mkdirs();
String fileName = "img/" + name + "_" + SystemInfo.getOsName() + ".png"; String fileName = "img/" + name + "_" + SystemInfo.getOsName() + ".png";
@ -259,14 +279,17 @@ public class CreateUITable {
} }
JComponent comp = JComponent comp =
(JComponent) new SampleRenderer().getTableCellRendererComponent(null, value, false, false, 0, 0); (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(); Graphics g = image.getGraphics();
((Graphics2D) g).scale(scale, scale);
if (!(value instanceof Icon) && !(value instanceof DropShadowBorder)) { if (!(value instanceof Icon) && !(value instanceof DropShadowBorder)) {
g.setColor(new JPanel().getBackground()); g.setColor(new JPanel().getBackground());
g.fillRect(0, 0, size.width, size.height); g.fillRect(0, 0, size.width, size.height);
} }
comp.setBounds(0, 0, size.width, size.height); comp.setBounds(0, 0, size.width, size.height);
comp.setOpaque(false); comp.setOpaque(false);
comp.doLayout();
comp.paint(g); comp.paint(g);
g.dispose(); g.dispose();
ImageIO.write(image, "png", imageFile); ImageIO.write(image, "png", imageFile);

Loading…
Cancel
Save