diff --git a/src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java b/src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java index 2c81f6e5..c6cd563d 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java +++ b/src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java @@ -181,9 +181,10 @@ private static void setFrameLocationRespectingBounds( } public static void showMessageDialog( - @SuppressWarnings("exports") final Component parentComponent, final Object message) + final Main main, @SuppressWarnings("exports") final Component parentComponent, final Object message) throws HeadlessException { showMessageDialog( + main, parentComponent, message, UIManager.getString("OptionPane.messageDialogTitle", parentComponent.getLocale()), @@ -191,15 +192,17 @@ public static void showMessageDialog( } public static void showMessageDialog( + final Main main, @SuppressWarnings("exports") final Component parentComponent, final Object message, final String title, final int messageType) throws HeadlessException { - showMessageDialog(parentComponent, message, title, messageType, null); + showMessageDialog(main, parentComponent, message, title, messageType, null); } public static void showMessageDialog( + final Main main, @SuppressWarnings("exports") final Component parentComponent, final Object message, final String title, @@ -210,6 +213,10 @@ public static void showMessageDialog( return; } + if (main != null) { + main.show(); + } + JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon); } diff --git a/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java b/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java index 276f8cfb..1dc0fc55 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java +++ b/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java @@ -868,12 +868,14 @@ public void windowOpened(final WindowEvent e) { if (isWindows || isLinux) { GuiUtils.showMessageDialog( + this, frame, strings.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT"), strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); } else { GuiUtils.showMessageDialog( + this, frame, strings.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT_MAC"), strings.getString("ERROR_DIALOG_TITLE"), @@ -908,6 +910,7 @@ public void windowOpened(final WindowEvent e) { log.log(Level.WARNING, "An error occurred while updating the SDL game controller mappings"); GuiUtils.showMessageDialog( + this, frame, strings.getString("ERROR_UPDATING_GAME_CONTROLLER_DB_DIALOG_TEXT"), strings.getString("ERROR_DIALOG_TITLE"), @@ -972,12 +975,14 @@ public void windowOpened(final WindowEvent e) { if (noControllerConnected) { if (isWindows || isLinux) { GuiUtils.showMessageDialog( + this, frame, strings.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT"), strings.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE); } else { GuiUtils.showMessageDialog( + this, frame, strings.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT_MAC"), strings.getString("INFORMATION_DIALOG_TITLE"), @@ -996,6 +1001,17 @@ public void windowOpened(final WindowEvent e) { } } + boolean show() { + if (frame == null || frame.isVisible()) { + return false; + } + + frame.setVisible(true); + updateShowMenuItem(); + + return true; + } + private static void addGlueToSettingsPanel(final JPanel settingsPanel) { final var constraints = new GridBagConstraints( 0, @@ -1161,7 +1177,11 @@ public static void main(final String[] args) { scrollPane.setPreferredSize(new Dimension(600, 400)); panel.add(scrollPane, BorderLayout.CENTER); GuiUtils.showMessageDialog( - main.frame, panel, strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); + main, + main.frame, + panel, + strings.getString("ERROR_DIALOG_TITLE"), + JOptionPane.ERROR_MESSAGE); terminate(1); }); @@ -1288,6 +1308,7 @@ private static void printCommandLineMessage(final String message) { final var imageIcon = new ImageIcon(getResourceLocation(Main.ICON_RESOURCE_PATHS[2])); GuiUtils.showMessageDialog( + null, null, textArea, strings.getString("APPLICATION_NAME"), @@ -1464,6 +1485,7 @@ public void exportVisualization(final File file) { } catch (final DOMException | ParserConfigurationException | TransformerException | IOException e) { log.log(Level.SEVERE, e.getMessage(), e); GuiUtils.showMessageDialog( + main, frame, strings.getString("COULD_NOT_EXPORT_VISUALIZATION_DIALOG_TEXT"), strings.getString("ERROR_DIALOG_TITLE"), @@ -1619,6 +1641,7 @@ private void handleRemainingCommandLine(final CommandLine commandLine) { startServer(); } else { GuiUtils.showMessageDialog( + this, frame, MessageFormat.format( strings.getString("INVALID_VALUE_FOR_COMMAND_LINE_OPTION_AUTOSTART_DIALOG_TEXT"), @@ -1661,6 +1684,7 @@ private void initOpenVrOverlay() { log.log(Level.WARNING, t.getMessage(), t); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), Main.strings.getString("OPENVR_OVERLAY_INITIALIZATION_ERROR_DIALOG_TEXT"), Main.strings.getString("WARNING_DIALOG_TITLE"), @@ -1849,6 +1873,7 @@ private void loadProfile( if (!skipMessageDialogs) { GuiUtils.showMessageDialog( + main, frame, MessageFormat.format( strings.getString("PROFILE_VERSION_MISMATCH_DIALOG_TEXT"), @@ -1864,6 +1889,7 @@ private void loadProfile( if (!skipMessageDialogs) { GuiUtils.showMessageDialog( + main, frame, MessageFormat.format( strings.getString("PROFILE_VERSION_MISMATCH_DIALOG_TEXT"), @@ -1877,6 +1903,7 @@ private void loadProfile( if (!skipMessageDialogs) { GuiUtils.showMessageDialog( + main, frame, MessageFormat.format( strings.getString("PROFILE_VERSION_MISMATCH_DIALOG_TEXT"), @@ -1897,6 +1924,7 @@ private void loadProfile( if (!skipMessageDialogs) { GuiUtils.showMessageDialog( + main, frame, MessageFormat.format( strings.getString("UNKNOWN_ACTION_TYPES_DIALOG_TEXT"), @@ -1937,6 +1965,7 @@ private void loadProfile( if (!skipMessageDialogs) { GuiUtils.showMessageDialog( + main, frame, strings.getString("COULD_NOT_LOAD_PROFILE_DIALOG_TEXT"), strings.getString("ERROR_DIALOG_TITLE"), @@ -1971,6 +2000,7 @@ public void newActivation(final String[] args) { } } else { EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.frame, strings.getString("ALREADY_RUNNING_DIALOG_TEXT"), strings.getString("ERROR_DIALOG_TITLE"), @@ -2377,6 +2407,7 @@ private void saveProfile(File file, final boolean saveAsLastProfile) { } catch (final IOException e) { log.log(Level.SEVERE, e.getMessage(), e); GuiUtils.showMessageDialog( + main, frame, strings.getString("COULD_NOT_SAVE_PROFILE_DIALOG_TEXT"), strings.getString("ERROR_DIALOG_TITLE"), @@ -2714,6 +2745,7 @@ private boolean updateGameControllerMappingsFromFile(final String path) { log.log(Level.WARNING, "Could not read external game controller mappings file: " + path); GuiUtils.showMessageDialog( + main, frame, MessageFormat.format( strings.getString("COULD_NOT_READ_GAME_CONTROLLER_MAPPINGS_FILE_DIALOG_TEXT"), path), @@ -2727,6 +2759,7 @@ private boolean updateGameControllerMappingsFromFile(final String path) { log.log(Level.WARNING, "An error occurred while updating the SDL game controller mappings"); GuiUtils.showMessageDialog( + main, frame, strings.getString("ERROR_UPDATING_GAME_CONTROLLER_DB_DIALOG_TEXT"), strings.getString("ERROR_DIALOG_TITLE"), @@ -3848,6 +3881,7 @@ public void actionPerformed(final ActionEvent e) { vJoyDirectoryLabel.setText(vjoyPath); } else { GuiUtils.showMessageDialog( + main, frame, MessageFormat.format(strings.getString("INVALID_VJOY_DIRECTORY_DIALOG_TEXT"), defaultVJoyPath), strings.getString("ERROR_DIALOG_TITLE"), @@ -3977,17 +4011,13 @@ private OpenAction() { @Override protected void doAction() { - final var frameVisible = frame.isVisible(); - if (!frameVisible) { - frame.setVisible(true); - updateShowMenuItem(); - } + final var wasInvisible = show(); if (profileFileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { loadProfile(profileFileChooser.getSelectedFile(), false, true); } - if (!frameVisible) { + if (wasInvisible) { frame.setVisible(false); updateShowMenuItem(); } @@ -4251,6 +4281,7 @@ public void actionPerformed(final ActionEvent e) { final var imageIcon = new ImageIcon(getResourceLocation(Main.ICON_RESOURCE_PATHS[2])); GuiUtils.showMessageDialog( + main, frame, MessageFormat.format(strings.getString("ABOUT_DIALOG_TEXT"), Version.VERSION), (String) getValue(NAME), @@ -4298,7 +4329,8 @@ public void actionPerformed(final ActionEvent e) { textArea.setEditable(false); final var scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new Dimension(600, 400)); - GuiUtils.showMessageDialog(frame, scrollPane, (String) getValue(NAME), JOptionPane.DEFAULT_OPTION); + GuiUtils.showMessageDialog( + main, frame, scrollPane, (String) getValue(NAME), JOptionPane.DEFAULT_OPTION); } catch (final IOException e1) { throw new RuntimeException(e1); } diff --git a/src/main/java/de/bwravencl/controllerbuddy/runmode/ClientRunMode.java b/src/main/java/de/bwravencl/controllerbuddy/runmode/ClientRunMode.java index 1c1b8703..90910ba8 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/runmode/ClientRunMode.java +++ b/src/main/java/de/bwravencl/controllerbuddy/runmode/ClientRunMode.java @@ -121,6 +121,7 @@ boolean readInput() throws IOException { "Protocol version mismatch: client " + ServerRunMode.PROTOCOL_VERSION + " vs server " + serverProtocolVersion); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("PROTOCOL_VERSION_MISMATCH_DIALOG_TEXT"), @@ -162,6 +163,7 @@ boolean readInput() throws IOException { if (retry != -1 && !Thread.currentThread().isInterrupted()) { log.log(Level.INFO, "Could not connect after " + N_CONNECTION_RETRIES + " retries"); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("COULD_NOT_CONNECT_DIALOG_TEXT"), @@ -288,6 +290,7 @@ boolean readInput() throws IOException { } catch (final SocketTimeoutException e) { log.log(Level.FINE, e.getMessage(), e); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), Main.strings.getString("CONNECTION_LOST_DIALOG_TEXT"), Main.strings.getString("ERROR_DIALOG_TITLE"), @@ -346,6 +349,7 @@ public void run() { log.log(Level.INFO, "Could not resolve host: " + host); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format(Main.strings.getString("INVALID_HOST_ADDRESS_DIALOG_TEXT"), host), Main.strings.getString("ERROR_DIALOG_TITLE"), diff --git a/src/main/java/de/bwravencl/controllerbuddy/runmode/OutputRunMode.java b/src/main/java/de/bwravencl/controllerbuddy/runmode/OutputRunMode.java index 269a495e..b8df2b2c 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/runmode/OutputRunMode.java +++ b/src/main/java/de/bwravencl/controllerbuddy/runmode/OutputRunMode.java @@ -437,6 +437,7 @@ private boolean enoughButtons(final int nButtons) { if (Main.isWindows) { log.log(Level.WARNING, "vJoy device has not enough buttons"); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("TOO_FEW_VJOY_BUTTONS_DIALOG_TEXT"), @@ -448,6 +449,7 @@ private boolean enoughButtons(final int nButtons) { } else if (Main.isLinux) { log.log(Level.WARNING, "uinput device has not enough buttons"); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("TOO_FEW_UINPUT_BUTTONS_DIALOG_TEXT"), @@ -470,6 +472,7 @@ final void handleIOException(final IOException ioException) { log.log(Level.SEVERE, ioException.getMessage(), ioException); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), Main.strings.getString("GENERAL_INPUT_OUTPUT_ERROR_DIALOG_TEXT"), Main.strings.getString("ERROR_DIALOG_TITLE"), @@ -491,6 +494,7 @@ final boolean init() { if (!vJoy.vJoyEnabled().booleanValue()) { log.log(Level.WARNING, "vJoy driver is not enabled"); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), Main.strings.getString("VJOY_DRIVER_NOT_ENABLED_DIALOG_TEXT"), Main.strings.getString("ERROR_DIALOG_TITLE"), @@ -505,6 +509,7 @@ final boolean init() { Level.WARNING, "vJoy DLL version " + dllVersion + " does not match driver version " + drvVersion); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("VJOY_VERSION_MISMATCH_DIALOG_TEXT"), @@ -520,6 +525,7 @@ final boolean init() { if (vJoy.GetVJDStatus(vJoyDevice) != VjoyInterface.VJD_STAT_FREE) { log.log(Level.WARNING, "vJoy device is not available"); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("INVALID_VJOY_DEVICE_STATUS_DIALOG_TEXT"), @@ -582,6 +588,7 @@ final boolean init() { final var missingAxesString = String.join(", ", missingAxes); log.log(Level.WARNING, "vJoy device is missing the following axes: " + missingAxesString); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("MISSING_AXES_DIALOG_TEXT"), @@ -595,6 +602,7 @@ final boolean init() { if (!vJoy.AcquireVJD(vJoyDevice).booleanValue()) { log.log(Level.WARNING, "Could not acquire vJoy device"); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("COULD_NOT_ACQUIRE_VJOY_DEVICE_DIALOG_TEXT"), @@ -607,6 +615,7 @@ final boolean init() { if (!vJoy.ResetVJD(vJoyDevice).booleanValue()) { log.log(Level.WARNING, "Could not reset vJoy device"); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format( Main.strings.getString("COULD_NOT_RESET_VJOY_DEVICE_DIALOG_TEXT"), @@ -639,6 +648,7 @@ final boolean init() { } catch (final UnsatisfiedLinkError e) { log.log(Level.SEVERE, e.getMessage(), e); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), Main.strings.getString("COULD_NOT_LOAD_VJOY_LIBRARY_DIALOG_TEXT"), Main.strings.getString("ERROR_DIALOG_TITLE"), @@ -700,6 +710,7 @@ final boolean init() { log.log(Level.WARNING, t.getMessage(), t); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), Main.strings.getString("COULD_NOT_OPEN_UINPUT_DEVICE_DIALOG_TEXT"), Main.strings.getString("ERROR_DIALOG_TITLE"), diff --git a/src/main/java/de/bwravencl/controllerbuddy/runmode/RunMode.java b/src/main/java/de/bwravencl/controllerbuddy/runmode/RunMode.java index f4bc8f95..50711f75 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/runmode/RunMode.java +++ b/src/main/java/de/bwravencl/controllerbuddy/runmode/RunMode.java @@ -51,6 +51,7 @@ final void controllerDisconnected() { log.log(Level.WARNING, Main.assembleControllerLoggingMessage("Could not read from", input.getController())); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), Main.strings.getString("COULD_NOT_READ_FROM_CONTROLLER_DIALOG_TEXT"), Main.strings.getString("ERROR_DIALOG_TITLE"), diff --git a/src/main/java/de/bwravencl/controllerbuddy/runmode/ServerRunMode.java b/src/main/java/de/bwravencl/controllerbuddy/runmode/ServerRunMode.java index 7f589e15..be799b65 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/runmode/ServerRunMode.java +++ b/src/main/java/de/bwravencl/controllerbuddy/runmode/ServerRunMode.java @@ -217,6 +217,7 @@ public void run() { } catch (final BindException e) { log.log(Level.WARNING, "Could not bind socket on port " + port); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), MessageFormat.format(Main.strings.getString("COULD_NOT_OPEN_SOCKET_DIALOG_TEXT"), port), Main.strings.getString("ERROR_DIALOG_TITLE"), @@ -226,6 +227,7 @@ public void run() { } catch (final IOException e) { log.log(Level.SEVERE, e.getMessage(), e); EventQueue.invokeLater(() -> GuiUtils.showMessageDialog( + main, main.getFrame(), Main.strings.getString("GENERAL_INPUT_OUTPUT_ERROR_DIALOG_TEXT"), Main.strings.getString("ERROR_DIALOG_TITLE"),