Search in sources :

Example 1 with Section

use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.

the class TerraMenuSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Menu menu = (Menu) component;
    menu.getMenuListeners().add(this);
    for (Menu.Section section : menu.getSections()) {
        section.getSectionListeners().add(this);
    }
    menu.setFocusTraversalPolicy(new IndexFocusTraversalPolicy(true));
}
Also used : Section(org.apache.pivot.wtk.Menu.Section) Menu(org.apache.pivot.wtk.Menu)

Example 2 with Section

use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.

the class TerraMenuSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    Menu menu = (Menu) getComponent();
    Menu.SectionSequence sections = menu.getSections();
    for (int i = 0, n = sections.getLength(); i < n; i++) {
        Menu.Section section = sections.get(i);
        for (Menu.Item item : section) {
            if (item.isVisible()) {
                preferredHeight += item.getPreferredHeight(width);
            }
        }
        if (i > 0) {
            preferredHeight += sectionSpacing;
        }
    }
    return preferredHeight;
}
Also used : Item(org.apache.pivot.wtk.Menu.Item) Section(org.apache.pivot.wtk.Menu.Section) Menu(org.apache.pivot.wtk.Menu)

Example 3 with Section

use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.

the class TerraMenuSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    Menu menu = (Menu) getComponent();
    Menu.SectionSequence sections = menu.getSections();
    for (int i = 0, n = sections.getLength(); i < n; i++) {
        Menu.Section section = sections.get(i);
        for (Menu.Item item : section) {
            if (item.isVisible()) {
                preferredWidth = Math.max(item.getPreferredWidth(-1), preferredWidth);
            }
        }
    }
    return preferredWidth;
}
Also used : Item(org.apache.pivot.wtk.Menu.Item) Section(org.apache.pivot.wtk.Menu.Section) Menu(org.apache.pivot.wtk.Menu)

Example 4 with Section

use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.

the class TerraMenuSkin method keyTyped.

/**
 * Select the next enabled menu item where the first character of the
 * rendered text matches the typed key (case insensitive).
 */
@Override
public boolean keyTyped(Component component, char character) {
    boolean consumed = super.keyTyped(component, character);
    Menu menu = (Menu) component;
    Menu.SectionSequence sections = menu.getSections();
    int sectionCount = sections.getLength();
    Menu.Item activeItem = menu.getActiveItem();
    int sectionIndex;
    int itemIndex;
    if (activeItem == null) {
        sectionIndex = 0;
        itemIndex = 0;
    } else {
        Menu.Section section = activeItem.getSection();
        sectionIndex = sections.indexOf(section);
        itemIndex = section.indexOf(activeItem) + 1;
    }
    char characterUpper = Character.toUpperCase(character);
    while (sectionIndex < sectionCount) {
        Section section = sections.get(sectionIndex);
        int sectionLength = section.getLength();
        while (itemIndex < sectionLength) {
            Item item = section.get(itemIndex);
            if (item.isEnabled()) {
                Button.DataRenderer itemDataRenderer = item.getDataRenderer();
                String string = itemDataRenderer.toString(item.getButtonData());
                if (string != null && string.length() > 0) {
                    char first = Character.toUpperCase(string.charAt(0));
                    if (first == characterUpper) {
                        item.setActive(true);
                        consumed = true;
                        break;
                    }
                }
            }
            itemIndex++;
        }
        if (itemIndex < sectionLength) {
            break;
        }
        sectionIndex++;
        itemIndex = 0;
    }
    return consumed;
}
Also used : Item(org.apache.pivot.wtk.Menu.Item) Button(org.apache.pivot.wtk.Button) Item(org.apache.pivot.wtk.Menu.Item) Section(org.apache.pivot.wtk.Menu.Section) Menu(org.apache.pivot.wtk.Menu) Section(org.apache.pivot.wtk.Menu.Section)

Example 5 with Section

use of org.apache.pivot.wtk.Menu.Section in project pivot by apache.

the class TerraMenuSkin method layout.

@Override
public void layout() {
    Menu menu = (Menu) getComponent();
    Menu.SectionSequence sections = menu.getSections();
    int width = getWidth();
    int itemY = 0;
    for (int i = 0, n = sections.getLength(); i < n; i++) {
        Menu.Section section = sections.get(i);
        for (Menu.Item item : section) {
            if (item.isVisible()) {
                item.setSize(width, item.getPreferredHeight(width));
                item.setLocation(0, itemY);
                itemY += item.getHeight();
            }
        }
        itemY += sectionSpacing;
    }
}
Also used : Item(org.apache.pivot.wtk.Menu.Item) Section(org.apache.pivot.wtk.Menu.Section) Menu(org.apache.pivot.wtk.Menu)

Aggregations

Menu (org.apache.pivot.wtk.Menu)10 Section (org.apache.pivot.wtk.Menu.Section)10 Item (org.apache.pivot.wtk.Menu.Item)7 Button (org.apache.pivot.wtk.Button)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Window (org.apache.pivot.wtk.Window)1