001 /* $Id: DialogExceptionHandler.java,v 1.2 2007/01/10 19:43:57 ringler Exp $
002 * This class is part of the mp3dings application
003 * Copyright (C) 2006 Moritz Ringler
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License
007 * as published by the Free Software Foundation; either version 2
008 * of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018 */
019 package net.sourceforge.mp3dings.utils;
020
021 import java.awt.Component;
022 import java.awt.EventQueue;
023 import java.text.MessageFormat;
024 import javax.swing.JOptionPane;
025 import javax.swing.SwingUtilities;
026 import de.mospace.lang.ExceptionHandler;
027 import net.sourceforge.mp3dings.Globals;
028
029
030 public class DialogExceptionHandler implements ExceptionHandler{
031 private Throwable ex;
032 private Runnable showDialog;
033
034 public DialogExceptionHandler(final String messageFormat, final Component owner){
035 showDialog = new Runnable(){
036 public void run(){
037 JOptionPane.showConfirmDialog(
038 owner,
039 MessageFormat.format(
040 messageFormat,
041 new Object[]{ex.getLocalizedMessage()}),
042 Globals.getString("WARNING"),
043 JOptionPane.OK_CANCEL_OPTION,
044 JOptionPane.WARNING_MESSAGE);
045 }
046 };
047 }
048
049 public void handleException(Throwable ex){
050 this.ex = ex;
051 if(EventQueue.isDispatchThread()){
052 showDialog.run();
053 } else {
054 SwingUtilities.invokeLater(showDialog);
055 }
056 }
057 }