Package com.cedarsoft.spring.rcp.dialog

Source Code of com.cedarsoft.spring.rcp.dialog.ExceptionDialog

package com.cedarsoft.spring.rcp.dialog;

import com.jidesoft.swing.StyleRange;
import com.jidesoft.swing.StyledLabel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.richclient.dialog.ApplicationDialog;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Window;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
* Shows an exception
*/
public class ExceptionDialog extends ApplicationDialog {
  @NotNull
  private final Throwable cause;

  public ExceptionDialog( @NotNull Throwable cause, @Nullable Window parentWindow ) {
    super( "", parentWindow );
    setTitle( getMessage( "exception.dialog.title" ) );
    this.cause = cause;
  }

  @Override
  protected JComponent createDialogContentPane() {
    JPanel panel = getComponentFactory().createPanel( new BorderLayout() );

    StringWriter out = new StringWriter();
    cause.printStackTrace( new PrintWriter( out ) );

    JTextArea textArea = getComponentFactory().createTextArea();
    textArea.setText( out.toString() );

    panel.add( getComponentFactory().createScrollPane( textArea ), BorderLayout.CENTER );

    StyledLabel label = new StyledLabel( cause.getMessage() );
    label.addStyleRange( new StyleRange( Font.BOLD ) );
    panel.add( new JLabel( cause.getMessage() ), BorderLayout.NORTH );

    return panel;
  }

  @Override
  protected boolean onFinish() {
    return true;
  }
}
TOP

Related Classes of com.cedarsoft.spring.rcp.dialog.ExceptionDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.