/** * Creates all the items located in the Search submenu and associate all the menu items with their * appropriate functions. * * @param menuBar Menu the <code>Menu</code> that file contain the Search submenu. */ private void createSearchMenu(Menu menuBar) { // Search menu. MenuItem item = new MenuItem(menuBar, SWT.CASCADE); item.setText(resMessages.getString("Search_menu_title")); Menu searchMenu = new Menu(shell, SWT.DROP_DOWN); item.setMenu(searchMenu); // Search -> Find... item = new MenuItem(searchMenu, SWT.NULL); item.setText(resMessages.getString("Find")); item.setAccelerator(SWT.MOD1 + 'F'); item.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { searchDialog.setMatchCase(false); searchDialog.setMatchWord(false); searchDialog.setSearchDown(true); searchDialog.setSearchString(""); searchDialog.setSelectedSearchArea(0); searchDialog.open(); } }); // Search -> Find Next item = new MenuItem(searchMenu, SWT.NULL); item.setText(resMessages.getString("Find_next")); item.setAccelerator(SWT.F3); item.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { searchDialog.open(); } }); }
/** * Create the options menu. * * @param header the header from which the menu hangs */ private void createOptionsMenu(final MenuItem header) { if (optionsMenu != null) { optionsMenu.dispose(); } optionsMenu = new Menu(shell, SWT.DROP_DOWN); MenuItem viewShowPathItem = new MenuItem(optionsMenu, SWT.CHECK); viewShowPathItem.setText("&Show agent's path\tCTRL+P"); viewShowPathItem.setAccelerator(SWT.CTRL + 'P'); viewShowPathItem.setSelection(true); viewShowPathItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { gui.setPathShown(!gui.isPathShown()); } }); MenuItem simulateNightItem = new MenuItem(optionsMenu, SWT.CHECK); simulateNightItem.setText("Simulate &night"); simulateNightItem.setSelection(gui.isNightSimulated()); simulateNightItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { gui.simulateNight(((MenuItem) e.getSource()).getSelection()); } }); new MenuItem(optionsMenu, SWT.SEPARATOR); MenuItem toolsOptionsItem = new MenuItem(optionsMenu, SWT.PUSH); toolsOptionsItem.setText("Con&figuration\tCtrl+T"); toolsOptionsItem.setAccelerator(SWT.CTRL + 'T'); toolsOptionsItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { new ConfigShell(siafuConfig); } }); optionsMenuHeader.setMenu(optionsMenu); }
org.eclipse.swt.widgets.Menu createFileMenu() { org.eclipse.swt.widgets.Menu bar = shell.getMenuBar(); org.eclipse.swt.widgets.Menu menu = new org.eclipse.swt.widgets.Menu(bar); org.eclipse.swt.widgets.MenuItem item; item = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH); item.setText(resources.getString("Open_menuitem")); item.setAccelerator(SWT.MOD1 + 'O'); item.addSelectionListener( new org.eclipse.swt.events.SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) { openFile(); } }); item = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH); item.setText(resources.getString("Exit_menuitem")); item.addSelectionListener( new org.eclipse.swt.events.SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { menuFileExit(); } }); return menu; }
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Text Editor"); Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); fileItem.setText("&File"); Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); fileItem.setMenu(fileMenu); MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH); saveItem.setText("&Save\tCtrl+S"); saveItem.setAccelerator(SWT.MOD1 + 'S'); saveItem.addListener(SWT.Selection, e -> shell.setModified(false)); MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH); exitItem.setText("Exit"); exitItem.addListener(SWT.Selection, e -> shell.close()); Text text = new Text(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); text.addListener(SWT.Modify, e -> shell.setModified(true)); shell.addListener( SWT.Close, e -> { if (shell.getModified()) { MessageBox box = new MessageBox(shell, SWT.PRIMARY_MODAL | SWT.OK | SWT.CANCEL); box.setText(shell.getText()); box.setMessage("You have unsaved changes, do you want to exit?"); e.doit = box.open() == SWT.OK; } }); shell.setLayout(new FillLayout()); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
/** * Create a MenuItem * * @param parent Containing menu * @param style Item's style * @param text Item's text (optional: null) * @param icon Item's icon (optional: null) * @param accel Item's accelerator (optional: <0) * @param enabled Item's enabled state * @param callback Name of zero-arg method to call */ protected MenuItem createMenuItem( Menu parent, int style, String text, Image icon, int accel, boolean enabled, String callback) { MenuItem mi = new MenuItem(parent, style); if (text != null) { mi.setText(text); } if (icon != null) { mi.setImage(icon); } if (accel != -1) { mi.setAccelerator(accel); } mi.setEnabled(enabled); if (callback != null) { registerCallback(mi, this, callback); } return mi; }
/** Open the dialog. */ public void open() { // シェルを作成 this.shell = new Shell(this.getParent(), this.getStyle()); this.shell.setSize(this.getSize()); // ウインドウ位置を復元 LayoutLogic.applyWindowLocation(this.getClass(), this.shell); // 閉じた時にウインドウ位置を保存 this.shell.addShellListener(new SaveWindowLocationAdapter(this.getClass())); this.shell.setText(this.getTitle()); this.shell.setLayout(new FillLayout()); // メニューバー this.menubar = new Menu(this.shell, SWT.BAR); this.shell.setMenuBar(this.menubar); // テーブルより前に作成する必要があるコンポジットを作成 this.createContentsBefore(); // テーブル this.table = new Table(this.getTableParent(), SWT.FULL_SELECTION | SWT.MULTI); this.table.addKeyListener(new TableKeyShortcutAdapter(this.header, this.table)); this.table.setLinesVisible(true); this.table.setHeaderVisible(true); // メニューバーのメニュー MenuItem fileroot = new MenuItem(this.menubar, SWT.CASCADE); fileroot.setText("ファイル"); this.filemenu = new Menu(fileroot); fileroot.setMenu(this.filemenu); MenuItem savecsv = new MenuItem(this.filemenu, SWT.NONE); savecsv.setText("CSVファイルに保存(&S)\tCtrl+S"); savecsv.setAccelerator(SWT.CTRL + 'S'); savecsv.addSelectionListener( new TableToCsvSaveAdapter(this.shell, this.getTitle(), this.getTableHeader(), this.table)); MenuItem operoot = new MenuItem(this.menubar, SWT.CASCADE); operoot.setText("操作"); this.opemenu = new Menu(operoot); operoot.setMenu(this.opemenu); MenuItem reload = new MenuItem(this.opemenu, SWT.NONE); reload.setText("再読み込み(&R)\tF5"); reload.setAccelerator(SWT.F5); reload.addSelectionListener(new TableReloadAdapter()); Boolean isCyclicReload = AppConfig.get().getCyclicReloadMap().get(this.getClass().getName()); MenuItem cyclicReload = new MenuItem(this.opemenu, SWT.CHECK); cyclicReload.setText("定期的に再読み込み(&A)\tCtrl+F5"); cyclicReload.setAccelerator(SWT.CTRL + SWT.F5); if ((isCyclicReload != null) && isCyclicReload.booleanValue()) { cyclicReload.setSelection(true); } CyclicReloadAdapter adapter = new CyclicReloadAdapter(cyclicReload); cyclicReload.addSelectionListener(adapter); adapter.setCyclicReload(cyclicReload); MenuItem selectVisible = new MenuItem(this.opemenu, SWT.NONE); selectVisible.setText("列の表示・非表示(&V)"); selectVisible.addSelectionListener(new SelectVisibleColumnAdapter()); new MenuItem(this.opemenu, SWT.SEPARATOR); // テーブル右クリックメニュー this.tablemenu = new Menu(this.table); this.table.setMenu(this.tablemenu); MenuItem sendclipbord = new MenuItem(this.tablemenu, SWT.NONE); sendclipbord.addSelectionListener(new TableToClipboardAdapter(this.header, this.table)); sendclipbord.setText("クリップボードにコピー(&C)"); MenuItem reloadtable = new MenuItem(this.tablemenu, SWT.NONE); reloadtable.setText("再読み込み(&R)"); reloadtable.addSelectionListener(new TableReloadAdapter()); // テーブルにヘッダーをセット this.setTableHeader(); // テーブルに内容をセット this.updateTableBody(); this.setTableBody(); // 列幅を整える this.packTableHeader(); // 閉じた時に設定を保存 this.shell.addShellListener( new ShellAdapter() { @Override public void shellClosed(ShellEvent e) { AppConfig.get() .getCyclicReloadMap() .put(AbstractTableDialog.this.getClass().getName(), cyclicReload.getSelection()); } }); this.createContents(); this.shell.open(); this.shell.layout(); this.display = this.getParent().getDisplay(); while (!this.shell.isDisposed()) { if (!this.display.readAndDispatch()) { this.display.sleep(); } } // タスクがある場合キャンセル if (this.future != null) { this.future.cancel(false); } }
public static void main(final String[] args) { System.setProperty("ardor3d.useMultipleContexts", "true"); final Timer timer = new Timer(); final FrameHandler frameWork = new FrameHandler(timer); final LogicalLayer logicalLayer = new LogicalLayer(); final MyExit exit = new MyExit(); final ExampleScene scene = new ExampleScene(); final RotatingCubeGame game = new RotatingCubeGame(scene, exit, logicalLayer, Key.T); frameWork.addUpdater(game); // INIT SWT STUFF final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // This is our tab folder, it will be accepting our 3d canvases final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER); // Add a menu item that will create and add a new canvas. final Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); final MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); fileItem.setText("&Tasks"); final Menu submenu = new Menu(shell, SWT.DROP_DOWN); fileItem.setMenu(submenu); final MenuItem item = new MenuItem(submenu, SWT.PUSH); item.addListener( SWT.Selection, new Listener() { public void handleEvent(final Event e) { Display.getDefault() .asyncExec( new Runnable() { public void run() { addNewCanvas(tabFolder, scene, frameWork, logicalLayer); } }); } }); item.setText("Add &3d Canvas"); item.setAccelerator(SWT.MOD1 + '3'); AWTImageLoader.registerLoader(); try { final SimpleResourceLocator srl = new SimpleResourceLocator( ResourceLocatorTool.getClassPathResource( LwjglSwtExample.class, "com/ardor3d/example/media/")); ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, srl); } catch (final URISyntaxException ex) { ex.printStackTrace(); } addNewCanvas(tabFolder, scene, frameWork, logicalLayer); shell.open(); game.init(); // frameWork.init(); while (!shell.isDisposed() && !exit.isExit()) { display.readAndDispatch(); frameWork.updateFrame(); Thread.yield(); // using the below way makes things really jerky. Not sure how to handle that. // if (display.readAndDispatch()) { // frameWork.updateFrame(); // } // else { // display.sleep(); // } } display.dispose(); System.exit(0); }
private void initMenus() { Menu menuBar = new Menu(shell, SWT.BAR); shell.setMenuBar(menuBar); // Jeu { MenuItem itemFile = new MenuItem(menuBar, SWT.CASCADE); itemFile.setText("&Jeu"); Menu menuFile = new Menu(shell, SWT.DROP_DOWN); itemFile.setMenu(menuFile); { itemConnectAndJoin = new MenuItem(menuFile, SWT.PUSH); itemConnectAndJoin.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickConnectAndJoin(); } }); itemConnectAndJoin.setText("Re&joindre une partie...\tCtrl+J"); itemConnectAndJoin.setAccelerator(SWT.CTRL + 'J'); } { itemCreateJoinAndPlay = new MenuItem(menuFile, SWT.PUSH); itemCreateJoinAndPlay.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickCreateJoinAndPlay(); } }); itemCreateJoinAndPlay.setText("&Créer une partie et jouer...\tCtrl+N"); itemCreateJoinAndPlay.setAccelerator(SWT.CTRL + 'N'); } { itemCreateJoin = new MenuItem(menuFile, SWT.PUSH); itemCreateJoin.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickCreateAndJoin(); } }); itemCreateJoin.setText("&Créer une partie et l'observer"); } new MenuItem(menuFile, SWT.SEPARATOR); { MenuItem itemClient = new MenuItem(menuFile, SWT.CASCADE); itemClient.setText("&Client..."); Menu menuClient = new Menu(shell, SWT.DROP_DOWN); itemClient.setMenu(menuClient); { itemObserve = new MenuItem(menuClient, SWT.PUSH); itemObserve.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickConnect(); } }); itemObserve.setText("Observer..."); } { itemJoin = new MenuItem(menuClient, SWT.PUSH); itemJoin.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickJoin(); } }); itemJoin.setText("Participer..."); } { itemDisconnect = new MenuItem(menuClient, SWT.PUSH); itemDisconnect.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickDisconnect(); } }); itemDisconnect.setText("&Déconnecter...\tCtrl+D"); itemDisconnect.setAccelerator(SWT.CTRL + 'D'); } } new MenuItem(menuFile, SWT.SEPARATOR); { MenuItem itemServer = new MenuItem(menuFile, SWT.CASCADE); itemServer.setText("&Serveur..."); Menu menuServer = new Menu(shell, SWT.DROP_DOWN); itemServer.setMenu(menuServer); { itemCreateServerLocal = new MenuItem(menuServer, SWT.PUSH); itemCreateServerLocal.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickCreateServerLocal(); } }); itemCreateServerLocal.setText("Créer un serveur &local"); } { itemCreateServer = new MenuItem(menuServer, SWT.PUSH); itemCreateServer.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickCreateServer(); } }); itemCreateServer.setText("Créer un serveur..."); } { itemShutdownServer = new MenuItem(menuServer, SWT.PUSH); itemShutdownServer.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickShutdownServer(); } }); itemShutdownServer.setText("Eteindre le serveur"); } { itemCreateGame = new MenuItem(menuServer, SWT.PUSH); itemCreateGame.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickCreateGame(); } }); itemCreateGame.setText("&Créer une partie...\tCtrl+C"); itemCreateGame.setAccelerator(SWT.CTRL + 'C'); } } new MenuItem(menuFile, SWT.SEPARATOR); { MenuItem itemQuit = new MenuItem(menuFile, SWT.PUSH); itemQuit.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickQuit(); } }); itemQuit.setText("&Quitter...\tCtrl+Q"); itemQuit.setAccelerator(SWT.CTRL + 'Q'); } // item.setAccelerator (SWT.MOD1 + 'A'); } { MenuItem itemView = new MenuItem(menuBar, SWT.CASCADE); itemView.setText("&Vue"); Menu menuView = new Menu(shell, SWT.DROP_DOWN); itemView.setMenu(menuView); { MenuItem itemZoomIn = new MenuItem(menuView, SWT.PUSH); itemZoomIn.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clientWhiteboard.zoomIn(); } }); itemZoomIn.setText("Zoom &in\tCtrl+'+'"); itemZoomIn.setAccelerator(SWT.CTRL + '+'); } { MenuItem itemZoomOut = new MenuItem(menuView, SWT.PUSH); itemZoomOut.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clientWhiteboard.zoomOut(); } }); itemZoomOut.setText("Zoom &out\tCtrl+'-'"); itemZoomOut.setAccelerator(SWT.CTRL + '-'); } { MenuItem itemZoomReset = new MenuItem(menuView, SWT.PUSH); itemZoomReset.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clientWhiteboard.zoomOne(); } }); itemZoomReset.setText("Zoom &1:1\tCtrl+0"); itemZoomReset.setAccelerator(SWT.CTRL + '0'); } { MenuItem itemZoomToFit = new MenuItem(menuView, SWT.PUSH); itemZoomToFit.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clientWhiteboard.fitToScreen(); } }); itemZoomToFit.setText("Zoom to &fit...\tCtrl+F"); itemZoomToFit.setAccelerator(SWT.CTRL + 'F'); } new MenuItem(menuView, SWT.SEPARATOR); { MenuItem itemShowRoot = new MenuItem(menuView, SWT.PUSH); itemShowRoot.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clientWhiteboard.centerOnRootIdea(); } }); itemShowRoot.setText("Voir idée &racine\tCtrl+R"); itemShowRoot.setAccelerator(SWT.CTRL + 'R'); } new MenuItem(menuView, SWT.SEPARATOR); { MenuItem itemParams = new MenuItem(menuView, SWT.PUSH); itemParams.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { clickEditVisuParams(); } }); itemParams.setText("&Parameters"); } } }
/** * Creates all the items located in the Edit submenu and associate all the menu items with their * appropriate functions. * * @param menuBar Menu the <code>Menu</code> that file contain the Edit submenu. * @see #createSortMenu() */ private MenuItem createEditMenu(Menu menuBar) { // Edit menu. MenuItem item = new MenuItem(menuBar, SWT.CASCADE); item.setText(resAddressBook.getString("Edit_menu_title")); Menu menu = new Menu(shell, SWT.DROP_DOWN); item.setMenu(menu); /** Add a listener to handle enabling and disabling some items in the Edit submenu. */ menu.addMenuListener( new MenuAdapter() { @Override public void menuShown(MenuEvent e) { Menu menu = (Menu) e.widget; MenuItem[] items = menu.getItems(); int count = table.getSelectionCount(); items[0].setEnabled(count != 0); // edit items[1].setEnabled(count != 0); // copy items[2].setEnabled(copyBuffer != null); // paste items[3].setEnabled(count != 0); // delete items[5].setEnabled(table.getItemCount() != 0); // sort } }); // Edit -> Edit MenuItem subItem = new MenuItem(menu, SWT.PUSH); subItem.setText(resAddressBook.getString("Edit")); subItem.setAccelerator(SWT.MOD1 + 'E'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TableItem[] items = table.getSelection(); if (items.length == 0) return; editEntry(items[0]); } }); // Edit -> Copy subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("Copy")); subItem.setAccelerator(SWT.MOD1 + 'C'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TableItem[] items = table.getSelection(); if (items.length == 0) return; copyBuffer = new String[table.getColumnCount()]; for (int i = 0; i < copyBuffer.length; i++) { copyBuffer[i] = items[0].getText(i); } } }); // Edit -> Paste subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("Paste")); subItem.setAccelerator(SWT.MOD1 + 'V'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (copyBuffer == null) return; TableItem item = new TableItem(table, SWT.NONE); item.setText(copyBuffer); isModified = true; } }); // Edit -> Delete subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("Delete")); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TableItem[] items = table.getSelection(); if (items.length == 0) return; items[0].dispose(); isModified = true; } }); new MenuItem(menu, SWT.SEPARATOR); // Edit -> Sort(Cascade) subItem = new MenuItem(menu, SWT.CASCADE); subItem.setText(resAddressBook.getString("Sort")); Menu submenu = createSortMenu(); subItem.setMenu(submenu); return item; }
/** * Creates all the items located in the File submenu and associate all the menu items with their * appropriate functions. * * @param menuBar Menu the <code>Menu</code> that file contain the File submenu. */ private void createFileMenu(Menu menuBar) { // File menu. MenuItem item = new MenuItem(menuBar, SWT.CASCADE); item.setText(resAddressBook.getString("File_menu_title")); Menu menu = new Menu(shell, SWT.DROP_DOWN); item.setMenu(menu); /** Adds a listener to handle enabling and disabling some items in the Edit submenu. */ menu.addMenuListener( new MenuAdapter() { @Override public void menuShown(MenuEvent e) { Menu menu = (Menu) e.widget; MenuItem[] items = menu.getItems(); items[1].setEnabled(table.getSelectionCount() != 0); // edit contact items[5].setEnabled((file != null) && isModified); // save items[6].setEnabled(table.getItemCount() != 0); // save as } }); // File -> New Contact MenuItem subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("New_contact")); subItem.setAccelerator(SWT.MOD1 + 'N'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { newEntry(); } }); subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("Edit_contact")); subItem.setAccelerator(SWT.MOD1 + 'E'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TableItem[] items = table.getSelection(); if (items.length == 0) return; editEntry(items[0]); } }); new MenuItem(menu, SWT.SEPARATOR); // File -> New Address Book subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("New_address_book")); subItem.setAccelerator(SWT.MOD1 + 'B'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (closeAddressBook()) { newAddressBook(); } } }); // File -> Open subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("Open_address_book")); subItem.setAccelerator(SWT.MOD1 + 'O'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (closeAddressBook()) { openAddressBook(); } } }); // File -> Save. subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("Save_address_book")); subItem.setAccelerator(SWT.MOD1 + 'S'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { save(); } }); // File -> Save As. subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("Save_book_as")); subItem.setAccelerator(SWT.MOD1 + 'A'); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { saveAs(); } }); new MenuItem(menu, SWT.SEPARATOR); // File -> Exit. subItem = new MenuItem(menu, SWT.NONE); subItem.setText(resAddressBook.getString("Exit")); subItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { shell.close(); } }); }
/** This method initializes sShell */ private void createSShell() { sShell = new Shell(); sShell.setText("Hosts Juggler"); sShell.setLayout(null); sShell.setSize(new Point(726, 766)); /* * Menu */ final Menu m = new Menu(sShell, SWT.BAR); sShell.setMenuBar(m); /* Hosts File */ // create a file menu and add an exit item final MenuItem file = new MenuItem(m, SWT.CASCADE); file.setText("&Hosts File"); final Menu filemenu = new Menu(sShell, SWT.DROP_DOWN); file.setMenu(filemenu); final MenuItem openItem = new MenuItem(filemenu, SWT.CASCADE); openItem.setText("&Open"); final Menu submenu = new Menu(sShell, SWT.DROP_DOWN); openItem.setMenu(submenu); final MenuItem childItem = new MenuItem(submenu, SWT.PUSH); childItem.setText("&Child\tCTRL+C"); childItem.setAccelerator(SWT.CTRL + 'C'); final MenuItem dialogItem = new MenuItem(submenu, SWT.PUSH); dialogItem.setText("&Dialog\tCTRL+D"); dialogItem.setAccelerator(SWT.CTRL + 'D'); final MenuItem separator = new MenuItem(filemenu, SWT.SEPARATOR); final MenuItem exitItem = new MenuItem(filemenu, SWT.PUSH); exitItem.setText("E&xit"); // create an edit menu and add cut copy and paste items final MenuItem edit = new MenuItem(m, SWT.CASCADE); edit.setText("&Edit"); final Menu editmenu = new Menu(sShell, SWT.DROP_DOWN); edit.setMenu(editmenu); final MenuItem cutItem = new MenuItem(editmenu, SWT.PUSH); cutItem.setText("&Cut"); final MenuItem copyItem = new MenuItem(editmenu, SWT.PUSH); copyItem.setText("Co&py"); final MenuItem pasteItem = new MenuItem(editmenu, SWT.PUSH); pasteItem.setText("&Paste"); // create an options menu and add menu items final MenuItem options = new MenuItem(m, SWT.CASCADE); options.setText("&Options"); final Menu optionsmenu = new Menu(sShell, SWT.DROP_DOWN); options.setMenu(optionsmenu); final MenuItem checkItem = new MenuItem(optionsmenu, SWT.CHECK); checkItem.setText("&Checked Option"); final MenuItem optionsseparator = new MenuItem(optionsmenu, SWT.SEPARATOR); final MenuItem radioItem1 = new MenuItem(optionsmenu, SWT.RADIO); radioItem1.setText("Radio &One"); final MenuItem radioItem2 = new MenuItem(optionsmenu, SWT.RADIO); radioItem2.setText("Radio &Two"); // create a Window menu and add Child item final MenuItem window = new MenuItem(m, SWT.CASCADE); window.setText("&Window"); final Menu windowmenu = new Menu(sShell, SWT.DROP_DOWN); window.setMenu(windowmenu); final MenuItem maxItem = new MenuItem(windowmenu, SWT.PUSH); maxItem.setText("Ma&ximize"); final MenuItem minItem = new MenuItem(windowmenu, SWT.PUSH); minItem.setText("Mi&nimize"); // create a Help menu and add an about item final MenuItem help = new MenuItem(m, SWT.CASCADE); help.setText("&Help"); final Menu helpmenu = new Menu(sShell, SWT.DROP_DOWN); help.setMenu(helpmenu); final MenuItem aboutItem = new MenuItem(helpmenu, SWT.PUSH); aboutItem.setText("&About"); // /* File */ // MenuItem fileItem = new MenuItem (menuBar, SWT.CASCADE); // fileItem.setText("&Hosts File"); // // Menu submenu = new Menu(sShell, SWT.DROP_DOWN); // fileItem.setMenu(submenu); // MenuItem menuItem = new MenuItem (submenu, SWT.PUSH); // menuItem.addListener(SWT.Selection, new Listener() // { // public void handleEvent(Event e) // { // System.out.println ("Create"); // } // }); // menuItem.setText("Create &New\tCtrl+N"); // menuItem.setAccelerator(SWT.MOD1 + 'N'); /* * Active hosts file location */ label = new Label(sShell, SWT.NONE); label.setBounds(new Rectangle(15, 10, 692, 15)); switchHostsFileButton = new Button(sShell, SWT.NONE); switchHostsFileButton.setBounds(new Rectangle(330, 682, 103, 26)); switchHostsFileButton.setText("Switch"); switchHostsFileButton.addSelectionListener( new org.eclipse.swt.events.SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) {} @Override public void widgetSelected(SelectionEvent e) { openSwitchDialog(sShell); } }); minimizeToTrayButton = new Button(sShell, SWT.NONE); minimizeToTrayButton.setBounds(new Rectangle(451, 682, 108, 28)); minimizeToTrayButton.setText("Hide"); exitButton = new Button(sShell, SWT.NONE); exitButton.setBounds(new Rectangle(574, 683, 117, 28)); exitButton.setText("Exit"); /* * Active file */ activeHostsFileStyledText = new StyledText(sShell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY); activeHostsFileStyledText.setText(""); activeHostsFileStyledText.setTabs(5); activeHostsFileStyledText.setBounds(new Rectangle(15, 33, 694, 616)); }
/** * Create the simulation menu. * * @param header the header from which the menu hangs */ private void createSimulationMenu(final MenuItem header) { if (simulationMenu != null) { simulationMenu.dispose(); } simulationMenu = new Menu(shell, SWT.DROP_DOWN); simulationOpenJarItem = new MenuItem(simulationMenu, SWT.PUSH); simulationOpenJarItem.setText("&Open packed simulation\tCtrl+O"); simulationOpenJarItem.setAccelerator(SWT.CTRL + 'O'); simulationOpenJarItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Open a simulation"); fd.setFilterPath(selected); String[] filterExt = {"*.jar"}; fd.setFilterExtensions(filterExt); openSimulation(fd.open()); } }); simulationOpenDirItem = new MenuItem(simulationMenu, SWT.PUSH); simulationOpenDirItem.setText("&Open unpacked simulation\tCtrl+Shift+O"); simulationOpenDirItem.setAccelerator(SWT.SHIFT + SWT.CTRL + 'O'); simulationOpenDirItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { DirectoryDialog fd = new DirectoryDialog(shell, SWT.OPEN); fd.setText("Choose the simulation's root folder"); fd.setFilterPath(getLastFolder()); openSimulation(fd.open()); } }); simulationCloseItem = new MenuItem(simulationMenu, SWT.PUSH); simulationCloseItem.setText("&Close\tCtrl+C"); simulationCloseItem.setAccelerator(SWT.CTRL + 'C'); simulationCloseItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { gui.reportSimulationDataChange(null); } }); addRecent(simulationMenu); new MenuItem(simulationMenu, SWT.SEPARATOR); MenuItem simulationQuitItem = new MenuItem(simulationMenu, SWT.PUSH); simulationQuitItem.setText("&Quit\tCtrl+Q"); simulationQuitItem.setAccelerator(SWT.CTRL + 'Q'); simulationQuitItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { gui.close(); } }); header.setMenu(simulationMenu); }