001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.components;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Dimension;
023:
024: import javax.swing.BorderFactory;
025: import javax.swing.JLabel;
026: import javax.swing.JScrollPane;
027: import javax.swing.JTextArea;
028:
029: import com.jeta.open.gui.framework.JETAPanel;
030: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
031:
032: /**
033: * This class is used to display a exception. It provides a text area to display
034: * the exception information
035: *
036: * @author Jeff Tassin
037: */
038: public class TSErrorPanel2 extends JETAPanel {
039: private JLabel m_error_label;
040:
041: /**
042: * ctor
043: */
044: public TSErrorPanel2() {
045: }
046:
047: /**
048: * @return the preferred size for this panel
049: */
050: public Dimension getPreferredSize() {
051: return FormDesignerUtils.getWindowDimension(this , 210, 160);
052: }
053:
054: /**
055: * Initializes the panel with the given data.
056: *
057: * @param msg
058: * a message to include with the exception msg
059: * @param e
060: * the exception that was thrown. The error message of this
061: * exception will be displayed.
062: */
063: public void initialize(String msg, Throwable e) {
064: StringBuffer msgbuff = new StringBuffer();
065:
066: if (msg != null) {
067: msgbuff.append(msg);
068: msgbuff.append("\n");
069: }
070:
071: String errormsg = e.getLocalizedMessage();
072: if (errormsg == null || errormsg.length() == 0)
073: errormsg = e.getMessage();
074:
075: if (errormsg != null) {
076: int pos = errormsg.indexOf("Stack Trace");
077: if (pos >= 0)
078: errormsg = errormsg.substring(0, pos);
079: }
080:
081: if (msgbuff.length() > 0)
082: msgbuff.append('\n');
083:
084: msgbuff.append(e.getClass().getName());
085: msgbuff.append(": ");
086:
087: msgbuff.append(errormsg);
088: initialize(msgbuff.toString());
089: }
090:
091: /**
092: * Initializes the panel with the given data.
093: *
094: * @param msg
095: * a message to display
096: */
097: public void initialize(String msg) {
098: setLayout(new BorderLayout());
099:
100: JTextArea msgcomp = new JTextArea();
101: msgcomp.setEditable(false);
102: msgcomp.setLineWrap(true);
103: msgcomp.setWrapStyleWord(true);
104: msgcomp.setText(msg);
105: JScrollPane msgpane = new JScrollPane(msgcomp);
106:
107: add(msgpane, BorderLayout.CENTER);
108: setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
109: try {
110: msgcomp.setCaretPosition(0);
111: } catch (Exception e) {
112:
113: }
114: }
115:
116: /**
117: * Shows an error message 'title' with an error icon at top of panel
118: */
119: public void showErrorIcon(String msg) {
120: if (m_error_label == null) {
121: m_error_label = new JLabel(msg);
122: m_error_label.setIcon(javax.swing.UIManager
123: .getIcon("OptionPane.errorIcon"));
124: m_error_label.setBorder(javax.swing.BorderFactory
125: .createEmptyBorder(0, 0, 10, 0));
126: add(m_error_label, BorderLayout.NORTH);
127: } else {
128: m_error_label.setText(msg);
129: }
130: }
131:
132: }
|