Search in sources :

Example 6 with Menu

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

the class TerraMenuSkin method keyReleased.

/**
 * {@link KeyCode#SPACE SPACE} 'presses' the active menu item if it does not
 * have a sub-menu.
 */
@Override
public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
    boolean consumed = super.keyReleased(component, keyCode, keyLocation);
    Menu menu = (Menu) component;
    if (keyCode == Keyboard.KeyCode.SPACE) {
        Menu.Item activeItem = menu.getActiveItem();
        // Press if the item does not have a sub-menu
        if (activeItem != null && activeItem.getMenu() == null) {
            activeItem.press();
            consumed = true;
        }
    }
    return consumed;
}
Also used : Item(org.apache.pivot.wtk.Menu.Item) Menu(org.apache.pivot.wtk.Menu)

Example 7 with Menu

use of org.apache.pivot.wtk.Menu 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)

Example 8 with Menu

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

the class TerraMenuItemSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    Menu.Item menuItem = (Menu.Item) getComponent();
    Menu menu = (Menu) menuItem.getParent();
    int width = getWidth();
    int height = getHeight();
    boolean highlight = menuItem.isActive();
    // Paint highlight state
    if (highlight) {
        Color activeBackgroundColor = menu.getStyles().getColor(Style.activeBackgroundColor);
        graphics.setPaint(new GradientPaint(width / 2f, 0, TerraTheme.brighten(activeBackgroundColor), width / 2f, height, activeBackgroundColor));
        graphics.fillRect(0, 0, width, height);
    }
    // Paint the content
    Button.DataRenderer dataRenderer = prepare(menuItem, highlight);
    dataRenderer.setSize(Math.max(width - EXPANDER_SIZE, 0), height);
    dataRenderer.paint(graphics);
    // Paint the expander
    if (menuItem.getMenu() != null) {
        Color color = menu.getStyles().getColor(highlight ? Style.activeColor : Style.color);
        graphics.setColor(color);
        graphics.setStroke(new BasicStroke(0));
        GraphicsUtilities.setAntialiasingOn(graphics);
        graphics.translate(dataRenderer.getWidth() + (EXPANDER_SIZE - EXPANDER_ICON_SIZE) / 2, (height - EXPANDER_ICON_SIZE) / 2);
        int[] xPoints = { 0, EXPANDER_ICON_SIZE, 0 };
        int[] yPoints = { 0, EXPANDER_ICON_SIZE / 2, EXPANDER_ICON_SIZE };
        graphics.fillPolygon(xPoints, yPoints, 3);
        graphics.drawPolygon(xPoints, yPoints, 3);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Button(org.apache.pivot.wtk.Button) Color(java.awt.Color) GradientPaint(java.awt.GradientPaint) Menu(org.apache.pivot.wtk.Menu) GradientPaint(java.awt.GradientPaint)

Example 9 with Menu

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

the class TerraMenuItemSkin method isOpaque.

@Override
public boolean isOpaque() {
    boolean opaque = false;
    Menu.Item menuItem = (Menu.Item) getComponent();
    if (menuItem.isActive()) {
        Menu menu = (Menu) menuItem.getParent();
        Color activeBackgroundColor = menu.getStyles().getColor(Style.activeBackgroundColor);
        opaque = (activeBackgroundColor.getTransparency() == Transparency.OPAQUE);
    }
    return opaque;
}
Also used : Color(java.awt.Color) Menu(org.apache.pivot.wtk.Menu)

Example 10 with Menu

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

the class TerraMenuPopupSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    MenuPopup menuPopup = (MenuPopup) component;
    menuPopup.getMenuPopupListeners().add(this);
    menuPopup.getMenuPopupStateListeners().add(this);
    Menu menu = menuPopup.getMenu();
    if (menu != null) {
        menu.getMenuItemSelectionListeners().add(menuItemSelectionListener);
    }
    panorama.setView(menu);
    menuPopup.setContent(border);
    // Attach the drop-shadow decorator
    if (!themeIsFlat()) {
        dropShadowDecorator = new DropShadowDecorator();
        menuPopup.getDecorators().add(dropShadowDecorator);
    }
}
Also used : MenuPopup(org.apache.pivot.wtk.MenuPopup) Menu(org.apache.pivot.wtk.Menu) DropShadowDecorator(org.apache.pivot.wtk.effects.DropShadowDecorator)

Aggregations

Menu (org.apache.pivot.wtk.Menu)21 Section (org.apache.pivot.wtk.Menu.Section)10 Item (org.apache.pivot.wtk.Menu.Item)8 Color (java.awt.Color)3 Display (org.apache.pivot.wtk.Display)3 Button (org.apache.pivot.wtk.Button)2 Component (org.apache.pivot.wtk.Component)2 Dimensions (org.apache.pivot.wtk.Dimensions)2 MenuPopup (org.apache.pivot.wtk.MenuPopup)2 Window (org.apache.pivot.wtk.Window)2 BasicStroke (java.awt.BasicStroke)1 Font (java.awt.Font)1 GradientPaint (java.awt.GradientPaint)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Vote (org.apache.pivot.util.Vote)1 Action (org.apache.pivot.wtk.Action)1 Insets (org.apache.pivot.wtk.Insets)1 Keyboard (org.apache.pivot.wtk.Keyboard)1 MenuButton (org.apache.pivot.wtk.MenuButton)1 MenuHandler (org.apache.pivot.wtk.MenuHandler)1