1 /*
2  * Created on 20-dic-2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package org.herac.tuxguitar.gui.util;
8 
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.widgets.MessageBox;
11 import org.eclipse.swt.widgets.Shell;
12 import org.herac.tuxguitar.gui.TuxGuitar;
13 import org.herac.tuxguitar.gui.actions.ActionLock;
14 import org.herac.tuxguitar.gui.helper.SyncThread;
15 
16 /**
17  * @author julian
18  *
19  * TODO To change the template for this generated type comment go to
newDialog(Display display,int style)20  * Window - Preferences - Java - Code Style - Code Templates
21  */
22 public class MessageDialog {
23 
24 	private int style;
25 	private String name;
26 	private String message;
27 
28 	protected MessageDialog(String name,String message,int style){
29 		this.name = name;
30 		this.message = message;
31 		this.style = style;
32 	}
33 
34 	protected void show(Shell parent){
35 		MessageBox messageBox = new MessageBox(parent, this.style);
36 		messageBox.setText(this.name);
37 		messageBox.setMessage(this.message);
38 		messageBox.open();
39 	}
40 
41 	public static void infoMessage(final String title,final String message){
42 		MessageDialog.infoMessage(TuxGuitar.instance().getShell(), title, message);
43 	}
44 
45 	public static void infoMessage(final Shell shell,final String title,final String message){
46 		new SyncThread(new Runnable() {
47 			public void run() {
48 				if(!shell.isDisposed()){
49 					new MessageDialog(title,message,SWT.ICON_INFORMATION).show(shell);
50 				}
51 			}
52 		}).start();
53 	}
54 
55 	public static void errorMessage(final Throwable throwable){
56 		MessageDialog.errorMessage(TuxGuitar.instance().getShell(),throwable);
57 	}
58 
59 	public static void errorMessage(final Shell shell,final Throwable throwable){
60 		MessageDialog.errorMessage(shell, (throwable.getMessage() != null ? throwable.getMessage() : throwable.getClass().getName() ));
61 		new Thread(new Runnable() {
62 			public void run() {
63 				throwable.printStackTrace();
64 			}
65 		}).start();
66 	}
67 
68 	public static void errorMessage(final Shell shell,final String message){
69 		if(!shell.isDisposed()){
70 			new SyncThread(new Runnable() {
71 				public void run() {
72 					if(!shell.isDisposed()){
73 						ActionLock.unlock();
74 						TuxGuitar.instance().unlock();
75 						shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
76 						new MessageDialog(TuxGuitar.getProperty("error"),message,SWT.ICON_ERROR).show(shell);
77 					}
78 				}
79 			}).start();
80 		}
81 	}
82 
83 }
84