X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fgui%2Fdialog%2FExceptionDialog.java;h=766a5f9c3d58feb192ba2ce7deb507c6b60e3adc;hb=443c6a564efa9f5868fd81c0db23a480cbe3cab4;hp=a80e6e3688408318ede3922ac9654b8b59f8975b;hpb=26f09b1ebcafae67855b55ad588d5332a107d202;p=svjatoslav_commons.git 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 a80e6e3..766a5f9 100755 --- a/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java +++ b/src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java @@ -1,106 +1,102 @@ /* * Svjatoslav Commons - shared library of common functionality. - * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. + * modify it under the terms of version 3 of the GNU Lesser General Public License + * or later as published by the Free Software Foundation. */ 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 { - 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(); - - } - - /** - * This method is for testing - */ - 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); + } + + /** + * 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(); + + } }