001: package net.sourceforge.tracelog.ui;
002:
003: import org.eclipse.swt.SWT;
004: import org.eclipse.swt.program.Program;
005: import org.eclipse.swt.widgets.Event;
006: import org.eclipse.swt.widgets.Listener;
007: import org.eclipse.swt.widgets.Menu;
008: import org.eclipse.swt.widgets.MenuItem;
009:
010: public class ShellMainMenuBar extends AbstractWidget {
011: ShellMainMenuBar() {
012: super ();
013: }
014:
015: public void run() {
016: Menu bar = new Menu(parentShell, SWT.BAR);
017:
018: Menu fileSubMenu = createSubMenu(bar, "&File");
019: Menu editSubMenu = createSubMenu(bar, "&Edit");
020: Menu helpSubMenu = createSubMenu(bar, "&Help");
021:
022: // file submenu
023: createMenuItem(fileSubMenu, null, "Exit", 0).addListener(
024: SWT.Selection, new Listener() {
025: public void handleEvent(Event e) {
026: parentShell.notifyListeners(SWT.Close, e);
027: }
028: });
029:
030: // edit submenu
031: createMenuItem(editSubMenu, null, "Options...", 0).addListener(
032: SWT.Selection, new Listener() {
033: public void handleEvent(Event e) {
034: mediator
035: .handleEvent(ActionMediator.EVENT_DISPLAY_OPTIONS);
036: }
037: });
038:
039: // introduction submenu
040: createMenuItem(helpSubMenu, null, "Project Web Page", 0)
041: .addListener(SWT.Selection, new Listener() {
042: public void handleEvent(Event e) {
043: Program.launch(projectProperties
044: .getProjectHomeURL());
045: }
046: });
047:
048: // tutorial submenu
049: createMenuItem(helpSubMenu, null, "Tutorial", 0).addListener(
050: SWT.Selection, new Listener() {
051: public void handleEvent(Event e) {
052: Program.launch(projectProperties
053: .getTutorialURL());
054: }
055: });
056:
057: // updates submenu
058: createMenuItem(helpSubMenu, null, "Find Updates", 0)
059: .addListener(SWT.Selection, new Listener() {
060: public void handleEvent(Event e) {
061: Program
062: .launch(projectProperties
063: .getUpdateURL());
064: }
065: });
066:
067: // Report a Bug submenu
068: createMenuItem(helpSubMenu, null, "Report a Bug", 0)
069: .addListener(SWT.Selection, new Listener() {
070: public void handleEvent(Event e) {
071: Program.launch(projectProperties
072: .getBugReportURL());
073: }
074: });
075:
076: // Feedback submenu
077: createMenuItem(helpSubMenu, null, "Leave Feedback", 0)
078: .addListener(SWT.Selection, new Listener() {
079: public void handleEvent(Event e) {
080: Program.launch(projectProperties
081: .getFeedbackURL());
082: }
083: });
084:
085: // Change History submenu
086: createMenuItem(helpSubMenu, null, "Change History", 0)
087: .addListener(SWT.Selection, new Listener() {
088: public void handleEvent(Event e) {
089: mediator
090: .handleEvent(ActionMediator.EVENT_DISPLAY_CHANGE_HISTORY);
091: }
092: });
093:
094: new MenuItem(helpSubMenu, SWT.SEPARATOR);
095:
096: createMenuItem(helpSubMenu, null,
097: "About " + projectProperties.getApplicationTitle(), 0)
098: .addListener(SWT.Selection, new Listener() {
099: public void handleEvent(Event e) {
100: mediator
101: .handleEvent(ActionMediator.EVENT_DISPLAY_ABOUT);
102: }
103: });
104:
105: parentShell.setMenuBar(bar);
106: }
107:
108: /**
109: * Creates a menu item.
110: *
111: * @param menu
112: * Parent menu.
113: * @param subMenu
114: * Submenu.
115: * @param menuItemName
116: * ShellOptionMenu item name.
117: * @param accelerator
118: * ShellOptionMenu item accelerator.
119: * @return MenuItem object.
120: */
121: private MenuItem createMenuItem(Menu menu, Menu subMenu,
122: String menuItemName, int accelerator) {
123: MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
124:
125: menuItem.setText(menuItemName);
126:
127: if (accelerator != 0) {
128: menuItem.setAccelerator(accelerator);
129: }
130:
131: if (subMenu != null) {
132: menuItem.setMenu(subMenu);
133: }
134:
135: return menuItem;
136: }
137:
138: /**
139: * Creates a submenu.
140: *
141: * @param menu
142: * Parent menu.
143: * @param subMenuName
144: * Submenu name.
145: * @return ShellOptionMenu object.
146: */
147: private Menu createSubMenu(Menu menu, String subMenuName) {
148: Menu subMenu = new Menu(parentShell, SWT.DROP_DOWN);
149:
150: MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
151: fileItem.setText(subMenuName);
152: fileItem.setMenu(subMenu);
153:
154: return subMenu;
155: }
156:
157: }
|