diff options
| author | 2021-03-21 18:20:06 +0100 | |
|---|---|---|
| committer | 2021-03-21 18:20:06 +0100 | |
| commit | e5d0ecb928d2b349b9c9a342f51d943a470554e5 (patch) | |
| tree | c4fedf383b7462266d29ce1806a97b7c93293c63 /enigma-swing/src/main/java | |
| parent | Less strict JRE check (#362) (diff) | |
| parent | Fix missing icon check (diff) | |
| download | enigma-fork-e5d0ecb928d2b349b9c9a342f51d943a470554e5.tar.gz enigma-fork-e5d0ecb928d2b349b9c9a342f51d943a470554e5.tar.xz enigma-fork-e5d0ecb928d2b349b9c9a342f51d943a470554e5.zip | |
Merge pull request #363 from Juuxel/svg-icons
Switch to SVG icons
Diffstat (limited to 'enigma-swing/src/main/java')
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java | 1 | ||||
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java | 24 |
2 files changed, 14 insertions, 11 deletions
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 { | |||
| 36 | 36 | ||
| 37 | public void setGlobalLAF() { | 37 | public void setGlobalLAF() { |
| 38 | // Configure FlatLaf's UI scale to be our scale factor. | 38 | // Configure FlatLaf's UI scale to be our scale factor. |
| 39 | // This is also used for the SVG icons, so it applies even when some other LaF is active. | ||
| 39 | System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(ScaleUtil.getScaleFactor())); | 40 | System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(ScaleUtil.getScaleFactor())); |
| 40 | 41 | ||
| 41 | try { | 42 | 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..7f08fc2 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,28 +1,29 @@ | |||
| 1 | package cuchaz.enigma.gui.util; | 1 | package cuchaz.enigma.gui.util; |
| 2 | 2 | ||
| 3 | import com.formdev.flatlaf.extras.FlatSVGIcon; | ||
| 3 | import cuchaz.enigma.gui.Gui; | 4 | import cuchaz.enigma.gui.Gui; |
| 4 | import cuchaz.enigma.translation.representation.AccessFlags; | 5 | import cuchaz.enigma.translation.representation.AccessFlags; |
| 5 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 6 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 6 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 7 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 7 | import cuchaz.enigma.utils.Os; | 8 | import cuchaz.enigma.utils.Os; |
| 8 | 9 | ||
| 9 | import javax.imageio.ImageIO; | ||
| 10 | import javax.swing.*; | 10 | import javax.swing.*; |
| 11 | import java.awt.*; | 11 | import java.awt.*; |
| 12 | import java.awt.event.MouseAdapter; | 12 | import java.awt.event.MouseAdapter; |
| 13 | import java.awt.event.MouseEvent; | 13 | import java.awt.event.MouseEvent; |
| 14 | import java.awt.font.TextAttribute; | 14 | import java.awt.font.TextAttribute; |
| 15 | import java.io.IOException; | 15 | import java.io.IOException; |
| 16 | import java.io.InputStream; | ||
| 17 | import java.net.URI; | 16 | import java.net.URI; |
| 18 | import java.net.URISyntaxException; | 17 | import java.net.URISyntaxException; |
| 19 | import java.util.Map; | 18 | import java.util.Map; |
| 19 | import java.util.NoSuchElementException; | ||
| 20 | 20 | ||
| 21 | public class GuiUtil { | 21 | public class GuiUtil { |
| 22 | public static final Icon CLASS_ICON = loadIcon("class"); | 22 | public static final Icon CLASS_ICON = loadIcon("class"); |
| 23 | public static final Icon INTERFACE_ICON = loadIcon("interface"); | 23 | public static final Icon INTERFACE_ICON = loadIcon("interface"); |
| 24 | public static final Icon ENUM_ICON = loadIcon("enum"); | 24 | public static final Icon ENUM_ICON = loadIcon("enum"); |
| 25 | public static final Icon ANNOTATION_ICON = loadIcon("annotation"); | 25 | public static final Icon ANNOTATION_ICON = loadIcon("annotation"); |
| 26 | public static final Icon RECORD_ICON = loadIcon("record"); | ||
| 26 | public static final Icon METHOD_ICON = loadIcon("method"); | 27 | public static final Icon METHOD_ICON = loadIcon("method"); |
| 27 | public static final Icon FIELD_ICON = loadIcon("field"); | 28 | public static final Icon FIELD_ICON = loadIcon("field"); |
| 28 | public static final Icon CONSTRUCTOR_ICON = loadIcon("constructor"); | 29 | public static final Icon CONSTRUCTOR_ICON = loadIcon("constructor"); |
| @@ -79,15 +80,16 @@ public class GuiUtil { | |||
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | public static Icon loadIcon(String name) { | 82 | public static Icon loadIcon(String name) { |
| 82 | try { | 83 | String path = "icons/" + name + ".svg"; |
| 83 | InputStream inputStream = GuiUtil.class.getResourceAsStream("/icons/" + name + ".png"); | 84 | |
| 84 | Image image = ImageIO.read(inputStream).getScaledInstance(ScaleUtil.scale(16), ScaleUtil.scale(16), Image.SCALE_DEFAULT); | 85 | // Do an eager check for a missing icon since FlatSVGIcon does it later at render time |
| 85 | return new ImageIcon(image); | 86 | if (GuiUtil.class.getResource('/' + path) == null) { |
| 86 | } catch (IOException e) { | 87 | throw new NoSuchElementException("Missing icon: '" + name + "' at " + path); |
| 87 | e.printStackTrace(); | ||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | return null; | 90 | // Note: the width and height are scaled automatically because the FlatLaf UI scale |
| 91 | // is set in LookAndFeel.setGlobalLAF() | ||
| 92 | return new FlatSVGIcon(path, 16, 16, GuiUtil.class.getClassLoader()); | ||
| 91 | } | 93 | } |
| 92 | 94 | ||
| 93 | public static Icon getClassIcon(Gui gui, ClassEntry entry) { | 95 | public static Icon getClassIcon(Gui gui, ClassEntry entry) { |
| @@ -100,9 +102,9 @@ public class GuiUtil { | |||
| 100 | return INTERFACE_ICON; | 102 | return INTERFACE_ICON; |
| 101 | } else if (access.isEnum()) { | 103 | } else if (access.isEnum()) { |
| 102 | return ENUM_ICON; | 104 | return ENUM_ICON; |
| 105 | } else if (access.isRecord()) { | ||
| 106 | return RECORD_ICON; | ||
| 103 | } | 107 | } |
| 104 | |||
| 105 | // TODO: Record icon? | ||
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | return CLASS_ICON; | 110 | return CLASS_ICON; |