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.duration.ChangeDottedDurationAction;
15 import org.herac.tuxguitar.gui.actions.duration.ChangeDoubleDottedDurationAction;
16 import org.herac.tuxguitar.gui.actions.duration.ChangeDivisionTypeAction;
17 import org.herac.tuxguitar.gui.actions.duration.SetEighthDurationAction;
18 import org.herac.tuxguitar.gui.actions.duration.SetHalfDurationAction;
19 import org.herac.tuxguitar.gui.actions.duration.SetQuarterDurationAction;
20 import org.herac.tuxguitar.gui.actions.duration.SetSixteenthDurationAction;
21 import org.herac.tuxguitar.gui.actions.duration.SetSixtyFourthDurationAction;
22 import org.herac.tuxguitar.gui.actions.duration.SetThirtySecondDurationAction;
23 import org.herac.tuxguitar.gui.actions.duration.SetWholeDurationAction;
24 import org.herac.tuxguitar.gui.items.MenuItems;
25 import org.herac.tuxguitar.song.models.TGDuration;
26 /**
27  * @author julian
28  *
29  * TODO To change the template for this generated type comment go to
30  * Window - Preferences - Java - Code Style - Code Templates
31  */
32 public class DurationMenuItem  extends MenuItems{
33 	private MenuItem durationMenuItem;
34 	private Menu menu;
35 	private MenuItem whole;
36 	private MenuItem half;
37 	private MenuItem quarter;
38 	private MenuItem eighth;
39 	private MenuItem sixteenth;
40 	private MenuItem thirtySecond;
41 	private MenuItem sixtyFourth;
42 	private MenuItem dotted;
43 	private MenuItem doubleDotted;
44 	private MenuItem division;
45 
DurationMenuItem(Shell shell,Menu parent, int style)46 	public DurationMenuItem(Shell shell,Menu parent, int style) {
47 		this.durationMenuItem = new MenuItem(parent, style);
48 		this.menu = new Menu(shell, SWT.DROP_DOWN);
49 	}
50 
showItems()51 	public void showItems(){
52 		//--whole--
53 		this.whole = new MenuItem(this.menu, SWT.PUSH);
54 		this.whole.addSelectionListener(TuxGuitar.instance().getAction(SetWholeDurationAction.NAME));
55 		//--half--
56 		this.half = new MenuItem(this.menu, SWT.PUSH);
57 		this.half.addSelectionListener(TuxGuitar.instance().getAction(SetHalfDurationAction.NAME));
58 		//--quarter--
59 		this.quarter = new MenuItem(this.menu, SWT.PUSH);
60 		this.quarter.addSelectionListener(TuxGuitar.instance().getAction(SetQuarterDurationAction.NAME));
61 		//--Eighth--
62 		this.eighth = new MenuItem(this.menu, SWT.PUSH);
63 		this.eighth.addSelectionListener(TuxGuitar.instance().getAction(SetEighthDurationAction.NAME));
64 		//--sixteenth--
65 		this.sixteenth = new MenuItem(this.menu, SWT.PUSH);
66 		this.sixteenth.addSelectionListener(TuxGuitar.instance().getAction(SetSixteenthDurationAction.NAME));
67 		//--thirtySecond--
68 		this.thirtySecond = new MenuItem(this.menu, SWT.PUSH);
69 		this.thirtySecond.addSelectionListener(TuxGuitar.instance().getAction(SetThirtySecondDurationAction.NAME));
70 		//--sixtyFourth--
71 		this.sixtyFourth = new MenuItem(this.menu, SWT.PUSH);
72 		this.sixtyFourth.addSelectionListener(TuxGuitar.instance().getAction(SetSixtyFourthDurationAction.NAME));
73 
74 		//--SEPARATOR--
75 		new MenuItem(this.menu, SWT.SEPARATOR);
76 
77 		//--dotted---
78 		this.dotted = new MenuItem(this.menu, SWT.PUSH);
79 		this.dotted.addSelectionListener(TuxGuitar.instance().getAction(ChangeDottedDurationAction.NAME));
80 
81 		this.doubleDotted = new MenuItem(this.menu, SWT.PUSH);
82 		this.doubleDotted.addSelectionListener(TuxGuitar.instance().getAction(ChangeDoubleDottedDurationAction.NAME));
83 
84 		//--division---
85 		this.division = new MenuItem(this.menu, SWT.PUSH);
86 		this.division.addSelectionListener(TuxGuitar.instance().getAction(ChangeDivisionTypeAction.NAME));
87 
88 		this.durationMenuItem.setMenu(this.menu);
89 
90 		this.loadIcons();
91 		this.loadProperties();
92 	}
93 
update()94 	public void update(){
95 		boolean running = TuxGuitar.instance().getPlayer().isRunning();
96 		this.whole.setEnabled(!running);
97 		this.half.setEnabled(!running);
98 		this.quarter.setEnabled(!running);
99 		this.eighth.setEnabled(!running);
100 		this.sixteenth.setEnabled(!running);
101 		this.thirtySecond.setEnabled(!running);
102 		this.sixtyFourth.setEnabled(!running);
103 		this.dotted.setEnabled(!running);
104 		this.doubleDotted.setEnabled(!running);
105 		this.division.setEnabled(!running);
106 	}
107 
loadProperties()108 	public void loadProperties(){
109 		setMenuItemTextAndAccelerator(this.durationMenuItem, "duration", null);
110 		setMenuItemTextAndAccelerator(this.whole, "duration.whole", SetWholeDurationAction.NAME);
111 		setMenuItemTextAndAccelerator(this.half, "duration.half", SetHalfDurationAction.NAME);
112 		setMenuItemTextAndAccelerator(this.quarter, "duration.quarter", SetQuarterDurationAction.NAME);
113 		setMenuItemTextAndAccelerator(this.eighth, "duration.eighth", SetEighthDurationAction.NAME);
114 		setMenuItemTextAndAccelerator(this.sixteenth, "duration.sixteenth", SetSixteenthDurationAction.NAME);
115 		setMenuItemTextAndAccelerator(this.thirtySecond, "duration.thirtysecond", SetThirtySecondDurationAction.NAME);
116 		setMenuItemTextAndAccelerator(this.sixtyFourth, "duration.sixtyfourth", SetSixtyFourthDurationAction.NAME);
117 		setMenuItemTextAndAccelerator(this.dotted, "duration.dotted", ChangeDottedDurationAction.NAME);
118 		setMenuItemTextAndAccelerator(this.doubleDotted, "duration.doubledotted", ChangeDoubleDottedDurationAction.NAME);
119 		setMenuItemTextAndAccelerator(this.division, "duration.division-type", ChangeDivisionTypeAction.NAME);
120 	}
121 
loadIcons()122 	public void loadIcons() {
123 		this.whole.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.WHOLE));
124 		this.half.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.HALF));
125 		this.quarter.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.QUARTER));
126 		this.eighth.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.EIGHTH));
127 		this.sixteenth.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.SIXTEENTH));
128 		this.thirtySecond.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.THIRTY_SECOND));
129 		this.sixtyFourth.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.SIXTY_FOURTH));
130 		this.dotted.setImage(TuxGuitar.instance().getIconManager().getDurationDotted());
131 		this.doubleDotted.setImage(TuxGuitar.instance().getIconManager().getDurationDoubleDotted());
132 		this.division.setImage(TuxGuitar.instance().getIconManager().getDivisionType());
133 	}
134 }
135