~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/items/menu/FileMenuItem.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 java.io.File;
10
 
import java.util.List;
11
 
 
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;
32
 
 
33
 
/**
34
 
 * @author julian
35
 
 * 
36
 
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
37
 
 */
38
 
public class FileMenuItem implements MenuItems {
39
 
    private TablatureEditor tablatureEditor;
40
 
    private MenuItem fileMenuItem;
41
 
    private Menu menu;
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;
60
 
    
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);
65
 
    }
66
 
 
67
 
    
68
 
    public void showItems(){  
69
 
        //---------------------------------------------------
70
 
        //--NEW--
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));
74
 
        //--OPEN--
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)); 
78
 
        //--SEPARATOR--
79
 
        new MenuItem(this.menu, SWT.SEPARATOR);
80
 
        //--SAVE--
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));       
84
 
        //--SAVE AS--
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));             
88
 
        //--SEPARATOR--
89
 
        new MenuItem(this.menu, SWT.SEPARATOR);
90
 
        
91
 
        //--IMPORT--
92
 
        this.importItem = new MenuItem(this.menu,SWT.CASCADE);
93
 
        this.importMenu = new Menu(this.menu.getShell(), SWT.DROP_DOWN);
94
 
        //midi
95
 
        this.importMidi = new MenuItem(this.importMenu, SWT.PUSH);
96
 
        this.importMidi.addSelectionListener(TuxGuitar.instance().getAction(ImportMidiAction.NAME));        
97
 
        
98
 
        //--EXPORT--
99
 
        this.exportItem = new MenuItem(this.menu,SWT.CASCADE);
100
 
        this.exportMenu = new Menu(this.menu.getShell(), SWT.DROP_DOWN);
101
 
        //midi
102
 
        this.exportMidi = new MenuItem(this.exportMenu, SWT.PUSH);
103
 
        this.exportMidi.addSelectionListener(TuxGuitar.instance().getAction(ExportMidiAction.NAME));
104
 
        //pdf
105
 
        this.exportPDF = new MenuItem(this.exportMenu, SWT.PUSH);
106
 
        this.exportPDF.addSelectionListener(TuxGuitar.instance().getAction(ExportPDFAction.NAME));
107
 
        //ascii
108
 
        this.exportASCII = new MenuItem(this.exportMenu, SWT.PUSH);
109
 
        this.exportASCII.addSelectionListener(TuxGuitar.instance().getAction(ExportASCIIAction.NAME));        
110
 
        //--SEPARATOR--
111
 
        new MenuItem(this.menu, SWT.SEPARATOR);
112
 
        //--PRINT PREVIEW--
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));          
116
 
        //--PRINT--
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));         
120
 
        //--SEPARATOR--
121
 
        new MenuItem(this.menu, SWT.SEPARATOR);
122
 
        
123
 
        //--HISTORY--
124
 
        this.historyItem = new MenuItem(this.menu,SWT.CASCADE);
125
 
        this.historyMenu = new Menu(this.menu.getShell(), SWT.DROP_DOWN);
126
 
        this.updateHistoryFiles();
127
 
        //--SEPARATOR--
128
 
        new MenuItem(this.menu, SWT.SEPARATOR);
129
 
        //--EXIT--
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();
135
 
                System.exit(0);
136
 
            }
137
 
        });
138
 
        //---------------------------------------------------
139
 
        this.importItem.setMenu(this.importMenu);
140
 
        this.exportItem.setMenu(this.exportMenu);
141
 
        this.historyItem.setMenu(this.historyMenu);
142
 
        this.fileMenuItem.setMenu(menu);
143
 
        
144
 
        this.loadProperties();
145
 
    }
146
 
 
147
 
    
148
 
    private void disposeHistoryFiles(){
149
 
        for(int i = 0;i < historyFiles.length; i++){
150
 
                this.historyFiles[i].dispose();
151
 
        }
152
 
    }
153
 
    
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));
163
 
        }
164
 
        this.historyItem.setEnabled(this.historyFiles.length > 0);
165
 
    }
166
 
    
167
 
    public void update(){
168
 
        if(TuxGuitar.instance().getFileHistory().hasPathChanges()){
169
 
                disposeHistoryFiles();
170
 
                updateHistoryFiles();
171
 
                TuxGuitar.instance().getFileHistory().setPathChanges(false);
172
 
        }
173
 
    }
174
 
    
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"));
191
 
    }         
192
 
}
 
 
b'\\ No newline at end of file'