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.note.ChangeVelocityAction; 15 import org.herac.tuxguitar.gui.items.MenuItems; 16 import org.herac.tuxguitar.song.models.TGNote; 17 import org.herac.tuxguitar.song.models.TGVelocities; 18 19 /** 20 * @author julian 21 * 22 * TODO To change the template for this generated type comment go to 23 * Window - Preferences - Java - Code Style - Code Templates 24 */ 25 public class DynamicMenuItem extends MenuItems{ 26 private MenuItem dynamicMenuItem; 27 private Menu menu; 28 private MenuItem pianoPianissimo; 29 private MenuItem pianissimo; 30 private MenuItem piano; 31 private MenuItem mezzoPiano; 32 private MenuItem mezzoForte; 33 private MenuItem forte; 34 private MenuItem fortissimo; 35 private MenuItem forteFortissimo; 36 DynamicMenuItem(Shell shell,Menu parent, int style)37 public DynamicMenuItem(Shell shell,Menu parent, int style) { 38 this.dynamicMenuItem = new MenuItem(parent, style); 39 this.menu = new Menu(shell, SWT.DROP_DOWN); 40 } 41 showItems()42 public void showItems(){ 43 44 this.pianoPianissimo = new MenuItem(this.menu, SWT.CHECK); 45 this.pianoPianissimo.setData(new Integer(TGVelocities.PIANO_PIANISSIMO)); 46 this.pianoPianissimo.addSelectionListener(TuxGuitar.instance().getAction(ChangeVelocityAction.NAME)); 47 48 this.pianissimo = new MenuItem(this.menu, SWT.CHECK); 49 this.pianissimo.setData(new Integer(TGVelocities.PIANISSIMO)); 50 this.pianissimo.addSelectionListener(TuxGuitar.instance().getAction(ChangeVelocityAction.NAME)); 51 52 this.piano = new MenuItem(this.menu, SWT.CHECK); 53 this.piano.setData(new Integer(TGVelocities.PIANO)); 54 this.piano.addSelectionListener(TuxGuitar.instance().getAction(ChangeVelocityAction.NAME)); 55 56 this.mezzoPiano = new MenuItem(this.menu, SWT.CHECK); 57 this.mezzoPiano.setData(new Integer(TGVelocities.MEZZO_PIANO)); 58 this.mezzoPiano.addSelectionListener(TuxGuitar.instance().getAction(ChangeVelocityAction.NAME)); 59 60 this.mezzoForte = new MenuItem(this.menu, SWT.CHECK); 61 this.mezzoForte.setData(new Integer(TGVelocities.MEZZO_FORTE)); 62 this.mezzoForte.addSelectionListener(TuxGuitar.instance().getAction(ChangeVelocityAction.NAME)); 63 64 this.forte = new MenuItem(this.menu, SWT.CHECK); 65 this.forte.setData(new Integer(TGVelocities.FORTE)); 66 this.forte.addSelectionListener(TuxGuitar.instance().getAction(ChangeVelocityAction.NAME)); 67 68 this.fortissimo = new MenuItem(this.menu, SWT.CHECK); 69 this.fortissimo.setData(new Integer(TGVelocities.FORTISSIMO)); 70 this.fortissimo.addSelectionListener(TuxGuitar.instance().getAction(ChangeVelocityAction.NAME)); 71 72 this.forteFortissimo = new MenuItem(this.menu, SWT.CHECK); 73 this.forteFortissimo.setData(new Integer(TGVelocities.FORTE_FORTISSIMO)); 74 this.forteFortissimo.addSelectionListener(TuxGuitar.instance().getAction(ChangeVelocityAction.NAME)); 75 76 this.dynamicMenuItem.setMenu(this.menu); 77 78 this.loadIcons(); 79 this.loadProperties(); 80 } 81 update()82 public void update(){ 83 TGNote note = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().getSelectedNote(); 84 int velocity = ((note != null)?note.getVelocity():TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().getVelocity()); 85 boolean running = TuxGuitar.instance().getPlayer().isRunning(); 86 this.pianoPianissimo.setSelection(velocity == TGVelocities.PIANO_PIANISSIMO); 87 this.pianoPianissimo.setEnabled(!running); 88 this.pianissimo.setSelection(velocity == TGVelocities.PIANISSIMO); 89 this.pianissimo.setEnabled(!running); 90 this.piano.setSelection(velocity == TGVelocities.PIANO); 91 this.piano.setEnabled(!running); 92 this.mezzoPiano.setSelection(velocity == TGVelocities.MEZZO_PIANO); 93 this.mezzoPiano.setEnabled(!running); 94 this.mezzoForte.setSelection(velocity == TGVelocities.MEZZO_FORTE); 95 this.mezzoForte.setEnabled(!running); 96 this.forte.setSelection(velocity == TGVelocities.FORTE); 97 this.forte.setEnabled(!running); 98 this.fortissimo.setSelection(velocity == TGVelocities.FORTISSIMO); 99 this.fortissimo.setEnabled(!running); 100 this.forteFortissimo.setSelection(velocity == TGVelocities.FORTE_FORTISSIMO); 101 this.forteFortissimo.setEnabled(!running); 102 } 103 loadProperties()104 public void loadProperties(){ 105 this.dynamicMenuItem.setText(TuxGuitar.getProperty("dynamic")); 106 this.pianoPianissimo.setText(TuxGuitar.getProperty("dynamic.piano-pianissimo")); 107 this.pianissimo.setText(TuxGuitar.getProperty("dynamic.pianissimo")); 108 this.piano.setText(TuxGuitar.getProperty("dynamic.piano")); 109 this.mezzoPiano.setText(TuxGuitar.getProperty("dynamic.mezzo-piano")); 110 this.mezzoForte.setText(TuxGuitar.getProperty("dynamic.mezzo-forte")); 111 this.forte.setText(TuxGuitar.getProperty("dynamic.forte")); 112 this.fortissimo.setText(TuxGuitar.getProperty("dynamic.fortissimo")); 113 this.forteFortissimo.setText(TuxGuitar.getProperty("dynamic.forte-fortissimo")); 114 } 115 loadIcons()116 public void loadIcons(){ 117 //Nothing to do 118 } 119 } 120