2
* Created on 17-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.actions.file;
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;
24
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
26
public class ImportMidiAction extends Action {
27
public static final String NAME = "action.file.import-midi";
29
public ImportMidiAction(TablatureEditor tablatureEditor) {
30
super(NAME, tablatureEditor);
33
public boolean doAction(final TypedEvent event) {
34
TuxGuitar.instance().getPlayer().reset();
35
Shell parent = getEditor().getTablature().getShell();
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() {
42
if(!TuxGuitar.isDisposed()){
44
Song song = new MidiImporter().importSong(fileName);
45
TuxGuitar.instance().getSongManager().setSong(song);
47
getEditor().resetDefaults();
48
TuxGuitar.instance().getMixer().update();
49
TuxGuitar.instance().getTableViewer().getTableInfo().fireUpdate();
51
getEditor().getTablature().changeCursor(SWT.CURSOR_ARROW);
52
}catch (Exception e) {
53
showErrorMessage(fileName);
55
TuxGuitar.instance().getAction(NewFileAction.NAME).process(event);
57
showErrorMessage(fileName);
68
private void showErrorMessage(final String fileName){
69
new SyncThread( new Runnable() {
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());
b'\\ No newline at end of file'