1 /*
2  * Created on 25-nov-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;
8 
9 import java.net.URL;
10 
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.events.MouseAdapter;
13 import org.eclipse.swt.events.MouseEvent;
14 import org.eclipse.swt.events.MouseTrackAdapter;
15 import org.eclipse.swt.events.SelectionAdapter;
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.layout.FormAttachment;
18 import org.eclipse.swt.layout.FormData;
19 import org.eclipse.swt.layout.FormLayout;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.swt.widgets.Event;
24 import org.eclipse.swt.widgets.Listener;
25 import org.eclipse.swt.widgets.Sash;
26 import org.eclipse.swt.widgets.Shell;
27 import org.herac.tuxguitar.gui.actions.Action;
28 import org.herac.tuxguitar.gui.actions.ActionLock;
29 import org.herac.tuxguitar.gui.actions.ActionManager;
30 import org.herac.tuxguitar.gui.actions.file.FileActionUtils;
31 import org.herac.tuxguitar.gui.actions.system.DisposeAction;
32 import org.herac.tuxguitar.gui.editors.EditorCache;
33 import org.herac.tuxguitar.gui.editors.FretBoardEditor;
34 import org.herac.tuxguitar.gui.editors.PianoEditor;
35 import org.herac.tuxguitar.gui.editors.TGEditorManager;
36 import org.herac.tuxguitar.gui.editors.TGRedrawListener;
37 import org.herac.tuxguitar.gui.editors.TGUpdateListener;
38 import org.herac.tuxguitar.gui.editors.TablatureEditor;
39 import org.herac.tuxguitar.gui.editors.chord.CustomChordManager;
40 import org.herac.tuxguitar.gui.editors.lyric.LyricEditor;
41 import org.herac.tuxguitar.gui.editors.matrix.MatrixEditor;
42 import org.herac.tuxguitar.gui.editors.tab.TGFactoryImpl;
43 import org.herac.tuxguitar.gui.helper.FileHistory;
44 import org.herac.tuxguitar.gui.helper.SyncThread;
45 import org.herac.tuxguitar.gui.items.ItemManager;
46 import org.herac.tuxguitar.gui.marker.MarkerList;
47 import org.herac.tuxguitar.gui.mixer.TGMixer;
48 import org.herac.tuxguitar.gui.system.config.TGConfigKeys;
49 import org.herac.tuxguitar.gui.system.config.TGConfigManager;
50 import org.herac.tuxguitar.gui.system.config.TGConfigManagerImpl;
51 import org.herac.tuxguitar.gui.system.icons.IconLoader;
52 import org.herac.tuxguitar.gui.system.icons.IconManager;
53 import org.herac.tuxguitar.gui.system.keybindings.KeyBindingActionManager;
54 import org.herac.tuxguitar.gui.system.language.LanguageManager;
55 import org.herac.tuxguitar.gui.system.plugins.TGPluginManager;
56 import org.herac.tuxguitar.gui.table.TGTableViewer;
57 import org.herac.tuxguitar.gui.tools.browser.dialog.TGBrowserDialog;
58 import org.herac.tuxguitar.gui.tools.scale.ScaleManager;
59 import org.herac.tuxguitar.gui.transport.TGTransport;
60 import org.herac.tuxguitar.gui.transport.TGTransportListener;
61 import org.herac.tuxguitar.gui.undo.UndoableManager;
62 import org.herac.tuxguitar.gui.util.ArgumentParser;
63 import org.herac.tuxguitar.gui.util.TGFileUtils;
64 import org.herac.tuxguitar.gui.util.TGSplash;
65 import org.herac.tuxguitar.gui.util.WindowTitleUtil;
66 import org.herac.tuxguitar.player.base.MidiPlayer;
67 import org.herac.tuxguitar.player.base.MidiPlayerException;
68 import org.herac.tuxguitar.player.impl.sequencer.MidiSequencerProviderImpl;
69 import org.herac.tuxguitar.song.managers.TGSongManager;
70 import org.herac.tuxguitar.song.models.TGBeat;
71 import org.herac.tuxguitar.song.models.TGSong;
72 import org.herac.tuxguitar.util.TGLock;
73 import org.herac.tuxguitar.util.TGSynchronizer;
74 
75 /**
76  * @author julian
77  *
78  * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
79  */
80 public class TuxGuitar {
81 
82 	public static final String APPLICATION_NAME = "TuxGuitar";
83 
84 	public static final int MARGIN_WIDTH = 5;
85 
86 	private static TuxGuitar instance;
87 
88 	private boolean initialized;
89 
90 	private TGLock lock;
91 
92 	private Display display;
93 
94 	private Shell shell;
95 
96 	private MidiPlayer player;
97 
98 	private TGSongManager songManager;
99 
100 	private TGConfigManager configManager;
101 
102 	private LanguageManager languageManager;
103 
104 	private KeyBindingActionManager keyBindingManager;
105 
106 	private IconManager iconManager;
107 
108 	private EditorCache editorCache;
109 
110 	private TablatureEditor tablatureEditor;
111 
112 	private TGTableViewer table;
113 
114 	private TGMixer songMixer;
115 
116 	private TGTransport songTransport;
117 
118 	private FretBoardEditor fretBoardEditor;
119 
120 	private PianoEditor pianoEditor;
121 
122 	private MatrixEditor matrixEditor;
123 
124 	private LyricEditor lyricEditor;
125 
126 	private TGEditorManager editorManager;
127 
128 	private TGBrowserDialog browser;
129 
130 	private UndoableManager undoableManager;
131 
132 	private ScaleManager scaleManager;
133 
134 	private ActionManager actionManager;
135 
136 	private ItemManager itemManager;
137 
138 	private CustomChordManager customChordManager;
139 
140 	private FileHistory fileHistory;
141 
142 	private TGPluginManager pluginManager;
143 
144 	protected Sash sash;
145 
146 	protected Composite sashComposite;
147 
TuxGuitar()148 	public TuxGuitar() {
149 		this.lock = new TGLock();
150 		this.initialized = false;
151 	}
152 
instance()153 	public static TuxGuitar instance() {
154 		if (instance == null) {
155 			synchronized (TuxGuitar.class) {
156 				instance = new TuxGuitar();
157 			}
158 		}
159 		return instance;
160 	}
161 
initSynchronizer()162 	private void initSynchronizer(){
163 		TGSynchronizer.instance().setController(new TGSynchronizer.TGSynchronizerController() {
164 			public void execute(final TGSynchronizer.TGSynchronizerTask task) {
165 				final Display display = getDisplay();
166 				if(display != null && !display.isDisposed()){
167 					display.syncExec(new Runnable() {
168 						public void run() {
169 							task.run();
170 						}
171 					});
172 				}
173 			}
174 
175 			public void executeLater(final TGSynchronizer.TGSynchronizerTask task) {
176 				final Display display = getDisplay();
177 				if(display != null && !display.isDisposed()){
178 					display.asyncExec(new Runnable() {
179 						public void run() {
180 							task.run();
181 						}
182 					});
183 				}
184 			}
185 		});
186 	}
187 
displayGUI(String[] args)188 	public void displayGUI(String[] args) {
189 		//checkeo los argumentos
190 		ArgumentParser argumentParser = new ArgumentParser(args);
191 		if(argumentParser.processAndExit()){
192 			return;
193 		}
194 
195 		// Priority 1 ----------------------------------------------//
196 		TGFileUtils.loadLibraries();
197 		TGFileUtils.loadClasspath();
198 
199 		// Priority 2 ----------------------------------------------//
200 		Display.setAppName(APPLICATION_NAME);
201 
202 		this.display = new Display();
203 		this.initSynchronizer();
204 
205 		TGSplash.instance().init();
206 
207 		this.shell = new Shell(getDisplay());
208 		this.shell.setLayout(getShellLayout());
209 		this.shell.setImage(getIconManager().getAppIcon());
210 
211 		this.createComposites(getShell());
212 
213 		// Priority 3 ----------------------------------------------//
214 		this.getPluginManager().openPlugins();
215 		this.restoreControlsConfig();
216 		this.restorePlayerConfig();
217 		this.updateCache(true);
218 		this.showTitle();
219 
220 		TGSplash.instance().finish();
221 
222 		// Priority 4 ----------------------------------------------//
223 		this.shell.addShellListener(getAction(DisposeAction.NAME));
224 		this.shell.open();
225 		this.startSong(argumentParser);
226 		this.setInitialized( true );
227 		while (!getDisplay().isDisposed() && !getShell().isDisposed()) {
228 			if (!getDisplay().readAndDispatch()) {
229 				getDisplay().sleep();
230 			}
231 		}
232 		getDisplay().dispose();
233 	}
234 
getShellLayout()235 	private FormLayout getShellLayout(){
236 		FormLayout layout = new FormLayout();
237 		layout.marginWidth = MARGIN_WIDTH;
238 		layout.marginHeight = MARGIN_WIDTH;
239 		return layout;
240 	}
241 
startSong(final ArgumentParser parser)242 	private void startSong(final ArgumentParser parser){
243 		final URL url = parser.getURL();
244 		if(url != null){
245 			ActionLock.lock();
246 			new SyncThread(new Runnable() {
247 				public void run() {
248 					TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
249 					new Thread(new Runnable() {
250 						public void run() {
251 							if(!TuxGuitar.isDisposed()){
252 								FileActionUtils.open(url);
253 								TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
254 								ActionLock.unlock();
255 							}
256 						}
257 					}).start();
258 				}
259 			}).start();
260 		}
261 	}
262 
createComposites(Composite composite)263 	public void createComposites(Composite composite) {
264 		FormData data = new FormData();
265 		data.left = new FormAttachment(0,0);
266 		data.right = new FormAttachment(100,0);
267 		data.top = new FormAttachment(getItemManager().getCoolbar(),MARGIN_WIDTH);
268 		data.bottom = new FormAttachment(100,0);
269 		this.sashComposite = new Composite(composite,SWT.NONE);
270 		this.sashComposite.setLayout(new FormLayout());
271 		this.sashComposite.setLayoutData(data);
272 
273 		data = new FormData();
274 		data.left = new FormAttachment(0,0);
275 		data.right = new FormAttachment(100,0);
276 		data.bottom = new FormAttachment(100,-150);
277 		data.height = MARGIN_WIDTH;
278 		this.sash = new Sash(this.sashComposite, SWT.HORIZONTAL);
279 		this.sash.setLayoutData(data);
280 
281 		data = new FormData();
282 		data.left = new FormAttachment(0,0);
283 		data.right = new FormAttachment(100,0);
284 		data.top = new FormAttachment(0,0);
285 		data.bottom = new FormAttachment(this.sash, 0);
286 		getTablatureEditor().showTablature(this.sashComposite);
287 		getTablatureEditor().getTablature().setLayoutData(data);
288 
289 		data = new FormData();
290 		data.left = new FormAttachment(0,0);
291 		data.right = new FormAttachment(100,0);
292 		data.top = new FormAttachment(this.sash,0);
293 		data.bottom = new FormAttachment(100,0);
294 		getTable().init(this.sashComposite);
295 		getTable().getComposite().setLayoutData(data);
296 
297 		data = new FormData();
298 		data.left = new FormAttachment(0,0);
299 		data.right = new FormAttachment(100,0);
300 		data.top = new FormAttachment(this.sashComposite,0);
301 		data.bottom = new FormAttachment(100,0);
302 
303 		Composite footer = new Composite(composite,SWT.NONE);
304 		footer.setLayout(new FormLayout());
305 		footer.setLayoutData(data);
306 		getFretBoardEditor().showFretBoard(footer);
307 
308 		this.sash.addMouseListener(new MouseAdapter() {
309 			public void mouseUp(MouseEvent e) {
310 				TuxGuitar.this.sashComposite.layout(true,true);
311 			}
312 		});
313 		this.sash.addSelectionListener(new SelectionAdapter() {
314 			public void widgetSelected(SelectionEvent event) {
315 				int maximumHeight = (TuxGuitar.this.sashComposite.getBounds().height - TuxGuitar.this.sash.getBounds().height);
316 				int height = (maximumHeight - event.y);
317 				height = Math.max(height,0);
318 				height = Math.min(height,maximumHeight);
319 				((FormData) TuxGuitar.this.sash.getLayoutData()).bottom = new FormAttachment(100, -height);
320 			}
321 		});
322 		this.sash.addMouseTrackListener(new MouseTrackAdapter() {
323 			public void mouseEnter(MouseEvent e) {
324 				TuxGuitar.this.sash.setCursor( getDisplay().getSystemCursor( SWT.CURSOR_SIZENS ) );
325 			}
326 		});
327 		this.sashComposite.addListener(SWT.Resize, new Listener() {
328 			public void handleEvent(Event arg0) {
329 				FormData data = ((FormData) TuxGuitar.this.sash.getLayoutData());
330 				int height = -data.bottom.offset;
331 				int maximumHeight = (TuxGuitar.this.sashComposite.getBounds().height - TuxGuitar.this.sash.getBounds().height);
332 				if(height > maximumHeight){
333 					data.bottom = new FormAttachment(100, -maximumHeight);
334 				}
335 			}
336 		});
337 	}
338 
restoreControlsConfig()339 	public void restoreControlsConfig(){
340 		final TGConfigManager config = getConfig();
341 
342 		//---Main Shell---
343 		boolean maximized = config.getBooleanConfigValue(TGConfigKeys.MAXIMIZED);
344 		getShell().setMaximized(maximized);
345 		if(!maximized){
346 			int width = config.getIntConfigValue(TGConfigKeys.WIDTH);
347 			int height = config.getIntConfigValue(TGConfigKeys.HEIGHT);
348 			if(width > 0 && height > 0){
349 				getShell().setSize(width,height);
350 			}
351 		}
352 		getShell().setMinimumSize(640,480);
353 		//---Fretboard---
354 		if(config.getBooleanConfigValue(TGConfigKeys.SHOW_FRETBOARD)){
355 			getFretBoardEditor().showFretBoard();
356 		}else{
357 			getFretBoardEditor().hideFretBoard();
358 		}
359 		//---Mixer---
360 		if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MIXER)){
361 			new SyncThread(new Runnable() {
362 				public void run() {
363 					getMixer().show();
364 				}
365 			}).start();
366 		}
367 		//---Transport---
368 		if(config.getBooleanConfigValue(TGConfigKeys.SHOW_TRANSPORT)){
369 			new SyncThread(new Runnable() {
370 				public void run() {
371 					getTransport().show();
372 				}
373 			}).start();
374 		}
375 		//---Matrix---
376 		if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MATRIX)){
377 			new SyncThread(new Runnable() {
378 				public void run() {
379 					getMatrixEditor().show();
380 				}
381 			}).start();
382 		}
383 		//---Piano---
384 		if(config.getBooleanConfigValue(TGConfigKeys.SHOW_PIANO)){
385 			new SyncThread(new Runnable() {
386 				public void run() {
387 					getPianoEditor().show();
388 				}
389 			}).start();
390 		}
391 		//---Markers---
392 		if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MARKERS)){
393 			new SyncThread(new Runnable() {
394 				public void run() {
395 					MarkerList.instance().show();
396 				}
397 			}).start();
398 		}
399 	}
400 
setTableHeight(int value)401 	public void setTableHeight(int value){
402 		int offset = ((FormData) getTable().getComposite().getLayoutData()).top.offset;
403 		int sashHeight = this.sash.getBounds().height;
404 		int maximumHeight = (this.sashComposite.getBounds().height - sashHeight);
405 		int height = (value + offset);
406 		height = Math.max( height,0);
407 		height = Math.min( height,maximumHeight);
408 		((FormData) TuxGuitar.this.sash.getLayoutData()).bottom = new FormAttachment(100, -height);
409 		this.sashComposite.layout(true,true);
410 	}
411 
updateShellFooter(int offset,int minimumWith,int minimumHeight)412 	public void updateShellFooter(int offset,int minimumWith,int minimumHeight){
413 		FormData data = ((FormData)this.sashComposite.getLayoutData());
414 		data.bottom.offset = -offset;
415 		getShell().setMinimumSize(Math.max(640,minimumWith),Math.max(480,minimumHeight));
416 		getShell().layout(true,true);
417 		getShell().redraw();
418 	}
419 
getTable()420 	public TGTableViewer getTable(){
421 		if(this.table == null){
422 			this.table = new TGTableViewer();
423 		}
424 		return this.table;
425 	}
426 
getTablatureEditor()427 	public TablatureEditor getTablatureEditor(){
428 		if(this.tablatureEditor == null){
429 			this.tablatureEditor = new TablatureEditor();
430 		}
431 		return this.tablatureEditor;
432 	}
433 
getFretBoardEditor()434 	public FretBoardEditor getFretBoardEditor(){
435 		if(this.fretBoardEditor == null){
436 			this.fretBoardEditor = new FretBoardEditor();
437 		}
438 		return this.fretBoardEditor;
439 	}
440 
getPianoEditor()441 	public PianoEditor getPianoEditor(){
442 		if(this.pianoEditor == null){
443 			this.pianoEditor = new PianoEditor();
444 		}
445 		return this.pianoEditor;
446 	}
447 
getMatrixEditor()448 	public MatrixEditor getMatrixEditor(){
449 		if(this.matrixEditor == null){
450 			this.matrixEditor = new MatrixEditor();
451 		}
452 		return this.matrixEditor;
453 	}
454 
getSongManager()455 	public TGSongManager getSongManager(){
456 		if(this.songManager == null){
457 			this.songManager = new TGSongManager(new TGFactoryImpl());
458 			this.songManager.setSong(this.songManager.newSong());
459 		}
460 		return this.songManager;
461 	}
462 
getMixer()463 	public TGMixer getMixer(){
464 		if(this.songMixer == null){
465 			this.songMixer = new TGMixer();
466 		}
467 		return this.songMixer;
468 	}
469 
getTransport()470 	public TGTransport getTransport(){
471 		if(this.songTransport == null){
472 			this.songTransport = new TGTransport();
473 		}
474 		return this.songTransport;
475 	}
476 
getEditorCache()477 	public EditorCache getEditorCache(){
478 		if(this.editorCache == null){
479 			this.editorCache = new EditorCache();
480 		}
481 		return this.editorCache;
482 	}
483 
getEditorManager()484 	public TGEditorManager getEditorManager(){
485 		if(this.editorManager == null){
486 			this.editorManager = new TGEditorManager();
487 		}
488 		return this.editorManager;
489 	}
490 
getLyricEditor()491 	public LyricEditor getLyricEditor(){
492 		if(this.lyricEditor == null){
493 			this.lyricEditor = new LyricEditor();
494 		}
495 		return this.lyricEditor;
496 	}
497 
getBrowser()498 	public TGBrowserDialog getBrowser(){
499 		if(this.browser == null){
500 			this.browser = new TGBrowserDialog();
501 		}
502 		return this.browser;
503 	}
504 
getUndoableManager()505 	public UndoableManager getUndoableManager(){
506 		if(this.undoableManager == null){
507 			this.undoableManager = new UndoableManager();
508 		}
509 		return this.undoableManager;
510 	}
511 
getScaleManager()512 	public ScaleManager getScaleManager(){
513 		if(this.scaleManager == null){
514 			this.scaleManager = new ScaleManager();
515 		}
516 		return this.scaleManager;
517 	}
518 
getPluginManager()519 	public TGPluginManager getPluginManager(){
520 		if(this.pluginManager == null){
521 			this.pluginManager = new TGPluginManager();
522 		}
523 		return this.pluginManager;
524 	}
525 
getIconManager()526 	public IconManager getIconManager(){
527 		if(this.iconManager == null){
528 			this.iconManager = new IconManager();
529 			this.iconManager.addLoader( new IconLoader() {
530 				public void loadIcons() {
531 					getShell().setImage(getIconManager().getAppIcon());
532 					getShell().layout(true);
533 				}
534 			});
535 		}
536 		return this.iconManager;
537 	}
538 
getCustomChordManager()539 	public CustomChordManager getCustomChordManager(){
540 		if(this.customChordManager == null){
541 			this.customChordManager = new CustomChordManager();
542 		}
543 		return this.customChordManager;
544 	}
545 
getItemManager()546 	public ItemManager getItemManager() {
547 		if(this.itemManager == null){
548 			this.itemManager = new ItemManager();
549 		}
550 		return this.itemManager;
551 	}
552 
getActionManager()553 	public ActionManager getActionManager() {
554 		if(this.actionManager == null){
555 			this.actionManager = new ActionManager();
556 		}
557 		return this.actionManager;
558 	}
559 
getLanguageManager()560 	public LanguageManager getLanguageManager() {
561 		if(this.languageManager == null){
562 			this.languageManager = new LanguageManager();
563 			this.loadLanguage();
564 		}
565 		return this.languageManager;
566 	}
567 
getConfig()568 	public TGConfigManager getConfig(){
569 		if(this.configManager == null){
570 			this.configManager = new TGConfigManagerImpl();
571 			this.configManager.init();
572 		}
573 		return this.configManager;
574 	}
575 
getkeyBindingManager()576 	public KeyBindingActionManager getkeyBindingManager(){
577 		if(this.keyBindingManager == null){
578 			this.keyBindingManager = new KeyBindingActionManager();
579 		}
580 		return this.keyBindingManager;
581 	}
582 
getFileHistory()583 	public FileHistory getFileHistory(){
584 		if(this.fileHistory == null){
585 			this.fileHistory = new FileHistory();
586 		}
587 		return this.fileHistory;
588 	}
589 
getPlayer()590 	public MidiPlayer getPlayer(){
591 		if(this.player == null){
592 			this.player = new MidiPlayer();
593 			this.player.init(getSongManager());
594 			this.player.addListener( new TGTransportListener() );
595 			try {
596 				getPlayer().addSequencerProvider(new MidiSequencerProviderImpl(), false);
597 			} catch (MidiPlayerException e) {
598 				e.printStackTrace();
599 			}
600 		}
601 		return this.player;
602 	}
603 
restorePlayerConfig()604 	public void restorePlayerConfig(){
605 		//check midi sequencer
606 		getPlayer().openSequencer(getConfig().getStringConfigValue(TGConfigKeys.MIDI_SEQUENCER), true);
607 
608 		//check midi port
609 		getPlayer().openOutputPort(getConfig().getStringConfigValue(TGConfigKeys.MIDI_PORT), true);
610 	}
611 
showTitle()612 	public void showTitle(){
613 		new SyncThread(new Runnable() {
614 			public void run() {
615 				if(!isDisposed()){
616 					getShell().setText(WindowTitleUtil.parseTitle());
617 				}
618 			}
619 		}).start();
620 	}
621 
updateCache(final boolean updateItems)622 	public void updateCache(final boolean updateItems){
623 		if(!this.isLocked()){
624 			this.lock();
625 			this.getEditorCache().updateEditMode();
626 			this.unlock();
627 			new SyncThread(new Runnable() {
628 				public void run() {
629 					if(!isDisposed() && !isLocked()){
630 						if(updateItems){
631 							lock();
632 							getEditorManager().doUpdate( TGUpdateListener.SELECTION );
633 							unlock();
634 						}
635 						redraw();
636 					}
637 				}
638 			}).start();
639 		}
640 	}
641 
redraw()642 	protected void redraw(){
643 		if(!isDisposed() && !this.isLocked()){
644 			this.lock();
645 			this.getEditorManager().doRedraw( TGRedrawListener.NORMAL );
646 			this.unlock();
647 		}
648 	}
649 
redrawPlayingMode()650 	public void redrawPlayingMode(){
651 		if(!isDisposed() && !this.isLocked()){
652 			this.lock();
653 			this.getEditorCache().updatePlayMode();
654 			this.getEditorManager().doRedraw( this.getEditorCache().shouldRedraw() ? TGRedrawListener.PLAYING_NEW_BEAT : TGRedrawListener.PLAYING_THREAD );
655 			this.unlock();
656 		}
657 	}
658 
showExternalBeat( TGBeat beat )659 	public void showExternalBeat( TGBeat beat ){
660 		if(!isDisposed() && !this.isLocked()){
661 			this.lock();
662 			this.getEditorManager().showExternalBeat(beat);
663 			this.updateCache(true);
664 			this.unlock();
665 		}
666 	}
667 
hideExternalBeat()668 	public void hideExternalBeat(){
669 		if(!isDisposed() && !this.isLocked()){
670 			this.lock();
671 			this.getEditorManager().hideExternalBeat();
672 			this.updateCache(true);
673 			this.unlock();
674 		}
675 	}
676 
getDisplay()677 	public Display getDisplay(){
678 		return this.display;
679 	}
680 
getShell()681 	public Shell getShell(){
682 		return this.shell;
683 	}
684 
getAction(String name)685 	public Action getAction(String name) {
686 		return this.getActionManager().getAction(name);
687 	}
688 
getProperty(String key)689 	public static String getProperty(String key) {
690 		return TuxGuitar.instance().getLanguageManager().getProperty(key);
691 	}
692 
getProperty(String key,String[] arguments)693 	public static String getProperty(String key,String[] arguments) {
694 		return  TuxGuitar.instance().getLanguageManager().getProperty(key,arguments);
695 	}
696 
isDisposed()697 	public static boolean isDisposed(){
698 		return (TuxGuitar.instance().getDisplay().isDisposed() || TuxGuitar.instance().getShell().isDisposed());
699 	}
700 
loadLanguage()701 	public void loadLanguage(){
702 		this.lock();
703 
704 		getLanguageManager().setLanguage(getConfig().getStringConfigValue(TGConfigKeys.LANGUAGE));
705 
706 		this.unlock();
707 	}
708 
loadToolBars()709 	public void loadToolBars(){
710 		this.lock();
711 
712 		getItemManager().createCoolbar();
713 
714 		this.unlock();
715 	}
716 
loadStyles()717 	public void loadStyles(){
718 		this.lock();
719 
720 		getTablatureEditor().getTablature().reloadStyles();
721 
722 		this.unlock();
723 	}
724 
loadSkin()725 	public void loadSkin(){
726 		this.lock();
727 
728 		getIconManager().reloadIcons();
729 
730 		this.unlock();
731 	}
732 
newSong()733 	public void newSong(){
734 		TuxGuitar.instance().fireNewSong(TuxGuitar.instance().getSongManager().newSong(),null);
735 	}
736 
fireNewSong(TGSong song,URL url)737 	public void fireNewSong(TGSong song,URL url){
738 		this.lock();
739 
740 		TuxGuitar.instance().getSongManager().setSong(song);
741 		getFileHistory().reset(url);
742 		getPlayer().reset();
743 		getPlayer().getMode().clear();
744 		getEditorCache().reset();
745 		getUndoableManager().discardAllEdits();
746 		getEditorManager().doUpdate( TGUpdateListener.SONG_LOADED );
747 
748 		this.unlock();
749 
750 		updateCache(true);
751 		showTitle();
752 	}
753 
fireSaveSong(URL url)754 	public void fireSaveSong(URL url){
755 		this.lock();
756 
757 		getFileHistory().reset(url);
758 		getEditorCache().reset();
759 		getUndoableManager().discardAllEdits();
760 		getEditorManager().doUpdate( TGUpdateListener.SONG_SAVED );
761 
762 		this.unlock();
763 
764 		updateCache(true);
765 		showTitle();
766 	}
767 
fireUpdate()768 	public void fireUpdate(){
769 		this.lock();
770 		this.getEditorCache().reset();
771 		this.getEditorManager().doUpdate( TGUpdateListener.SONG_UPDATED );
772 		this.unlock();
773 	}
774 
loadCursor(int style)775 	public void loadCursor(int style){
776 		this.loadCursor(getShell(),style);
777 	}
778 
loadCursor(final Control control,final int style)779 	public void loadCursor(final Control control,final int style){
780 		try {
781 			TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
782 				public void run() throws Throwable {
783 					if(!control.isDisposed()){
784 						control.setCursor(getDisplay().getSystemCursor(style));
785 					}
786 				}
787 			});
788 		} catch (Throwable e) {
789 			e.printStackTrace();
790 		}
791 	}
792 
isInitialized()793 	public boolean isInitialized() {
794 		return this.initialized;
795 	}
796 
setInitialized(boolean initialized)797 	public void setInitialized(boolean initialized) {
798 		this.initialized = initialized;
799 	}
800 
lock()801 	public void lock(){
802 		this.lock.lock();
803 	}
804 
unlock()805 	public void unlock(){
806 		this.lock.unlock();
807 	}
808 
isLocked()809 	public boolean isLocked(){
810 		return this.lock.isLocked();
811 	}
812 }