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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/actions/file/ImportMidiAction.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
 
/*
2
 
 * Created on 17-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.actions.file;
8
 
 
9
 
import org.eclipse.swt.SWT;
10
 
import org.eclipse.swt.events.TypedEvent;
11
 
import org.eclipse.swt.widgets.Shell;
12
 
import org.herac.tuxguitar.gui.TuxGuitar;
13
 
import org.herac.tuxguitar.gui.actions.Action;
14
 
import org.herac.tuxguitar.gui.editors.TablatureEditor;
15
 
import org.herac.tuxguitar.gui.helper.SyncThread;
16
 
import org.herac.tuxguitar.gui.util.FileChooser;
17
 
import org.herac.tuxguitar.gui.util.MessageDialog;
18
 
import org.herac.tuxguitar.io.importer.MidiImporter;
19
 
import org.herac.tuxguitar.song.models.Song;
20
 
 
21
 
/**
22
 
 * @author julian
23
 
 * 
24
 
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
25
 
 */
26
 
public class ImportMidiAction extends Action {
27
 
    public static final String NAME = "action.file.import-midi";
28
 
 
29
 
    public ImportMidiAction(TablatureEditor tablatureEditor) {
30
 
        super(NAME, tablatureEditor);
31
 
    }
32
 
 
33
 
    public boolean doAction(final TypedEvent event) {
34
 
        TuxGuitar.instance().getPlayer().reset();
35
 
        Shell parent = getEditor().getTablature().getShell();
36
 
        
37
 
        final String fileName = FileChooser.instance().open(parent,FileChooser.IMPORT_MIDI_FORMAT);
38
 
        if (fileName != null) {
39
 
            getEditor().getTablature().changeCursor(SWT.CURSOR_WAIT);
40
 
            new SyncThread(new Runnable() {
41
 
                public void run() {
42
 
                        if(!TuxGuitar.isDisposed()){
43
 
                                try {
44
 
                                        Song song = new MidiImporter().importSong(fileName);
45
 
                                        TuxGuitar.instance().getSongManager().setSong(song);                                            
46
 
                                        
47
 
                            getEditor().resetDefaults();
48
 
                            TuxGuitar.instance().getMixer().update();
49
 
                            TuxGuitar.instance().getTableViewer().getTableInfo().fireUpdate();
50
 
                            redraw();
51
 
                            getEditor().getTablature().changeCursor(SWT.CURSOR_ARROW);
52
 
                                }catch (Exception e) {
53
 
                                        showErrorMessage(fileName);
54
 
                                        e.printStackTrace();
55
 
                                        TuxGuitar.instance().getAction(NewFileAction.NAME).process(event);
56
 
                                }catch (Error e) {
57
 
                                        showErrorMessage(fileName);
58
 
                                        e.printStackTrace();
59
 
                                }                               
60
 
                        }
61
 
                }
62
 
            }).start();
63
 
        }
64
 
        return true;
65
 
    }
66
 
    
67
 
    
68
 
    private void showErrorMessage(final String fileName){
69
 
        new SyncThread( new Runnable() {
70
 
            public void run() {
71
 
                if(!TuxGuitar.isDisposed()){
72
 
                getEditor().getTablature().changeCursor(SWT.CURSOR_ARROW);                
73
 
                String name = "Error Message";
74
 
                String message = "Cannot Open file: " + fileName;
75
 
                new MessageDialog(name,message,SWT.ICON_ERROR | SWT.OK).show(getEditor().getTablature().getShell());
76
 
                }
77
 
            }
78
 
        }).start();        
79
 
    }
80
 
 
81
 
}
 
 
b'\\ No newline at end of file'