Search in sources :

Example 1 with MenuBar

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

the class MenuBarItemDataRenderer method render.

@Override
public void render(Object data, Button button, boolean highlighted) {
    Image icon = null;
    String text = null;
    if (data instanceof BaseContent) {
        BaseContent baseContent = (BaseContent) data;
        icon = baseContent.getIcon();
    } else if (data instanceof Image) {
        icon = (Image) data;
    }
    text = toString(data);
    // Update the image view
    MenuBar.Item menuBarItem = (MenuBar.Item) button;
    MenuBar menuBar = (MenuBar) menuBarItem.getParent();
    if (icon == null) {
        imageView.setVisible(false);
    } else {
        imageView.setVisible(true);
        imageView.setImage(icon);
        imageView.getStyles().put(Style.opacity, button.isEnabled() ? 1.0f : 0.5f);
    }
    // Update the label
    label.setText(text != null ? text : "");
    if (text == null) {
        label.setVisible(false);
    } else {
        label.setVisible(true);
        Font font = menuBar.getStyles().getFont(Style.font);
        label.getStyles().put(Style.font, font);
        Color color;
        if (button.isEnabled()) {
            if (highlighted) {
                color = menuBar.getStyles().getColor(Style.activeColor);
            } else {
                color = menuBar.getStyles().getColor(Style.color);
            }
        } else {
            color = menuBar.getStyles().getColor(Style.disabledColor);
        }
        label.getStyles().put(Style.color, color);
    }
}
Also used : Color(java.awt.Color) MenuBar(org.apache.pivot.wtk.MenuBar) Image(org.apache.pivot.wtk.media.Image) Font(java.awt.Font)

Example 2 with MenuBar

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

the class TerraFrameSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    Frame frame = (Frame) getComponent();
    // Include title bar width plus left/right title bar borders
    Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
    preferredWidth = Math.max(titleBarSize.width + 2, preferredWidth);
    if (height != -1) {
        // Subtract title bar height and top/bottom title bar borders
        // from height constraint
        height -= titleBarSize.height + 2;
    }
    // Include menu bar width
    MenuBar menuBar = frame.getMenuBar();
    if (menuBar != null) {
        Dimensions menuBarSize = menuBar.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, menuBarSize.width);
        if (height != -1) {
            // Subtract menu bar height from height constraint
            height -= menuBarSize.height;
        }
    }
    Component content = frame.getContent();
    if (content != null) {
        if (height != -1) {
            // Subtract padding, top/bottom content borders, and content bevel
            // from height constraint
            height -= (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
            height = Math.max(height, 0);
        }
        preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(height));
    }
    // Add padding and left/right content borders
    preferredWidth += (padding.left + padding.right) + 2;
    return preferredWidth;
}
Also used : Frame(org.apache.pivot.wtk.Frame) Dimensions(org.apache.pivot.wtk.Dimensions) MenuBar(org.apache.pivot.wtk.MenuBar) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 3 with MenuBar

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

the class TerraFrameSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    Frame frame = (Frame) getComponent();
    // Include title bar height plus top/bottom title bar borders
    preferredHeight += titleBarTablePane.getPreferredHeight() + 2;
    // Include menu bar height
    MenuBar menuBar = frame.getMenuBar();
    if (menuBar != null) {
        preferredHeight += menuBar.getPreferredHeight();
    }
    Component content = frame.getContent();
    if (content != null) {
        if (width != -1) {
            // Subtract padding and left/right content borders from constraint
            width -= (padding.left + padding.right) + 2;
            width = Math.max(width, 0);
        }
        preferredHeight += content.getPreferredHeight(width);
    }
    // Add padding, top/bottom content borders, and content bevel
    preferredHeight += (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
    return preferredHeight;
}
Also used : Frame(org.apache.pivot.wtk.Frame) MenuBar(org.apache.pivot.wtk.MenuBar) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 4 with MenuBar

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

the class TerraFrameSkin method keyPressed.

@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
    boolean consumed = super.keyPressed(component, keyCode, keyLocation);
    Frame frame = (Frame) component;
    MenuBar menuBar = frame.getMenuBar();
    if (menuBar != null && keyCode == Keyboard.KeyCode.SPACE && Keyboard.isPressed(Keyboard.Modifier.ALT)) {
        MenuBar.Item activeItem = menuBar.getActiveItem();
        MenuBar.ItemSequence items = menuBar.getItems();
        if (activeItem == null && items.getLength() > 0) {
            items.get(0).setActive(true);
            consumed = true;
        }
    }
    return consumed;
}
Also used : Frame(org.apache.pivot.wtk.Frame) MenuBar(org.apache.pivot.wtk.MenuBar)

Example 5 with MenuBar

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

the class TerraMenuBarSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    MenuBar menuBar = (MenuBar) component;
    menuBar.getMenuBarListeners().add(this);
}
Also used : MenuBar(org.apache.pivot.wtk.MenuBar)

Aggregations

MenuBar (org.apache.pivot.wtk.MenuBar)11 Frame (org.apache.pivot.wtk.Frame)6 Component (org.apache.pivot.wtk.Component)5 GradientPaint (java.awt.GradientPaint)4 Point (org.apache.pivot.wtk.Point)4 Color (java.awt.Color)3 Dimensions (org.apache.pivot.wtk.Dimensions)2 Font (java.awt.Font)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Action (org.apache.pivot.wtk.Action)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 Button (org.apache.pivot.wtk.Button)1 MenuHandler (org.apache.pivot.wtk.MenuHandler)1 TextInput (org.apache.pivot.wtk.TextInput)1 Image (org.apache.pivot.wtk.media.Image)1