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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/items/menu/TransportMenuItem.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.menu;
 
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.Menu;
 
13
import org.eclipse.swt.widgets.MenuItem;
 
14
import org.eclipse.swt.widgets.Shell;
 
15
import org.herac.tuxguitar.gui.TuxGuitar;
 
16
import org.herac.tuxguitar.gui.actions.transport.TransportMetronomeAction;
 
17
import org.herac.tuxguitar.gui.actions.transport.TransportModeAction;
 
18
import org.herac.tuxguitar.gui.items.MenuItems;
 
19
 
 
20
/**
 
21
 * @author julian
 
22
 *
 
23
 * TODO To change the template for this generated type comment go to
 
24
 * Window - Preferences - Java - Code Style - Code Templates
 
25
 */
 
26
public class TransportMenuItem implements MenuItems{
 
27
        private static final int STATUS_STOPPED = 1;
 
28
        private static final int STATUS_PAUSED = 2;
 
29
        private static final int STATUS_RUNNING = 3;
 
30
        
 
31
        private MenuItem transportMenuItem;
 
32
        private Menu menu;
 
33
        private MenuItem play;
 
34
        private MenuItem stop;
 
35
        private MenuItem mode;
 
36
        private MenuItem metronome;
 
37
        
 
38
        private int status;
 
39
        
 
40
        public TransportMenuItem(Shell shell,Menu parent, int style) {
 
41
                this.transportMenuItem = new MenuItem(parent, style);
 
42
                this.menu = new Menu(shell, SWT.DROP_DOWN);
 
43
        }
 
44
        
 
45
        public void showItems(){
 
46
                this.play = new MenuItem(this.menu,SWT.PUSH);
 
47
                this.play.addSelectionListener(new SelectionAdapter() {
 
48
                        public void widgetSelected(SelectionEvent e) {
 
49
                                TuxGuitar.instance().getTransport().play(e);
 
50
                        }
 
51
                });
 
52
                
 
53
                this.stop = new MenuItem(this.menu, SWT.PUSH);
 
54
                this.stop.addSelectionListener(new SelectionAdapter() {
 
55
                        public void widgetSelected(SelectionEvent e) {
 
56
                                TuxGuitar.instance().getTransport().stop(e);
 
57
                        }
 
58
                });
 
59
                
 
60
                //--SEPARATOR--
 
61
                new MenuItem(this.menu, SWT.SEPARATOR);
 
62
                
 
63
                this.metronome = new MenuItem(this.menu, SWT.CHECK);
 
64
                this.metronome.addSelectionListener(TuxGuitar.instance().getAction(TransportMetronomeAction.NAME));
 
65
                
 
66
                this.mode = new MenuItem(this.menu, SWT.PUSH);
 
67
                this.mode.addSelectionListener(TuxGuitar.instance().getAction(TransportModeAction.NAME));
 
68
                
 
69
                this.transportMenuItem.setMenu(this.menu);
 
70
                
 
71
                this.status = STATUS_STOPPED;
 
72
                this.loadIcons();
 
73
                this.loadProperties();
 
74
        }
 
75
        
 
76
        public void update(){
 
77
                this.metronome.setSelection(TuxGuitar.instance().getPlayer().isMetronomeEnabled());
 
78
                this.loadIcons(false);
 
79
        }
 
80
        
 
81
        public void loadProperties(){
 
82
                this.transportMenuItem.setText(TuxGuitar.getProperty("transport"));
 
83
                this.play.setText(TuxGuitar.getProperty("transport.start"));
 
84
                this.stop.setText(TuxGuitar.getProperty("transport.stop"));
 
85
                this.mode.setText(TuxGuitar.getProperty("transport.mode"));
 
86
                this.metronome.setText(TuxGuitar.getProperty("transport.metronome"));
 
87
        }
 
88
        
 
89
        public void loadIcons(){
 
90
                this.loadIcons(true);
 
91
                this.mode.setImage(TuxGuitar.instance().getIconManager().getTransportMode());
 
92
                this.metronome.setImage(TuxGuitar.instance().getIconManager().getTransportMetronome());
 
93
        }
 
94
        
 
95
        public void loadIcons(boolean force){
 
96
                int lastStatus = this.status;
 
97
                
 
98
                if(TuxGuitar.instance().getPlayer().isRunning()){
 
99
                        this.status = STATUS_RUNNING;
 
100
                }else if(TuxGuitar.instance().getPlayer().isPaused()){
 
101
                        this.status = STATUS_PAUSED;
 
102
                }else{
 
103
                        this.status = STATUS_STOPPED;
 
104
                }
 
105
                
 
106
                if(force || lastStatus != this.status){
 
107
                        if(this.status == STATUS_RUNNING){
 
108
                                this.stop.setImage(TuxGuitar.instance().getIconManager().getTransportIconStop2());
 
109
                                this.play.setImage(TuxGuitar.instance().getIconManager().getTransportIconPause());
 
110
                        }else if(this.status == STATUS_PAUSED){
 
111
                                this.stop.setImage(TuxGuitar.instance().getIconManager().getTransportIconStop2());
 
112
                                this.play.setImage(TuxGuitar.instance().getIconManager().getTransportIconPlay2());
 
113
                        }else if(this.status == STATUS_STOPPED){
 
114
                                this.stop.setImage(TuxGuitar.instance().getIconManager().getTransportIconStop1());
 
115
                                this.play.setImage(TuxGuitar.instance().getIconManager().getTransportIconPlay1());
 
116
                        }
 
117
                }
 
118
        }
 
119
}