//*********************************************************************************
// class tig.Debug
// Software released under the General Public License (version 2 or later), available at
// http://www.gnu.org/copyleft/gpl.html
//*********************************************************************************
package tig;
import tig.GeneralConstants;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
/******************************************************************************
Contains methods to debug and print exceptions.
@author Thierry Graff
@history oct 02 2001 : creation.
@history mar 11 2002 : added trace modes.
@todo
*********************************************************************************/
public abstract class Debug implements GeneralConstants{
//=================================================================================
// CONSTANTS
//=================================================================================
/** Constant to indicate that the way to trace exceptions is equivalent to <CODE>printStackTrace()</CODE>. */
public static final int STACK_TRACE = 0;
//=================================================================================
// STATIC VARIABLES
//=================================================================================
private static int _traceMode = STACK_TRACE;
private static File errorFile = new File("errors.txt");
//=================================================================================
// METHODS
//=================================================================================
//*************** traceError ***************
/** Traces an exception in a text area of an autonom frame.
@param e The exception being thrown.
*/
public static void traceError(Exception e){
}
//*************** traceError ***************
/** Traces an exception in a text area of an autonom frame.
@param e The exception being thrown.
*/
public static void trace(Exception e){
try{
System.out.println("==============================");
e.printStackTrace();
System.out.println("==============================");
/*
PrintStream ps = new PrintStream(new FileOutputStream(errorFile));
System.setErr(ps);
e.printStackTrace();
String strError;
LineNumberReader lnr = new LineNumberReader(new FileReader(errorFile));
String message = "";
String line;
while((line = lnr.readLine()) != null) message += line + LS;
lnr.close();
ps.close();
boolean useless = errorFile.delete();
//System.out.println(useless);
//System.out.println(message);
//Build an autonom frame.
final JFrame f = new JFrame("Error");
Container contentPane = f.getContentPane();
contentPane.add(new JScrollPane(new JTextArea(message, 30, 45)), BorderLayout.CENTER);
JButton btnOK = new JButton("OK");
btnOK.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
f.setVisible(false);
}
});
contentPane.add(btnOK, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
*/
}
catch(Exception e2){
System.out.println("*** Debug.traceError - Failed to trace an exception ***");
}
}// end traceError
}// end class Debug