diff --git a/src/main/java/net/nikr/eve/jeveasset/LibraryManager.java b/src/main/java/net/nikr/eve/jeveasset/LibraryManager.java index 495dfb875f..a419d149d5 100644 --- a/src/main/java/net/nikr/eve/jeveasset/LibraryManager.java +++ b/src/main/java/net/nikr/eve/jeveasset/LibraryManager.java @@ -77,7 +77,7 @@ private static void checkMissing() { } } if (temp && missing) { //Running from zip file... - JOptionPane.showMessageDialog(null, "You need to unzip jEveAssets to run it\r\nIt will not work from inside the zip file", "Critical Error", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(Main.getTop(), "You need to unzip jEveAssets to run it\r\nIt will not work from inside the zip file", Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } else if (missing) { //Missing libraries Updater updater = new Updater(); diff --git a/src/main/java/net/nikr/eve/jeveasset/Main.java b/src/main/java/net/nikr/eve/jeveasset/Main.java index b3a59db544..e2c74f4332 100644 --- a/src/main/java/net/nikr/eve/jeveasset/Main.java +++ b/src/main/java/net/nikr/eve/jeveasset/Main.java @@ -25,12 +25,14 @@ import java.net.URISyntaxException; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.JDialog; import net.nikr.eve.jeveasset.io.local.FileLock; import net.nikr.eve.jeveasset.io.online.Updater; import org.slf4j.bridge.SLF4JBridgeHandler; public final class Main { + private static JDialog top; private static boolean debug = false; private static boolean portable = false; private static boolean forceNoUpdate = false; @@ -84,6 +86,14 @@ public static boolean isJmemory() { return jmemory; } + public static JDialog getTop() { + if (top == null) { + top = new JDialog(); + top.setAlwaysOnTop(true); + } + return top; + } + /** * Entry point for jEveAssets. * diff --git a/src/main/java/net/nikr/eve/jeveasset/NikrUncaughtExceptionHandler.java b/src/main/java/net/nikr/eve/jeveasset/NikrUncaughtExceptionHandler.java index 15764c0b85..00f484b9d1 100644 --- a/src/main/java/net/nikr/eve/jeveasset/NikrUncaughtExceptionHandler.java +++ b/src/main/java/net/nikr/eve/jeveasset/NikrUncaughtExceptionHandler.java @@ -83,7 +83,7 @@ private void reportError(String s, Throwable t) { error = false; return; } else if (causes.contains(UnsupportedClassVersionError.class)) { //Old Java - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), "Please update Java to the latest version.\r\n" + "The minimum supported version is " + JAVA + "\r\n" + "\r\n" @@ -92,7 +92,7 @@ private void reportError(String s, Throwable t) { + "\r\n" , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); } else if (causes.contains(OutOfMemoryError.class)) { //Out of memory - int value = JOptionPane.showConfirmDialog(null, + int value = JOptionPane.showConfirmDialog(Main.getTop(), "Java has run out of memory. jEveAssets will now close\r\n" + "Do you want to browse to the wiki article explaining how to fix this?\r\n" + "\r\n" @@ -109,7 +109,7 @@ private void reportError(String s, Throwable t) { Updater updater = new Updater(); updater.fixMissingClasses(); } catch (Throwable ex) { //Better safe than sorry... - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + "Press OK to close jEveAssets" , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); @@ -120,7 +120,7 @@ private void reportError(String s, Throwable t) { System.out.println("ERROR: Your version of java does not support a GUI"); System.out.println(" Please, install in non-headless version of " + JAVA + " (or later) to run jEveAssets"); try { - JOptionPane.showMessageDialog(null, "Your version of java does not support a GUI\r\n" + JOptionPane.showMessageDialog(Main.getTop(), "Your version of java does not support a GUI\r\n" + "Please, install in non-headless version of " + JAVA + " (or later) to run jEveAssets", Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); @@ -129,7 +129,7 @@ private void reportError(String s, Throwable t) { } } else { //Bug if (isJavaBug(t)) { //Java Bug - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), "You have encountered a bug that is most likely a java bug.\r\n" + "Updating to the latest version of java may fix this problem.\r\n" + "It's still very helpful to send the the bug report.\r\n" @@ -139,7 +139,7 @@ private void reportError(String s, Throwable t) { + "\r\n" , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); } - int value = JOptionPane.showConfirmDialog(null, + int value = JOptionPane.showConfirmDialog(Main.getTop(), "Send bug report?\r\n" + "\r\n" + "Data send and saved:\r\n" @@ -153,7 +153,7 @@ private void reportError(String s, Throwable t) { , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (value == JOptionPane.OK_OPTION) { String result = send(t); - JOptionPane.showMessageDialog(null, result, "Bug Report", JOptionPane.PLAIN_MESSAGE); + JOptionPane.showMessageDialog(Main.getTop(), result, "Bug Report", JOptionPane.PLAIN_MESSAGE); } } System.exit(-1); diff --git a/src/main/java/net/nikr/eve/jeveasset/SingleInstance.java b/src/main/java/net/nikr/eve/jeveasset/SingleInstance.java index fb51f25910..94c9684978 100644 --- a/src/main/java/net/nikr/eve/jeveasset/SingleInstance.java +++ b/src/main/java/net/nikr/eve/jeveasset/SingleInstance.java @@ -55,7 +55,7 @@ public boolean isSingleInstance() { private void test() { if (!msgShown && findExisting()) { msgShown = true; - int value = JOptionPane.showConfirmDialog(null, General.get().singleInstanceMsg(), General.get().singleInstanceTitle(), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + int value = JOptionPane.showConfirmDialog(Main.getTop(), General.get().singleInstanceMsg(), General.get().singleInstanceTitle(), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (value != JOptionPane.YES_OPTION) { System.exit(0); } diff --git a/src/main/java/net/nikr/eve/jeveasset/io/online/Updater.java b/src/main/java/net/nikr/eve/jeveasset/io/online/Updater.java index 6607b01c5a..454140646a 100644 --- a/src/main/java/net/nikr/eve/jeveasset/io/online/Updater.java +++ b/src/main/java/net/nikr/eve/jeveasset/io/online/Updater.java @@ -40,6 +40,7 @@ import java.util.logging.Logger; import javax.swing.JOptionPane; import net.nikr.eve.jeveasset.Main; +import net.nikr.eve.jeveasset.Program; import net.nikr.eve.jeveasset.data.settings.ProxyData; import net.nikr.eve.jeveasset.io.shared.FileUtil; @@ -93,19 +94,19 @@ public boolean checkDataUpdate(String localData) { public void fixData() { if (isPackageManager()) { - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), "One of the data files in the data folder is corrupted or missing\r\n" + "jEveAssets will not work without it\r\n" + "Please use your package manager to correct the problem\r\n" - , "jEveAssets - Critical Error", JOptionPane.ERROR_MESSAGE); + , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } - int value = JOptionPane.showConfirmDialog(null, + int value = JOptionPane.showConfirmDialog(Main.getTop(), "One of the data files in the data folder is corrupted or missing\r\n" + "jEveAssets will not work without it\r\n" + "Download the latest version with auto update?\r\n" , - "jEveAssets - Critical Error", + Program.PROGRAM_NAME + " - Critical Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (value == JOptionPane.OK_OPTION) { LOG.info("Updating data"); @@ -113,18 +114,18 @@ public void fixData() { if (download) { runUpdate(DATA, null); } else { - JOptionPane.showMessageDialog(null, "Auto update failed\r\n" + JOptionPane.showMessageDialog(Main.getTop(), "Auto update failed\r\n" + "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + "Press OK to close jEveAssets", - "jEveAssets - Critical Error", + Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } } else { - JOptionPane.showMessageDialog(null, "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + JOptionPane.showMessageDialog(Main.getTop(), "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + "Restart jEveAssets to use auto update to fix the problem\r\n" + "Press OK to close jEveAssets", - "jEveAssets - Critical Error", + Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } @@ -132,19 +133,19 @@ public void fixData() { public void fixLibs() { if (isPackageManager()) { - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), "One of the libraies in the lib folder is corrupted or missing\r\n" + "jEveAssets will not work without it\r\n" + "Please use your package manager to correct the problem\r\n" - , "jEveAssets - Critical Error", JOptionPane.ERROR_MESSAGE); + , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } - int value = JOptionPane.showConfirmDialog(null, + int value = JOptionPane.showConfirmDialog(Main.getTop(), "One of the libraies in the lib folder is corrupted or missing\r\n" + "jEveAssets will not work without it\r\n" + "Download the latest version with auto update?\r\n" , - "jEveAssets - Critical Error", + Program.PROGRAM_NAME + " - Critical Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (value == JOptionPane.OK_OPTION) { LOG.info("Updating program"); @@ -152,18 +153,18 @@ public void fixLibs() { if (download) { runUpdate(PROGRAM, null); } else { - JOptionPane.showMessageDialog(null, "Auto update failed\r\n" + JOptionPane.showMessageDialog(Main.getTop(), "Auto update failed\r\n" + "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + "Press OK to close jEveAssets", - "jEveAssets - Critical Error", + Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } } else { - JOptionPane.showMessageDialog(null, "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + JOptionPane.showMessageDialog(Main.getTop(), "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + "Restart jEveAssets to use auto update to fix the problem\r\n" + "Press OK to close jEveAssets", - "jEveAssets - Critical Error", + Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } @@ -171,36 +172,36 @@ public void fixLibs() { public void fixMissingClasses() { if (isPackageManager()) { - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), "jEveAssets have been corrupted\r\n" + "Please use your package manager to correct the problem\r\n" - , "jEveAssets - Critical Error", JOptionPane.ERROR_MESSAGE); + , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } - int value = JOptionPane.showConfirmDialog(null, + int value = JOptionPane.showConfirmDialog(Main.getTop(), "jEveAssets have been corrupted\r\n" + "You may be able to use auto update to fix the problem\r\n" + "Download the latest version with auto update?\r\n" - , "jEveAssets - Critical Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); + , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (value == JOptionPane.OK_OPTION) { LOG.info("Updating program"); boolean download = downloadUpdater(); if (download) { runUpdate(PROGRAM, null); } else { - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), "Auto update failed\r\n" + "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + "Press OK to close jEveAssets" - , "jEveAssets - Critical Error", JOptionPane.ERROR_MESSAGE); + , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } } else { - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), "Please, re-download jEveAssets and leave the unzipped directory intact\r\n" + "Restart jEveAssets to use auto update to fix the problem\r\n" + "Press OK to close jEveAssets" - , "jEveAssets - Critical Error", JOptionPane.ERROR_MESSAGE); + , Program.PROGRAM_NAME + " - Critical Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } } @@ -214,7 +215,7 @@ private void update(String title, String online, String local, String link, Prox LOG.log(Level.INFO, "{0} Online: {1} Local: {2}", new Object[]{title.toUpperCase(), online, local}); if (online != null && !online.equals(local)) { if (isPackageManager()) { - JOptionPane.showMessageDialog(null, + JOptionPane.showMessageDialog(Main.getTop(), title + " update available\r\n" + "\r\n" + "Your version: " + local + "\r\n" @@ -223,11 +224,11 @@ private void update(String title, String online, String local, String link, Prox + "Please use your package manager to update\r\n" + "\r\n" , - "jEveAssets - Auto Update", + Program.PROGRAM_NAME + " - Auto Update", JOptionPane.PLAIN_MESSAGE); return; } - int value = JOptionPane.showConfirmDialog(null, + int value = JOptionPane.showConfirmDialog(Main.getTop(), title + " update available\r\n" + "\r\n" + "Your version: " + local + "\r\n" @@ -236,7 +237,7 @@ private void update(String title, String online, String local, String link, Prox + "Update " + title.toLowerCase() + " now?\r\n" + "\r\n" , - "jEveAssets - Auto Update", + Program.PROGRAM_NAME + " - Auto Update", JOptionPane.OK_CANCEL_OPTION); if (value == JOptionPane.OK_OPTION) { LOG.log(Level.INFO, "Updating {0}", title); @@ -244,7 +245,7 @@ private void update(String title, String online, String local, String link, Prox if (download) { runUpdate(link, proxyData); } else { - JOptionPane.showMessageDialog(null, "Auto update failed\r\n" + JOptionPane.showMessageDialog(Main.getTop(), "Auto update failed\r\n" + "Restart jEveAssets to try again...", "jEveAssets - Auto Update", JOptionPane.ERROR_MESSAGE); @@ -270,7 +271,7 @@ private File getJavaHome() { } private List getArgsString(String link, ProxyData proxyData) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add("java"); if (proxyData != null) { list.addAll(proxyData.getArgs());