diff options
| author | 2021-03-20 14:02:47 +0200 | |
|---|---|---|
| committer | 2021-03-20 14:02:47 +0200 | |
| commit | cb338dd7e6ab834a1446b65ea9adcc47b233217b (patch) | |
| tree | 1dbaa3864212367dcfbc40ebe58d940071482881 /enigma-swing/src/main/java | |
| parent | Merge pull request #358 from Juuxel/flatlaf (diff) | |
| download | enigma-fork-cb338dd7e6ab834a1446b65ea9adcc47b233217b.tar.gz enigma-fork-cb338dd7e6ab834a1446b65ea9adcc47b233217b.tar.xz enigma-fork-cb338dd7e6ab834a1446b65ea9adcc47b233217b.zip | |
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).
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 | 20 |
2 files changed, 8 insertions, 13 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..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 @@ | |||
| 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; |
| @@ -23,6 +22,7 @@ public class GuiUtil { | |||
| 23 | public static final Icon INTERFACE_ICON = loadIcon("interface"); | 22 | public static final Icon INTERFACE_ICON = loadIcon("interface"); |
| 24 | public static final Icon ENUM_ICON = loadIcon("enum"); | 23 | public static final Icon ENUM_ICON = loadIcon("enum"); |
| 25 | public static final Icon ANNOTATION_ICON = loadIcon("annotation"); | 24 | public static final Icon ANNOTATION_ICON = loadIcon("annotation"); |
| 25 | public static final Icon RECORD_ICON = loadIcon("record"); | ||
| 26 | public static final Icon METHOD_ICON = loadIcon("method"); | 26 | public static final Icon METHOD_ICON = loadIcon("method"); |
| 27 | public static final Icon FIELD_ICON = loadIcon("field"); | 27 | public static final Icon FIELD_ICON = loadIcon("field"); |
| 28 | public static final Icon CONSTRUCTOR_ICON = loadIcon("constructor"); | 28 | public static final Icon CONSTRUCTOR_ICON = loadIcon("constructor"); |
| @@ -79,15 +79,9 @@ public class GuiUtil { | |||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | public static Icon loadIcon(String name) { | 81 | public static Icon loadIcon(String name) { |
| 82 | try { | 82 | // Note: the width and height are scaled automatically because the FlatLaf UI scale |
| 83 | InputStream inputStream = GuiUtil.class.getResourceAsStream("/icons/" + name + ".png"); | 83 | // is set in LookAndFeel.setGlobalLAF() |
| 84 | Image image = ImageIO.read(inputStream).getScaledInstance(ScaleUtil.scale(16), ScaleUtil.scale(16), Image.SCALE_DEFAULT); | 84 | return new FlatSVGIcon("icons/" + name + ".svg", 16, 16, GuiUtil.class.getClassLoader()); |
| 85 | return new ImageIcon(image); | ||
| 86 | } catch (IOException e) { | ||
| 87 | e.printStackTrace(); | ||
| 88 | } | ||
| 89 | |||
| 90 | return null; | ||
| 91 | } | 85 | } |
| 92 | 86 | ||
| 93 | public static Icon getClassIcon(Gui gui, ClassEntry entry) { | 87 | public static Icon getClassIcon(Gui gui, ClassEntry entry) { |
| @@ -100,9 +94,9 @@ public class GuiUtil { | |||
| 100 | return INTERFACE_ICON; | 94 | return INTERFACE_ICON; |
| 101 | } else if (access.isEnum()) { | 95 | } else if (access.isEnum()) { |
| 102 | return ENUM_ICON; | 96 | return ENUM_ICON; |
| 97 | } else if (access.isRecord()) { | ||
| 98 | return RECORD_ICON; | ||
| 103 | } | 99 | } |
| 104 | |||
| 105 | // TODO: Record icon? | ||
| 106 | } | 100 | } |
| 107 | 101 | ||
| 108 | return CLASS_ICON; | 102 | return CLASS_ICON; |