KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > tracelog > ui > ShellMainMenuBar


1 /*
2  * ShellMainMenuBar.java May 7, 2007
3  */

4 package net.sourceforge.tracelog.ui;
5
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.program.Program;
8 import org.eclipse.swt.widgets.Event;
9 import org.eclipse.swt.widgets.Listener;
10 import org.eclipse.swt.widgets.Menu;
11 import org.eclipse.swt.widgets.MenuItem;
12
13 public class ShellMainMenuBar extends AbstractWidget {
14     ShellMainMenuBar() {
15         super();
16     }
17
18     public void run() {
19         Menu bar = new Menu(parentShell, SWT.BAR);
20
21         Menu fileSubMenu = createSubMenu(bar, "&File");
22         Menu editSubMenu = createSubMenu(bar, "&Edit");
23         Menu helpSubMenu = createSubMenu(bar, "&Help");
24
25         // file submenu
26
createMenuItem(fileSubMenu, null, "Exit", 0).addListener(SWT.Selection, new Listener() {
27             public void handleEvent(Event e) {
28                 parentShell.notifyListeners(SWT.Close, e);
29             }
30         });
31
32         // edit submenu
33
createMenuItem(editSubMenu, null, "Options...", 0).addListener(SWT.Selection, new Listener() {
34             public void handleEvent(Event e) {
35                 mediator.handleEvent(ActionMediator.EVENT_DISPLAY_OPTIONS);
36             }
37         });
38
39         // new MenuItem(editSubMenu, SWT.SEPARATOR);
40
//
41
// // increase text size submenu
42
// createMenuItem(editSubMenu, null, "Increase Font Size",
43
// 0).addListener(SWT.Selection, new Listener() {
44
// public void handleEvent(Event e) {
45
// mediator.handleEvent(ActionMediator.EVENT_INCREASE_FONT_SIZE);
46
// }
47
// });
48
//
49
// // decrease text size submenu
50
// createMenuItem(editSubMenu, null, "Decrease Font Size",
51
// 0).addListener(SWT.Selection, new Listener() {
52
// public void handleEvent(Event e) {
53
// mediator.handleEvent(ActionMediator.EVENT_DECREASE_FONT_SIZE);
54
// }
55
// });
56

57         // introduction submenu
58
createMenuItem(helpSubMenu, null, "Project Web Page", 0).addListener(SWT.Selection, new Listener() {
59             public void handleEvent(Event e) {
60                 Program.launch(projectProperties.getProjectHomeURL());
61             }
62         });
63
64         // tutorial submenu
65
createMenuItem(helpSubMenu, null, "Tutorial", 0).addListener(SWT.Selection, new Listener() {
66             public void handleEvent(Event e) {
67                 Program.launch(projectProperties.getTutorialURL());
68             }
69         });
70
71         // updates submenu
72
createMenuItem(helpSubMenu, null, "Find Updates", 0).addListener(SWT.Selection, new Listener() {
73             public void handleEvent(Event e) {
74                 Program.launch(projectProperties.getUpdateURL());
75             }
76         });
77
78         // Report a Bug submenu
79
createMenuItem(helpSubMenu, null, "Report a Bug", 0).addListener(SWT.Selection, new Listener() {
80             public void handleEvent(Event e) {
81                 Program.launch(projectProperties.getBugReportURL());
82             }
83         });
84
85         // Feedback submenu
86
createMenuItem(helpSubMenu, null, "Leave Feedback", 0).addListener(SWT.Selection, new Listener() {
87             public void handleEvent(Event e) {
88                 Program.launch(projectProperties.getFeedbackURL());
89             }
90         });
91
92         // Change History submenu
93
createMenuItem(helpSubMenu, null, "Change History", 0).addListener(SWT.Selection, new Listener() {
94             public void handleEvent(Event e) {
95                 mediator.handleEvent(ActionMediator.EVENT_DISPLAY_CHANGE_HISTORY);
96             }
97         });
98
99         new MenuItem(helpSubMenu, SWT.SEPARATOR);
100
101         createMenuItem(helpSubMenu, null, "About " + projectProperties.getApplicationTitle(), 0).addListener(SWT.Selection, new Listener() {
102             public void handleEvent(Event e) {
103                 mediator.handleEvent(ActionMediator.EVENT_DISPLAY_ABOUT);
104             }
105         });
106
107         parentShell.setMenuBar(bar);
108     }
109
110     /**
111      * Creates a submenu.
112      *
113      * @param menu
114      * Parent menu.
115      * @param subMenuName
116      * Submenu name.
117      * @return Menu object.
118      */

119     private Menu createSubMenu(Menu menu, String JavaDoc subMenuName) {
120         Menu subMenu = new Menu(parentShell, SWT.DROP_DOWN);
121
122         MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
123         fileItem.setText(subMenuName);
124         fileItem.setMenu(subMenu);
125
126         return subMenu;
127     }
128
129     /**
130      * Creates a menu item.
131      *
132      * @param menu
133      * Parent menu.
134      * @param subMenu
135      * Submenu.
136      * @param menuItemName
137      * Menu item name.
138      * @param accelerator
139      * Menu item accelerator.
140      * @return MenuItem object.
141      */

142     private MenuItem createMenuItem(Menu menu, Menu subMenu, String JavaDoc menuItemName, int accelerator) {
143         MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
144
145         menuItem.setText(menuItemName);
146
147         if (accelerator != 0) {
148             menuItem.setAccelerator(accelerator);
149         }
150
151         if (subMenu != null) {
152             menuItem.setMenu(subMenu);
153         }
154
155         return menuItem;
156     }
157
158 }
159
Popular Tags