Search in sources :

Example 1 with MenuButton

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

the class Pivot765 method startup.

@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
    final MenuButton button = new MenuButton();
    button.setButtonData("Populate menu and open!");
    Window window = new Window(button);
    button.getListPopup().getWindowStateListeners().add(new WindowStateListener() {

        @Override
        public Vote previewWindowOpen(Window windowArgument) {
            Menu menu = new Menu();
            Menu.Section section = new Menu.Section();
            menu.getSections().add(section);
            section.add(new Menu.Item("A dynamically added menu item"));
            button.setMenu(menu);
            menuPopulated = true;
            return Vote.APPROVE;
        }

        @Override
        public void windowOpened(Window windowArgument) {
            if (!menuPopulated) {
                Alert.alert("Window was opened before the menu was populated." + "Either previewWindowOpen threw an exception, or it wasn't called before the Window was opened.", windowArgument);
            }
        }

        @Override
        public void windowClosed(Window windowArgument, Display displayArgument, Window owner) {
            // Remove menu for subsequent open attempt
            button.setMenu(null);
            menuPopulated = false;
        }
    });
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Vote(org.apache.pivot.util.Vote) WindowStateListener(org.apache.pivot.wtk.WindowStateListener) MenuButton(org.apache.pivot.wtk.MenuButton) Menu(org.apache.pivot.wtk.Menu) Display(org.apache.pivot.wtk.Display)

Example 2 with MenuButton

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

the class MenuButtonSkin method keyReleased.

/**
 * {@link KeyCode#SPACE SPACE} 'presses' the button.
 */
@Override
public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
    boolean consumed = false;
    MenuButton menuButton = (MenuButton) getComponent();
    if (keyCode == Keyboard.KeyCode.SPACE) {
        pressed = false;
        repaintComponent();
        menuButton.press();
    } else {
        consumed = super.keyReleased(component, keyCode, keyLocation);
    }
    return consumed;
}
Also used : MenuButton(org.apache.pivot.wtk.MenuButton)

Example 3 with MenuButton

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

the class TerraMenuButtonSkin method setCloseTransitionDuration.

public void setCloseTransitionDuration(int closeTransitionDuration) {
    menuPopup.getStyles().put(Style.closeTransitionDuration, closeTransitionDuration);
    MenuButton menuButton = (MenuButton) getComponent();
    menuButton.setQueuedActionDelay(closeTransitionDuration + 50);
}
Also used : MenuButton(org.apache.pivot.wtk.MenuButton)

Example 4 with MenuButton

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

the class MenuButtonSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    MenuButton menuButton = (MenuButton) getComponent();
    menuButton.getMenuButtonListeners().add(this);
    menuPopup.setMenu(menuButton.getMenu());
    menuPopup.getWindowStateListeners().add(menuPopupWindowStateListener);
    menuPopup.getMenuPopupStateListeners().add(menuPopupStateListener);
}
Also used : MenuButton(org.apache.pivot.wtk.MenuButton)

Example 5 with MenuButton

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

the class TerraMenuButtonSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    MenuButton menuButton = (MenuButton) getComponent();
    Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
    dataRenderer.render(menuButton.getButtonData(), menuButton, false);
    int clientWidth = Math.max(width - (TRIGGER_WIDTH + padding.left + padding.right + 2), 0);
    int clientHeight = Math.max(height - (padding.top + padding.bottom + 2), 0);
    int baseline = dataRenderer.getBaseline(clientWidth, clientHeight);
    if (baseline != -1) {
        baseline += padding.top + 1;
    }
    return baseline;
}
Also used : MenuButton(org.apache.pivot.wtk.MenuButton) Button(org.apache.pivot.wtk.Button) MenuButton(org.apache.pivot.wtk.MenuButton) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Aggregations

MenuButton (org.apache.pivot.wtk.MenuButton)9 GradientPaint (java.awt.GradientPaint)5 Button (org.apache.pivot.wtk.Button)5 Point (org.apache.pivot.wtk.Point)5 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 RoundRectangle2D (java.awt.geom.RoundRectangle2D)1 Vote (org.apache.pivot.util.Vote)1 Bounds (org.apache.pivot.wtk.Bounds)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Display (org.apache.pivot.wtk.Display)1 Menu (org.apache.pivot.wtk.Menu)1 Window (org.apache.pivot.wtk.Window)1 WindowStateListener (org.apache.pivot.wtk.WindowStateListener)1