");
// TRANSLATOR: When an error dialog is presented to the user, this labels the cause of the error.
retcode.append(BDMsg.gettext("This was caused by:"));
retcode.append("");
retcode.append(getHTMLDescription(nex));
}
return retcode.toString();
}
/**
*
*/
private static final class SelectedItemListener implements ItemListener {
/**
* @param ep
*/
SelectedItemListener(ExceptionPane ep) {
pane = ep;
}
/* (non-Javadoc)
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
*/
@Override
public void itemStateChanged(ItemEvent ev) {
pane.changeDetail();
}
private ExceptionPane pane;
}
/**
*
*/
private static final class SelectActionListener implements ActionListener {
/**
* @param ep
* @param cb
*/
SelectActionListener(ExceptionPane ep, JComboBox cb) {
pane = ep;
traces = cb;
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent ev) {
Throwable th = (Throwable) traces.getSelectedItem();
pane.setDisplayedException(th);
}
private ExceptionPane pane;
private JComboBox traces;
}
/**
* List listener to update the contents of the text area whenever someone
* clicks in the list
*/
private static final class CustomLister implements ListSelectionListener {
/**
* Initialize with the stuff we need to act on the change, when the list
* is clicked.
*
* @param st
* The list of elements in the exception
* @param text
* The editable file
* @param label
* The filename label
*/
CustomLister(StackTrace st, JTextArea text, JLabel label) {
this.st = st;
this.mytext = text;
this.mylabel = label;
}
/* (non-Javadoc)
* @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
*/
@Override
public void valueChanged(ListSelectionEvent ev) {
if (ev.getValueIsAdjusting()) {
return;
}
// Wait cursor
SwingUtilities.getRoot(mylabel).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// Get a stack trace
JList lst = (JList) ev.getSource();
int level = lst.getSelectedIndex();
String name = st.getClassName(level);
if (name.indexOf('$') != -1) {
name = name.substring(0, name.indexOf('$'));
}
int lineNum = st.getLineNumber(level);
String orig = name;
Integer errorLine = Integer.valueOf(lineNum);
// TRANSLATOR: When an error dialog is presented to the user, this indicates that the Java source is unavailable.
mylabel.setText(BDMsg.gettext("No File"));
// Find a file
name = File.separator + orig.replace('.', File.separatorChar) + FileUtil.EXTENSION_JAVA;
File[] srcs = ExceptionPane.getSourcePath();
for (int i = 0; i < srcs.length; i++) {
File file = new File(srcs[i], name);
if (file.isFile() && file.canRead()) {
// Found the file, load it into the window
StringBuilder data = new StringBuilder();
// Attempt to note the line to highlight
int selectionStart = 0;
int selectionEnd = 0;
LineNumberReader in = null;
try {
// TRANSLATOR: When an error dialog is presented to the user, this indicates that the location of the error in the Java source.
// {0} is a placeholder for the line number on which the error occurred.
// {1} is a placeholder for the Java file.
String found = BDMsg.gettext("Error on line {0} in file {1}", errorLine, file.getCanonicalPath());
mylabel.setText(found);
in = new LineNumberReader(new FileReader(file));
while (true) {
String line = in.readLine();
if (line == null) {
break;
}
data.append(line).append('\n');
int currentLine = in.getLineNumber();
if (currentLine == lineNum - 1) {
selectionStart = data.length();
}
if (currentLine == lineNum) {
selectionEnd = data.length() - 1;
}
}
} catch (IOException ex) {
data.append(ex.getMessage());
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
data.append(e.getMessage());
}
}
}
// Actually set the text
mytext.setText(data.toString());
mytext.setSelectionStart(selectionStart);
mytext.setSelectionEnd(selectionEnd);
SwingUtilities.getRoot(mylabel).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
return;
}
}
// TRANSLATOR: When an error dialog is presented to the user, this indicates that the Java source could not be found.
// {1} is a placeholder for the line number on which the error occurred.
// {0} is a placeholder for the Java file.
StringBuilder error = new StringBuilder(BDMsg.gettext("Cannot open source for: {0}, line: {1}\n", st.getClassName(level), errorLine));
for (int i = 0; i < srcs.length; i++) {
// TRANSLATOR: When an error dialog is presented to the user, and the Java source could not be found
// this indicates what locations were tried.
// {0} is a placeholder for the location.
error.append(BDMsg.gettext("Tried: {0}\n", srcs[i].getAbsolutePath() + name));
}
mytext.setText(error.toString());
SwingUtilities.getRoot(mylabel).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
/**
* The StackTrace
*/
private StackTrace st;
/**
* The Text to write to
*/
private JTextArea mytext;
/**
* The Text to write to
*/
private JLabel mylabel;
}
/**
* The ExceptionPane instance that we add to the Log
*/
static final class ExceptionPaneReporterListener implements ReporterListener {
/**
* Called whenever Reporter.informUser() is passed an Exception
*
* @param ev
* The event describing the Exception
*/
@Override
public void reportException(ReporterEvent ev) {
// This is to ensure that we don't break any SwingThread rules
SwingUtilities.invokeLater(new ExceptionRunner(ev));
}
/**
* Called whenever Reporter.informUser() is passed a message
*
* @param ev
* The event describing the message
*/
@Override
public void reportMessage(ReporterEvent ev) {
// This is to ensure that we don't break any SwingThread rules
SwingUtilities.invokeLater(new MessageRunner(ev));
}
}
/**
*
*/
private static final class ExceptionRunner implements Runnable {
/**
* @param ev
*/
ExceptionRunner(ReporterEvent ev) {
event = ev;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
if (event.getSource() instanceof Component) {
showExceptionDialog((Component) event.getSource(), event.getException());
} else {
showExceptionDialog(null, event.getException());
}
}
private ReporterEvent event;
}
/**
*
*/
private static final class MessageRunner implements Runnable {
/**
* @param ev
*/
MessageRunner(ReporterEvent ev) {
event = ev;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
if (event.getSource() instanceof Component) {
CWOptionPane.showMessageDialog((Component) event.getSource(), event.getMessage());
} else {
CWOptionPane.showMessageDialog(null, event.getMessage());
}
}
private ReporterEvent event;
}
/**
* The exception we are displaying
*/
private Throwable ex;
// The components - contained, top to containing, bottom
private JList list;
private JPanel upper;
private JLabel label;
private JTextArea text;
private JPanel okBox;
private JCheckBox detail;
private JPanel lower;
/**
* Whether full details should be given.
*/
private static boolean detailShown;
/**
* The directories searched for source
*/
private static File[] sources = new File[0];
/**
* The listener that pops up the ExceptionPanes
*/
private static ExceptionPaneReporterListener li = new ExceptionPaneReporterListener();
/**
* Serialization ID
*/
private static final long serialVersionUID = 3258126947203495219L;
}