KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > swing > AjdeErrorHandler


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

25
26
27 package org.aspectj.ajde.ui.swing;
28
29 import java.awt.*;
30 import java.awt.event.*;
31 import javax.swing.*;
32 import java.io.*;
33 import org.aspectj.ajde.*;
34
35 public class AjdeErrorHandler implements ErrorHandler {
36
37     public void handleWarning(String JavaDoc message) {
38         JOptionPane.showMessageDialog(AjdeUIManager.getDefault().getRootFrame(),
39                                       message,
40                                       "AJDE Warning",
41                                       JOptionPane.WARNING_MESSAGE);
42     }
43
44     public void handleError(String JavaDoc errorMessage) {
45         handleError(errorMessage, null);
46     }
47
48     public void handleError(String JavaDoc message, Throwable JavaDoc t) {
49         String JavaDoc stack = getStackTraceAsString(t);
50         Ajde.getDefault().logEvent("Error: " + stack);
51         ErrorDialog errorDialog = new ErrorDialog(AjdeUIManager.getDefault().getRootFrame(), "AJDE Error", t, message, stack);
52         errorDialog.setVisible(true);
53     }
54
55     private String JavaDoc getStackTraceAsString(Throwable JavaDoc t) {
56         StringWriter stringWriter = new StringWriter();
57         if (t != null) {
58             t.printStackTrace(new PrintWriter(stringWriter));
59             return stringWriter.getBuffer().toString();
60         } else {
61             return "<no stack trace available>";
62         }
63     }
64 }
65
66
Popular Tags