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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/TuxGuitar.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 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.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;
 
68
 
 
69
/**
 
70
 * @author julian
 
71
 * 
 
72
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
 
73
 */
 
74
public class TuxGuitar {
 
75
        
 
76
        public static final String APPLICATION_NAME = "TuxGuitar";
 
77
        
 
78
        public static final int MARGIN_WIDTH = 5;
 
79
        
 
80
        private static TuxGuitar instance;
 
81
        
 
82
        private TGLock lock;
 
83
        
 
84
        private Display display;
 
85
        
 
86
        private Shell shell;
 
87
        
 
88
        private MidiPlayer player;
 
89
        
 
90
        private TGSongManager songManager;
 
91
        
 
92
        private TGConfigManager configManager;
 
93
        
 
94
        private LanguageManager languageManager;
 
95
        
 
96
        private KeyBindingActionManager keyBindingManager;
 
97
        
 
98
        private IconManager iconManager;
 
99
        
 
100
        private EditorCache editorCache;
 
101
        
 
102
        private TablatureEditor tablatureEditor;
 
103
        
 
104
        private TGTableViewer table;
 
105
        
 
106
        private TGMixer songMixer;
 
107
        
 
108
        private TGTransport songTransport;
 
109
        
 
110
        private FretBoardEditor fretBoardEditor;
 
111
        
 
112
        private PianoEditor pianoEditor;
 
113
        
 
114
        private MatrixEditor matrixEditor;
 
115
        
 
116
        private LyricEditor lyricEditor;
 
117
        
 
118
        private TGBrowserDialog browser;
 
119
        
 
120
        private UndoableManager undoableManager;
 
121
        
 
122
        private ScaleManager scaleManager;
 
123
        
 
124
        private ActionManager actionManager;
 
125
        
 
126
        private ItemManager itemManager;
 
127
        
 
128
        private CustomChordManager customChordManager;
 
129
        
 
130
        private FileHistory fileHistory;
 
131
        
 
132
        private TGPluginManager pluginManager;
 
133
        
 
134
        protected Sash sash;
 
135
        
 
136
        protected Composite sashComposite;
 
137
        
 
138
        public TuxGuitar() {
 
139
                this.lock = new TGLock();
 
140
        }
 
141
        
 
142
        public static TuxGuitar instance() {
 
143
                if (instance == null) {
 
144
                        synchronized (TuxGuitar.class) {
 
145
                                instance = new TuxGuitar();
 
146
                        }
 
147
                }
 
148
                return instance;
 
149
        }
 
150
        
 
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() {
 
157
                                                public void run() {
 
158
                                                        task.run();
 
159
                                                }
 
160
                                        });
 
161
                                }
 
162
                        }
 
163
                });
 
164
        }
 
165
        
 
166
        public void displayGUI(String[] args) {
 
167
                //checkeo los argumentos
 
168
                ArgumentParser argumentParser = new ArgumentParser(args);
 
169
                if(argumentParser.processAndExit()){
 
170
                        return;
 
171
                }
 
172
                
 
173
                TGFileUtils.loadLibraries();
 
174
                TGFileUtils.loadClasspath();
 
175
                
 
176
                this.display = new Display();
 
177
                this.initSynchronizer();
 
178
                
 
179
                TGSplash.instance().init();
 
180
                
 
181
                this.shell = new Shell(getDisplay());
 
182
                this.shell.setLayout(getShellLayout());
 
183
                this.shell.setImage(getIconManager().getAppIcon());
 
184
                
 
185
                this.createComposites(getShell());
 
186
                
 
187
                boolean maximized = getConfig().getBooleanConfigValue(TGConfigKeys.MAXIMIZED);
 
188
                this.shell.setMaximized(maximized);
 
189
                if(!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);
 
194
                        }
 
195
                }
 
196
                this.shell.setMinimumSize(640,480);
 
197
                
 
198
                this.showDefaultControls();
 
199
                this.updateCache(true);
 
200
                this.showTitle();
 
201
                this.getPluginManager().openPlugins();
 
202
                
 
203
                TGSplash.instance().finish();
 
204
                
 
205
                this.shell.addShellListener(getAction(DisposeAction.NAME));
 
206
                this.shell.open();
 
207
                this.startSong(argumentParser);
 
208
                while (!getDisplay().isDisposed() && !getShell().isDisposed()) {
 
209
                        if (!getDisplay().readAndDispatch()) {
 
210
                                getDisplay().sleep();
 
211
                        }
 
212
                }
 
213
                getDisplay().dispose();
 
214
        }
 
215
        
 
216
        private FormLayout getShellLayout(){
 
217
                FormLayout layout = new FormLayout();
 
218
                layout.marginWidth = MARGIN_WIDTH;
 
219
                layout.marginHeight = MARGIN_WIDTH;
 
220
                return layout;
 
221
        }
 
222
        
 
223
        private void startSong(final ArgumentParser parser){
 
224
                final URL url = parser.getURL();
 
225
                if(url != null){
 
226
                        ActionLock.lock();
 
227
                        new SyncThread(new Runnable() {
 
228
                                public void run() {
 
229
                                        TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
 
230
                                        new Thread(new Runnable() {
 
231
                                                public void run() {
 
232
                                                        if(!TuxGuitar.isDisposed()){
 
233
                                                                FileActionUtils.open(url);
 
234
                                                                TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
 
235
                                                                ActionLock.unlock();
 
236
                                                        }
 
237
                                                }
 
238
                                        }).start();
 
239
                                }
 
240
                        }).start();
 
241
                }
 
242
        }
 
243
        
 
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);
 
253
                
 
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);
 
259
                
 
260
                this.sash.setLayoutData(data);
 
261
                
 
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);
 
269
                
 
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);
 
277
                
 
278
                this.sash.addMouseListener(new MouseAdapter() {
 
279
                        public void mouseUp(MouseEvent e) {
 
280
                                TuxGuitar.this.sashComposite.layout(true,true);
 
281
                        }
 
282
                });
 
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);
 
290
                        }
 
291
                });
 
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);
 
299
                                }
 
300
                        }
 
301
                });
 
302
                
 
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);
 
308
                
 
309
                Composite footer = new Composite(composite,SWT.NONE);
 
310
                footer.setLayout(new FormLayout());
 
311
                footer.setLayoutData(data);
 
312
                getFretBoardEditor().showFretBoard(footer);
 
313
        }
 
314
        
 
315
        public void showDefaultControls(){
 
316
                final TGConfigManager config = getConfig();
 
317
                //---Fretboard---
 
318
                if(config.getBooleanConfigValue(TGConfigKeys.SHOW_FRETBOARD)){
 
319
                        getFretBoardEditor().showFretBoard();
 
320
                }else{
 
321
                        getFretBoardEditor().hideFretBoard();
 
322
                }
 
323
                //---Mixer---
 
324
                if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MIXER)){
 
325
                        new SyncThread(new Runnable() {
 
326
                                public void run() {
 
327
                                        getMixer().show();
 
328
                                }
 
329
                        }).start();
 
330
                }
 
331
                //---Transport---
 
332
                if(config.getBooleanConfigValue(TGConfigKeys.SHOW_TRANSPORT)){
 
333
                        new SyncThread(new Runnable() {
 
334
                                public void run() {
 
335
                                        getTransport().show();
 
336
                                }
 
337
                        }).start();
 
338
                }
 
339
                //---Matrix---
 
340
                if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MATRIX)){
 
341
                        new SyncThread(new Runnable() {
 
342
                                public void run() {
 
343
                                        getMatrixEditor().show();
 
344
                                }
 
345
                        }).start();
 
346
                }
 
347
                //---Piano---
 
348
                if(config.getBooleanConfigValue(TGConfigKeys.SHOW_PIANO)){
 
349
                        new SyncThread(new Runnable() {
 
350
                                public void run() {
 
351
                                        getPianoEditor().show();
 
352
                                }
 
353
                        }).start();
 
354
                }
 
355
                //---Markers---
 
356
                if(config.getBooleanConfigValue(TGConfigKeys.SHOW_MARKERS)){
 
357
                        new SyncThread(new Runnable() {
 
358
                                public void run() {
 
359
                                        MarkerList.instance().show();
 
360
                                }
 
361
                        }).start();
 
362
                }
 
363
        }
 
364
        
 
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);
 
374
        }
 
375
        
 
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);
 
381
                getShell().redraw();
 
382
        }
 
383
        
 
384
        public TGTableViewer getTable(){
 
385
                if(this.table == null){
 
386
                        this.table = new TGTableViewer();
 
387
                }
 
388
                return this.table;
 
389
        }
 
390
        
 
391
        public TablatureEditor getTablatureEditor(){
 
392
                if(this.tablatureEditor == null){
 
393
                        this.tablatureEditor = new TablatureEditor();
 
394
                }
 
395
                return this.tablatureEditor;
 
396
        }
 
397
        
 
398
        public FretBoardEditor getFretBoardEditor(){
 
399
                if(this.fretBoardEditor == null){
 
400
                        this.fretBoardEditor = new FretBoardEditor();
 
401
                }
 
402
                return this.fretBoardEditor;
 
403
        }
 
404
        
 
405
        public PianoEditor getPianoEditor(){
 
406
                if(this.pianoEditor == null){
 
407
                        this.pianoEditor = new PianoEditor();
 
408
                }
 
409
                return this.pianoEditor;
 
410
        }
 
411
        
 
412
        public MatrixEditor getMatrixEditor(){
 
413
                if(this.matrixEditor == null){
 
414
                        this.matrixEditor = new MatrixEditor();
 
415
                }
 
416
                return this.matrixEditor;
 
417
        }
 
418
        
 
419
        public TGSongManager getSongManager(){
 
420
                if(this.songManager == null){
 
421
                        this.songManager = new TGSongManager(new TGFactoryImpl());
 
422
                        this.songManager.setSong(this.songManager.newSong());
 
423
                }
 
424
                return this.songManager;
 
425
        }
 
426
        
 
427
        public TGMixer getMixer(){
 
428
                if(this.songMixer == null){
 
429
                        this.songMixer = new TGMixer();
 
430
                }
 
431
                return this.songMixer;
 
432
        }
 
433
        
 
434
        public TGTransport getTransport(){
 
435
                if(this.songTransport == null){
 
436
                        this.songTransport = new TGTransport();
 
437
                }
 
438
                return this.songTransport;
 
439
        }
 
440
        
 
441
        public EditorCache getEditorCache(){
 
442
                if(this.editorCache == null){
 
443
                        this.editorCache = new EditorCache();
 
444
                }
 
445
                return this.editorCache;
 
446
        }
 
447
        
 
448
        public LyricEditor getLyricEditor(){
 
449
                if(this.lyricEditor == null){
 
450
                        this.lyricEditor = new LyricEditor();
 
451
                }
 
452
                return this.lyricEditor;
 
453
        }
 
454
        
 
455
        public TGBrowserDialog getBrowser(){
 
456
                if(this.browser == null){
 
457
                        this.browser = new TGBrowserDialog();
 
458
                }
 
459
                return this.browser;
 
460
        }
 
461
        
 
462
        public UndoableManager getUndoableManager(){
 
463
                if(this.undoableManager == null){
 
464
                        this.undoableManager = new UndoableManager();
 
465
                }
 
466
                return this.undoableManager;
 
467
        }
 
468
        
 
469
        public ScaleManager getScaleManager(){
 
470
                if(this.scaleManager == null){
 
471
                        this.scaleManager = new ScaleManager();
 
472
                }
 
473
                return this.scaleManager;
 
474
        }
 
475
        
 
476
        public TGPluginManager getPluginManager(){
 
477
                if(this.pluginManager == null){
 
478
                        this.pluginManager = new TGPluginManager();
 
479
                }
 
480
                return this.pluginManager;
 
481
        }
 
482
        
 
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);
 
490
                                }
 
491
                        });
 
492
                }
 
493
                return this.iconManager;
 
494
        }
 
495
        
 
496
        public CustomChordManager getCustomChordManager(){
 
497
                if(this.customChordManager == null){
 
498
                        this.customChordManager = new CustomChordManager();
 
499
                }
 
500
                return this.customChordManager;
 
501
        }
 
502
        
 
503
        public ItemManager getItemManager() {
 
504
                if(this.itemManager == null){
 
505
                        this.itemManager = new ItemManager();
 
506
                }
 
507
                return this.itemManager;
 
508
        }
 
509
        
 
510
        public ActionManager getActionManager() {
 
511
                if(this.actionManager == null){
 
512
                        this.actionManager = new ActionManager();
 
513
                }
 
514
                return this.actionManager;
 
515
        }
 
516
        
 
517
        public LanguageManager getLanguageManager() {
 
518
                if(this.languageManager == null){
 
519
                        this.languageManager = new LanguageManager();
 
520
                        this.loadLanguage();
 
521
                }
 
522
                return this.languageManager;
 
523
        }
 
524
        
 
525
        public TGConfigManager getConfig(){
 
526
                if(this.configManager == null){
 
527
                        this.configManager = new TGConfigManagerImpl();
 
528
                        this.configManager.init();
 
529
                }
 
530
                return this.configManager;
 
531
        }
 
532
        
 
533
        public KeyBindingActionManager getkeyBindingManager(){
 
534
                if(this.keyBindingManager == null){
 
535
                        this.keyBindingManager = new KeyBindingActionManager();
 
536
                }
 
537
                return this.keyBindingManager;
 
538
        }
 
539
        
 
540
        public FileHistory getFileHistory(){
 
541
                if(this.fileHistory == null){
 
542
                        this.fileHistory = new FileHistory();
 
543
                }
 
544
                return this.fileHistory;
 
545
        }
 
546
        
 
547
        public MidiPlayer getPlayer(){
 
548
                if(this.player == null){
 
549
                        this.player = new MidiPlayer();
 
550
                        this.player.init(getSongManager());
 
551
                        try {
 
552
                                //check midi sequencer
 
553
                                getPlayer().openSequencer(getConfig().getStringConfigValue(TGConfigKeys.MIDI_SEQUENCER));
 
554
                                
 
555
                                //check midi port
 
556
                                getPlayer().openPort(getConfig().getStringConfigValue(TGConfigKeys.MIDI_PORT));
 
557
                                
 
558
                                getPlayer().addSequencerProvider(new MidiSequencerProviderImpl());
 
559
                        } catch (MidiPlayerException e) {
 
560
                                e.printStackTrace();
 
561
                        }
 
562
                }
 
563
                return this.player;
 
564
        }
 
565
        
 
566
        public void showTitle(){
 
567
                new SyncThread(new Runnable() {
 
568
                        public void run() {
 
569
                                if(!isDisposed()){
 
570
                                        getShell().setText(WindowTitleUtil.parseTitle());
 
571
                                }
 
572
                        }
 
573
                }).start();
 
574
        }
 
575
        
 
576
        public void updateCache(final boolean updateItems){
 
577
                if(!this.isLocked()){
 
578
                        this.lock();
 
579
                        this.getEditorCache().updateEditMode();
 
580
                        this.unlock();
 
581
                        new SyncThread(new Runnable() {
 
582
                                public void run() {
 
583
                                        if(!isDisposed() && !isLocked()){
 
584
                                                if(updateItems){
 
585
                                                        lock();
 
586
                                                        getItemManager().updateItems();
 
587
                                                        getTransport().updateItems();
 
588
                                                        getMixer().updateItems();
 
589
                                                        getLyricEditor().updateItems();
 
590
                                                        getTable().updateItems();
 
591
                                                        unlock();
 
592
                                                }
 
593
                                                redraw();
 
594
                                        }
 
595
                                }
 
596
                        }).start();
 
597
                }
 
598
        }
 
599
        
 
600
        protected void redraw(){
 
601
                if(!isDisposed() && !this.isLocked()){
 
602
                        this.lock();
 
603
                        this.getTablatureEditor().getTablature().redraw();
 
604
                        this.getFretBoardEditor().redraw();
 
605
                        this.getPianoEditor().redraw();
 
606
                        this.getTable().redraw();
 
607
                        this.getMatrixEditor().redraw();
 
608
                        this.unlock();
 
609
                }
 
610
        }
 
611
        
 
612
        public void redrawPayingMode(){
 
613
                if(!isDisposed() && !this.isLocked()){
 
614
                        this.lock();
 
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();
 
622
                        }
 
623
                        this.getTransport().redrawPlayingMode();
 
624
                        this.unlock();
 
625
                }
 
626
        }
 
627
        
 
628
        public Display getDisplay(){
 
629
                return this.display;
 
630
        }
 
631
        
 
632
        public Shell getShell(){
 
633
                return this.shell;
 
634
        }
 
635
        
 
636
        public Action getAction(String name) {
 
637
                return this.getActionManager().getAction(name);
 
638
        }
 
639
        
 
640
        public static String getProperty(String key) {
 
641
                return TuxGuitar.instance().getLanguageManager().getProperty(key);
 
642
        }
 
643
        
 
644
        public static String getProperty(String key,String[] arguments) {
 
645
                return  TuxGuitar.instance().getLanguageManager().getProperty(key,arguments);
 
646
        }
 
647
        
 
648
        public static boolean isDisposed(){
 
649
                return (TuxGuitar.instance().getDisplay().isDisposed() || TuxGuitar.instance().getShell().isDisposed());
 
650
        }
 
651
        
 
652
        public void loadLanguage(){
 
653
                this.lock();
 
654
                
 
655
                getLanguageManager().setLanguage(getConfig().getStringConfigValue(TGConfigKeys.LANGUAGE));
 
656
                
 
657
                this.unlock();
 
658
        }
 
659
        
 
660
        public void loadToolBars(){
 
661
                this.lock();
 
662
                
 
663
                getItemManager().createCoolbar();
 
664
                
 
665
                this.unlock();
 
666
        }
 
667
        
 
668
        public void loadStyles(){
 
669
                this.lock();
 
670
                
 
671
                getTablatureEditor().getTablature().reloadStyles();
 
672
                
 
673
                this.unlock();
 
674
        }
 
675
        
 
676
        public void loadSkin(){
 
677
                this.lock();
 
678
                
 
679
                getIconManager().reloadIcons();
 
680
                
 
681
                this.unlock();
 
682
        }
 
683
        
 
684
        public void newSong(){
 
685
                TuxGuitar.instance().fireNewSong(TuxGuitar.instance().getSongManager().newSong(),null);
 
686
        }
 
687
        
 
688
        public void fireNewSong(TGSong song,URL url){
 
689
                this.lock();
 
690
                
 
691
                TuxGuitar.instance().getSongManager().setSong(song);
 
692
                getFileHistory().reset(url);
 
693
                getPlayer().reset();
 
694
                getEditorCache().reset();
 
695
                getUndoableManager().discardAllEdits();
 
696
                getTablatureEditor().getTablature().updateTablature();
 
697
                getTablatureEditor().getTablature().resetScroll();
 
698
                getTablatureEditor().getTablature().initCaret();
 
699
                getTable().fireUpdate(true);
 
700
                getMixer().update();
 
701
                getLyricEditor().update();
 
702
                MarkerList.instance().update();
 
703
                
 
704
                this.unlock();
 
705
                
 
706
                updateCache(true);
 
707
                showTitle();
 
708
        }
 
709
        
 
710
        public void fireSaveSong(URL url){
 
711
                this.lock();
 
712
                
 
713
                getFileHistory().reset(url);
 
714
                getEditorCache().reset();
 
715
                getUndoableManager().discardAllEdits();
 
716
                
 
717
                this.unlock();
 
718
                
 
719
                updateCache(true);
 
720
                showTitle();
 
721
        }
 
722
        
 
723
        public void fireUpdate(){
 
724
                this.lock();
 
725
                
 
726
                this.getEditorCache().reset();
 
727
                this.getTablatureEditor().getTablature().updateTablature();
 
728
                this.getTable().fireUpdate(false);
 
729
                this.getLyricEditor().update();
 
730
                
 
731
                this.unlock();
 
732
        }
 
733
        
 
734
        public void loadCursor(int style){
 
735
                this.loadCursor(getShell(),style);
 
736
        }
 
737
        
 
738
        public void loadCursor(final Control control,final int style){
 
739
                try {
 
740
                        TGSynchronizer.instance().addRunnable(new TGSynchronizer.TGRunnable() {
 
741
                                public void run() throws Throwable {
 
742
                                        if(!control.isDisposed()){
 
743
                                                control.setCursor(getDisplay().getSystemCursor(style));
 
744
                                        }
 
745
                                }
 
746
                        });
 
747
                } catch (Throwable e) {
 
748
                        e.printStackTrace();
 
749
                }
 
750
        }
 
751
        
 
752
        public void lock(){
 
753
                this.lock.lock();
 
754
        }
 
755
        
 
756
        public void unlock(){
 
757
                this.lock.unlock();
 
758
        }
 
759
        
 
760
        public boolean isLocked(){
 
761
                return this.lock.isLocked();
 
762
        }
 
763
}
 
 
b'\\ No newline at end of file'