/* * Moonlight|3D Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Jan 14, 2005 */ package ml.ui.core; import ml.core.exceptions.Exception; import com.trolltech.qt.gui.QDialog; import com.trolltech.qt.gui.QGridLayout; import com.trolltech.qt.gui.QLabel; import com.trolltech.qt.gui.QPushButton; import com.trolltech.qt.gui.QWidget; /** * This class is an error dialog displaying all information which is * contained in the given exception. * TODO make this dialog less intimidating * * @author gregor */ public class ExceptionDialog extends QDialog { private QPushButton okButton; private QPushButton detailButton; private QLabel label; private QGridLayout layout; private static QWidget parent = null; private Exception exception; private boolean detailed = false; /** * @param parentShell */ protected ExceptionDialog(Exception e) { super(parent); exception = e; setWindowTitle("An exception occured"); createContents(); } private void createContents() { label = new QLabel(this); label.setText(exception.getReasons()); okButton = new QPushButton(this); okButton.setText("OK"); okButton.clicked.connect(this,"onOK()"); detailButton = new QPushButton(this); detailButton.setText("Details >>"); detailButton.clicked.connect(this,"onDetails()"); layout=new QGridLayout(); layout.addWidget(label,0,0,1,2); layout.addWidget(okButton,1,0); layout.addWidget(detailButton,1,1); setLayout(layout); } public void onOK() { close(); } public void onDetails() { detailed = !detailed; if (detailed) { detailButton.setText("Details <<"); label.setText(exception.getFullText()); } else { detailButton.setText("Details >>"); label.setText(exception.getReasons()); } } // public static void setParent(QWidget parent) { // ExceptionDialog.parent = parent; // } public static void run(Exception e) { e.printStackTrace(); // dump stack trace to console make it possible to capture it as clear text ExceptionDialog dialog = new ExceptionDialog(e); dialog.exec(); } }