KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > menus > MenuBar


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window.menus;
20
21 import java.awt.Font JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import javax.swing.JMenu JavaDoc;
26 import javax.swing.JMenuBar JavaDoc;
27
28 import org.openharmonise.him.actions.*;
29 import org.openharmonise.him.actions.file.*;
30 import org.openharmonise.him.actions.help.*;
31 import org.openharmonise.him.actions.publish.*;
32 import org.openharmonise.him.actions.system.*;
33 import org.openharmonise.vfs.context.*;
34
35 import org.openharmonise.him.actions.system.ActionExportContent;
36
37
38 /**
39  * Main menu bar for the application.
40  *
41  * @author Matthew Large
42  * @version $Revision: 1.3 $
43  *
44  */

45 public class MenuBar extends JMenuBar JavaDoc implements ContextListener {
46
47     /**
48      * List of {@link HIMAction} objects.
49      */

50     private ArrayList JavaDoc m_aActions = new ArrayList JavaDoc();
51
52     /**
53      * Constructs a new menu bar.
54      */

55     public MenuBar() {
56         super();
57         this.setup();
58     }
59
60     /**
61      * Initialises this component.
62      *
63      */

64     private void setup() {
65         this.add(this.getSystemMenu());
66         this.add(this.getFileMenu());
67         this.add(this.getPublishMenu());
68         this.add(this.getCMHelpMenu());
69
70         ContextHandler.getInstance().addListener(
71             ContextType.CONTEXT_FILES,
72             this);
73         ContextHandler.getInstance().addListener(
74             ContextType.CONTEXT_DIRS,
75             this);
76         ContextHandler.getInstance().addListener(
77             ContextType.CONTEXT_TABS,
78             this);
79     }
80
81     /**
82      * Gets the System menu.
83      *
84      * @return System menu.
85      */

86     private JMenu JavaDoc getSystemMenu() {
87         JMenu JavaDoc menu = new JMenu JavaDoc("System");
88         menu.setMnemonic('S');
89
90         String JavaDoc fontName = "Dialog";
91         int fontSize = 11;
92         Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
93         menu.setFont(font);
94
95         HIMAction action = new ActionSystemSettings();
96         this.m_aActions.add(action);
97         menu.add(action.getMenuItem());
98         
99         action = new ActionPreviewSettings();
100         this.m_aActions.add(action);
101         menu.add(action.getMenuItem());
102
103         action = new ActionCustomise();
104         this.m_aActions.add(action);
105         menu.add(action.getMenuItem());
106
107         action = new ActionChangeMyPassword();
108         this.m_aActions.add(action);
109         menu.add(action.getMenuItem());
110
111         menu.addSeparator();
112
113         action = new ActionRefresh();
114         this.m_aActions.add(action);
115         menu.add(action.getMenuItem());
116
117         action = new ActionSyncWithServer();
118         this.m_aActions.add(action);
119         menu.add(action.getMenuItem());
120         
121         action = new ActionExportContent();
122         this.m_aActions.add(action);
123         menu.add(action.getMenuItem());
124
125         menu.addSeparator();
126
127         action = new ActionExitReject();
128         this.m_aActions.add(action);
129         menu.add(action.getMenuItem());
130
131         action = new ActionExitCommit();
132         this.m_aActions.add(action);
133         menu.add(action.getMenuItem());
134
135         return menu;
136     }
137
138     /**
139      * Gets the File menu.
140      *
141      * @return File menu.
142      */

143     private JMenu JavaDoc getFileMenu() {
144         JMenu JavaDoc menu = new JMenu JavaDoc("Resource");
145         menu.setMnemonic('R');
146
147         String JavaDoc fontName = "Dialog";
148         int fontSize = 11;
149         Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
150         menu.setFont(font);
151
152         HIMAction action = new ActionNewFile();
153         this.m_aActions.add(action);
154         menu.add(action.getMenuItem());
155
156         action = new ActionUpload();
157         this.m_aActions.add(action);
158         menu.add(action.getMenuItem());
159
160         action = new ActionNewCollection();
161         this.m_aActions.add(action);
162         menu.add(action.getMenuItem());
163
164         menu.addSeparator();
165
166         action = new ActionOpen();
167         this.m_aActions.add(action);
168         menu.add(action.getMenuItem());
169         
170         //commenting out as renaming a resource changes the path
171
//which then can mess up property domain references
172
//will be fixed in later releases
173

174 // action = new ActionRename();
175
// this.m_aActions.add(action);
176
// menu.add(action.getMenuItem());
177

178         action = new ActionCreateCopy();
179         this.m_aActions.add(action);
180         menu.add(action.getMenuItem());
181
182         menu.addSeparator();
183
184         action = new ActionSynchronise();
185         this.m_aActions.add(action);
186         menu.add(action.getMenuItem());
187
188         action = new ActionLock();
189         this.m_aActions.add(action);
190         menu.add(action.getMenuItem());
191
192         action = new ActionUnlock();
193         this.m_aActions.add(action);
194         menu.add(action.getMenuItem());
195
196         return menu;
197     }
198
199     /**
200      * Gets the Publish menu.
201      *
202      * @return Publish menu.
203      */

204     private JMenu JavaDoc getPublishMenu() {
205         JMenu JavaDoc menu = new JMenu JavaDoc("Publish");
206         menu.setMnemonic('P');
207
208         String JavaDoc fontName = "Dialog";
209         int fontSize = 11;
210         Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
211         menu.setFont(font);
212
213         HIMAction action = new ActionPreview();
214         this.m_aActions.add(action);
215         menu.add(action.getMenuItem());
216
217         action = new ActionPublishToInternet();
218         this.m_aActions.add(action);
219         menu.add(action.getMenuItem());
220
221         action = new ActionExport();
222         this.m_aActions.add(action);
223         menu.add(action.getMenuItem());
224
225         menu.addSeparator();
226
227         action = new ActionArchive();
228         this.m_aActions.add(action);
229         menu.add(action.getMenuItem());
230
231         action = new ActionRetrieve();
232         this.m_aActions.add(action);
233         menu.add(action.getMenuItem());
234
235         return menu;
236     }
237
238     /**
239      * Gets the Help menu.
240      *
241      * @return Help menu.
242      */

243     private JMenu JavaDoc getCMHelpMenu() {
244         JMenu JavaDoc menu = new JMenu JavaDoc("Help");
245         menu.setMnemonic('H');
246
247         String JavaDoc fontName = "Dialog";
248         int fontSize = 11;
249         Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
250         menu.setFont(font);
251
252         HIMAction action = new ActionHelp();
253         this.m_aActions.add(action);
254         menu.add(action.getMenuItem());
255
256         action = new ActionKeyboardShortcuts();
257         this.m_aActions.add(action);
258         menu.add(action.getMenuItem());
259
260         action = new ActionAbout();
261         this.m_aActions.add(action);
262         menu.add(action.getMenuItem());
263
264         return menu;
265     }
266
267     /* (non-Javadoc)
268      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
269      */

270     public void contextMessage(ContextEvent ce) {
271         if (ce.CONTEXT_TYPE == ContextType.CONTEXT_DIRS) {
272             Iterator JavaDoc itor = this.m_aActions.iterator();
273             while(itor.hasNext()) {
274                 HIMAction action = (HIMAction) itor.next();
275                 action.isEnabled(ce);
276             }
277         } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_FILES) {
278             Iterator JavaDoc itor = this.m_aActions.iterator();
279             while(itor.hasNext()) {
280                 HIMAction action = (HIMAction) itor.next();
281                 action.isEnabled(ce);
282             }
283         } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_TABS) {
284             Iterator JavaDoc itor = this.m_aActions.iterator();
285             while(itor.hasNext()) {
286                 HIMAction action = (HIMAction) itor.next();
287                 action.isEnabled(ce);
288             }
289         }
290     }
291
292 }
293
Popular Tags