2
* Created on 02-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.items.tool;
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.graphics.Point;
13
import org.eclipse.swt.graphics.Rectangle;
14
import org.eclipse.swt.widgets.Menu;
15
import org.eclipse.swt.widgets.MenuItem;
16
import org.eclipse.swt.widgets.ToolBar;
17
import org.eclipse.swt.widgets.ToolItem;
18
import org.herac.tuxguitar.gui.SystemImages;
19
import org.herac.tuxguitar.gui.TuxGuitar;
20
import org.herac.tuxguitar.gui.actions.insert.InsertChordAction;
21
import org.herac.tuxguitar.gui.actions.note.ChangeTiedNoteAction;
22
import org.herac.tuxguitar.gui.items.ToolItems;
23
import org.herac.tuxguitar.song.models.Chord;
28
* TODO To change the template for this generated type comment go to
29
* Window - Preferences - Java - Code Style - Code Templates
31
public class NoteToolItems extends ToolItems{
32
public static final String NAME = "note.items";
34
private ToolBar toolBar;
35
private ToolItem tiedNote;
36
private ChordMenuItem chordItems;
38
public NoteToolItems(){
42
public void showItems(ToolBar toolBar){
43
this.toolBar = toolBar;
45
this.tiedNote = new ToolItem(toolBar, SWT.PUSH);
46
this.tiedNote.setImage(SystemImages.TIED_NOTE_IMAGE);
47
this.tiedNote.addSelectionListener(TuxGuitar.instance().getAction(ChangeTiedNoteAction.NAME));
49
this.chordItems = new ChordMenuItem();
50
this.chordItems.addItems();
58
this.chordItems.update();
61
public void loadProperties(){
62
this.tiedNote.setToolTipText(TuxGuitar.getProperty("note.tiednote"));
63
this.chordItems.setToolTipText(TuxGuitar.getProperty("insert.chord"));
67
private class ChordMenuItem extends SelectionAdapter {
68
private long lastEdit;
69
private ToolItem item;
71
private MenuItem[] subMenuItems;
73
public ChordMenuItem() {
74
this.item = new ToolItem(toolBar, SWT.DROP_DOWN);
75
this.item.setImage(SystemImages.CHORD_IMAGE);
76
this.item.addSelectionListener(this);
77
this.subMenu = new Menu(this.item.getParent().getShell());
80
public void setToolTipText(String text){
81
this.item.setToolTipText(text);
84
public void addItems() {
86
this.subMenuItems = new MenuItem[TuxGuitar.instance().getCustomChordManager().countChords()];
87
for(int i = 0;i < this.subMenuItems.length; i++){
88
Chord chord = TuxGuitar.instance().getCustomChordManager().getChord(i);
89
this.subMenuItems[i] = new MenuItem(this.subMenu, SWT.PUSH);
90
this.subMenuItems[i].setData(chord);
91
this.subMenuItems[i].setText(chord.getName());
92
this.subMenuItems[i].addSelectionListener(TuxGuitar.instance().getAction(InsertChordAction.NAME));
96
public void disposeItems() {
97
if(this.subMenuItems != null){
98
for(int i = 0;i < this.subMenuItems.length; i++){
99
this.subMenuItems[i].dispose();
104
public void widgetSelected(SelectionEvent event) {
105
if (event.detail == SWT.ARROW && this.subMenuItems != null && this.subMenuItems.length > 0) {
106
ToolItem item = (ToolItem) event.widget;
107
Rectangle rect = item.getBounds();
108
Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
109
this.subMenu.setLocation(pt.x, pt.y + rect.height);
110
this.subMenu.setVisible(true);
112
TuxGuitar.instance().getAction(InsertChordAction.NAME).process(event);
116
public void update(){
117
if(lastEdit != TuxGuitar.instance().getCustomChordManager().getLastEdit()){
119
this.lastEdit = TuxGuitar.instance().getCustomChordManager().getLastEdit();