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.menu;
10
import java.util.List;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.SelectionAdapter;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.widgets.Menu;
16
import org.eclipse.swt.widgets.MenuItem;
17
import org.eclipse.swt.widgets.Shell;
18
import org.herac.tuxguitar.gui.SystemImages;
19
import org.herac.tuxguitar.gui.TuxGuitar;
20
import org.herac.tuxguitar.gui.actions.file.ExportASCIIAction;
21
import org.herac.tuxguitar.gui.actions.file.ExportMidiAction;
22
import org.herac.tuxguitar.gui.actions.file.ExportPDFAction;
23
import org.herac.tuxguitar.gui.actions.file.ImportMidiAction;
24
import org.herac.tuxguitar.gui.actions.file.NewFileAction;
25
import org.herac.tuxguitar.gui.actions.file.OpenFileAction;
26
import org.herac.tuxguitar.gui.actions.file.PrintAction;
27
import org.herac.tuxguitar.gui.actions.file.PrintPreviewAction;
28
import org.herac.tuxguitar.gui.actions.file.SaveAsFileAction;
29
import org.herac.tuxguitar.gui.actions.file.SaveFileAction;
30
import org.herac.tuxguitar.gui.editors.TablatureEditor;
31
import org.herac.tuxguitar.gui.items.MenuItems;
36
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
38
public class FileMenuItem implements MenuItems {
39
private TablatureEditor tablatureEditor;
40
private MenuItem fileMenuItem;
42
private Menu importMenu;
43
private Menu exportMenu;
44
private Menu historyMenu;
45
private MenuItem newSong;
46
private MenuItem open;
47
private MenuItem save;
48
private MenuItem saveAs;
49
private MenuItem importItem;
50
private MenuItem importMidi;
51
private MenuItem exportItem;
52
private MenuItem exportMidi;
53
private MenuItem exportPDF;
54
private MenuItem exportASCII;
55
private MenuItem printPreview;
56
private MenuItem print;
57
private MenuItem historyItem;
58
private MenuItem[] historyFiles;
59
private MenuItem exit;
61
public FileMenuItem(Shell shell,Menu parent, int style, TablatureEditor tablatureEditor) {
62
this.fileMenuItem = new MenuItem(parent, style);
63
this.tablatureEditor = tablatureEditor;
64
this.menu = new Menu(shell, SWT.DROP_DOWN);
68
public void showItems(){
69
//---------------------------------------------------
71
this.newSong = new MenuItem(this.menu, SWT.PUSH);
72
this.newSong.setImage(SystemImages.NEW_IMAGE);
73
this.newSong.addSelectionListener(TuxGuitar.instance().getAction(NewFileAction.NAME));
75
this.open = new MenuItem(this.menu, SWT.PUSH);
76
this.open.setImage(SystemImages.OPEN_IMAGE);
77
this.open.addSelectionListener(TuxGuitar.instance().getAction(OpenFileAction.NAME));
79
new MenuItem(this.menu, SWT.SEPARATOR);
81
this.save = new MenuItem(this.menu, SWT.PUSH);
82
this.save.setImage(SystemImages.SAVE_IMAGE);
83
this.save.addSelectionListener(TuxGuitar.instance().getAction(SaveFileAction.NAME));
85
this.saveAs = new MenuItem(this.menu, SWT.PUSH);
86
this.saveAs.setImage(SystemImages.SAVE_AS_IMAGE);
87
this.saveAs.addSelectionListener(TuxGuitar.instance().getAction(SaveAsFileAction.NAME));
89
new MenuItem(this.menu, SWT.SEPARATOR);
92
this.importItem = new MenuItem(this.menu,SWT.CASCADE);
93
this.importMenu = new Menu(this.menu.getShell(), SWT.DROP_DOWN);
95
this.importMidi = new MenuItem(this.importMenu, SWT.PUSH);
96
this.importMidi.addSelectionListener(TuxGuitar.instance().getAction(ImportMidiAction.NAME));
99
this.exportItem = new MenuItem(this.menu,SWT.CASCADE);
100
this.exportMenu = new Menu(this.menu.getShell(), SWT.DROP_DOWN);
102
this.exportMidi = new MenuItem(this.exportMenu, SWT.PUSH);
103
this.exportMidi.addSelectionListener(TuxGuitar.instance().getAction(ExportMidiAction.NAME));
105
this.exportPDF = new MenuItem(this.exportMenu, SWT.PUSH);
106
this.exportPDF.addSelectionListener(TuxGuitar.instance().getAction(ExportPDFAction.NAME));
108
this.exportASCII = new MenuItem(this.exportMenu, SWT.PUSH);
109
this.exportASCII.addSelectionListener(TuxGuitar.instance().getAction(ExportASCIIAction.NAME));
111
new MenuItem(this.menu, SWT.SEPARATOR);
113
this.printPreview = new MenuItem(this.menu, SWT.PUSH);
114
this.printPreview.setImage(SystemImages.PRINT_PREVIEW_IMAGE);
115
this.printPreview.addSelectionListener(TuxGuitar.instance().getAction(PrintPreviewAction.NAME));
117
this.print = new MenuItem(this.menu, SWT.PUSH);
118
this.print.setImage(SystemImages.PRINT_IMAGE);
119
this.print.addSelectionListener(TuxGuitar.instance().getAction(PrintAction.NAME));
121
new MenuItem(this.menu, SWT.SEPARATOR);
124
this.historyItem = new MenuItem(this.menu,SWT.CASCADE);
125
this.historyMenu = new Menu(this.menu.getShell(), SWT.DROP_DOWN);
126
this.updateHistoryFiles();
128
new MenuItem(this.menu, SWT.SEPARATOR);
130
this.exit = new MenuItem(this.menu, SWT.PUSH);
131
this.exit.addSelectionListener(new SelectionAdapter() {
132
public void widgetSelected(SelectionEvent arg0) {
133
tablatureEditor.getTablature().dispose();
134
TuxGuitar.instance().getPlayer().close();
138
//---------------------------------------------------
139
this.importItem.setMenu(this.importMenu);
140
this.exportItem.setMenu(this.exportMenu);
141
this.historyItem.setMenu(this.historyMenu);
142
this.fileMenuItem.setMenu(menu);
144
this.loadProperties();
148
private void disposeHistoryFiles(){
149
for(int i = 0;i < historyFiles.length; i++){
150
this.historyFiles[i].dispose();
154
private void updateHistoryFiles(){
155
List paths = TuxGuitar.instance().getFileHistory().getPaths();
156
this.historyFiles = new MenuItem[paths.size()];
157
for(int i = 0;i < historyFiles.length; i++){
158
String pathName = (String)paths.get(i);
159
this.historyFiles[i] = new MenuItem(this.historyMenu, SWT.PUSH);
160
this.historyFiles[i].setText(new File(pathName).getName());
161
this.historyFiles[i].setData(pathName);
162
this.historyFiles[i].addSelectionListener(TuxGuitar.instance().getAction(OpenFileAction.NAME));
164
this.historyItem.setEnabled(this.historyFiles.length > 0);
167
public void update(){
168
if(TuxGuitar.instance().getFileHistory().hasPathChanges()){
169
disposeHistoryFiles();
170
updateHistoryFiles();
171
TuxGuitar.instance().getFileHistory().setPathChanges(false);
175
public void loadProperties(){
176
this.fileMenuItem.setText(TuxGuitar.getProperty("file"));
177
this.newSong.setText(TuxGuitar.getProperty("file.new"));
178
this.open.setText(TuxGuitar.getProperty("file.open"));
179
this.save.setText(TuxGuitar.getProperty("file.save"));
180
this.saveAs.setText(TuxGuitar.getProperty("file.save-as"));
181
this.importItem.setText(TuxGuitar.getProperty("file.import"));
182
this.importMidi.setText(TuxGuitar.getProperty("file.import-midi"));
183
this.exportItem.setText(TuxGuitar.getProperty("file.export"));
184
this.exportMidi.setText(TuxGuitar.getProperty("file.export-midi"));
185
this.exportPDF.setText(TuxGuitar.getProperty("file.export-pdf"));
186
this.exportASCII.setText(TuxGuitar.getProperty("file.export-ascii"));
187
this.printPreview.setText(TuxGuitar.getProperty("file.print-preview"));
188
this.print.setText(TuxGuitar.getProperty("file.print"));
189
this.historyItem.setText(TuxGuitar.getProperty("file.history"));
190
this.exit.setText(TuxGuitar.getProperty("file.exit"));
b'\\ No newline at end of file'