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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/items/tool/TransportToolItems.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 02-dic-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.items.tool;
 
8
 
 
9
import org.eclipse.swt.SWT;
 
10
import org.eclipse.swt.events.SelectionAdapter;
 
11
import org.eclipse.swt.events.SelectionEvent;
 
12
import org.eclipse.swt.widgets.ToolBar;
 
13
import org.eclipse.swt.widgets.ToolItem;
 
14
import org.herac.tuxguitar.gui.TuxGuitar;
 
15
import org.herac.tuxguitar.gui.items.ToolItems;
 
16
/**
 
17
 * @author julian
 
18
 *
 
19
 * TODO To change the template for this generated type comment go to
 
20
 * Window - Preferences - Java - Code Style - Code Templates
 
21
 */
 
22
public class TransportToolItems  extends ToolItems{
 
23
        public static final String NAME = "transport.items";
 
24
        
 
25
        private static final int STATUS_STOPPED = 1;
 
26
        private static final int STATUS_PAUSED = 2;
 
27
        private static final int STATUS_RUNNING = 3;
 
28
        
 
29
        private ToolItem first;
 
30
        private ToolItem last;
 
31
        private ToolItem previous;
 
32
        private ToolItem next;
 
33
        private ToolItem stop;
 
34
        private ToolItem play;
 
35
        private int status;
 
36
        
 
37
        public TransportToolItems(){
 
38
                super(NAME);
 
39
        }
 
40
        
 
41
        public void showItems(ToolBar toolBar){
 
42
                this.first = new ToolItem(toolBar,SWT.PUSH);
 
43
                this.first.addSelectionListener(new SelectionAdapter() {
 
44
                        public void widgetSelected(SelectionEvent e) {
 
45
                                TuxGuitar.instance().getTransport().gotoFirst();
 
46
                        }
 
47
                });
 
48
                
 
49
                this.previous = new ToolItem(toolBar,SWT.PUSH);
 
50
                this.previous.addSelectionListener(new SelectionAdapter() {
 
51
                        public void widgetSelected(SelectionEvent e) {
 
52
                                TuxGuitar.instance().getTransport().gotoPrevious();
 
53
                        }
 
54
                });
 
55
                
 
56
                this.stop = new ToolItem(toolBar,SWT.PUSH);
 
57
                this.stop.addSelectionListener(new SelectionAdapter() {
 
58
                        public void widgetSelected(SelectionEvent e) {
 
59
                                TuxGuitar.instance().getTransport().stop(e);
 
60
                        }
 
61
                });
 
62
                
 
63
                this.play = new ToolItem(toolBar,SWT.PUSH);
 
64
                this.play.addSelectionListener(new SelectionAdapter() {
 
65
                        public void widgetSelected(SelectionEvent e) {
 
66
                                TuxGuitar.instance().getTransport().play(e);
 
67
                        }
 
68
                });
 
69
                
 
70
                this.next = new ToolItem(toolBar,SWT.PUSH);
 
71
                this.next.addSelectionListener(new SelectionAdapter() {
 
72
                        public void widgetSelected(SelectionEvent e) {
 
73
                                TuxGuitar.instance().getTransport().gotoNext();
 
74
                        }
 
75
                });
 
76
                
 
77
                this.last = new ToolItem(toolBar,SWT.PUSH);
 
78
                this.last.addSelectionListener(new SelectionAdapter() {
 
79
                        public void widgetSelected(SelectionEvent e) {
 
80
                                TuxGuitar.instance().getTransport().gotoLast();
 
81
                        }
 
82
                });
 
83
                
 
84
                this.status = STATUS_STOPPED;
 
85
                this.loadIcons();
 
86
                this.loadProperties();
 
87
        }
 
88
        
 
89
        public void update(){
 
90
                loadIcons(false);
 
91
        }
 
92
        
 
93
        public void loadProperties(){
 
94
                this.play.setToolTipText(TuxGuitar.getProperty("transport.start"));
 
95
                this.stop.setToolTipText(TuxGuitar.getProperty("transport.stop"));
 
96
                this.first.setToolTipText(TuxGuitar.getProperty("transport.first"));
 
97
                this.last.setToolTipText(TuxGuitar.getProperty("transport.last"));
 
98
                this.previous.setToolTipText(TuxGuitar.getProperty("transport.previous"));
 
99
                this.next.setToolTipText(TuxGuitar.getProperty("transport.next"));
 
100
        }
 
101
        
 
102
        public void loadIcons(){
 
103
                loadIcons(true);
 
104
        }
 
105
        
 
106
        public void loadIcons(boolean force){
 
107
                int lastStatus = this.status;
 
108
                
 
109
                if(TuxGuitar.instance().getPlayer().isRunning()){
 
110
                        this.status = STATUS_RUNNING;
 
111
                }else if(TuxGuitar.instance().getPlayer().isPaused()){
 
112
                        this.status = STATUS_PAUSED;
 
113
                }else{
 
114
                        this.status = STATUS_STOPPED;
 
115
                }
 
116
                
 
117
                if(force || lastStatus != this.status){
 
118
                        if(this.status == STATUS_RUNNING){
 
119
                                this.first.setImage(TuxGuitar.instance().getIconManager().getTransportIconFirst2());
 
120
                                this.last.setImage(TuxGuitar.instance().getIconManager().getTransportIconLast2());
 
121
                                this.previous.setImage(TuxGuitar.instance().getIconManager().getTransportIconPrevious2());
 
122
                                this.next.setImage(TuxGuitar.instance().getIconManager().getTransportIconNext2());
 
123
                                this.stop.setImage(TuxGuitar.instance().getIconManager().getTransportIconStop2());
 
124
                                this.play.setImage(TuxGuitar.instance().getIconManager().getTransportIconPause());
 
125
                                this.play.setToolTipText(TuxGuitar.getProperty("transport.pause"));
 
126
                        }else if(this.status == STATUS_PAUSED){
 
127
                                this.first.setImage(TuxGuitar.instance().getIconManager().getTransportIconFirst2());
 
128
                                this.last.setImage(TuxGuitar.instance().getIconManager().getTransportIconLast2());
 
129
                                this.previous.setImage(TuxGuitar.instance().getIconManager().getTransportIconPrevious2());
 
130
                                this.next.setImage(TuxGuitar.instance().getIconManager().getTransportIconNext2());
 
131
                                this.stop.setImage(TuxGuitar.instance().getIconManager().getTransportIconStop2());
 
132
                                this.play.setImage(TuxGuitar.instance().getIconManager().getTransportIconPlay2());
 
133
                                this.play.setToolTipText(TuxGuitar.getProperty("transport.start"));
 
134
                        }else if(this.status == STATUS_STOPPED){
 
135
                                this.first.setImage(TuxGuitar.instance().getIconManager().getTransportIconFirst1());
 
136
                                this.last.setImage(TuxGuitar.instance().getIconManager().getTransportIconLast1());
 
137
                                this.previous.setImage(TuxGuitar.instance().getIconManager().getTransportIconPrevious1());
 
138
                                this.next.setImage(TuxGuitar.instance().getIconManager().getTransportIconNext1());
 
139
                                this.stop.setImage(TuxGuitar.instance().getIconManager().getTransportIconStop1());
 
140
                                this.play.setImage(TuxGuitar.instance().getIconManager().getTransportIconPlay1());
 
141
                                this.play.setToolTipText(TuxGuitar.getProperty("transport.start"));
 
142
                        }
 
143
                }
 
144
                
 
145
        }
 
146
}