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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/system/plugins/base/TGToolItemPlugin.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
package org.herac.tuxguitar.gui.system.plugins.base;
 
2
 
 
3
import org.eclipse.swt.events.TypedEvent;
 
4
import org.herac.tuxguitar.gui.TuxGuitar;
 
5
import org.herac.tuxguitar.gui.actions.Action;
 
6
import org.herac.tuxguitar.gui.tools.custom.TGCustomTool;
 
7
import org.herac.tuxguitar.gui.tools.custom.TGCustomToolManager;
 
8
 
 
9
public abstract class TGToolItemPlugin extends TGPluginAdapter{
 
10
        
 
11
        private boolean loaded;
 
12
        private TGCustomTool tool;
 
13
        private TGCustomToolAction toolAction;
 
14
        
 
15
        protected abstract String getItemName();
 
16
        
 
17
        protected abstract void doAction();
 
18
        
 
19
        public void init(){
 
20
                String name = getItemName();
 
21
                this.tool = new TGCustomTool(name,name);
 
22
                this.toolAction = new TGCustomToolAction(this.tool.getName());
 
23
        }
 
24
        
 
25
        public void close(){
 
26
                this.removePlugin();
 
27
        }
 
28
        
 
29
        protected void addPlugin(){
 
30
                if(!this.loaded){
 
31
                        TuxGuitar.instance().getActionManager().addAction(this.toolAction);
 
32
                        TGCustomToolManager.instance().addCustomTool(this.tool);
 
33
                        TuxGuitar.instance().getItemManager().createMenu();
 
34
                        this.loaded = true;
 
35
                }
 
36
        }
 
37
        
 
38
        protected void removePlugin(){
 
39
                if(this.loaded){
 
40
                        TGCustomToolManager.instance().removeCustomTool(this.tool);
 
41
                        TuxGuitar.instance().getActionManager().removeAction(this.tool.getAction());
 
42
                        TuxGuitar.instance().getItemManager().createMenu();
 
43
                        this.loaded = false;
 
44
                }
 
45
        }
 
46
        
 
47
        public void setEnabled(boolean enabled) {
 
48
                if(enabled){
 
49
                        addPlugin();
 
50
                }else{
 
51
                        removePlugin();
 
52
                }
 
53
        }
 
54
        
 
55
        protected class TGCustomToolAction extends Action{
 
56
                
 
57
                public TGCustomToolAction(String name) {
 
58
                        super(name, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | KEY_BINDING_AVAILABLE);
 
59
                }
 
60
                
 
61
                protected int execute(TypedEvent e) {
 
62
                        doAction();
 
63
                        return 0;
 
64
                }
 
65
        }
 
66
}
 
 
b'\\ No newline at end of file'