Search in sources :

Example 1 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.

the class MenuFactory method ensureNexusCascade.

// createNexusCascade
protected static Menu ensureNexusCascade(Menu windowMenu, MenuItem[] windowMenuItems, IWindowMenuData<?> menuData) {
    String nexusLabel = menuData.getNexusLabel();
    Class<?> nexusType = menuData.getNexusType();
    Object nexusData = menuData.getNexusData();
    int i;
    for (i = windowMenuItems.length; i > 0; i--) {
        MenuItem windowItem = windowMenuItems[i - 1];
        if ((windowItem.getStyle() == SWT.CASCADE) && (nexusType != null) && nexusType.isInstance(windowItem.getData())) {
            if (windowItem.getData() == nexusData) {
                return windowItem.getMenu();
            }
            // Check if the current nexus item comes after nexusLabel
            if (windowItem.getText().compareToIgnoreCase(nexusLabel) < 0) {
                break;
            }
        } else {
            // no longer within the group of nexus cascades
            break;
        }
    }
    return createNexusCascade(windowMenu, i, menuData);
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem)

Example 2 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.

the class MenuFactory method copyExistingNexusWindows.

protected static void copyExistingNexusWindows(MenuItem existingNexusItem, Menu newWindowMenu) {
    MenuItem newNexusItem = new MenuItem(newWindowMenu, SWT.CASCADE);
    newNexusItem.setText(existingNexusItem.getText());
    newNexusItem.setImage(existingNexusItem.getImage());
    // the nexus!
    newNexusItem.setData(existingNexusItem.getData());
    Menu newNexusMenu = new Menu(newWindowMenu.getShell(), SWT.DROP_DOWN);
    newNexusItem.setMenu(newNexusMenu);
    MenuItem[] nestedNexusItems = existingNexusItem.getMenu().getItems();
    for (MenuItem nestedNexusItem : nestedNexusItems) {
        MenuItem newNestedItem = new MenuItem(newNexusMenu, nestedNexusItem.getStyle());
        newNestedItem.setText(nestedNexusItem.getText());
        newNestedItem.setImage(nestedNexusItem.getImage());
        Object windowLID = nestedNexusItem.getData();
        if (windowLID != null) {
            newNestedItem.setData(windowLID);
            newNestedItem.addListener(SWT.Selection, windowItemSelectionListener);
        }
    }
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 3 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.

the class MenuFactory method createNexusCascade.

// copyExistingWindows
protected static Menu createNexusCascade(Menu windowMenu, int index, IWindowMenuData<?> menuData) {
    MenuItem newNexusItem = (index != -1) ? new MenuItem(windowMenu, SWT.CASCADE, index) : new MenuItem(windowMenu, SWT.CASCADE);
    Menu cascadeParent = new Menu(windowMenu.getShell(), SWT.DROP_DOWN);
    newNexusItem.setMenu(cascadeParent);
    newNexusItem.setText(menuData.getNexusLabel());
    // the nexus!
    newNexusItem.setData(menuData.getNexusData());
    return cascadeParent;
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 4 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.

the class MenuFactory method addWindowMenu.

// addToCascade
protected static void addWindowMenu(Menu newWindowMenu, IWindowMenuData<?> menuData) {
    if (windowMenus.size() > 0) {
        copyExistingWindows(windowMenus.get(0), newWindowMenu);
    }
    // Add to global registry
    windowMenus.add(newWindowMenu);
    newWindowMenu.setData(menuData);
    // i.e. the RootView will not be added!
    if (menuData.getNexusData() != null) {
        Iterator<Menu> menus = windowMenus.iterator();
        while (menus.hasNext()) {
            Menu windowMenu = menus.next();
            Menu nexusCascade = null;
            // Remove the last item if it is the NO_WINDOWS_SENTINEL
            MenuItem[] nexusItems = windowMenu.getItems();
            if (nexusItems.length > 0) {
                MenuItem lastItem = nexusItems[nexusItems.length - 1];
                if (lastItem.getData() == NO_WINDOWS_SENTINEL) {
                    lastItem.dispose();
                    nexusCascade = createNexusCascade(windowMenu, -1, menuData);
                }
            }
            if (nexusCascade == null) {
                nexusCascade = ensureNexusCascade(windowMenu, nexusItems, menuData);
            }
            addToCascade(nexusCascade, menuData);
        }
        newWindowMenu.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                removeWindowMenu((Menu) e.getSource());
            }
        });
    } else {
        newWindowMenu.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                windowMenus.remove(e.getSource());
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 5 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.

the class MenuFactory method removeNexusCascadeItem.

// Returns true if it removed the last item from the cascade
protected static boolean removeNexusCascadeItem(Menu fromNexusMenu, IWindowMenuData<?> menuData) {
    ListenerIdentifier itemLID = menuData.getLID();
    boolean precedingWasSeparator = false;
    MenuItem[] windowMenuItems = fromNexusMenu.getItems();
    int originalItemCount = windowMenuItems.length;
    int i;
    for (i = 0; i < originalItemCount; i++) {
        MenuItem windowItem = windowMenuItems[i];
        Object itemData = windowItem.getData();
        if (itemData == null) {
            // indicates a SEPARATOR
            precedingWasSeparator = true;
        } else if (itemData == itemLID) {
            windowItem.dispose();
            break;
        } else {
            precedingWasSeparator = false;
        }
    }
    if (i == originalItemCount) {
        throw new RcvrUIException("Cannot find window item");
    }
    // Check if we need to remove a SEPARATOR
    if (i == 0) {
        if ((originalItemCount > 1) && (windowMenuItems[1].getData() == null)) {
            // Removed first and second was a SEPARATOR; remove it
            windowMenuItems[1].dispose();
        }
    } else if (precedingWasSeparator) {
        // following item is also a SEPARATOR; if so, remove preceding.
        if (((i + 1) == originalItemCount) || (windowMenuItems[i + 1].getData() == null)) {
            windowMenuItems[i - 1].dispose();
        }
    }
    // Return true if no items remain
    return fromNexusMenu.getItems().length == 0;
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) ListenerIdentifier(edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier) RcvrUIException(edu.cmu.cs.hcii.cogtool.util.RcvrUIException)

Aggregations

MenuItem (org.eclipse.swt.widgets.MenuItem)396 Menu (org.eclipse.swt.widgets.Menu)266 SelectionEvent (org.eclipse.swt.events.SelectionEvent)254 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)213 Event (org.eclipse.swt.widgets.Event)58 Point (org.eclipse.swt.graphics.Point)55 ArrayList (java.util.ArrayList)54 GridData (org.eclipse.swt.layout.GridData)49 SelectionListener (org.eclipse.swt.events.SelectionListener)48 Listener (org.eclipse.swt.widgets.Listener)48 Composite (org.eclipse.swt.widgets.Composite)45 GridLayout (org.eclipse.swt.layout.GridLayout)42 Rectangle (org.eclipse.swt.graphics.Rectangle)36 Shell (org.eclipse.swt.widgets.Shell)35 Label (org.eclipse.swt.widgets.Label)34 Button (org.eclipse.swt.widgets.Button)33 Table (org.eclipse.swt.widgets.Table)33 List (java.util.List)32 MenuEvent (org.eclipse.swt.events.MenuEvent)32 File (java.io.File)29