001 /*
002 * Copyright 2002-2004 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy
006 * of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations
014 * under the License.
015 */
016 package org.springframework.richclient.components;
017
018 import java.io.PrintWriter;
019 import java.io.StringWriter;
020
021 import javax.swing.JComponent;
022 import javax.swing.JScrollPane;
023 import javax.swing.JTextArea;
024 import javax.swing.text.BadLocationException;
025
026 import org.springframework.richclient.factory.AbstractControlFactory;
027
028 /**
029 * A simple pane which can display an exception stack trace.
030 *
031 * @author Keith Donald
032 * @author Oliver Hutchison
033 */
034 public class ExceptionDetailsPane extends AbstractControlFactory {
035 private JTextArea exceptionDetails;
036
037 public void setException(Throwable t) {
038 createControlIfNecessary();
039 StringWriter writer = new StringWriter();
040 t.printStackTrace(new PrintWriter(writer));
041 exceptionDetails.setText(writer.toString());
042 exceptionDetails.setCaretPosition(0);
043 exceptionDetails.setSelectionStart(0);
044 exceptionDetails.setSelectionEnd(0);
045 try {
046 exceptionDetails.scrollRectToVisible(exceptionDetails.modelToView(0));
047 } catch(BadLocationException ex) {
048 }
049 }
050
051
052 /**
053 * @see org.springframework.richclient.factory.AbstractControlFactory#createControl()
054 */
055 protected JComponent createControl() {
056 exceptionDetails = new JTextArea();
057 exceptionDetails.setEditable(false);
058 exceptionDetails.setRows(10);
059 exceptionDetails.setColumns(80);
060 JScrollPane sp = new JScrollPane(exceptionDetails);
061 return sp;
062 }
063
064 }