Code cleanup and formatting. Migrated to java 1.8.
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / gui / dialog / ExceptionDialog.java
index 24ba80e..d4bf2f5 100755 (executable)
 
 package eu.svjatoslav.commons.gui.dialog;
 
-import java.awt.BorderLayout;
-import java.awt.TextArea;
-
-import javax.swing.BoxLayout;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
+import javax.swing.*;
+import java.awt.*;
 
 public class ExceptionDialog {
 
-       /**
-        * This method is for testing
-        * 
-        * @param args
-        *            commandline arguments
-        */
-       public static void main(final String[] args) {
-
-               final Throwable cause = new Throwable("details.....");
-
-               final Exception exception = new Exception("test", cause);
-
-               new ExceptionDialog(exception);
-       }
-
-       public ExceptionDialog(final Exception exception) {
-               showException(exception);
-       }
-
-       /**
-        * @param exception
-        *            exception to show
-        */
-       public void showException(final Exception exception) {
-
-               final JFrame frame = new JFrame("Exception occured!");
-               final JPanel contentPanel = new JPanel(new BorderLayout());
-               final Throwable cause = exception.getCause();
-
-               // build top panel
-               {
-                       final JPanel topPanel = new JPanel();
-                       topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
-
-                       // add exception type
-                       final JLabel exceptionType = new JLabel("Exception type: "
-                                       + exception.getClass().getCanonicalName());
-                       topPanel.add(exceptionType);
-
-                       // add error message
-                       final JLabel message = new JLabel("Error message: "
-                                       + exception.getMessage());
-                       topPanel.add(message);
-
-                       // add cause message
-                       if (cause != null)
-                               if (cause.getMessage() != null) {
-                                       final JLabel message2 = new JLabel("Cause: "
-                                                       + cause.getMessage());
-                                       topPanel.add(message2);
-                               }
-
-                       contentPanel.add(topPanel, BorderLayout.NORTH);
-               }
-
-               // build stack trace view
-               {
-                       final StringBuffer buffer = new StringBuffer();
-
-                       // if cause is available, show original stack trace
-                       if (cause != null) {
-                               buffer.append("Stack trace:\n");
-                               final StackTraceElement[] stackTrace = cause.getStackTrace();
-                               for (final StackTraceElement stackTraceElement : stackTrace)
-                                       buffer.append(stackTraceElement.toString() + "\n");
-                       } else {
-                               // otherwise show at least current stack trace
-                               buffer.append("Stack trace from original cause is not available.\nShowing current stack trace instead:\n");
-
-                               for (final StackTraceElement stackTraceElement : new Exception(
-                                               "Stack trace").getStackTrace())
-                                       buffer.append(stackTraceElement.toString() + "\n");
-                       }
-
-                       final TextArea textArea = new TextArea(buffer.toString());
-                       contentPanel.add(textArea, BorderLayout.CENTER);
-               }
-
-               // finalize frame
-               frame.getContentPane().add(contentPanel);
-               frame.setSize(800, 600);
-               frame.setVisible(true);
-
-               // Thread.dumpStack();
-
-       }
+    public ExceptionDialog(final Exception exception) {
+        showException(exception);
+    }
+
+    /**
+     * This method is for testing
+     *
+     * @param args commandline arguments
+     */
+    public static void main(final String[] args) {
+
+        final Throwable cause = new Throwable("details.....");
+
+        final Exception exception = new Exception("test", cause);
+
+        new ExceptionDialog(exception);
+    }
+
+    /**
+     * @param exception exception to show
+     */
+    public void showException(final Exception exception) {
+
+        final JFrame frame = new JFrame("Exception occurred!");
+        final JPanel contentPanel = new JPanel(new BorderLayout());
+        final Throwable cause = exception.getCause();
+
+        // build top panel
+        {
+            final JPanel topPanel = new JPanel();
+            topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
+
+            // add exception type
+            final JLabel exceptionType = new JLabel("Exception type: "
+                    + exception.getClass().getCanonicalName());
+            topPanel.add(exceptionType);
+
+            // add error message
+            final JLabel message = new JLabel("Error message: "
+                    + exception.getMessage());
+            topPanel.add(message);
+
+            // add cause message
+            if (cause != null)
+                if (cause.getMessage() != null) {
+                    final JLabel message2 = new JLabel("Cause: "
+                            + cause.getMessage());
+                    topPanel.add(message2);
+                }
+
+            contentPanel.add(topPanel, BorderLayout.NORTH);
+        }
+
+        // build stack trace view
+        {
+            final StringBuilder buffer = new StringBuilder();
+
+            // if cause is available, show original stack trace
+            if (cause != null) {
+                buffer.append("Stack trace:\n");
+                final StackTraceElement[] stackTrace = cause.getStackTrace();
+                for (final StackTraceElement stackTraceElement : stackTrace)
+                    buffer.append(stackTraceElement.toString() + "\n");
+            } else {
+                // otherwise show at least current stack trace
+                buffer.append("Stack trace from original cause is not available.\nShowing current stack trace instead:\n");
+
+                for (final StackTraceElement stackTraceElement : new Exception(
+                        "Stack trace").getStackTrace())
+                    buffer.append(stackTraceElement.toString() + "\n");
+            }
+
+            final TextArea textArea = new TextArea(buffer.toString());
+            contentPanel.add(textArea, BorderLayout.CENTER);
+        }
+
+        // finalize frame
+        frame.getContentPane().add(contentPanel);
+        frame.setSize(800, 600);
+        frame.setVisible(true);
+
+        // Thread.dumpStack();
+
+    }
 
 }