1
package org.herac.tuxguitar.player.impl.jsa.assistant;
3
import java.net.MalformedURLException;
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.events.SelectionAdapter;
8
import org.eclipse.swt.events.SelectionEvent;
9
import org.eclipse.swt.layout.GridData;
10
import org.eclipse.swt.layout.GridLayout;
11
import org.eclipse.swt.widgets.Button;
12
import org.eclipse.swt.widgets.Composite;
13
import org.eclipse.swt.widgets.Group;
14
import org.eclipse.swt.widgets.Shell;
15
import org.herac.tuxguitar.gui.TuxGuitar;
16
import org.herac.tuxguitar.gui.util.ConfirmDialog;
17
import org.herac.tuxguitar.gui.util.DialogUtils;
18
import org.herac.tuxguitar.player.impl.jsa.midiport.MidiPortSynthesizer;
19
import org.herac.tuxguitar.util.TGSynchronizer;
21
public class SBAssistant {
23
public static final SBUrl[] URLS = new SBUrl[]{
24
new SBUrl(toURL("http://java.sun.com/products/java-media/sound/soundbank-min.gm.zip"),TuxGuitar.getProperty("jsa.soundbank-assistant.minimal")),
25
new SBUrl(toURL("http://java.sun.com/products/java-media/sound/soundbank-mid.gm.zip"),TuxGuitar.getProperty("jsa.soundbank-assistant.medium")),
26
new SBUrl(toURL("http://java.sun.com/products/java-media/sound/soundbank-deluxe.gm.zip"),TuxGuitar.getProperty("jsa.soundbank-assistant.deluxe")),
29
private MidiPortSynthesizer synthesizer;
31
public SBAssistant(MidiPortSynthesizer synthesizer){
32
this.synthesizer = synthesizer;
35
public void process(){
36
new Thread(new Runnable() {
39
TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
41
ConfirmDialog dialog = new ConfirmDialog(TuxGuitar.getProperty("jsa.soundbank-assistant.confirm-message"));
42
dialog.setDefaultStatus( ConfirmDialog.STATUS_NO );
43
if (dialog.confirm(ConfirmDialog.BUTTON_YES | ConfirmDialog.BUTTON_NO , ConfirmDialog.BUTTON_YES) == ConfirmDialog.STATUS_YES){
48
} catch (Throwable e) {
55
protected void open(){
56
final Shell dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
57
dialog.setLayout(new GridLayout());
59
//------------------------------------------------------------------------------
60
Group group = new Group(dialog,SWT.SHADOW_ETCHED_IN);
61
group.setLayout(new GridLayout());
62
group.setLayoutData(getGroupData());
63
group.setText(TuxGuitar.getProperty("jsa.soundbank-assistant.select"));
66
final Button urls[] = new Button[ URLS.length ];
67
for(int i = 0; i < URLS.length ; i ++){
68
urls[i] = new Button(group, SWT.RADIO);
69
urls[i].setText(URLS[i].getName());
70
urls[i].setData(URLS[i]);
71
urls[i].setSelection(i == 0);
74
//------------------BUTTONS--------------------------
75
Composite buttons = new Composite(dialog, SWT.NONE);
76
buttons.setLayout(new GridLayout(2,false));
77
buttons.setLayoutData(new GridData(SWT.RIGHT,SWT.BOTTOM,true,false));
79
Button buttonOk = new Button(buttons, SWT.PUSH);
80
buttonOk.setText(TuxGuitar.getProperty("ok"));
81
buttonOk.setLayoutData(getButtonsData());
82
buttonOk.addSelectionListener(new SelectionAdapter() {
83
public void widgetSelected(SelectionEvent arg0) {
84
URL url = getSelection(urls);
94
Button buttonCancel = new Button(buttons, SWT.PUSH);
95
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
96
buttonCancel.setLayoutData(getButtonsData());
97
buttonCancel.addSelectionListener(new SelectionAdapter() {
98
public void widgetSelected(SelectionEvent arg0) {
103
dialog.setDefaultButton( buttonOk );
105
DialogUtils.openDialog(dialog, DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK);
108
protected GridData getGroupData(){
109
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
110
data.minimumWidth = 250;
114
protected GridData getButtonsData(){
115
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
116
data.minimumWidth = 80;
117
data.minimumHeight = 25;
121
protected URL getSelection(Button[] buttons){
122
for(int i = 0; i < buttons.length ; i ++){
123
if( buttons[i].getSelection() && buttons[i].getData() instanceof SBUrl ){
124
return ((SBUrl)buttons[i].getData()).getUrl();
130
protected void install(URL url ){
131
new SBInstallerGui(url,this.synthesizer).open();
134
private static URL toURL(String s){
137
} catch (MalformedURLException e) {