1 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 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 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 57 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 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 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 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 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 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 119 private Menu createSubMenu(Menu menu, String 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 142 private MenuItem createMenuItem(Menu menu, Menu subMenu, String 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 |