Skip to content

Commit

Permalink
Code: Show critical JOptionPane messages always on top
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenGnu committed Dec 3, 2021
1 parent f72bd0b commit d0fb5b8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/nikr/eve/jeveasset/LibraryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/nikr/eve/jeveasset/SingleInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
61 changes: 31 additions & 30 deletions src/main/java/net/nikr/eve/jeveasset/io/online/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -93,114 +94,114 @@ 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");
boolean download = downloadUpdater();
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);
}
}

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");
boolean download = downloadUpdater();
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);
}
}

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);
}
}
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -236,15 +237,15 @@ 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);
boolean download = downloadUpdater();
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);
Expand All @@ -270,7 +271,7 @@ private File getJavaHome() {
}

private List<String> getArgsString(String link, ProxyData proxyData) {
List<String> list = new ArrayList<String>();
List<String> list = new ArrayList<>();
list.add("java");
if (proxyData != null) {
list.addAll(proxyData.getArgs());
Expand Down

0 comments on commit d0fb5b8

Please sign in to comment.