ErrorDialog.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.xnap.gui |
![]() |
![]() |
XNap 3 |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* XNap - A P2P framework and client.
*
* See the file AUTHORS for copyright information.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xnap.gui;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import org.xnap.XNap;
import org.xnap.action.AbstractToggleAction;
import org.xnap.gui.component.DefaultDialog;
import org.xnap.gui.component.MultiLineLabel;
import org.xnap.gui.component.XNapButton;
import org.xnap.gui.component.XNapToggleButton;
import org.xnap.gui.util.GUIHelper;
import org.xnap.gui.util.GridBagHelper;
import org.xnap.gui.util.IconHelper;
import org.xnap.net.NetHelper;
import org.xnap.util.Preferences;
import org.xnap.util.UncaughtExceptionManager;
public class ErrorDialog extends DefaultDialog
{
//--- Constant(s) ---
//--- Data field(s) ---
private static Preferences prefs = Preferences.getInstance();
private JPanel jpDetails;
private JTextArea jtaDetails;
private JCheckBox jcbDoNotShowExceptionAgain;
private JCheckBox jcbDoNotShowDialogAgain;
private SendAction acSend = new SendAction();
private LinkedList threads = new LinkedList();
private LinkedList throwables = new LinkedList();
/**
* If true, the dialog can not handle more exceptions.
*/
private boolean busy = false;
//--- Constructor(s) ---
public ErrorDialog(String description)
{
super(BUTTON_NONE);
// top
JPanel jpMain = getMainPanel();
jpMain.setLayout(new GridBagLayout());
description += "\n\n" + XNap.tr("Feel free to press <Show Details> and send the bug report below. The report will be publicly visible at http://xnap.sf.net/report/.\n\nPlease note that you still have to file a proper bug report at http://bugs.xnap.org if you want to get the problem fixed.");
MultiLineLabel jlInfo = new MultiLineLabel(description);
jlInfo.setColumns(40);
GridBagHelper.addComponent
(jpMain, new JLabel(IconHelper.getIcon("error.png", 32)));
GridBagHelper.add(jpMain, jlInfo);
// details, instantiate prior to action
jpDetails = new JPanel(new GridBagLayout());
updateBorder();
jtaDetails = new JTextArea(10, 60);
jtaDetails.setEditable (false);
jtaDetails.setFont(new Font("Monospaced", Font.PLAIN, 10));
GridBagHelper.addPanel(jpDetails, new JScrollPane(jtaDetails));
GridBagHelper.addComponent(jpDetails, new XNapButton(acSend));
// top buttons
JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
GridBagHelper.add(jpMain, jpButtons);
jpButtons.add(new XNapToggleButton(new DetailsAction()));
GridBagHelper.addPanel(jpMain, jpDetails);
jtaDetails.append(FeedbackWizardDialog.getSystemInfo(false) + "\n");
jtaDetails.setCaretPosition(0);
// check boxes
jcbDoNotShowExceptionAgain
= new JCheckBox(XNap.tr("Do not show this exception again"),
!XNap.isRunFromCvs());
GridBagHelper.add(jpMain, jcbDoNotShowExceptionAgain);
jcbDoNotShowDialogAgain
= new JCheckBox(XNap.tr("Do not show this dialog again"),
false);
GridBagHelper.add(jpMain, jcbDoNotShowDialogAgain);
Action continueAction = new ContinueAction();
GUIHelper.bindEscapeKey(getTopPanel(), continueAction);
getButtonPanel().add(new XNapButton(continueAction));
getButtonPanel().add(new XNapButton(new ExitAction()));
// dialog
setTitle(XNap.tr("XNap Error"));
pack();
setSize(prefs.getInt("errorDialogWidth"),
prefs.getInt("errorDialogHeight"));
}
//--- Method(s) ---
public void add(Thread t, Throwable e)
{
threads.add(t);
throwables.add(e);
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(out);
e.printStackTrace(writer);
writer.close();
// jtaDetails.append("Thread: " + t.getName() + "\n");
// jtaDetails.append("Loaded jars:\n");
// URL[] urls = XNapClassLoader.getInstance().getURLs();
// for (int i=0; i < urls.length; i++) {
// jtaDetails.append(urls[i].toString()+"\n");
// }
String pluginName = UncaughtExceptionManager.getPlugin(e);
if (pluginName != null) {
jtaDetails.append(XNap.tr("Plugin: {0}", pluginName) + "\n");
}
jtaDetails.append(out.toString() + "\n");
updateBorder();
}
/* public static String printStackTrace(Throwable t) {
StringBuffer sb = new StringBuffer(t.toString());
StackTraceElement[] trace = t.getStackTrace();
for (int i = 0; i < trace.length; i++) {
sb.append("\tat " + trace[i]);
}
Throwable ourCause = get // to be continued or not...
}*/
public void close()
{
prefs.set("errorDialogWidth", getBounds().getSize().width);
prefs.set("errorDialogHeight", getBounds().getSize().height);
Dialogs.setShowDialog("Error", !jcbDoNotShowDialogAgain.isSelected());
prefs.set("errorDialogDetailsVisible", jpDetails.isVisible());
if (jcbDoNotShowExceptionAgain.isSelected()) {
for (Iterator i = throwables.iterator(); i.hasNext();) {
UncaughtExceptionManager.getInstance().dontNotifyAgain
((Throwable)i.next());
}
}
busy = true;
dispose();
}
public boolean isBusy()
{
return busy;
}
public void updateBorder()
{
jpDetails.setBorder
(GUIHelper.createDefaultBorder
(XNap.tr("Details") + " - "
+ XNap.tr("{0} Problems", new Integer(threads.size()))));
}
public static void show(Component c, String description,
Throwable e)
{
ErrorDialog d = new ErrorDialog(description);
d.setModal(true);
d.add(Thread.currentThread(), e);
d.show(d);
}
//--- Inner Class(es) ---
private class DetailsAction extends AbstractToggleAction
{
public DetailsAction()
{
super(prefs.getBoolean("errorDialogDetailsVisible"));
putValue(Action.NAME, XNap.tr("Show Details"));
putValue(IconHelper.XNAP_ICON, "2downarrow.png");
putValue(Action.SHORT_DESCRIPTION,
XNap.tr("Shows more information about the problem."));
toggled(isSelected());
}
public void toggled(boolean visible)
{
jpDetails.setVisible(visible);
pack();
}
}
private class ContinueAction extends AbstractAction
{
public ContinueAction()
{
putValue(Action.NAME, XNap.tr("Continue"));
putValue(IconHelper.XNAP_ICON, "1rightarrow.png");
putValue(Action.SHORT_DESCRIPTION,
XNap.tr("Tries to continue."));
}
public void actionPerformed(ActionEvent event)
{
close();
}
}
private class ExitAction extends AbstractAction
{
public ExitAction()
{
putValue(Action.NAME, XNap.tr("Quit XNap"));
putValue(IconHelper.XNAP_ICON, "exit.png");
putValue(Action.SHORT_DESCRIPTION,
XNap.tr("Quits the application."));
}
public void actionPerformed(ActionEvent event)
{
close();
System.exit(1);
}
}
private class SendAction extends AbstractAction
{
public SendAction()
{
putValue(Action.NAME, XNap.tr("Send Report"));
putValue(IconHelper.XNAP_ICON, "mail_send2.png");
putValue(Action.SHORT_DESCRIPTION,
XNap.tr("Sends the details to the XNap team for analyzation."));
}
public void actionPerformed(ActionEvent event)
{
busy = true;
Thread t = new Thread(new SendWorker(), "SendFeedback");
t.start();
}
}
private class SendWorker implements Runnable
{
public void run()
{
acSend.setEnabled(false);
getCancelAction().setEnabled(false);
setTitle(XNap.tr("Sending error report") + "...");
try {
Iterator i1 = threads.iterator();
Iterator i2 = throwables.iterator();
while (i1.hasNext() && i2.hasNext()) {
UncaughtExceptionManager.getInstance().sendProblemReport
((Thread)i1.next(), (Throwable)i2.next());
}
}
catch(final IOException e) {
Runnable runner = new Runnable()
{
public void run()
{
failed(NetHelper.getErrorMessage(e));
}
};
SwingUtilities.invokeLater(runner);
return;
}
Runnable runner = new Runnable()
{
public void run()
{
JOptionPane.showMessageDialog
(ErrorDialog.this, XNap.tr("Thank you."),
XNap.tr("XNap Error"),
JOptionPane.INFORMATION_MESSAGE);
close();
}
};
SwingUtilities.invokeLater(runner);
}
public void failed(String response)
{
JOptionPane.showMessageDialog
(ErrorDialog.this,
XNap.tr("Could not send error report: {0}.", response),
XNap.tr("XNap Error"),
JOptionPane.ERROR_MESSAGE);
setTitle(XNap.tr("XNap Error"));
acSend.setEnabled(true);
getCancelAction().setEnabled(true);
busy = false;
}
}
}
The table below shows all metrics for ErrorDialog.java.




