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);
}
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;
}
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);
}
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);
}
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;
}
Aggregations