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

« back to all changes in this revision

Viewing changes to TuxGuitar-jsa/src/org/herac/tuxguitar/player/impl/jsa/assistant/SBInstallerGui.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.player.impl.jsa.assistant;
 
2
 
 
3
import java.io.File;
 
4
import java.net.URL;
 
5
 
 
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;
 
26
 
 
27
public class SBInstallerGui implements SBInstallerlistener{
 
28
 
 
29
        private static final String SB_PATH = ( TGFileUtils.PATH_USER_PLUGINS_CONFIG + File.separator + "tuxguitar-jsa" );
 
30
        
 
31
        private Shell dialog;
 
32
        private Label progressLabel;
 
33
 
 
34
        private SBInstaller installer;  
 
35
        
 
36
        public SBInstallerGui(URL url,MidiPortSynthesizer synthesizer){
 
37
                initInstaller(url,synthesizer);
 
38
        }
 
39
        
 
40
        public void initInstaller(URL url,MidiPortSynthesizer synthesizer){
 
41
                File tmpPath = new File(SB_PATH);
 
42
                File dstPath = new File(SB_PATH);
 
43
                
 
44
                if(!tmpPath.exists()){
 
45
                        tmpPath.mkdirs();
 
46
                }
 
47
                if(!dstPath.exists()){
 
48
                        dstPath.mkdirs();
 
49
                }
 
50
                this.installer = new SBInstaller(url,tmpPath,dstPath,synthesizer,this);
 
51
        }
 
52
        
 
53
        public void open(){
 
54
                this.dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
55
                this.dialog.setLayout(new GridLayout());
 
56
 
 
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));                
 
61
        
 
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));
 
65
                
 
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"));
 
69
                
 
70
                FontData[] fontData = headerTip.getFont().getFontData();
 
71
                for(int i = 0; i < fontData.length; i ++){
 
72
                        fontData[i].setStyle(SWT.BOLD);
 
73
                }
 
74
                final Font font = new Font(headerTip.getDisplay(),fontData);
 
75
                headerTip.setFont(font);
 
76
                headerTip.addDisposeListener(new DisposeListener() {
 
77
                        public void widgetDisposed(DisposeEvent arg0) {
 
78
                                font.dispose();
 
79
                        }
 
80
                });
 
81
                        
 
82
                
 
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));             
 
87
                
 
88
                final ProgressBar progressBar = new ProgressBar(composite, SWT.INDETERMINATE);
 
89
                progressBar.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
 
90
                
 
91
                this.progressLabel = new Label(composite, SWT.WRAP);
 
92
                this.progressLabel.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,true));
 
93
                
 
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));           
 
98
 
 
99
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
100
                data.minimumWidth = 80;
 
101
                data.minimumHeight = 25;        
 
102
 
 
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();
 
110
            }
 
111
        });
 
112
 
 
113
        this.process();
 
114
        
 
115
        DialogUtils.openDialog(this.dialog, DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK);
 
116
        }
 
117
 
 
118
        private void process(){
 
119
                new Thread(new Runnable() {
 
120
                        public void run() {                             
 
121
                                if(!isDisposed()){
 
122
                                        getInstaller().process();
 
123
                                }
 
124
                        }
 
125
                }).start();
 
126
        }
 
127
        
 
128
        public void notifyProcess(final String process){
 
129
                if(!isDisposed()){
 
130
                        try {
 
131
                                TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
 
132
                                        public void run() {
 
133
                                                if(!isDisposed()){
 
134
                                                        getProgressLabel().setText(process);
 
135
                                                }
 
136
                                        }
 
137
                                });
 
138
                        } catch (Throwable e) {
 
139
                                e.printStackTrace();
 
140
                        }
 
141
                }
 
142
        }
 
143
 
 
144
        public void notifyFinish(){
 
145
                if(!isDisposed()){
 
146
                        try {
 
147
                                TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
 
148
                                        public void run() {
 
149
                                                if(!isDisposed()){
 
150
                                                        getDialog().dispose();
 
151
                                                }
 
152
                                        }
 
153
                                });
 
154
                        } catch (Throwable e) {
 
155
                                e.printStackTrace();
 
156
                        }
 
157
                }
 
158
        }
 
159
        
 
160
        public void notifyFailed(final Throwable throwable){
 
161
                if(!isDisposed()){
 
162
                        try {
 
163
                                TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
 
164
                                        public void run() {
 
165
                                                if(!isDisposed()){
 
166
                                                        getDialog().dispose();
 
167
                                                        MessageDialog.errorMessage( throwable );
 
168
                                                }
 
169
                                        }
 
170
                                });
 
171
                        } catch (Throwable e) {
 
172
                                e.printStackTrace();
 
173
                        }
 
174
                }
 
175
        }       
 
176
 
 
177
        public boolean isDisposed(){
 
178
                return ( TuxGuitar.isDisposed() || getDialog().isDisposed() );
 
179
        }
 
180
        
 
181
        public Shell getDialog() {
 
182
                return this.dialog;
 
183
        }
 
184
        
 
185
        public Label getProgressLabel() {
 
186
                return this.progressLabel;
 
187
        }
 
188
        
 
189
        public SBInstaller getInstaller() {
 
190
                return this.installer;
 
191
        }
 
192
}