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;
10
import java.util.Iterator;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.MouseAdapter;
14
import org.eclipse.swt.events.MouseEvent;
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.Display;
22
import org.eclipse.swt.widgets.Sash;
23
import org.eclipse.swt.widgets.Shell;
24
import org.herac.tuxguitar.gui.actions.Action;
25
import org.herac.tuxguitar.gui.actions.ActionContainer;
26
import org.herac.tuxguitar.gui.actions.dispose.DisposeAction;
27
import org.herac.tuxguitar.gui.editors.EditorCache;
28
import org.herac.tuxguitar.gui.editors.FretBoardEditor;
29
import org.herac.tuxguitar.gui.editors.PianoEditor;
30
import org.herac.tuxguitar.gui.editors.TablatureEditor;
31
import org.herac.tuxguitar.gui.editors.chord.CustomChordManager;
32
import org.herac.tuxguitar.gui.editors.lyric.LyricEditor;
33
import org.herac.tuxguitar.gui.helper.FileHistory;
34
import org.herac.tuxguitar.gui.helper.SyncThread;
35
import org.herac.tuxguitar.gui.items.ItemManager;
36
import org.herac.tuxguitar.gui.mixer.SongMixer;
37
import org.herac.tuxguitar.gui.scale.MusicScaleManager;
38
import org.herac.tuxguitar.gui.system.config.ConfigKeys;
39
import org.herac.tuxguitar.gui.system.config.ConfigManager;
40
import org.herac.tuxguitar.gui.system.keybindings.KeyBindingManager;
41
import org.herac.tuxguitar.gui.system.language.LanguageManager;
42
import org.herac.tuxguitar.gui.system.plugins.PluginManager;
43
import org.herac.tuxguitar.gui.transport.SongTransport;
44
import org.herac.tuxguitar.gui.util.ArgumentParser;
45
import org.herac.tuxguitar.gui.util.ClassLoaderUtil;
46
import org.herac.tuxguitar.gui.util.MessageDialog;
47
import org.herac.tuxguitar.gui.util.SplashShell;
48
import org.herac.tuxguitar.gui.util.SystemError;
49
import org.herac.tuxguitar.gui.util.WindowTitleUtil;
50
import org.herac.tuxguitar.io.FileFormatFormatException;
51
import org.herac.tuxguitar.player.NullPlayer;
52
import org.herac.tuxguitar.player.base.MidiPlayer;
53
import org.herac.tuxguitar.song.managers.SongManager;
58
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
60
public class TuxGuitar {
61
public static final String TUXGUITAR_NAME = "TuxGuitar";
63
public static final String TUXGUITAR_VERSION = "0.9";
65
private static final String appConfigDomain = ".tuxguitar";
67
private static final String appConfigDomainEnvVar = "TUXGUITAR_CONFIG_HOME";
69
public static final int MARGIN_WIDTH = 5;
71
private static TuxGuitar instance;
73
private Display display;
77
private SongManager songManager;
79
private MidiPlayer player;
81
private LanguageManager languageManager;
83
private ConfigManager configManager;
85
private KeyBindingManager keyBindingManager;
87
private Composite sashComposite;
91
private EditorCache editorCache;
93
private TablatureEditor tablatureEditor;
95
private SongTableViewer tableViewer;
97
private SongMixer songMixer;
99
private SongTransport songTransport;
101
private FretBoardEditor fretBoardEditor;
103
private PianoEditor pianoEditor;
105
private LyricEditor lyricEditor;
107
private MusicScaleManager scaleManager;
109
private ActionContainer actionContainer;
111
private ItemManager itemManager;
113
private CustomChordManager customChordManager;
115
private FileHistory fileHistory;
117
private PluginManager pluginManager;
119
public static void main(String[] args) {
120
TuxGuitar.instance().displayGUI(args);
126
public static TuxGuitar instance() {
127
if (instance == null) {
128
synchronized (TuxGuitar.class) {
129
instance = new TuxGuitar();
135
private void initLanguage() {
136
this.languageManager = new LanguageManager();
137
this.languageManager.setLanguage(getConfig().getStringConfigValue(ConfigKeys.LANGUAGE));
140
public void displayGUI(String[] args) {
141
//checkeo los argumentos
142
ArgumentParser argumentParser = new ArgumentParser(args);
143
if(argumentParser.printAndExit()){
146
this.initConfigManager();
148
this.display = new Display();
150
SplashShell splash = new SplashShell(display);
152
this.shell = new Shell(display);
153
this.shell.setLayout(getShellLayout());
154
this.shell.setImage(SystemImages.TUXGUITAR_ICON);
156
this.songManager = new SongManager();
157
this.initPluginManager();
158
if(argumentParser.getFile() != null){
160
this.songManager.open(argumentParser.getFile().getPath());
161
}catch (FileFormatFormatException e) {
163
this.songManager.newSong();
166
this.initPlayer(false);
167
this.fileHistory = new FileHistory();
168
this.editorCache = new EditorCache();
169
this.scaleManager = new MusicScaleManager();
170
this.tablatureEditor = new TablatureEditor(this.songManager);
171
this.tableViewer = new SongTableViewer(this.tablatureEditor);
172
this.fretBoardEditor = new FretBoardEditor(this.tablatureEditor);
173
this.pianoEditor = new PianoEditor(this.tablatureEditor);
174
this.songMixer = new SongMixer();
175
this.songTransport = new SongTransport();
176
this.customChordManager = new CustomChordManager();
177
this.lyricEditor = new LyricEditor();
180
this.adjustKeyBindings();
182
this.createComposites(shell);
184
boolean maximized = getConfig().getBooleanConfigValue(ConfigKeys.MAXIMIZED);
185
this.shell.setMaximized(maximized);
187
int width = getConfig().getIntConfigValue(ConfigKeys.WIDTH);
188
int height = getConfig().getIntConfigValue(ConfigKeys.HEIGHT);
189
if(width > 0 && height > 0){
190
this.shell.setSize(width,height);
193
this.tablatureEditor.getTablature().setFocus();
195
this.shell.setMinimumSize(640,480);
197
this.showDefaultControls();
198
this.updateCache(true);
202
this.shell.addDisposeListener(getAction(DisposeAction.NAME));
204
while (!shell.isDisposed()) {
205
if (!display.readAndDispatch()) {
209
getDisplay().dispose();
213
private FormLayout getShellLayout(){
214
FormLayout layout = new FormLayout();
215
layout.marginWidth = MARGIN_WIDTH;
216
layout.marginHeight = MARGIN_WIDTH;
220
public void createComposites(Composite composite) {
221
this.sashComposite = new Composite(composite,SWT.NONE);
222
this.sashComposite.setLayout(new FormLayout());
223
FormData data = new FormData();
224
data.left = new FormAttachment(0,0);
225
data.right = new FormAttachment(100,0);
226
data.top = new FormAttachment(this.itemManager.getCoolbar(),MARGIN_WIDTH);
227
data.bottom = new FormAttachment(100,0);
228
sashComposite.setLayoutData(data);
230
this.sash = new Sash(sashComposite, SWT.HORIZONTAL | SWT.SEPARATOR);
231
data = new FormData();
232
data.left = new FormAttachment(0,0);
233
data.right = new FormAttachment(100,0);
234
data.top = new FormAttachment(75,0);
235
sash.setLayoutData(data);
237
this.tablatureEditor.showTablature(sashComposite);
238
data = new FormData();
239
data.left = new FormAttachment(0,0);
240
data.right = new FormAttachment(100,0);
241
data.top = new FormAttachment(0,0);
242
data.bottom = new FormAttachment(sash, 0);
243
this.tablatureEditor.getTablature().setLayoutData(data);
245
this.tableViewer.showTable(sashComposite);
246
data = new FormData();
247
data.left = new FormAttachment(0,0);
248
data.right = new FormAttachment(100,0);
249
data.top = new FormAttachment(sash,10);
250
data.bottom = new FormAttachment(100,0);
251
this.tableViewer.getTableInfo().setLayoutData(data);
253
sash.addSelectionListener(new SelectionAdapter() {
254
public void widgetSelected(SelectionEvent event) {
255
int sashNumerator = (event.y * 100 / sashComposite.getBounds().height);
256
sashNumerator = Math.max(sashNumerator,0);
257
sashNumerator = Math.min(sashNumerator,100);
258
((FormData) sash.getLayoutData()).top = new FormAttachment(sashNumerator,0);
261
sash.addMouseListener(new MouseAdapter() {
262
public void mouseUp(MouseEvent e) {
263
sash.getParent().layout();
267
data = new FormData();
268
data.left = new FormAttachment(0,0);
269
data.right = new FormAttachment(100,0);
270
data.top = new FormAttachment(sashComposite,0);
271
data.bottom = new FormAttachment(100,0);
273
Composite footer = new Composite(composite,SWT.NONE);
274
footer.setLayout(new FormLayout());
275
footer.setLayoutData(data);
276
this.fretBoardEditor.showFretBoard(footer);
279
public void checkSoundbank(){
280
boolean customSoundbank = getConfig().getBooleanConfigValue(ConfigKeys.SOUNDBANK_CUSTOM);
282
if(!getPlayer().loadSoundbank(new File(getConfig().getStringConfigValue(ConfigKeys.SOUNDBANK_CUSTOM_PATH)))){
283
String title = TuxGuitar.getProperty("soundbank.error");
284
String message = TuxGuitar.getProperty("soundbank.error.custom");
285
new MessageDialog(title,message,SWT.ICON_ERROR | SWT.OK).show(shell);
290
public void initPlayer(boolean forceDefault){
291
if(getPlayer() == null || forceDefault){
292
MidiPlayer player = null;
293
Object object = ClassLoaderUtil.newInstance(getConfig().getStringConfigValue(ConfigKeys.SYSTEM_PLAYER));
294
if(object instanceof MidiPlayer){
295
player = (MidiPlayer)object;
298
player = new NullPlayer();
304
public void initPlayer(MidiPlayer player){
305
if(this.player != null){
308
this.player = player;
309
Iterator it = player.getSystemErrors().iterator();
311
SystemError error = (SystemError)it.next();
312
new MessageDialog(error.getTitle(),error.getMessage(),SWT.ICON_ERROR | SWT.OK).show(shell);
316
public void showDefaultControls(){
318
if(getConfig().getBooleanConfigValue(ConfigKeys.SHOW_FRETBOARD)){
319
getFretBoardEditor().showFretBoard();
321
getFretBoardEditor().hideFretBoard();
325
if(getConfig().getBooleanConfigValue(ConfigKeys.SHOW_MIXER)){
326
new SyncThread(new Runnable() {
333
getMixer().dispose();
337
if(getConfig().getBooleanConfigValue(ConfigKeys.SHOW_TRANSPORT)){
338
new SyncThread(new Runnable() {
340
getTransport().show();
344
getTransport().dispose();
348
if(getConfig().getBooleanConfigValue(ConfigKeys.SHOW_PIANO)){
349
new SyncThread(new Runnable() {
351
getPianoEditor().show();
355
getPianoEditor().dispose();
359
public void updateShellFooter(int offset,int minimunWith,int minimunHeight){
360
minimunWith = Math.max(640,minimunWith);
361
minimunHeight = Math.max(480,minimunHeight);
363
FormData data = ((FormData)this.sashComposite.getLayoutData());
364
data.bottom.offset = -offset;
365
shell.setMinimumSize(minimunWith,minimunHeight);
369
public TablatureEditor getTablatureEditor(){
370
return this.tablatureEditor;
373
public FretBoardEditor getFretBoardEditor(){
374
return this.fretBoardEditor;
377
public PianoEditor getPianoEditor(){
378
return this.pianoEditor;
381
private void initItems() {
382
this.itemManager = new ItemManager(this.tablatureEditor);
383
this.itemManager.createItems(this.shell);
386
private void initActions() {
387
this.actionContainer = new ActionContainer(this.tablatureEditor);
388
this.actionContainer.initActions();
391
private void initConfigManager(){
392
this.configManager = new ConfigManager();
393
this.configManager.init();
397
private void adjustKeyBindings() {
398
this.keyBindingManager = new KeyBindingManager();
399
this.keyBindingManager.init();
402
private void initPluginManager(){
403
this.pluginManager = new PluginManager();
404
this.pluginManager.loadPlugins();
405
this.pluginManager.initPLugins();
408
public SongManager getSongManager(){
409
return this.songManager;
412
public SongMixer getMixer(){
413
return this.songMixer;
416
public SongTransport getTransport(){
417
return this.songTransport;
420
public SongTableViewer getTableViewer(){
421
return this.tableViewer;
424
public EditorCache getEditorCache(){
425
return this.editorCache;
428
public LyricEditor getLyricEditor(){
429
return this.lyricEditor;
433
public MusicScaleManager getScaleManager(){
434
return this.scaleManager;
437
public PluginManager getPluginManager(){
438
return this.pluginManager;
441
public CustomChordManager getCustomChordManager(){
442
return this.customChordManager;
445
public MidiPlayer getPlayer(){
449
public void showTitle(){
450
getShell().setText(WindowTitleUtil.parseTitle());
453
public void updateCache(boolean updateItems){
454
getEditorCache().updateCaretMode();
456
getItemManager().updateItems();
457
getTransport().updateItems();
458
getLyricEditor().updateSongTrack();
466
public void redraw(){
467
if(!getDisplay().isDisposed()){
468
this.tablatureEditor.getTablature().redraw();
469
this.fretBoardEditor.redraw();
470
this.pianoEditor.redraw();
471
this.tableViewer.getTableInfo().redraw();
475
public void redrawPayingMode(){
476
if(!getDisplay().isDisposed()){
477
this.editorCache.updatePlayingMode();
478
if(editorCache.shouldRedraw()){
479
this.tablatureEditor.getTablature().redrawPlayingMode();
480
this.fretBoardEditor.redrawPlayingMode();
481
this.pianoEditor.redrawPlayingMode();
482
this.tableViewer.getTableInfo().redrawPlayingMode();
483
this.songTransport.redraw();
488
public void fireUpdate(){
489
this.editorCache.reset();
490
this.tablatureEditor.getTablature().updateTablature();
491
this.tableViewer.getTableInfo().fireUpdate();
496
public Display getDisplay(){
500
public Shell getShell(){
504
public Action getAction(String name) {
505
return this.actionContainer.getAction(name);
508
public ItemManager getItemManager() {
512
public ActionContainer getActionContainer() {
513
return this.actionContainer;
516
public LanguageManager getLanguageManager() {
517
return this.languageManager;
520
public static String getProperty(String key) {
521
return TuxGuitar.instance().languageManager.getProperty(key);
524
public ConfigManager getConfig(){
525
return this.configManager;
528
public KeyBindingManager getkeyBindingManager(){
529
return this.keyBindingManager;
532
public FileHistory getFileHistory(){
533
return this.fileHistory;
536
public static boolean isDisposed(){
537
return TuxGuitar.instance().getDisplay().isDisposed();
540
public void showErrorMessage(final Throwable throwable){
541
new SyncThread(new Runnable() {
543
throwable.printStackTrace();
544
String title = getProperty("error");
545
String message = throwable.toString();
546
new MessageDialog(title,message,SWT.ICON_ERROR).show(shell);
551
public void loadLanguage(){
552
getLanguageManager().setLanguage(getConfig().getStringConfigValue(ConfigKeys.LANGUAGE));
555
public void loadProperties(){
556
getItemManager().loadProperties();
557
getTableViewer().getTableInfo().loadProperties();
558
getFretBoardEditor().loadProperties();
559
getPianoEditor().loadProperties();
560
getMixer().loadProperties();
561
getTransport().loadProperties();
564
public void loadToolBars(){
565
getItemManager().makeCoolItems();
568
public void loadStyles(){
569
getTablatureEditor().getTablature().reloadStyles();
b'\\ No newline at end of file'