diff --git a/src/main/java/dcccontroller/ErrorManager.java b/src/main/java/dcccontroller/ErrorManager.java new file mode 100644 index 0000000..36407ee --- /dev/null +++ b/src/main/java/dcccontroller/ErrorManager.java @@ -0,0 +1,12 @@ +package dcccontroller; + +import javax.swing.*; + +public class ErrorManager { + + static public void showErrorMessage(String title, String msg) { + SwingUtilities.invokeLater(() -> { + JOptionPane.showMessageDialog(null, msg, title, JOptionPane.ERROR_MESSAGE); + }); + } +} diff --git a/src/main/java/dcccontroller/configuration/ConfigurationManager.java b/src/main/java/dcccontroller/configuration/ConfigurationManager.java index e490253..a88ecfe 100644 --- a/src/main/java/dcccontroller/configuration/ConfigurationManager.java +++ b/src/main/java/dcccontroller/configuration/ConfigurationManager.java @@ -1,6 +1,7 @@ package dcccontroller.configuration; +import dcccontroller.ErrorManager; import dcccontroller.configuration.csv.CSVFileHandler; import dcccontroller.model.CPFunctionItem; import dcccontroller.util.Change; @@ -151,9 +152,7 @@ private HashMap mapRowValues(String line) { } private void showErrorMessage(Exception e) { - SwingUtilities.invokeLater(() -> { - JOptionPane.showMessageDialog(null, "Could not open file \n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); - }); + ErrorManager.showErrorMessage("Configuration Error", "Could not open file \n" + e.getMessage()); } private String createConfigName(File file) { diff --git a/src/main/java/dcccontroller/serial/SerialCommunicationHelper.java b/src/main/java/dcccontroller/serial/SerialCommunicationHelper.java index bd76b61..5f841ac 100644 --- a/src/main/java/dcccontroller/serial/SerialCommunicationHelper.java +++ b/src/main/java/dcccontroller/serial/SerialCommunicationHelper.java @@ -1,6 +1,7 @@ package dcccontroller.serial; import com.fazecast.jSerialComm.SerialPort; +import dcccontroller.ErrorManager; import dcccontroller.util.Change; import java.io.InputStream; @@ -121,7 +122,7 @@ private void sendMessage(String message) { } listenForMessages(3); } else { - System.out.println("Port busy!"); + ErrorManager.showErrorMessage("Connection Error", "Port busy!"); } }