From 045d822dbc08ef1b63d2f4b14f79c4f7b88eca2d Mon Sep 17 00:00:00 2001 From: mawenzy Date: Sat, 2 May 2020 11:28:34 +0200 Subject: [PATCH 1/2] Added catch for HeadlessException --- .../gui/profileselect/ProfileSelectWindow.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/amidst/gui/profileselect/ProfileSelectWindow.java b/src/main/java/amidst/gui/profileselect/ProfileSelectWindow.java index 61417f6ee..d189788f6 100644 --- a/src/main/java/amidst/gui/profileselect/ProfileSelectWindow.java +++ b/src/main/java/amidst/gui/profileselect/ProfileSelectWindow.java @@ -3,6 +3,7 @@ import java.awt.Font; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.HeadlessException; import java.io.IOException; import java.util.List; @@ -68,7 +69,17 @@ public ProfileSelectWindow( @CalledOnlyBy(AmidstThread.EDT) private JFrame createFrame() { - JFrame frame = new JFrame("Profile Selector"); + JFrame frame = null; + try { + frame = new JFrame("Profile Selector"); + } catch (HeadlessException e) { + String s = "Caught a HeadlessException.\n" + + "This exception is thrown when code that is dependent on a keyboard, " + + "display, or mouse is called in an environment that does not support a keyboard, display, or mouse.\n\n" + + "Some linux distros only come with openjdk headless preinstalled. Make sure java-1.8.0-openjdk is installed."; + AmidstLogger.error(e, s); + System.exit(1); + } frame.setIconImages(metadata.getIcons()); frame.getContentPane().setLayout(new MigLayout()); frame.add(createTitleLabel(), "h 20!,w :400:, growx, pushx, wrap"); From 6465801747bcd5d19d4407d76a262324c78079dd Mon Sep 17 00:00:00 2001 From: mawenzy Date: Sun, 3 May 2020 21:46:16 +0200 Subject: [PATCH 2/2] Moved headless check before the start of the application --- src/main/java/amidst/Amidst.java | 7 +++++++ .../gui/profileselect/ProfileSelectWindow.java | 13 +------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/amidst/Amidst.java b/src/main/java/amidst/Amidst.java index cb16b8f44..ded140065 100644 --- a/src/main/java/amidst/Amidst.java +++ b/src/main/java/amidst/Amidst.java @@ -1,5 +1,6 @@ package amidst; +import java.awt.GraphicsEnvironment; import java.nio.file.Path; import java.sql.Timestamp; import java.util.Date; @@ -80,6 +81,12 @@ private static void run(CommandLineParameters parameters, AmidstMetaData metadat logTimeAndProperties(); enableGraphicsAcceleration(); osxMenuProperties(); + if (GraphicsEnvironment.isHeadless()) { + String s = "Trying to run amidst in a headless environment that does not support a keyboard, display, or mouse.\n\n" + + "Some linux distros only come with openjdk headless preinstalled. Make sure java-1.8.0-openjdk is installed."; + AmidstLogger.crash(s); + System.exit(1); + } startApplication(parameters, metadata, createSettings()); } } diff --git a/src/main/java/amidst/gui/profileselect/ProfileSelectWindow.java b/src/main/java/amidst/gui/profileselect/ProfileSelectWindow.java index d189788f6..61417f6ee 100644 --- a/src/main/java/amidst/gui/profileselect/ProfileSelectWindow.java +++ b/src/main/java/amidst/gui/profileselect/ProfileSelectWindow.java @@ -3,7 +3,6 @@ import java.awt.Font; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.awt.HeadlessException; import java.io.IOException; import java.util.List; @@ -69,17 +68,7 @@ public ProfileSelectWindow( @CalledOnlyBy(AmidstThread.EDT) private JFrame createFrame() { - JFrame frame = null; - try { - frame = new JFrame("Profile Selector"); - } catch (HeadlessException e) { - String s = "Caught a HeadlessException.\n" - + "This exception is thrown when code that is dependent on a keyboard, " - + "display, or mouse is called in an environment that does not support a keyboard, display, or mouse.\n\n" - + "Some linux distros only come with openjdk headless preinstalled. Make sure java-1.8.0-openjdk is installed."; - AmidstLogger.error(e, s); - System.exit(1); - } + JFrame frame = new JFrame("Profile Selector"); frame.setIconImages(metadata.getIcons()); frame.getContentPane().setLayout(new MigLayout()); frame.add(createTitleLabel(), "h 20!,w :400:, growx, pushx, wrap");