2
* Created on 30-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.editors;
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.KeyAdapter;
11
import org.eclipse.swt.events.KeyEvent;
12
import org.eclipse.swt.widgets.Composite;
13
import org.herac.tuxguitar.gui.TuxGuitar;
14
import org.herac.tuxguitar.gui.actions.Action;
15
import org.herac.tuxguitar.gui.actions.caret.GoDownAction;
16
import org.herac.tuxguitar.gui.actions.caret.GoLeftAction;
17
import org.herac.tuxguitar.gui.actions.caret.GoRightAction;
18
import org.herac.tuxguitar.gui.actions.caret.GoUpAction;
19
import org.herac.tuxguitar.gui.actions.duration.DecrementDurationAction;
20
import org.herac.tuxguitar.gui.actions.duration.IncrementDurationAction;
21
import org.herac.tuxguitar.gui.actions.note.ChangeNoteAction;
22
import org.herac.tuxguitar.gui.actions.note.InsertNoteAction;
23
import org.herac.tuxguitar.gui.actions.note.RemoveNoteAction;
24
import org.herac.tuxguitar.gui.clipboard.ClipBoard;
25
import org.herac.tuxguitar.gui.editors.tab.Tablature;
26
import org.herac.tuxguitar.gui.undo.UndoManager;
27
import org.herac.tuxguitar.song.managers.SongManager;
32
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
34
public class TablatureEditor {
35
private SongManager songManager;
36
private Tablature tablature;
37
private UndoManager undoManager;
38
private ClipBoard clipBoard;
40
public TablatureEditor(SongManager songManager) {
41
this.songManager = songManager;
42
this.undoManager = new UndoManager();
43
this.clipBoard = new ClipBoard();
46
public void showTablature(Composite parent) {
47
this.tablature = new Tablature(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.DOUBLE_BUFFERED);
48
this.tablature.loadFlags();
49
this.tablature.initGUI();
50
this.tablature.setSongManager(this.songManager);
51
this.tablature.reloadStyles();
52
this.tablature.reloadViewLayout();
53
this.tablature.initDefaults();
54
this.tablature.updateTablature();
55
this.tablature.initCaret();
57
this.initKeyActions();
61
private void initKeyActions(){
62
this.tablature.addKeyListener(new TablatureKeyListener());
63
TuxGuitar.instance().getkeyBindingManager().appendListenersTo(tablature);
66
private void initMenu(){
67
this.tablature.setMenu(TuxGuitar.instance().getItemManager().getPopupMenu());
70
public void resetDefaults(){
71
getUndoManager().discardAllEdits();
72
getTablature().resetScroll();
73
getTablature().updateTablature();
74
getTablature().initCaret();
75
TuxGuitar.instance().getPlayer().reset();
76
TuxGuitar.instance().getEditorCache().reset();
77
TuxGuitar.instance().updateCache(true);
80
public void reloadConfig(){
81
getTablature().reloadStyles();
85
public Tablature getTablature() {
86
return this.tablature;
89
public SongManager getSongManager(){
90
return this.songManager;
93
public UndoManager getUndoManager(){
94
return this.undoManager;
97
public ClipBoard getClipBoard(){
98
return this.clipBoard;
101
private class TablatureKeyListener extends KeyAdapter{
103
public void keyPressed(KeyEvent e) {
104
Action action = switchAction(e);
111
private Action switchAction(KeyEvent event){
112
Action action = null;
113
if(event.stateMask == 0 && isNumber(event.character)){
114
action = TuxGuitar.instance().getAction(ChangeNoteAction.NAME);
116
else if (event.stateMask == 0 && event.keyCode == SWT.INSERT ){
117
action = TuxGuitar.instance().getAction(InsertNoteAction.NAME);
119
else if (event.stateMask == 0 && (event.keyCode == SWT.DEL || event.keyCode == SWT.BS)){
120
action = TuxGuitar.instance().getAction(RemoveNoteAction.NAME);
122
else if (event.stateMask == 0 && event.keyCode == SWT.ARROW_UP){
123
action = TuxGuitar.instance().getAction(GoUpAction.NAME);
125
else if (event.stateMask == 0 && event.keyCode == SWT.ARROW_DOWN){
126
action = TuxGuitar.instance().getAction(GoDownAction.NAME);
128
else if (event.stateMask == 0 && event.keyCode == SWT.ARROW_RIGHT){
129
action = TuxGuitar.instance().getAction(GoRightAction.NAME);
131
else if (event.stateMask == 0 && event.keyCode == SWT.ARROW_LEFT){
132
action = TuxGuitar.instance().getAction(GoLeftAction.NAME);
134
else if (event.stateMask == 0 && event.character == '+'){
135
action = TuxGuitar.instance().getAction(IncrementDurationAction.NAME);
137
else if (event.stateMask == 0 && event.character == '-'){
138
action = TuxGuitar.instance().getAction(DecrementDurationAction.NAME);
143
private boolean isNumber(char c){
144
return (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9');
b'\\ No newline at end of file'