X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=svjatoslav_commons.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fgui%2Fdialog%2FExceptionDialog.java;h=d4bf2f599179996f7198397d9bbfe177f29593b7;hp=24ba80e87f0e7376f0a74f4ce9cc76bccd41597e;hb=9bf004ce4e9b5edff36c65fcc8cc0f303390d7fc;hpb=afaa928dd10304ee3e8e6bad3a377ced6a7b2f42 diff --git a/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java b/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java index 24ba80e..d4bf2f5 100755 --- a/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java +++ b/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java @@ -9,101 +9,94 @@ 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(); + + } }