1
package org.herac.tuxguitar.player.impl.jsa.assistant;
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.events.DisposeEvent;
8
import org.eclipse.swt.events.DisposeListener;
9
import org.eclipse.swt.events.SelectionAdapter;
10
import org.eclipse.swt.events.SelectionEvent;
11
import org.eclipse.swt.graphics.Font;
12
import org.eclipse.swt.graphics.FontData;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Button;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.swt.widgets.ProgressBar;
19
import org.eclipse.swt.widgets.Shell;
20
import org.herac.tuxguitar.gui.TuxGuitar;
21
import org.herac.tuxguitar.gui.util.DialogUtils;
22
import org.herac.tuxguitar.gui.util.MessageDialog;
23
import org.herac.tuxguitar.gui.util.TGFileUtils;
24
import org.herac.tuxguitar.player.impl.jsa.midiport.MidiPortSynthesizer;
25
import org.herac.tuxguitar.util.TGSynchronizer;
27
public class SBInstallerGui implements SBInstallerlistener{
29
private static final String SB_PATH = ( TGFileUtils.PATH_USER_PLUGINS_CONFIG + File.separator + "tuxguitar-jsa" );
32
private Label progressLabel;
34
private SBInstaller installer;
36
public SBInstallerGui(URL url,MidiPortSynthesizer synthesizer){
37
initInstaller(url,synthesizer);
40
public void initInstaller(URL url,MidiPortSynthesizer synthesizer){
41
File tmpPath = new File(SB_PATH);
42
File dstPath = new File(SB_PATH);
44
if(!tmpPath.exists()){
47
if(!dstPath.exists()){
50
this.installer = new SBInstaller(url,tmpPath,dstPath,synthesizer,this);
54
this.dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
55
this.dialog.setLayout(new GridLayout());
57
//-----------------------------------------------------
58
Composite header = new Composite(this.dialog,SWT.NONE);
59
header.setLayout(new GridLayout(2,false));
60
header.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
62
Label headerImage = new Label(header, SWT.NONE);
63
headerImage.setImage(TuxGuitar.instance().getDisplay().getSystemImage(SWT.ICON_INFORMATION));
64
headerImage.setLayoutData(new GridData(SWT.LEFT,SWT.TOP,false,false));
66
Label headerTip = new Label(header, SWT.WRAP);
67
headerTip.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
68
headerTip.setText(TuxGuitar.getProperty("jsa.soundbank-assistant.process.tip"));
70
FontData[] fontData = headerTip.getFont().getFontData();
71
for(int i = 0; i < fontData.length; i ++){
72
fontData[i].setStyle(SWT.BOLD);
74
final Font font = new Font(headerTip.getDisplay(),fontData);
75
headerTip.setFont(font);
76
headerTip.addDisposeListener(new DisposeListener() {
77
public void widgetDisposed(DisposeEvent arg0) {
83
//------------------PROGRESS--------------------------
84
Composite composite = new Composite(this.dialog,SWT.NONE);
85
composite.setLayout(new GridLayout());
86
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
88
final ProgressBar progressBar = new ProgressBar(composite, SWT.INDETERMINATE);
89
progressBar.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
91
this.progressLabel = new Label(composite, SWT.WRAP);
92
this.progressLabel.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,true));
94
//------------------BUTTONS--------------------------
95
Composite buttons = new Composite(this.dialog, SWT.NONE);
96
buttons.setLayout(new GridLayout());
97
buttons.setLayoutData(new GridData(SWT.RIGHT,SWT.BOTTOM,true,false));
99
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
100
data.minimumWidth = 80;
101
data.minimumHeight = 25;
103
Button buttonCancel = new Button(buttons, SWT.PUSH);
104
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
105
buttonCancel.setLayoutData(data);
106
buttonCancel.addSelectionListener(new SelectionAdapter() {
107
public void widgetSelected(SelectionEvent arg0) {
108
getInstaller().setCancelled(true);
109
getDialog().dispose();
115
DialogUtils.openDialog(this.dialog, DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK);
118
private void process(){
119
new Thread(new Runnable() {
122
getInstaller().process();
128
public void notifyProcess(final String process){
131
TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
134
getProgressLabel().setText(process);
138
} catch (Throwable e) {
144
public void notifyFinish(){
147
TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
150
getDialog().dispose();
154
} catch (Throwable e) {
160
public void notifyFailed(final Throwable throwable){
163
TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
166
getDialog().dispose();
167
MessageDialog.errorMessage( throwable );
171
} catch (Throwable e) {
177
public boolean isDisposed(){
178
return ( TuxGuitar.isDisposed() || getDialog().isDisposed() );
181
public Shell getDialog() {
185
public Label getProgressLabel() {
186
return this.progressLabel;
189
public SBInstaller getInstaller() {
190
return this.installer;