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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/editors/TablatureEditor.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 30-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.editors;
8
 
 
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;
28
 
 
29
 
/**
30
 
 * @author julian
31
 
 * 
32
 
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
33
 
 */
34
 
public class TablatureEditor {
35
 
    private SongManager songManager;
36
 
    private Tablature tablature;  
37
 
    private UndoManager undoManager;
38
 
    private ClipBoard clipBoard;
39
 
    
40
 
    public TablatureEditor(SongManager songManager) {
41
 
        this.songManager = songManager;        
42
 
        this.undoManager = new UndoManager();
43
 
        this.clipBoard = new ClipBoard();
44
 
    }
45
 
 
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();
56
 
        
57
 
        this.initKeyActions();
58
 
        this.initMenu();
59
 
    }
60
 
 
61
 
    private void initKeyActions(){
62
 
        this.tablature.addKeyListener(new TablatureKeyListener());
63
 
        TuxGuitar.instance().getkeyBindingManager().appendListenersTo(tablature);
64
 
    }    
65
 
    
66
 
    private void initMenu(){
67
 
        this.tablature.setMenu(TuxGuitar.instance().getItemManager().getPopupMenu());
68
 
    }
69
 
    
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);
78
 
    }
79
 
 
80
 
    public void reloadConfig(){
81
 
        getTablature().reloadStyles();
82
 
        
83
 
    }    
84
 
    
85
 
    public Tablature getTablature() {
86
 
        return this.tablature;
87
 
    }
88
 
    
89
 
    public SongManager getSongManager(){
90
 
        return this.songManager;
91
 
    }
92
 
 
93
 
    public UndoManager getUndoManager(){
94
 
        return this.undoManager;
95
 
    }    
96
 
    
97
 
    public ClipBoard getClipBoard(){
98
 
        return this.clipBoard;
99
 
    }        
100
 
 
101
 
    private class TablatureKeyListener extends KeyAdapter{
102
 
                
103
 
        public void keyPressed(KeyEvent e) {        
104
 
                Action action = switchAction(e);
105
 
                
106
 
                if(action != null){
107
 
                        action.process(e);
108
 
                }
109
 
        }       
110
 
        
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);
115
 
                }
116
 
                else if (event.stateMask == 0 && event.keyCode == SWT.INSERT ){
117
 
                        action = TuxGuitar.instance().getAction(InsertNoteAction.NAME);
118
 
                }
119
 
                else if (event.stateMask == 0 && (event.keyCode == SWT.DEL || event.keyCode == SWT.BS)){
120
 
                        action = TuxGuitar.instance().getAction(RemoveNoteAction.NAME);
121
 
                }
122
 
                else if (event.stateMask == 0 && event.keyCode == SWT.ARROW_UP){
123
 
                        action = TuxGuitar.instance().getAction(GoUpAction.NAME);
124
 
                }
125
 
                else if (event.stateMask == 0 && event.keyCode == SWT.ARROW_DOWN){
126
 
                        action = TuxGuitar.instance().getAction(GoDownAction.NAME);
127
 
                }
128
 
                else if (event.stateMask == 0 && event.keyCode == SWT.ARROW_RIGHT){
129
 
                        action = TuxGuitar.instance().getAction(GoRightAction.NAME);
130
 
                }
131
 
                else if (event.stateMask == 0 && event.keyCode == SWT.ARROW_LEFT){
132
 
                        action = TuxGuitar.instance().getAction(GoLeftAction.NAME);
133
 
                }
134
 
                else if (event.stateMask == 0 && event.character == '+'){
135
 
                        action = TuxGuitar.instance().getAction(IncrementDurationAction.NAME);
136
 
                }
137
 
                else if (event.stateMask == 0 && event.character == '-'){
138
 
                        action = TuxGuitar.instance().getAction(DecrementDurationAction.NAME);
139
 
                }
140
 
                return action;
141
 
        }
142
 
        
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');
145
 
        }
146
 
    }
147
 
}
 
 
b'\\ No newline at end of file'