summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Juuxel2021-03-20 14:19:41 +0200
committerGravatar Juuxel2021-03-20 14:20:11 +0200
commit6feac8fd8839f54c1f91176cc0412c397de2b19e (patch)
tree11a4f112975d6e0f9390a40c666531e2935ebdc9
parentSwitch to SVG icons instead of PNGs and add icon for records (diff)
downloadenigma-6feac8fd8839f54c1f91176cc0412c397de2b19e.tar.gz
enigma-6feac8fd8839f54c1f91176cc0412c397de2b19e.tar.xz
enigma-6feac8fd8839f54c1f91176cc0412c397de2b19e.zip
Add a check for missing SVG icon files
Improves debugging if the icon is missing as FlatLaf's own error is thrown at render time.
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java10
1 files changed, 9 insertions, 1 deletions
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 60414f99..cfa02cbd 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
@@ -16,6 +16,7 @@ import java.io.IOException;
16import java.net.URI; 16import java.net.URI;
17import java.net.URISyntaxException; 17import java.net.URISyntaxException;
18import java.util.Map; 18import java.util.Map;
19import java.util.NoSuchElementException;
19 20
20public class GuiUtil { 21public class GuiUtil {
21 public static final Icon CLASS_ICON = loadIcon("class"); 22 public static final Icon CLASS_ICON = loadIcon("class");
@@ -79,9 +80,16 @@ public class GuiUtil {
79 } 80 }
80 81
81 public static Icon loadIcon(String name) { 82 public static Icon loadIcon(String name) {
83 String path = "icons/" + name + ".svg";
84
85 // Do an eager check for a missing icon since FlatSVGIcon does it later at render time
86 if (GuiUtil.class.getResource(path) == null) {
87 throw new NoSuchElementException("Missing icon: '" + name + "' at " + path);
88 }
89
82 // Note: the width and height are scaled automatically because the FlatLaf UI scale 90 // Note: the width and height are scaled automatically because the FlatLaf UI scale
83 // is set in LookAndFeel.setGlobalLAF() 91 // is set in LookAndFeel.setGlobalLAF()
84 return new FlatSVGIcon("icons/" + name + ".svg", 16, 16, GuiUtil.class.getClassLoader()); 92 return new FlatSVGIcon(path, 16, 16, GuiUtil.class.getClassLoader());
85 } 93 }
86 94
87 public static Icon getClassIcon(Gui gui, ClassEntry entry) { 95 public static Icon getClassIcon(Gui gui, ClassEntry entry) {