2
* Created on 25-nov-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;
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.SelectionAdapter;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.layout.FormAttachment;
17
import org.eclipse.swt.layout.FormData;
18
import org.eclipse.swt.layout.FormLayout;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.swt.widgets.Event;
23
import org.eclipse.swt.widgets.Listener;
24
import org.eclipse.swt.widgets.Sash;
25
import org.eclipse.swt.widgets.Shell;
26
import org.herac.tuxguitar.gui.actions.Action;
27
import org.herac.tuxguitar.gui.actions.ActionLock;
28
import org.herac.tuxguitar.gui.actions.ActionManager;
29
import org.herac.tuxguitar.gui.actions.file.FileActionUtils;
30
import org.herac.tuxguitar.gui.actions.system.DisposeAction;
31
import org.herac.tuxguitar.gui.editors.EditorCache;
32
import org.herac.tuxguitar.gui.editors.FretBoardEditor;
33
import org.herac.tuxguitar.gui.editors.PianoEditor;
34
import org.herac.tuxguitar.gui.editors.TablatureEditor;
35
import org.herac.tuxguitar.gui.editors.chord.CustomChordManager;
36
import org.herac.tuxguitar.gui.editors.lyric.LyricEditor;
37
import org.herac.tuxguitar.gui.editors.matrix.MatrixEditor;
38
import org.herac.tuxguitar.gui.editors.tab.TGFactoryImpl;
39
import org.herac.tuxguitar.gui.helper.FileHistory;
40
import org.herac.tuxguitar.gui.helper.SyncThread;
41
import org.herac.tuxguitar.gui.items.ItemManager;
42
import org.herac.tuxguitar.gui.marker.MarkerList;
43
import org.herac.tuxguitar.gui.mixer.TGMixer;
44
import org.herac.tuxguitar.gui.system.config.TGConfigKeys;
45
import org.herac.tuxguitar.gui.system.config.TGConfigManager;
46
import org.herac.tuxguitar.gui.system.config.TGConfigManagerImpl;
47
import org.herac.tuxguitar.gui.system.icons.IconLoader;
48
import org.herac.tuxguitar.gui.system.icons.IconManager;
49
import org.herac.tuxguitar.gui.system.keybindings.KeyBindingActionManager;
50
import org.herac.tuxguitar.gui.system.language.LanguageManager;
51
import org.herac.tuxguitar.gui.system.plugins.TGPluginManager;
52
import org.herac.tuxguitar.gui.table.TGTableViewer;
53
import org.herac.tuxguitar.gui.tools.browser.dialog.TGBrowserDialog;
54
import org.herac.tuxguitar.gui.tools.scale.ScaleManager;
55
import org.herac.tuxguitar.gui.transport.TGTransport;
56
import org.herac.tuxguitar.gui.undo.UndoableManager;
57
import org.herac.tuxguitar.gui.util.ArgumentParser;
58
import org.herac.tuxguitar.gui.util.TGFileUtils;
59
import org.herac.tuxguitar.gui.util.TGSplash;
60
import org.herac.tuxguitar.gui.util.WindowTitleUtil;
61
import org.herac.tuxguitar.player.base.MidiPlayer;
62
import org.herac.tuxguitar.player.base.MidiPlayerException;
63
import org.herac.tuxguitar.player.impl.sequencer.MidiSequencerProviderImpl;
64
import org.herac.tuxguitar.song.managers.TGSongManager;
65
import org.herac.tuxguitar.song.models.TGSong;
66
import org.herac.tuxguitar.util.TGLock;
67
import org.herac.tuxguitar.util.TGSynchronizer;
72
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
74
public class TuxGuitar {
76
public static final String APPLICATION_NAME = "TuxGuitar";
78
public static final int MARGIN_WIDTH = 5;
80
private static TuxGuitar instance;
84
private Display display;
88
private MidiPlayer player;
90
private TGSongManager songManager;
92
private TGConfigManager configManager;
94
private LanguageManager languageManager;
96
private KeyBindingActionManager keyBindingManager;
98
private IconManager iconManager;
100
private EditorCache editorCache;
102
private TablatureEditor tablatureEditor;
104
private TGTableViewer table;
106
private TGMixer songMixer;
108
private TGTransport songTransport;
110
private FretBoardEditor fretBoardEditor;
112
private PianoEditor pianoEditor;
114
private MatrixEditor matrixEditor;
116
private LyricEditor lyricEditor;
118
private TGBrowserDialog browser;
120
private UndoableManager undoableManager;
122
private ScaleManager scaleManager;
124
private ActionManager actionManager;
126
private ItemManager itemManager;
128
private CustomChordManager customChordManager;
130
private FileHistory fileHistory;
132
private TGPluginManager pluginManager;
136
protected Composite sashComposite;
139
this.lock = new TGLock();
142
public static TuxGuitar instance() {
143
if (instance == null) {
144
synchronized (TuxGuitar.class) {
145
instance = new TuxGuitar();
151
private void initSynchronizer(){
152
TGSynchronizer.instance().setController(new TGSynchronizer.TGSynchronizerController() {
153
public void excecute(final TGSynchronizer.TGSynchronizerTask task) {
154
final Display display = getDisplay();
155
if(display != null && !display.isDisposed()){
156
display.syncExec(new Runnable() {
166
public void displayGUI(String[] args) {
167
//checkeo los argumentos
168
ArgumentParser argumentParser = new ArgumentParser(args);
169
if(argumentParser.processAndExit()){
173
TGFileUtils.loadLibraries();
174
TGFileUtils.loadClasspath();
176
this.display = new Display();
177
this.initSynchronizer();
179
TGSplash.instance().init();
181
this.shell = new Shell(getDisplay());
182
this.shell.setLayout(getShellLayout());
183
this.shell.setImage(getIconManager().getAppIcon());
185
this.createComposites(getShell());
187
boolean maximized = getConfig().getBooleanConfigValue(TGConfigKeys.MAXIMIZED);
188
this.shell.setMaximized(maximized);
190
int width = getConfig().getIntConfigValue(TGConfigKeys.WIDTH);
191
int height = getConfig().getIntConfigValue(TGConfigKeys.HEIGHT);
192
if(width > 0 && height > 0){
193
this.shell.setSize(width,height);
196
this.shell.setMinimumSize(640,480);
198
this.showDefaultControls();
199
this.updateCache(true);
201
this.getPluginManager().openPlugins();
203
TGSplash.instance().finish();
205
this.shell.addShellListener(getAction(DisposeAction.NAME));
207
this.startSong(argumentParser);
208
while (!getDisplay().isDisposed() && !getShell().isDisposed()) {
209
if (!getDisplay().readAndDispatch()) {
210
getDisplay().sleep();
213
getDisplay().dispose();
216
private FormLayout getShellLayout(){
217
FormLayout layout = new FormLayout();
218
layout.marginWidth = MARGIN_WIDTH;
219
layout.marginHeight = MARGIN_WIDTH;
223
private void startSong(final ArgumentParser parser){
224
final URL url = parser.getURL();
227
new SyncThread(new Runnable() {
229
TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
230
new Thread(new Runnable() {
232
if(!TuxGuitar.isDisposed()){
233
FileActionUtils.open(url);
234
TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
244
public void createComposites(Composite composite) {
245
this.sashComposite = new Composite(composite,SWT.NONE);
246
this.sashComposite.setLayout(new FormLayout());
247
FormData data = new FormData();
248
data.left = new FormAttachment(0,0);
249
data.right = new FormAttachment(100,0);
250
data.top = new FormAttachment(getItemManager().getCoolbar(),MARGIN_WIDTH);
251
data.bottom = new FormAttachment(100,0);
252
this.sashComposite.setLayoutData(data);
254
this.sash = new Sash(this.sashComposite, SWT.HORIZONTAL);
255
data = new FormData();
256
data.left = new FormAttachment(0,0);
257
data.right = new FormAttachment(100,0);
258
data.bottom = new FormAttachment(100,-150);
260
this.sash.setLayoutData(data);
262
getTablatureEditor().showTablature(this.sashComposite);
263
data = new FormData();
264
data.left = new FormAttachment(0,0);
265
data.right = new FormAttachment(100,0);
266
data.top = new FormAttachment(0,0);
267
data.bottom = new FormAttachment(this.sash, 0);
268
getTablatureEditor().getTablature().setLayoutData(data);
270
getTable().init(this.sashComposite);
271
data = new FormData();
272
data.left = new FormAttachment(0,0);
273
data.right = new FormAttachment(100,0);
274
data.top = new FormAttachment(this.sash,10);
275
data.bottom = new FormAttachment(100,0);
276
getTable().getComposite().setLayoutData(data);
278
this.sash.addMouseListener(new MouseAdapter() {
279
public void mouseUp(MouseEvent e) {
280
TuxGuitar.this.sashComposite.layout(true,true);
283
this.sash.addSelectionListener(new SelectionAdapter() {
284
public void widgetSelected(SelectionEvent event) {
285
int maximumHeight = (TuxGuitar.this.sashComposite.getBounds().height - TuxGuitar.this.sash.getBounds().height);
286
int height = (maximumHeight - event.y);
287
height = Math.max(height,0);
288
height = Math.min(height,maximumHeight);
289
((FormData) TuxGuitar.this.sash.getLayoutData()).bottom = new FormAttachment(100, -height);
292
this.sashComposite.addListener(SWT.Resize, new Listener() {
293
public void handleEvent(Event arg0) {
294
FormData data = ((FormData) TuxGuitar.this.sash.getLayoutData());
295
int height = -data.bottom.offset;
296
int maximumHeight = (TuxGuitar.this.sashComposite.getBounds().height - TuxGuitar.this.sash.getBounds().height);
297
if(height > maximumHeight){
298
data.bottom = new FormAttachment(100, -maximumHeight);
303
data = new FormData();
304
data.left = new FormAttachment(0,0);
305
data.right = new FormAttachment(100,0);
306
data.top = new FormAttachment(this.sashComposite,0);
307
data.bottom = new FormAttachment(100,0);
309
Composite footer = new Composite(composite,SWT.NONE);
310
footer.setLayout(new FormLayout());
311
footer.setLayoutData(data);
312
getFretBoardEditor().showFretBoard(footer);
315
public void showDefaultControls(){
316
final TGConfigManager config = getConfig();
318
if(config.getBooleanConfigValue(TGConfigKeys.SHOW_FRETBOARD)){
319
getFretBoardEditor().showFretBoard();
321
getFretBoardEditor().hideFretBoard();
324
if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MIXER)){
325
new SyncThread(new Runnable() {
332
if(config.getBooleanConfigValue(TGConfigKeys.SHOW_TRANSPORT)){
333
new SyncThread(new Runnable() {
335
getTransport().show();
340
if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MATRIX)){
341
new SyncThread(new Runnable() {
343
getMatrixEditor().show();
348
if(config.getBooleanConfigValue(TGConfigKeys.SHOW_PIANO)){
349
new SyncThread(new Runnable() {
351
getPianoEditor().show();
356
if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MARKERS)){
357
new SyncThread(new Runnable() {
359
MarkerList.instance().show();
365
public void setTableHeight(int value){
366
int offset = ((FormData) getTable().getComposite().getLayoutData()).top.offset;
367
int sashHeight = this.sash.getBounds().height;
368
int maximumHeight = (this.sashComposite.getBounds().height - sashHeight);
369
int height = (value + sashHeight + offset);
370
height = Math.max( height,0);
371
height = Math.min( height,maximumHeight);
372
((FormData) TuxGuitar.this.sash.getLayoutData()).bottom = new FormAttachment(100, -height);
373
this.sashComposite.layout(true,true);
376
public void updateShellFooter(int offset,int minimunWith,int minimunHeight){
377
FormData data = ((FormData)this.sashComposite.getLayoutData());
378
data.bottom.offset = -offset;
379
getShell().setMinimumSize(Math.max(640,minimunWith),Math.max(480,minimunHeight));
380
getShell().layout(true,true);
384
public TGTableViewer getTable(){
385
if(this.table == null){
386
this.table = new TGTableViewer();
391
public TablatureEditor getTablatureEditor(){
392
if(this.tablatureEditor == null){
393
this.tablatureEditor = new TablatureEditor();
395
return this.tablatureEditor;
398
public FretBoardEditor getFretBoardEditor(){
399
if(this.fretBoardEditor == null){
400
this.fretBoardEditor = new FretBoardEditor();
402
return this.fretBoardEditor;
405
public PianoEditor getPianoEditor(){
406
if(this.pianoEditor == null){
407
this.pianoEditor = new PianoEditor();
409
return this.pianoEditor;
412
public MatrixEditor getMatrixEditor(){
413
if(this.matrixEditor == null){
414
this.matrixEditor = new MatrixEditor();
416
return this.matrixEditor;
419
public TGSongManager getSongManager(){
420
if(this.songManager == null){
421
this.songManager = new TGSongManager(new TGFactoryImpl());
422
this.songManager.setSong(this.songManager.newSong());
424
return this.songManager;
427
public TGMixer getMixer(){
428
if(this.songMixer == null){
429
this.songMixer = new TGMixer();
431
return this.songMixer;
434
public TGTransport getTransport(){
435
if(this.songTransport == null){
436
this.songTransport = new TGTransport();
438
return this.songTransport;
441
public EditorCache getEditorCache(){
442
if(this.editorCache == null){
443
this.editorCache = new EditorCache();
445
return this.editorCache;
448
public LyricEditor getLyricEditor(){
449
if(this.lyricEditor == null){
450
this.lyricEditor = new LyricEditor();
452
return this.lyricEditor;
455
public TGBrowserDialog getBrowser(){
456
if(this.browser == null){
457
this.browser = new TGBrowserDialog();
462
public UndoableManager getUndoableManager(){
463
if(this.undoableManager == null){
464
this.undoableManager = new UndoableManager();
466
return this.undoableManager;
469
public ScaleManager getScaleManager(){
470
if(this.scaleManager == null){
471
this.scaleManager = new ScaleManager();
473
return this.scaleManager;
476
public TGPluginManager getPluginManager(){
477
if(this.pluginManager == null){
478
this.pluginManager = new TGPluginManager();
480
return this.pluginManager;
483
public IconManager getIconManager(){
484
if(this.iconManager == null){
485
this.iconManager = new IconManager();
486
this.iconManager.addLoader( new IconLoader() {
487
public void loadIcons() {
488
getShell().setImage(getIconManager().getAppIcon());
489
getShell().layout(true);
493
return this.iconManager;
496
public CustomChordManager getCustomChordManager(){
497
if(this.customChordManager == null){
498
this.customChordManager = new CustomChordManager();
500
return this.customChordManager;
503
public ItemManager getItemManager() {
504
if(this.itemManager == null){
505
this.itemManager = new ItemManager();
507
return this.itemManager;
510
public ActionManager getActionManager() {
511
if(this.actionManager == null){
512
this.actionManager = new ActionManager();
514
return this.actionManager;
517
public LanguageManager getLanguageManager() {
518
if(this.languageManager == null){
519
this.languageManager = new LanguageManager();
522
return this.languageManager;
525
public TGConfigManager getConfig(){
526
if(this.configManager == null){
527
this.configManager = new TGConfigManagerImpl();
528
this.configManager.init();
530
return this.configManager;
533
public KeyBindingActionManager getkeyBindingManager(){
534
if(this.keyBindingManager == null){
535
this.keyBindingManager = new KeyBindingActionManager();
537
return this.keyBindingManager;
540
public FileHistory getFileHistory(){
541
if(this.fileHistory == null){
542
this.fileHistory = new FileHistory();
544
return this.fileHistory;
547
public MidiPlayer getPlayer(){
548
if(this.player == null){
549
this.player = new MidiPlayer();
550
this.player.init(getSongManager());
552
//check midi sequencer
553
getPlayer().openSequencer(getConfig().getStringConfigValue(TGConfigKeys.MIDI_SEQUENCER));
556
getPlayer().openPort(getConfig().getStringConfigValue(TGConfigKeys.MIDI_PORT));
558
getPlayer().addSequencerProvider(new MidiSequencerProviderImpl());
559
} catch (MidiPlayerException e) {
566
public void showTitle(){
567
new SyncThread(new Runnable() {
570
getShell().setText(WindowTitleUtil.parseTitle());
576
public void updateCache(final boolean updateItems){
577
if(!this.isLocked()){
579
this.getEditorCache().updateEditMode();
581
new SyncThread(new Runnable() {
583
if(!isDisposed() && !isLocked()){
586
getItemManager().updateItems();
587
getTransport().updateItems();
588
getMixer().updateItems();
589
getLyricEditor().updateItems();
590
getTable().updateItems();
600
protected void redraw(){
601
if(!isDisposed() && !this.isLocked()){
603
this.getTablatureEditor().getTablature().redraw();
604
this.getFretBoardEditor().redraw();
605
this.getPianoEditor().redraw();
606
this.getTable().redraw();
607
this.getMatrixEditor().redraw();
612
public void redrawPayingMode(){
613
if(!isDisposed() && !this.isLocked()){
615
this.getEditorCache().updatePlayMode();
616
if(this.getEditorCache().shouldRedraw()){
617
this.getTablatureEditor().getTablature().redrawPlayingMode();
618
this.getFretBoardEditor().redrawPlayingMode();
619
this.getPianoEditor().redrawPlayingMode();
620
this.getTable().redrawPlayingMode();
621
this.getMatrixEditor().redrawPlayingMode();
623
this.getTransport().redrawPlayingMode();
628
public Display getDisplay(){
632
public Shell getShell(){
636
public Action getAction(String name) {
637
return this.getActionManager().getAction(name);
640
public static String getProperty(String key) {
641
return TuxGuitar.instance().getLanguageManager().getProperty(key);
644
public static String getProperty(String key,String[] arguments) {
645
return TuxGuitar.instance().getLanguageManager().getProperty(key,arguments);
648
public static boolean isDisposed(){
649
return (TuxGuitar.instance().getDisplay().isDisposed() || TuxGuitar.instance().getShell().isDisposed());
652
public void loadLanguage(){
655
getLanguageManager().setLanguage(getConfig().getStringConfigValue(TGConfigKeys.LANGUAGE));
660
public void loadToolBars(){
663
getItemManager().createCoolbar();
668
public void loadStyles(){
671
getTablatureEditor().getTablature().reloadStyles();
676
public void loadSkin(){
679
getIconManager().reloadIcons();
684
public void newSong(){
685
TuxGuitar.instance().fireNewSong(TuxGuitar.instance().getSongManager().newSong(),null);
688
public void fireNewSong(TGSong song,URL url){
691
TuxGuitar.instance().getSongManager().setSong(song);
692
getFileHistory().reset(url);
694
getEditorCache().reset();
695
getUndoableManager().discardAllEdits();
696
getTablatureEditor().getTablature().updateTablature();
697
getTablatureEditor().getTablature().resetScroll();
698
getTablatureEditor().getTablature().initCaret();
699
getTable().fireUpdate(true);
701
getLyricEditor().update();
702
MarkerList.instance().update();
710
public void fireSaveSong(URL url){
713
getFileHistory().reset(url);
714
getEditorCache().reset();
715
getUndoableManager().discardAllEdits();
723
public void fireUpdate(){
726
this.getEditorCache().reset();
727
this.getTablatureEditor().getTablature().updateTablature();
728
this.getTable().fireUpdate(false);
729
this.getLyricEditor().update();
734
public void loadCursor(int style){
735
this.loadCursor(getShell(),style);
738
public void loadCursor(final Control control,final int style){
740
TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
741
public void run() throws Throwable {
742
if(!control.isDisposed()){
743
control.setCursor(getDisplay().getSystemCursor(style));
747
} catch (Throwable e) {
756
public void unlock(){
760
public boolean isLocked(){
761
return this.lock.isLocked();
b'\\ No newline at end of file'