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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/tools/browser/dialog/TGBrowserMenuBar.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
package org.herac.tuxguitar.gui.tools.browser.dialog;
 
2
 
 
3
import java.util.Iterator;
 
4
 
 
5
import org.eclipse.swt.SWT;
 
6
import org.eclipse.swt.events.SelectionAdapter;
 
7
import org.eclipse.swt.events.SelectionEvent;
 
8
import org.eclipse.swt.widgets.Menu;
 
9
import org.eclipse.swt.widgets.MenuItem;
 
10
import org.eclipse.swt.widgets.Shell;
 
11
import org.herac.tuxguitar.gui.TuxGuitar;
 
12
import org.herac.tuxguitar.gui.tools.browser.TGBrowserCollection;
 
13
import org.herac.tuxguitar.gui.tools.browser.TGBrowserManager;
 
14
import org.herac.tuxguitar.gui.tools.browser.base.TGBrowserFactory;
 
15
 
 
16
public class TGBrowserMenuBar extends TGBrowserBar{
 
17
        private Menu menu;
 
18
        private Menu newCollection;
 
19
        private Menu openCollection;
 
20
        private Menu removeCollection;
 
21
        
 
22
        private MenuItem menuFileItem;
 
23
        private MenuItem menuCollectionItem;
 
24
        private MenuItem menuGoItem;
 
25
        private MenuItem open;
 
26
        private MenuItem exit;
 
27
        private MenuItem newItem;
 
28
        private MenuItem openItem;
 
29
        private MenuItem removeItem;
 
30
        private MenuItem close;
 
31
        private MenuItem root;
 
32
        private MenuItem back;
 
33
        private MenuItem refresh;
 
34
        
 
35
        public TGBrowserMenuBar(TGBrowserDialog browser){
 
36
                super(browser);
 
37
        }
 
38
        
 
39
        public void init(Shell shell){
 
40
                this.menu = new Menu(shell, SWT.BAR);
 
41
                
 
42
                //---File menu------------------------------------------------------
 
43
                Menu menuFile = new Menu(shell,SWT.DROP_DOWN);
 
44
                this.menuFileItem = new MenuItem(this.menu, SWT.CASCADE);
 
45
                this.menuFileItem.setMenu(menuFile);
 
46
                
 
47
                this.open = new MenuItem(menuFile,SWT.PUSH);
 
48
                this.open.setImage(TuxGuitar.instance().getIconManager().getFileOpen());
 
49
                this.open.addSelectionListener(new SelectionAdapter() {
 
50
                        public void widgetSelected(SelectionEvent e) {
 
51
                                getBrowser().openElement();
 
52
                        }
 
53
                });
 
54
                
 
55
                new MenuItem(menuFile,SWT.SEPARATOR);
 
56
                
 
57
                this.exit = new MenuItem(menuFile,SWT.PUSH);
 
58
                this.exit.addSelectionListener(new SelectionAdapter() {
 
59
                        public void widgetSelected(SelectionEvent e) {
 
60
                                getBrowser().getShell().dispose();
 
61
                        }
 
62
                });
 
63
                
 
64
                //---Collection menu------------------------------------------------------
 
65
                Menu menuCollection = new Menu(shell,SWT.DROP_DOWN);
 
66
                this.menuCollectionItem = new MenuItem(this.menu, SWT.CASCADE);
 
67
                this.menuCollectionItem.setMenu(menuCollection);
 
68
                
 
69
                this.newCollection = new Menu(menuCollection.getShell(), SWT.DROP_DOWN);
 
70
                this.newItem = new MenuItem(menuCollection,SWT.CASCADE);
 
71
                this.newItem.setImage(TuxGuitar.instance().getIconManager().getBrowserNew());
 
72
                this.newItem.setMenu(this.newCollection);
 
73
                this.updateTypes();
 
74
                
 
75
                this.openCollection = new Menu(menuCollection.getShell(), SWT.DROP_DOWN);
 
76
                this.openItem = new MenuItem(menuCollection,SWT.CASCADE);
 
77
                this.openItem.setImage(TuxGuitar.instance().getIconManager().getFileOpen());
 
78
                this.openItem.setMenu(this.openCollection);
 
79
                
 
80
                this.removeCollection = new Menu(menuCollection.getShell(), SWT.DROP_DOWN);
 
81
                this.removeItem = new MenuItem(menuCollection,SWT.CASCADE);
 
82
                this.removeItem.setMenu(this.removeCollection);
 
83
                
 
84
                new MenuItem(menuCollection,SWT.SEPARATOR);
 
85
                
 
86
                this.close = new MenuItem(menuCollection,SWT.PUSH);
 
87
                this.close.addSelectionListener(new SelectionAdapter() {
 
88
                        public void widgetSelected(SelectionEvent e) {
 
89
                                closeCollection();
 
90
                        }
 
91
                });
 
92
                
 
93
                //---Go menu------------------------------------------------------
 
94
                final Menu menuGo = new Menu(shell,SWT.DROP_DOWN);  
 
95
                this.menuGoItem = new MenuItem(this.menu, SWT.CASCADE);
 
96
                this.menuGoItem.setMenu(menuGo);
 
97
                
 
98
                this.root = new MenuItem(menuGo,SWT.PUSH);
 
99
                this.root.setImage(TuxGuitar.instance().getIconManager().getBrowserRoot());
 
100
                this.root.addSelectionListener(new SelectionAdapter() {
 
101
                        public void widgetSelected(SelectionEvent e) {
 
102
                                getBrowser().getConnection().cdRoot(TGBrowserDialog.CALL_CD_ROOT);
 
103
                        }
 
104
                });
 
105
                
 
106
                //---Back Folder------------------------------------------------------
 
107
                this.back = new MenuItem(menuGo,SWT.PUSH);
 
108
                this.back.setImage(TuxGuitar.instance().getIconManager().getBrowserBack());
 
109
                this.back.addSelectionListener(new SelectionAdapter() {
 
110
                        public void widgetSelected(SelectionEvent e) {
 
111
                                getBrowser().getConnection().cdUp(TGBrowserDialog.CALL_CD_UP);
 
112
                        }
 
113
                });
 
114
                
 
115
                //---Refresh Folder------------------------------------------------------
 
116
                this.refresh = new MenuItem(menuGo,SWT.PUSH);
 
117
                this.refresh.setImage(TuxGuitar.instance().getIconManager().getBrowserRefresh());
 
118
                this.refresh.addSelectionListener(new SelectionAdapter() {
 
119
                        public void widgetSelected(SelectionEvent e) {
 
120
                                getBrowser().getConnection().listElements(TGBrowserDialog.CALL_LIST);
 
121
                        }
 
122
                });
 
123
                
 
124
                shell.setMenuBar(this.menu);
 
125
        }
 
126
        
 
127
        public void updateItems(){
 
128
                this.open.setEnabled(!getBrowser().getConnection().isLocked() && getBrowser().getConnection().isOpen());
 
129
                this.root.setEnabled(!getBrowser().getConnection().isLocked() && getBrowser().getConnection().isOpen());
 
130
                this.back.setEnabled(!getBrowser().getConnection().isLocked() && getBrowser().getConnection().isOpen());
 
131
                this.refresh.setEnabled(!getBrowser().getConnection().isLocked() && getBrowser().getConnection().isOpen());
 
132
                this.newItem.setEnabled(!getBrowser().getConnection().isLocked());
 
133
                this.openItem.setEnabled(!getBrowser().getConnection().isLocked());
 
134
                this.removeItem.setEnabled(!getBrowser().getConnection().isLocked());
 
135
                this.close.setEnabled(!getBrowser().getConnection().isLocked());
 
136
        }
 
137
        
 
138
        public void loadProperties(){
 
139
                this.menuFileItem.setText(TuxGuitar.getProperty("browser.menu.file"));
 
140
                this.menuCollectionItem.setText(TuxGuitar.getProperty("browser.menu.collection"));
 
141
                this.menuGoItem.setText(TuxGuitar.getProperty("browser.menu.go"));
 
142
                this.open.setText(TuxGuitar.getProperty("browser.open"));
 
143
                this.exit.setText(TuxGuitar.getProperty("browser.exit"));
 
144
                this.newItem.setText(TuxGuitar.getProperty("browser.collection.new"));
 
145
                this.openItem.setText(TuxGuitar.getProperty("browser.collection.open"));
 
146
                this.removeItem.setText(TuxGuitar.getProperty("browser.collection.remove"));
 
147
                this.close.setText(TuxGuitar.getProperty("browser.collection.close"));
 
148
                this.root.setText(TuxGuitar.getProperty("browser.go-root"));
 
149
                this.back.setText(TuxGuitar.getProperty("browser.go-back"));
 
150
                this.refresh.setText(TuxGuitar.getProperty("browser.refresh"));
 
151
        }
 
152
        
 
153
        public void updateCollections(TGBrowserCollection selection){
 
154
                MenuItem[] openItems = this.openCollection.getItems();
 
155
                for(int i = 0;i < openItems.length; i ++){
 
156
                        openItems[i].dispose();
 
157
                }
 
158
                MenuItem[] removeItems = this.removeCollection.getItems();
 
159
                for(int i = 0;i < removeItems.length; i ++){
 
160
                        removeItems[i].dispose();
 
161
                }
 
162
                Iterator it = TGBrowserManager.instance().getCollections();
 
163
                while(it.hasNext()){
 
164
                        final TGBrowserCollection collection = (TGBrowserCollection)it.next();
 
165
                        if(collection.getData() != null){
 
166
                                MenuItem openItem = new MenuItem(this.openCollection,SWT.PUSH);
 
167
                                openItem.setText(collection.getData().getTitle());
 
168
                                openItem.addSelectionListener(new SelectionAdapter() {
 
169
                                        public void widgetSelected(SelectionEvent e) {
 
170
                                                openCollection(collection);
 
171
                                        }
 
172
                                });
 
173
                                if(selection != null && selection.equals(collection)){
 
174
                                        openItem.setSelection(true);
 
175
                                }
 
176
                                
 
177
                                MenuItem removeItem = new MenuItem(this.removeCollection,SWT.PUSH);
 
178
                                removeItem.setText(collection.getData().getTitle());
 
179
                                removeItem.addSelectionListener(new SelectionAdapter() {
 
180
                                        public void widgetSelected(SelectionEvent e) {
 
181
                                                removeCollection(collection);
 
182
                                        }
 
183
                                });
 
184
                                if(selection != null && selection.equals(collection)){
 
185
                                        removeItem.setSelection(true);
 
186
                                }
 
187
                        }
 
188
                }
 
189
        }
 
190
        
 
191
        public void updateTypes(){
 
192
                MenuItem[] items = this.newCollection.getItems();
 
193
                for(int i = 0;i < items.length; i ++){
 
194
                        items[i].dispose();
 
195
                }
 
196
                Iterator bookTypes = TGBrowserManager.instance().getFactories();
 
197
                while(bookTypes.hasNext()){
 
198
                        final TGBrowserFactory bookType = (TGBrowserFactory)bookTypes.next();
 
199
                        MenuItem item = new MenuItem(this.newCollection,SWT.PUSH);
 
200
                        item.setText(bookType.getName());
 
201
                        item.addSelectionListener(new SelectionAdapter() {
 
202
                                public void widgetSelected(SelectionEvent e) {
 
203
                                        newCollection( bookType.getType());
 
204
                                }
 
205
                        });
 
206
                }
 
207
        }
 
208
        
 
209
        public void reload(Shell shell){
 
210
                if(this.menu != null && !this.menu.isDisposed()){
 
211
                        this.menu.dispose();
 
212
                }
 
213
                this.init(shell);
 
214
        }
 
215
}