01: /*
02: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/gui/ErrorManager.java,v 1.1 2005/04/20 21:04:57 paulby Exp $
03: *
04: * Sun Public License Notice
05: *
06: * The contents of this file are subject to the Sun Public License Version
07: * 1.0 (the "License"). You may not use this file except in compliance with
08: * the License. A copy of the License is available at http://www.sun.com/
09: *
10: * The Original Code is Java 3D(tm) Fly Through.
11: * The Initial Developer of the Original Code is Paul Byrne.
12: * Portions created by Paul Byrne are Copyright (C) 2002.
13: * All Rights Reserved.
14: *
15: * Contributor(s): Paul Byrne.
16: *
17: **/
18: package org.jdesktop.j3dfly.utils.gui;
19:
20: import javax.swing.JOptionPane;
21:
22: /**
23: *
24: * @author Jan Becicka
25: */
26: public class ErrorManager {
27:
28: private static ErrorManager currentErrorManager = null;
29:
30: /** Holds value of property errorHandler. */
31: private ErrorHandler errorHandler;
32:
33: /** Creates new ErrorManager */
34: private ErrorManager() {
35: this (new ErrorHandlerImpl());
36: }
37:
38: private ErrorManager(ErrorHandler errorHandler) {
39: this .errorHandler = errorHandler;
40: }
41:
42: public static ErrorManager createManager() {
43: return currentErrorManager = new ErrorManager();
44: }
45:
46: public static ErrorManager createManager(ErrorHandler errorHandler) {
47: return currentErrorManager = new ErrorManager(errorHandler);
48: }
49:
50: public static ErrorManager getDefault() {
51: if (currentErrorManager == null)
52: createManager();
53: return currentErrorManager;
54: }
55:
56: /** Getter for property errorHandler.
57: * @return Value of property errorHandler.
58: */
59: public ErrorHandler getErrorHandler() {
60: return this .errorHandler;
61: }
62:
63: /** Setter for property errorHandler.
64: * @param errorHandler New value of property errorHandler.
65: */
66: public void setErrorHandler(ErrorHandler errorHandler) {
67: this .errorHandler = errorHandler;
68: }
69:
70: public void notify(Throwable t) {
71: errorHandler.notify(t);
72: }
73:
74: public void notify(Throwable t, int severity) {
75: errorHandler.notify(t, severity);
76: }
77:
78: public void notify(Throwable t, int severity, String message) {
79: errorHandler.notify(t, severity, message);
80: }
81:
82: private static class ErrorHandlerImpl implements ErrorHandler {
83:
84: public void notify(Throwable t) {
85: notify(t, UNKNOWN);
86: }
87:
88: public void notify(Throwable t, int severity) {
89: notify(t, severity, t.toString());
90: }
91:
92: public void notify(Throwable t, int severity, String message) {
93: if (t != null)
94: t.printStackTrace();
95: JOptionPane.showMessageDialog(null, message, "Error",
96: JOptionPane.ERROR_MESSAGE);
97: }
98: }
99: }
|