001: package net.sf.memoranda.ui;
002:
003: import java.awt.*;
004: import javax.swing.*;
005: import java.awt.event.*;
006: import java.io.*;
007: import net.sf.memoranda.util.*;
008:
009: /*$Id: ExceptionDialog.java,v 1.2 2004/10/18 19:09:10 ivanrise Exp $*/
010: public class ExceptionDialog extends JDialog {
011: JPanel panel1 = new JPanel();
012: BorderLayout borderLayout1 = new BorderLayout();
013: private JPanel jPanel1 = new JPanel();
014: private JLabel jLabel1 = new JLabel();
015: private JPanel jPanel2 = new JPanel();
016: private JLabel jLabel2 = new JLabel();
017: private BorderLayout borderLayout2 = new BorderLayout();
018: private BorderLayout borderLayout3 = new BorderLayout();
019: private JLabel descLabel = new JLabel();
020:
021: private String description;
022: private String tip;
023: private String trace;
024: private JPanel jPanel3 = new JPanel();
025: private JScrollPane jScrollPane1 = new JScrollPane();
026: private JTextArea traceTextArea = new JTextArea();
027: private JButton reportB = new JButton();
028: private JButton closeB = new JButton();
029: private FlowLayout flowLayout1 = new FlowLayout();
030: private JPanel jPanel4 = new JPanel();
031: private JButton copyB = new JButton();
032: private BorderLayout borderLayout4 = new BorderLayout();
033:
034: private Frame owner;
035:
036: public ExceptionDialog(Exception exc, String description, String tip) {
037: super (App.getFrame(), "Problem", true);
038: exc.printStackTrace();
039: owner = App.getFrame();
040: if ((description != null) && (description.length() > 0))
041: this .description = description;
042: else if (exc.getMessage() != null)
043: this .description = exc.getMessage();
044: else
045: this .description = "Unknown error";
046: this .tip = tip;
047: StringWriter sw = new StringWriter();
048: exc.printStackTrace(new PrintWriter(sw));
049: this .trace = sw.toString();
050: try {
051: jbInit();
052: setVisible(true);
053: } catch (Exception ex) {
054: ex.printStackTrace();
055: }
056: }
057:
058: public ExceptionDialog(Exception exc) {
059: this (exc, "", "");
060: }
061:
062: public ExceptionDialog() {
063: this (null, "", "");
064: }
065:
066: private void jbInit() throws Exception {
067: panel1.setLayout(borderLayout1);
068: jPanel1.setBackground(Color.white);
069: jPanel1.setLayout(borderLayout3);
070: jLabel1.setFont(new java.awt.Font("Dialog", 1, 16));
071: jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
072: jLabel1.setHorizontalTextPosition(SwingConstants.RIGHT);
073: jLabel1.setText("Problem occured");
074: jLabel1.setIcon(new ImageIcon(
075: net.sf.memoranda.ui.ExceptionDialog.class
076: .getResource("resources/icons/error.png")));
077:
078: jLabel2.setFont(new java.awt.Font("Dialog", 0, 11));
079: jLabel2
080: .setText("<html>An internal exception occured. It is may be a result of bug in the "
081: + "program, corrupted data, incorrect configuration or hardware failure.<br><br>"
082: + "Click on <b>Report bug..</b> button to submit a bug to the Memoranda bugs tracker on SourceForge.net </html>");
083: jPanel2.setLayout(borderLayout2);
084: jPanel2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
085: borderLayout3.setVgap(5);
086: String labelText = "<html><b>Description:</b><br>"
087: + description;
088: if ((tip != null) && (tip.length() > 0))
089: labelText = labelText + "<br><br><b>Tip:</b><br>" + tip;
090: labelText = labelText + "<br><br><b>Stack trace:</b></html>";
091: descLabel.setText(labelText);
092: descLabel.setFont(new java.awt.Font("Dialog", 0, 12));
093: jScrollPane1.setEnabled(false);
094: reportB.setMaximumSize(new Dimension(120, 25));
095: reportB.setMinimumSize(new Dimension(120, 25));
096: reportB.setPreferredSize(new Dimension(120, 25));
097: reportB.setText("Report bug...");
098: reportB.addActionListener(new java.awt.event.ActionListener() {
099: public void actionPerformed(ActionEvent e) {
100: reportB_actionPerformed(e);
101: }
102: });
103: closeB.setMaximumSize(new Dimension(120, 25));
104: closeB.setMinimumSize(new Dimension(120, 25));
105: closeB.setPreferredSize(new Dimension(120, 25));
106: closeB.setText("Close");
107: closeB.addActionListener(new java.awt.event.ActionListener() {
108: public void actionPerformed(ActionEvent e) {
109: closeB_actionPerformed(e);
110: }
111: });
112: this .getRootPane().setDefaultButton(closeB);
113: jPanel3.setLayout(flowLayout1);
114: flowLayout1.setAlignment(FlowLayout.RIGHT);
115: copyB.setText("Copy to clipboard");
116: copyB.addActionListener(new java.awt.event.ActionListener() {
117: public void actionPerformed(ActionEvent e) {
118: copyB_actionPerformed(e);
119: }
120: });
121: copyB.setHorizontalAlignment(SwingConstants.RIGHT);
122: jPanel4.setLayout(borderLayout4);
123: traceTextArea.setText(trace);
124: traceTextArea.setEditable(false);
125: borderLayout1.setVgap(5);
126: getContentPane().add(panel1);
127: panel1.add(jPanel1, BorderLayout.NORTH);
128: jPanel1.add(jLabel1, BorderLayout.NORTH);
129: jPanel1.add(jLabel2, BorderLayout.CENTER);
130: panel1.add(jPanel2, BorderLayout.CENTER);
131: jPanel2.add(descLabel, BorderLayout.NORTH);
132: jPanel2.add(jScrollPane1, BorderLayout.CENTER);
133: jPanel2.add(jPanel4, BorderLayout.SOUTH);
134: jPanel4.add(copyB, BorderLayout.WEST);
135: jScrollPane1.getViewport().add(traceTextArea, null);
136: panel1.add(jPanel3, BorderLayout.SOUTH);
137: jPanel3.add(closeB, null);
138: jPanel3.add(reportB, null);
139: Dimension dlgSize = new Dimension(400, 500);
140: this .setSize(dlgSize);
141: if (owner != null) {
142: Dimension frmSize = owner.getSize();
143: Point loc = owner.getLocation();
144: this .setLocation((frmSize.width - dlgSize.width) / 2
145: + loc.x, (frmSize.height - dlgSize.height) / 2
146: + loc.y);
147: }
148: }
149:
150: void copyB_actionPerformed(ActionEvent e) {
151: traceTextArea.selectAll();
152: traceTextArea.copy();
153: traceTextArea.setSelectionEnd(0);
154: }
155:
156: void closeB_actionPerformed(ActionEvent e) {
157: this .dispose();
158: }
159:
160: void reportB_actionPerformed(ActionEvent e) {
161: Util.runBrowser(App.BUGS_TRACKER_URL);
162: }
163: }
|