Search in sources :

Example 61 with MenuItem

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()));
}
Also used : Arrays(java.util.Arrays) TableColumn(org.eclipse.swt.widgets.TableColumn) Table(org.eclipse.swt.widgets.Table) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) ResourceBundle(java.util.ResourceBundle) FillLayout(org.eclipse.swt.layout.FillLayout) Cursor(org.eclipse.swt.graphics.Cursor) SelectionListener.widgetDefaultSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetDefaultSelectedAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Display(org.eclipse.swt.widgets.Display) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) MenuListener.menuShownAdapter(org.eclipse.swt.events.MenuListener.menuShownAdapter) ShellListener(org.eclipse.swt.events.ShellListener) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) MessageBox(org.eclipse.swt.widgets.MessageBox) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Menu(org.eclipse.swt.widgets.Menu) Comparator(java.util.Comparator) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 62 with MenuItem

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++;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 63 with MenuItem

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);
    }
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 64 with MenuItem

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;
            }
        });
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 65 with MenuItem

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");
    }));
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Button(org.eclipse.swt.widgets.Button) TableColumn(org.eclipse.swt.widgets.TableColumn) Image(org.eclipse.swt.graphics.Image) Table(org.eclipse.swt.widgets.Table) Point(org.eclipse.swt.graphics.Point) Group(org.eclipse.swt.widgets.Group) Event(org.eclipse.swt.widgets.Event) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) Color(org.eclipse.swt.graphics.Color) Item(org.eclipse.swt.widgets.Item) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) FontData(org.eclipse.swt.graphics.FontData) RGB(org.eclipse.swt.graphics.RGB) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) Menu(org.eclipse.swt.widgets.Menu) Widget(org.eclipse.swt.widgets.Widget) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point)

Aggregations

MenuItem (org.eclipse.swt.widgets.MenuItem)386 Menu (org.eclipse.swt.widgets.Menu)259 SelectionEvent (org.eclipse.swt.events.SelectionEvent)247 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)208 Event (org.eclipse.swt.widgets.Event)58 ArrayList (java.util.ArrayList)55 Point (org.eclipse.swt.graphics.Point)52 GridData (org.eclipse.swt.layout.GridData)49 Listener (org.eclipse.swt.widgets.Listener)48 SelectionListener (org.eclipse.swt.events.SelectionListener)46 Composite (org.eclipse.swt.widgets.Composite)43 GridLayout (org.eclipse.swt.layout.GridLayout)42 Rectangle (org.eclipse.swt.graphics.Rectangle)35 Label (org.eclipse.swt.widgets.Label)34 Shell (org.eclipse.swt.widgets.Shell)34 Table (org.eclipse.swt.widgets.Table)33 MenuEvent (org.eclipse.swt.events.MenuEvent)32 Button (org.eclipse.swt.widgets.Button)32 List (java.util.List)31 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)29