From cb338dd7e6ab834a1446b65ea9adcc47b233217b Mon Sep 17 00:00:00 2001 From: Juuxel Date: Sat, 20 Mar 2021 14:02:47 +0200 Subject: Switch to SVG icons instead of PNGs and add icon for records The PNG icons scaled horribly on FlatLaf but these ones look smooth on any scaling level. Note: even though the icons are FlatSVGIcons from FlatLaf, they work properly on all LaFs if the FlatLaf UI scale property is set to the correct value (which LookAndFeel.setGlobalLAF does). --- .../java/cuchaz/enigma/gui/config/LookAndFeel.java | 1 + .../main/java/cuchaz/enigma/gui/util/GuiUtil.java | 20 +++++++------------- 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'enigma-swing/src/main/java') diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java index e21ef52..3edc87a 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java @@ -36,6 +36,7 @@ public enum LookAndFeel { public void setGlobalLAF() { // Configure FlatLaf's UI scale to be our scale factor. + // This is also used for the SVG icons, so it applies even when some other LaF is active. System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(ScaleUtil.getScaleFactor())); try { diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java index 1a86148..60414f9 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java @@ -1,19 +1,18 @@ package cuchaz.enigma.gui.util; +import com.formdev.flatlaf.extras.FlatSVGIcon; import cuchaz.enigma.gui.Gui; import cuchaz.enigma.translation.representation.AccessFlags; import cuchaz.enigma.translation.representation.entry.ClassEntry; import cuchaz.enigma.translation.representation.entry.MethodEntry; import cuchaz.enigma.utils.Os; -import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.font.TextAttribute; import java.io.IOException; -import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.util.Map; @@ -23,6 +22,7 @@ public class GuiUtil { public static final Icon INTERFACE_ICON = loadIcon("interface"); public static final Icon ENUM_ICON = loadIcon("enum"); public static final Icon ANNOTATION_ICON = loadIcon("annotation"); + public static final Icon RECORD_ICON = loadIcon("record"); public static final Icon METHOD_ICON = loadIcon("method"); public static final Icon FIELD_ICON = loadIcon("field"); public static final Icon CONSTRUCTOR_ICON = loadIcon("constructor"); @@ -79,15 +79,9 @@ public class GuiUtil { } public static Icon loadIcon(String name) { - try { - InputStream inputStream = GuiUtil.class.getResourceAsStream("/icons/" + name + ".png"); - Image image = ImageIO.read(inputStream).getScaledInstance(ScaleUtil.scale(16), ScaleUtil.scale(16), Image.SCALE_DEFAULT); - return new ImageIcon(image); - } catch (IOException e) { - e.printStackTrace(); - } - - return null; + // Note: the width and height are scaled automatically because the FlatLaf UI scale + // is set in LookAndFeel.setGlobalLAF() + return new FlatSVGIcon("icons/" + name + ".svg", 16, 16, GuiUtil.class.getClassLoader()); } public static Icon getClassIcon(Gui gui, ClassEntry entry) { @@ -100,9 +94,9 @@ public class GuiUtil { return INTERFACE_ICON; } else if (access.isEnum()) { return ENUM_ICON; + } else if (access.isRecord()) { + return RECORD_ICON; } - - // TODO: Record icon? } return CLASS_ICON; -- cgit v1.2.3