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.edit.RedoAction; 15 import org.herac.tuxguitar.gui.actions.edit.SetMouseModeEditionAction; 16 import org.herac.tuxguitar.gui.actions.edit.SetMouseModeSelectionAction; 17 import org.herac.tuxguitar.gui.actions.edit.SetNaturalKeyAction; 18 import org.herac.tuxguitar.gui.actions.edit.SetVoice1Action; 19 import org.herac.tuxguitar.gui.actions.edit.SetVoice2Action; 20 import org.herac.tuxguitar.gui.actions.edit.UndoAction; 21 import org.herac.tuxguitar.gui.editors.tab.edit.EditorKit; 22 import org.herac.tuxguitar.gui.items.MenuItems; 23 24 /** 25 * @author julian 26 * 27 * TODO To change the template for this generated type comment go to 28 * Window - Preferences - Java - Code Style - Code Templates 29 */ 30 public class EditMenuItem extends MenuItems{ 31 32 private MenuItem editMenuItem; 33 private Menu menu; 34 private MenuItem undo; 35 private MenuItem redo; 36 private MenuItem modeSelection; 37 private MenuItem modeEdition; 38 private MenuItem notNaturalKey; 39 private MenuItem voice1; 40 private MenuItem voice2; 41 EditMenuItem(Shell shell,Menu parent, int style)42 public EditMenuItem(Shell shell,Menu parent, int style) { 43 this.editMenuItem = new MenuItem(parent, style); 44 this.menu = new Menu(shell, SWT.DROP_DOWN); 45 } 46 showItems()47 public void showItems(){ 48 //--------------------------------------------------- 49 //--UNDO-- 50 this.undo = new MenuItem(this.menu, SWT.PUSH); 51 this.undo.addSelectionListener(TuxGuitar.instance().getAction(UndoAction.NAME)); 52 //--REDO-- 53 this.redo = new MenuItem(this.menu, SWT.PUSH); 54 this.redo.addSelectionListener(TuxGuitar.instance().getAction(RedoAction.NAME)); 55 //--SEPARATOR 56 new MenuItem(this.menu, SWT.SEPARATOR); 57 //--TABLATURE EDIT MODE 58 this.modeSelection = new MenuItem(this.menu, SWT.RADIO); 59 this.modeSelection.addSelectionListener(TuxGuitar.instance().getAction(SetMouseModeSelectionAction.NAME)); 60 //--SCORE EDIT MODE 61 this.modeEdition = new MenuItem(this.menu, SWT.RADIO); 62 this.modeEdition.addSelectionListener(TuxGuitar.instance().getAction(SetMouseModeEditionAction.NAME)); 63 //--NATURAL NOTES 64 this.notNaturalKey = new MenuItem(this.menu, SWT.CHECK); 65 this.notNaturalKey.addSelectionListener(TuxGuitar.instance().getAction(SetNaturalKeyAction.NAME)); 66 //--SEPARATOR 67 new MenuItem(this.menu, SWT.SEPARATOR); 68 //--VOICE 1 69 this.voice1 = new MenuItem(this.menu, SWT.RADIO); 70 this.voice1.addSelectionListener(TuxGuitar.instance().getAction(SetVoice1Action.NAME)); 71 //--VOICE 2 72 this.voice2 = new MenuItem(this.menu, SWT.RADIO); 73 this.voice2.addSelectionListener(TuxGuitar.instance().getAction(SetVoice2Action.NAME)); 74 75 this.editMenuItem.setMenu(this.menu); 76 77 this.loadIcons(); 78 this.loadProperties(); 79 } 80 update()81 public void update(){ 82 EditorKit kit = TuxGuitar.instance().getTablatureEditor().getTablature().getEditorKit(); 83 boolean running = TuxGuitar.instance().getPlayer().isRunning(); 84 this.undo.setEnabled(!running && TuxGuitar.instance().getUndoableManager().canUndo()); 85 this.redo.setEnabled(!running && TuxGuitar.instance().getUndoableManager().canRedo()); 86 this.modeSelection.setSelection(kit.getMouseMode() == EditorKit.MOUSE_MODE_SELECTION); 87 this.modeSelection.setEnabled(!running); 88 this.modeEdition.setSelection(kit.getMouseMode() == EditorKit.MOUSE_MODE_EDITION); 89 this.modeEdition.setEnabled(!running); 90 this.notNaturalKey.setSelection(!kit.isNatural()); 91 this.notNaturalKey.setEnabled(!running && kit.getMouseMode() == EditorKit.MOUSE_MODE_EDITION); 92 this.voice1.setSelection(kit.getTablature().getCaret().getVoice() == 0); 93 this.voice2.setSelection(kit.getTablature().getCaret().getVoice() == 1); 94 } 95 loadProperties()96 public void loadProperties(){ 97 setMenuItemTextAndAccelerator(this.editMenuItem, "edit.menu", null); 98 setMenuItemTextAndAccelerator(this.undo, "edit.undo", UndoAction.NAME); 99 setMenuItemTextAndAccelerator(this.redo, "edit.redo", RedoAction.NAME); 100 setMenuItemTextAndAccelerator(this.modeSelection, "edit.mouse-mode-selection", SetMouseModeSelectionAction.NAME); 101 setMenuItemTextAndAccelerator(this.modeEdition, "edit.mouse-mode-edition", SetMouseModeEditionAction.NAME); 102 setMenuItemTextAndAccelerator(this.notNaturalKey, "edit.not-natural-key", SetNaturalKeyAction.NAME); 103 setMenuItemTextAndAccelerator(this.voice1, "edit.voice-1", SetVoice1Action.NAME); 104 setMenuItemTextAndAccelerator(this.voice2, "edit.voice-2", SetVoice2Action.NAME); 105 } 106 loadIcons()107 public void loadIcons(){ 108 this.undo.setImage(TuxGuitar.instance().getIconManager().getEditUndo()); 109 this.redo.setImage(TuxGuitar.instance().getIconManager().getEditRedo()); 110 } 111 } 112