diff --git a/.classpath b/.classpath index 0aa9c77..672b2e7 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,7 @@ + diff --git a/src/main/java/com/leo/oobfg/LoadFrame.java b/src/main/java/com/leo/oobfg/LoadFrame.java index 96eebc7..c92cfd4 100644 --- a/src/main/java/com/leo/oobfg/LoadFrame.java +++ b/src/main/java/com/leo/oobfg/LoadFrame.java @@ -2,7 +2,6 @@ import java.awt.Dimension; import java.awt.Font; -import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JLabel; @@ -34,7 +33,7 @@ public LoadFrame() { add(loadLabel); pack(); setLocationRelativeTo(null); - setIconImage(Toolkit.getDefaultToolkit().getImage(OOBFlagGen.class.getResource("/com/leo/oobfg/icon.png"))); + setIconImages(OOBFlagGen.icons); setVisible(true); requestFocus(); } diff --git a/src/main/java/com/leo/oobfg/OOBFlagGen.java b/src/main/java/com/leo/oobfg/OOBFlagGen.java index 5b7537f..32f33ba 100644 --- a/src/main/java/com/leo/oobfg/OOBFlagGen.java +++ b/src/main/java/com/leo/oobfg/OOBFlagGen.java @@ -5,6 +5,7 @@ import java.awt.Dimension; import java.awt.EventQueue; import java.awt.GraphicsEnvironment; +import java.awt.Image; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; @@ -22,6 +23,8 @@ import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.text.ParseException; +import java.util.LinkedList; +import java.util.List; import javax.swing.ButtonGroup; import javax.swing.JButton; @@ -39,10 +42,21 @@ import javax.swing.text.MaskFormatter; public class OOBFlagGen implements ActionListener { - + + public static List icons; + + public static void initAppIcons() throws IOException { + icons = new LinkedList<>(); + final String[] sizes = new String[] { "16", "32", "64" }; + for (String size : sizes) + icons.add(Toolkit.getDefaultToolkit() + .getImage(OOBFlagGen.class.getResource("/com/leo/oobfg/icon" + size + ".png"))); + } + public static final Version VERSION = new Version("1.0"); public static final String UPDATE_CHECK_SITE = "https://raw.githubusercontent.com/Leo40Git/OOBFlagGen/master/.version"; public static final String DOWNLOAD_SITE = "https://github.com/Leo40Git/OOBFlagGen/releases/"; + public static final String ISSUES_SITE = "https://github.com/Leo40Git/OOBFlagGen/issues"; public static final String A_GENERATE = "generate"; public static final String A_COPY = "copy"; @@ -64,6 +78,15 @@ public class OOBFlagGen implements ActionListener { private JRadioButton rdbtnDword; private JButton btnUpdate; + public static void resourceError(Throwable e) { + System.err.println("Error while loading resources!"); + e.printStackTrace(); + JOptionPane.showMessageDialog(null, + "Could not load resources:" + e + "\nPlease report this error here:\n" + ISSUES_SITE, + "Could not load resources!", JOptionPane.ERROR_MESSAGE); + System.exit(1); + } + /** * Launch the application. */ @@ -94,6 +117,11 @@ public static void main(String[] args) { Config.setBoolean(Config.KEY_SKIP_UPDATE_CHECK, false); skipucF = skipucR; } + try { + initAppIcons(); + } catch (IOException e1) { + resourceError(e1); + } LoadFrame loadFrame; if (skipucF) { System.out.println("Update check: skip file detected, skipping"); @@ -130,7 +158,7 @@ public OOBFlagGen() { */ private void initialize() { frame = new JFrame(); - frame.setIconImage(Toolkit.getDefaultToolkit().getImage(OOBFlagGen.class.getResource("/com/leo/oobfg/icon.png"))); + frame.setIconImages(icons); frame.setResizable(false); frame.setTitle("OOB Flag Generator v" + VERSION); frame.setBounds(100, 100, 353, 334); @@ -206,14 +234,14 @@ private void initialize() { rdbtnWord.addActionListener(this); rdbtnWord.setBounds(241, 35, 83, 23); frame.getContentPane().add(rdbtnWord); - + rdbtnDword = new JRadioButton("DWORD"); btnGSize.add(rdbtnDword); rdbtnDword.setActionCommand(A_SIZE_DWORD); rdbtnDword.addActionListener(this); rdbtnDword.setBounds(241, 61, 109, 23); frame.getContentPane().add(rdbtnDword); - + btnUpdate = new JButton("Check for Updates"); btnUpdate.setActionCommand(A_UPDATE); btnUpdate.addActionListener(this); @@ -333,7 +361,7 @@ else if (btnGSize.isSelected(rdbtnDword.getModel())) break; } } - + public static void downloadFile(String url, File dest) throws IOException { URL site = new URL(url); try (InputStream siteIn = site.openStream(); @@ -342,7 +370,7 @@ public static void downloadFile(String url, File dest) throws IOException { out.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } } - + public static boolean browseTo(String url) throws URISyntaxException, IOException { URI dlSite = new URI(url); if (Desktop.isDesktopSupported()) diff --git a/src/main/java/com/leo/oobfg/icon.png b/src/main/resources/com/leo/oobfg/icon16.png similarity index 100% rename from src/main/java/com/leo/oobfg/icon.png rename to src/main/resources/com/leo/oobfg/icon16.png diff --git a/src/main/resources/com/leo/oobfg/icon32.png b/src/main/resources/com/leo/oobfg/icon32.png new file mode 100644 index 0000000..53b1fed Binary files /dev/null and b/src/main/resources/com/leo/oobfg/icon32.png differ diff --git a/src/main/resources/com/leo/oobfg/icon64.png b/src/main/resources/com/leo/oobfg/icon64.png new file mode 100644 index 0000000..8d3329e Binary files /dev/null and b/src/main/resources/com/leo/oobfg/icon64.png differ