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.widgets.Menu; 11 import org.eclipse.swt.widgets.MenuItem; 12 import org.eclipse.swt.widgets.Shell; 13 import org.herac.tuxguitar.gui.TuxGuitar; 14 import org.herac.tuxguitar.gui.actions.track.AddTrackAction; 15 import org.herac.tuxguitar.gui.actions.track.CloneTrackAction; 16 import org.herac.tuxguitar.gui.actions.track.EditLyricsAction; 17 import org.herac.tuxguitar.gui.actions.track.GoFirstTrackAction; 18 import org.herac.tuxguitar.gui.actions.track.GoLastTrackAction; 19 import org.herac.tuxguitar.gui.actions.track.GoNextTrackAction; 20 import org.herac.tuxguitar.gui.actions.track.GoPreviousTrackAction; 21 import org.herac.tuxguitar.gui.actions.track.MoveTrackDownAction; 22 import org.herac.tuxguitar.gui.actions.track.MoveTrackUpAction; 23 import org.herac.tuxguitar.gui.actions.track.RemoveTrackAction; 24 import org.herac.tuxguitar.gui.actions.track.TrackPropertiesAction; 25 import org.herac.tuxguitar.gui.editors.tab.TGTrackImpl; 26 import org.herac.tuxguitar.gui.items.MenuItems; 27 28 /** 29 * @author julian 30 * 31 * TODO To change the template for this generated type comment go to 32 * Window - Preferences - Java - Code Style - Code Templates 33 */ 34 public class TrackMenuItem extends MenuItems{ 35 private MenuItem trackMenuItem; 36 private Menu menu; 37 private MenuItem first; 38 private MenuItem last; 39 private MenuItem next; 40 private MenuItem previous; 41 private MenuItem addTrack; 42 private MenuItem cloneTrack; 43 private MenuItem removeTrack; 44 private MenuItem moveUp; 45 private MenuItem moveDown; 46 private MenuItem lyrics; 47 private MenuItem properties; 48 49 public TrackMenuItem(Shell shell,Menu parent, int style) { 50 this.trackMenuItem = new MenuItem(parent, style); 51 this.menu = new Menu(shell, SWT.DROP_DOWN); 52 } 53 54 public void showItems(){ 55 //--First-- 56 this.first = new MenuItem(this.menu, SWT.PUSH); 57 this.first.addSelectionListener(TuxGuitar.instance().getAction(GoFirstTrackAction.NAME)); 58 //--previous-- 59 this.previous = new MenuItem(this.menu, SWT.PUSH); 60 this.previous.addSelectionListener(TuxGuitar.instance().getAction(GoPreviousTrackAction.NAME)); 61 //--next-- 62 this.next = new MenuItem(this.menu, SWT.PUSH); 63 this.next.addSelectionListener(TuxGuitar.instance().getAction(GoNextTrackAction.NAME)); 64 //--last-- 65 this.last = new MenuItem(this.menu, SWT.PUSH); 66 this.last.addSelectionListener(TuxGuitar.instance().getAction(GoLastTrackAction.NAME)); 67 //--SEPARATOR 68 new MenuItem(this.menu, SWT.SEPARATOR); 69 //--ADD TRACK-- 70 this.addTrack = new MenuItem(this.menu, SWT.PUSH); 71 this.addTrack.addSelectionListener(TuxGuitar.instance().getAction(AddTrackAction.NAME)); 72 //--CLONE TRACK-- 73 this.cloneTrack = new MenuItem(this.menu, SWT.PUSH); 74 this.cloneTrack.addSelectionListener(TuxGuitar.instance().getAction(CloneTrackAction.NAME)); 75 //--REMOVE TRACK-- 76 this.removeTrack = new MenuItem(this.menu, SWT.PUSH); 77 this.removeTrack.addSelectionListener(TuxGuitar.instance().getAction(RemoveTrackAction.NAME)); 78 //--SEPARATOR 79 new MenuItem(this.menu, SWT.SEPARATOR); 80 //--MOVE UP-- 81 this.moveUp = new MenuItem(this.menu, SWT.PUSH); 82 this.moveUp.addSelectionListener(TuxGuitar.instance().getAction(MoveTrackUpAction.NAME)); 83 //--MOVE DOWN-- 84 this.moveDown = new MenuItem(this.menu, SWT.PUSH); 85 this.moveDown.addSelectionListener(TuxGuitar.instance().getAction(MoveTrackDownAction.NAME)); 86 //--SEPARATOR 87 new MenuItem(this.menu, SWT.SEPARATOR); 88 //--LYRICS-- 89 this.lyrics = new MenuItem(this.menu, SWT.PUSH); 90 this.lyrics.addSelectionListener(TuxGuitar.instance().getAction(EditLyricsAction.NAME)); 91 //--PROPERTIES-- 92 this.properties = new MenuItem(this.menu, SWT.PUSH); 93 this.properties.addSelectionListener(TuxGuitar.instance().getAction(TrackPropertiesAction.NAME)); 94 95 this.trackMenuItem.setMenu(this.menu); 96 97 this.loadIcons(); 98 this.loadProperties(); 99 } 100 101 public void loadProperties(){ 102 setMenuItemTextAndAccelerator(this.trackMenuItem, "track", null); 103 setMenuItemTextAndAccelerator(this.first, "track.first", GoFirstTrackAction.NAME); 104 setMenuItemTextAndAccelerator(this.last, "track.last", GoLastTrackAction.NAME); 105 setMenuItemTextAndAccelerator(this.previous, "track.previous", GoPreviousTrackAction.NAME); 106 setMenuItemTextAndAccelerator(this.next, "track.next", GoNextTrackAction.NAME); 107 setMenuItemTextAndAccelerator(this.addTrack, "track.add", AddTrackAction.NAME); 108 setMenuItemTextAndAccelerator(this.cloneTrack, "track.clone", CloneTrackAction.NAME); 109 setMenuItemTextAndAccelerator(this.removeTrack, "track.remove", RemoveTrackAction.NAME); 110 setMenuItemTextAndAccelerator(this.moveUp, "track.move-up", MoveTrackUpAction.NAME); 111 setMenuItemTextAndAccelerator(this.moveDown, "track.move-down", MoveTrackDownAction.NAME); 112 setMenuItemTextAndAccelerator(this.lyrics, "track.lyrics", EditLyricsAction.NAME); 113 setMenuItemTextAndAccelerator(this.properties, "track.properties", TrackPropertiesAction.NAME); 114 } 115 116 public void update(){ 117 TGTrackImpl track = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().getTrack(); 118 int tracks = track.getSong().countTracks(); 119 boolean isFirst = (track.getNumber() == 1); 120 boolean isLast = (track.getNumber() == tracks); 121 boolean running = TuxGuitar.instance().getPlayer().isRunning(); 122 this.addTrack.setEnabled(!running); 123 this.cloneTrack.setEnabled(!running); 124 this.removeTrack.setEnabled(!running); 125 this.moveUp.setEnabled(!running && tracks > 1); 126 this.moveDown.setEnabled(!running && tracks > 1); 127 this.first.setEnabled(!isFirst); 128 this.previous.setEnabled(!isFirst); 129 this.next.setEnabled(!isLast); 130 this.last.setEnabled(!isLast); 131 this.properties.setEnabled(!running); 132 } 133 134 public void loadIcons(){ 135 //Nothing to do 136 } 137 } 138