use of org.eclipse.swt.widgets.MenuItem in project eclipse.platform.swt by eclipse.
the class AddressBook method createSearchMenu.
/**
* 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(resAddressBook.getString("Search_menu_title"));
Menu searchMenu = new Menu(shell, SWT.DROP_DOWN);
item.setMenu(searchMenu);
// Search -> Find...
item = new MenuItem(searchMenu, SWT.NONE);
item.setText(resAddressBook.getString("Find"));
item.setAccelerator(SWT.MOD1 + 'F');
item.addSelectionListener(widgetSelectedAdapter(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.NONE);
item.setText(resAddressBook.getString("Find_next"));
item.setAccelerator(SWT.F3);
item.addSelectionListener(widgetSelectedAdapter(e -> searchDialog.open()));
}
use of org.eclipse.swt.widgets.MenuItem in project eclipse.platform.swt by eclipse.
the class MenuTab method createButtonSelected.
/**
* Handle the Create button selection event.
*
* @param event org.eclipse.swt.events.SelectionEvent
*/
public void createButtonSelected(SelectionEvent event) {
/*
* Remember the example shells so they
* can be disposed by the user.
*/
if (shellCount >= shells.length) {
Shell[] newShells = new Shell[shells.length + 4];
System.arraycopy(shells, 0, newShells, 0, shells.length);
shells = newShells;
}
int orientation = 0;
if (leftToRightButton.getSelection())
orientation |= SWT.LEFT_TO_RIGHT;
if (rightToLeftButton.getSelection())
orientation |= SWT.RIGHT_TO_LEFT;
int radioBehavior = 0;
if (noRadioGroupButton.getSelection())
radioBehavior |= SWT.NO_RADIO_GROUP;
/* Create the shell and menu(s) */
Shell shell = new Shell(SWT.SHELL_TRIM | orientation);
shells[shellCount] = shell;
if (barButton.getSelection()) {
/* Create menu bar. */
Menu menuBar = new Menu(shell, SWT.BAR | radioBehavior);
shell.setMenuBar(menuBar);
hookListeners(menuBar);
if (dropDownButton.getSelection() && cascadeButton.getSelection()) {
/* Create cascade button and drop-down menu in menu bar. */
MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
item.setText(getMenuItemText("Cascade"));
if (imagesButton.getSelection())
item.setImage(instance.images[ControlExample.ciOpenFolder]);
if (tooltipButton.getSelection())
item.setToolTipText(ControlExample.getResourceString("Tooltip", item.getText()));
hookListeners(item);
Menu dropDownMenu = new Menu(shell, SWT.DROP_DOWN | radioBehavior);
item.setMenu(dropDownMenu);
hookListeners(dropDownMenu);
/* Create various menu items, depending on selections. */
createMenuItems(dropDownMenu, subMenuButton.getSelection(), subSubMenuButton.getSelection());
}
}
if (popUpButton.getSelection()) {
/* Create pop-up menu. */
Menu popUpMenu = new Menu(shell, SWT.POP_UP | radioBehavior);
shell.setMenu(popUpMenu);
hookListeners(popUpMenu);
/* Create various menu items, depending on selections. */
createMenuItems(popUpMenu, subMenuButton.getSelection(), subSubMenuButton.getSelection());
}
/* Set the size, title and open the shell. */
shell.setSize(300, 100);
shell.setText(ControlExample.getResourceString("Title") + shellCount);
shell.addPaintListener(e -> e.gc.drawString(ControlExample.getResourceString("PopupMenuHere"), 20, 20));
shell.open();
shellCount++;
}
use of org.eclipse.swt.widgets.MenuItem in project eclipse.platform.swt by eclipse.
the class MenuTab method createMenuItems.
/* Create various menu items, depending on selections. */
void createMenuItems(Menu menu, boolean createSubMenu, boolean createSubSubMenu) {
MenuItem item;
if (pushButton.getSelection()) {
item = new MenuItem(menu, SWT.PUSH);
item.setText(getMenuItemText("Push"));
if (acceleratorsButton.getSelection())
item.setAccelerator(SWT.MOD1 + SWT.MOD2 + 'P');
if (imagesButton.getSelection())
item.setImage(instance.images[ControlExample.ciClosedFolder]);
item.setEnabled(enabledButton.getSelection());
if (tooltipButton.getSelection())
item.setToolTipText(ControlExample.getResourceString("Tooltip", item.getText()));
hookListeners(item);
}
if (separatorButton.getSelection()) {
item = new MenuItem(menu, SWT.SEPARATOR);
if (tooltipButton.getSelection())
item.setToolTipText(ControlExample.getResourceString("Tooltip", item.getText()));
}
if (checkButton.getSelection()) {
item = new MenuItem(menu, SWT.CHECK);
item.setText(getMenuItemText("Check"));
if (acceleratorsButton.getSelection())
item.setAccelerator(SWT.MOD1 + SWT.MOD2 + 'C');
if (imagesButton.getSelection())
item.setImage(instance.images[ControlExample.ciOpenFolder]);
item.setEnabled(enabledButton.getSelection());
if (tooltipButton.getSelection())
item.setToolTipText(ControlExample.getResourceString("Tooltip", item.getText()));
hookListeners(item);
}
if (radioButton.getSelection()) {
item = new MenuItem(menu, SWT.RADIO);
item.setText(getMenuItemText("1Radio"));
if (acceleratorsButton.getSelection())
item.setAccelerator(SWT.MOD1 + SWT.MOD2 + '1');
if (imagesButton.getSelection())
item.setImage(instance.images[ControlExample.ciTarget]);
item.setSelection(true);
item.setEnabled(enabledButton.getSelection());
if (tooltipButton.getSelection())
item.setToolTipText(ControlExample.getResourceString("Tooltip", item.getText()));
hookListeners(item);
item = new MenuItem(menu, SWT.RADIO);
item.setText(getMenuItemText("2Radio"));
if (acceleratorsButton.getSelection())
item.setAccelerator(SWT.MOD1 + SWT.MOD2 + '2');
if (imagesButton.getSelection())
item.setImage(instance.images[ControlExample.ciTarget]);
item.setEnabled(enabledButton.getSelection());
if (tooltipButton.getSelection())
item.setToolTipText(ControlExample.getResourceString("Tooltip", item.getText()));
hookListeners(item);
}
if (createSubMenu && cascadeButton.getSelection()) {
/* Create cascade button and drop-down menu for the sub-menu. */
item = new MenuItem(menu, SWT.CASCADE);
item.setText(getMenuItemText("Cascade"));
if (imagesButton.getSelection())
item.setImage(instance.images[ControlExample.ciOpenFolder]);
hookListeners(item);
Menu subMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
item.setMenu(subMenu);
item.setEnabled(enabledButton.getSelection());
hookListeners(subMenu);
if (tooltipButton.getSelection())
item.setToolTipText(ControlExample.getResourceString("Tooltip", item.getText()));
createMenuItems(subMenu, createSubSubMenu, false);
}
}
use of org.eclipse.swt.widgets.MenuItem in project eclipse.platform.swt by eclipse.
the class Tab method setExampleWidgetPopupMenu.
void setExampleWidgetPopupMenu() {
Control[] controls = getExampleControls();
for (final Control control : controls) {
control.addListener(SWT.MenuDetect, event -> {
Menu menu = control.getMenu();
if (menu != null && samplePopup) {
menu.dispose();
menu = null;
}
if (menu == null && popupMenuButton.getSelection()) {
menu = new Menu(shell, SWT.POP_UP | (control.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT)));
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText("Sample popup menu item");
specialPopupMenuItems(menu, event);
control.setMenu(menu);
samplePopup = true;
}
});
}
}
use of org.eclipse.swt.widgets.MenuItem in project eclipse.platform.swt by eclipse.
the class TableTab method specialPopupMenuItems.
@Override
protected void specialPopupMenuItems(Menu menu, Event event) {
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText("getItem(Point) on mouse coordinates");
menuMouseCoords = table1.toControl(new Point(event.x, event.y));
item.addSelectionListener(widgetSelectedAdapter(e -> {
eventConsole.append("getItem(Point(" + menuMouseCoords + ")) returned: " + table1.getItem(menuMouseCoords));
eventConsole.append("\n");
}));
}
Aggregations