~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Created on 20-dic-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.herac.tuxguitar.gui.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.herac.tuxguitar.gui.TuxGuitar;
import org.herac.tuxguitar.gui.actions.ActionLock;
import org.herac.tuxguitar.gui.helper.SyncThread;

/**
 * @author julian
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class MessageDialog {
	
	private int style;
	private String name;
	private String message;
	
	protected MessageDialog(String name,String message,int style){
		this.name = name;
		this.message = message;
		this.style = style;
	}
	
	protected void show(Shell parent){
		MessageBox messageBox = new MessageBox(parent, this.style);
		messageBox.setText(this.name);
		messageBox.setMessage(this.message);
		messageBox.open();
	}
	
	public static void infoMessage(final String title,final String message){
		MessageDialog.infoMessage(TuxGuitar.instance().getShell(), title, message);
	}
	
	public static void infoMessage(final Shell shell,final String title,final String message){
		new SyncThread(new Runnable() {
			public void run() {
				if(!shell.isDisposed()){
					new MessageDialog(title,message,SWT.ICON_INFORMATION).show(shell);
				}
			}
		}).start();
	}
	
	public static void errorMessage(final Throwable throwable){
		MessageDialog.errorMessage(TuxGuitar.instance().getShell(),throwable);
	}
	
	public static void errorMessage(final Shell shell,final Throwable throwable){
		MessageDialog.errorMessage(shell, (throwable.getMessage() != null ? throwable.getMessage() : throwable.getClass().getName() ));
		new Thread(new Runnable() {
			public void run() {
				throwable.printStackTrace();
			}
		}).start();
	}
	
	public static void errorMessage(final Shell shell,final String message){
		if(!shell.isDisposed()){
			new SyncThread(new Runnable() {
				public void run() {
					if(!shell.isDisposed()){
						ActionLock.unlock();
						TuxGuitar.instance().unlock();
						shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
						new MessageDialog(TuxGuitar.getProperty("error"),message,SWT.ICON_ERROR).show(shell);
					}
				}
			}).start();
		}
	}
	
}