Search in sources :

Example 11 with Menu

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

the class TerraMenuPopupSkin method windowOpened.

@Override
public void windowOpened(Window window) {
    super.windowOpened(window);
    Display display = window.getDisplay();
    display.getContainerMouseListeners().add(displayMouseListener);
    MenuPopup menuPopup = (MenuPopup) window;
    Menu menu = menuPopup.getMenu();
    if (menu != null) {
        Menu.Item activeItem = menu.getActiveItem();
        if (activeItem != null) {
            activeItem.setActive(false);
        }
        menu.requestFocus();
    }
    panorama.setScrollTop(0);
    // Always ensure that the menu popup fits on the display.
    ApplicationContext.queueCallback(repositionCallback);
}
Also used : MenuPopup(org.apache.pivot.wtk.MenuPopup) Menu(org.apache.pivot.wtk.Menu) Display(org.apache.pivot.wtk.Display)

Example 12 with Menu

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

the class ContextMenuTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(ContextMenuTest.class, "context_menu_test.bxml");
    bxmlSerializer.bind(this, ContextMenuTest.class);
    window.setMenuHandler(new MenuHandler() {

        @Override
        public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
            menu.getSections().add(globalSection);
            menu.getSections().add(helpSection);
            menu.getSections().add(hoursSection);
            return false;
        }
    });
    window.open(display);
}
Also used : MenuHandler(org.apache.pivot.wtk.MenuHandler) Menu(org.apache.pivot.wtk.Menu) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 13 with Menu

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

the class ContextMenusSampleMenuHandlerAdapter method configureContextMenu.

@Override
public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
    Menu.Section menuSection = new Menu.Section();
    menu.getSections().add(menuSection);
    menuSection.add(new Menu.Item("Do Nothing"));
    Menu.Item doNothingMenuItem = new Menu.Item("Do Nothing and disabled");
    doNothingMenuItem.setEnabled(false);
    menuSection.add(doNothingMenuItem);
    Menu.Item whatIsThisMenuItem = new Menu.Item("What is this?");
    whatIsThisMenuItem.setAction(new Action() {

        @Override
        public void perform(Component source) {
            String description = (descendant != null) ? (String) descendant.getUserData().get("description") : "empty";
            String message = "This is a " + description + " description.";
            System.out.println("perform: " + message);
        }
    });
    menuSection.add(whatIsThisMenuItem);
    Menu.Item nullActionMenuItem = new Menu.Item("Item with null action");
    nullActionMenuItem.setAction((Action) null);
    menuSection.add(nullActionMenuItem);
    Menu.Item disabledActionMenuItem = new Menu.Item("Item with disabled action");
    disabledActionMenuItem.setAction(new Action() {

        @Override
        public void perform(Component source) {
            System.out.println("in perform");
        }
    });
    disabledActionMenuItem.getAction().setEnabled(false);
    menuSection.add(disabledActionMenuItem);
    return false;
}
Also used : Action(org.apache.pivot.wtk.Action) Menu(org.apache.pivot.wtk.Menu) Component(org.apache.pivot.wtk.Component)

Example 14 with Menu

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

the class MenuItemDataRenderer method render.

@Override
public void render(Object data, Button button, boolean highlighted) {
    Image icon = null;
    String text = null;
    Keyboard.KeyStroke keyboardShortcut = null;
    if (data instanceof BaseContent) {
        BaseContent buttonData = (BaseContent) data;
        icon = buttonData.getIcon();
        if (buttonData instanceof MenuItemData) {
            MenuItemData menuItemData = (MenuItemData) buttonData;
            keyboardShortcut = menuItemData.getKeyboardShortcut();
        }
    } else if (data instanceof Image) {
        icon = (Image) data;
    }
    text = toString(data);
    // attempt to retrieve icon from button data
    if (button.isSelected()) {
        icon = (Image) button.getStyles().get(Style.checkmarkImage);
    }
    // Update the image view
    Menu.Item menuItem = (Menu.Item) button;
    Menu menu = (Menu) menuItem.getParent();
    int margin = menu.getStyles().getInt(Style.margin);
    Insets padding = (Insets) getStyles().get(Style.padding);
    imageView.setImage(icon);
    imageView.setPreferredWidth(margin - padding.left * 2);
    imageView.getStyles().put(Style.opacity, button.isEnabled() ? new Float(1.0f) : new Float(0.5f));
    // Update the labels
    textLabel.setText(text != null ? text : "");
    Font font = menu.getStyles().getFont(Style.font);
    textLabel.getStyles().put(Style.font, font);
    keyboardShortcutLabel.getStyles().put(Style.font, font.deriveFont(Font.ITALIC));
    Color color;
    if (button.isEnabled()) {
        if (highlighted) {
            color = menu.getStyles().getColor(Style.activeColor);
        } else {
            color = menu.getStyles().getColor(Style.color);
        }
    } else {
        color = menu.getStyles().getColor(Style.disabledColor);
    }
    textLabel.getStyles().put(Style.color, color);
    keyboardShortcutLabel.getStyles().put(Style.color, color);
    boolean showKeyboardShortcuts = false;
    if (menu.getStyles().containsKey(Style.showKeyboardShortcuts)) {
        showKeyboardShortcuts = menu.getStyles().getBoolean(Style.showKeyboardShortcuts);
    }
    if (showKeyboardShortcuts) {
        keyboardShortcutLabel.setVisible(true);
        keyboardShortcutLabel.setText(keyboardShortcut != null ? keyboardShortcut.toString() : "");
    } else {
        keyboardShortcutLabel.setVisible(false);
    }
}
Also used : Insets(org.apache.pivot.wtk.Insets) Keyboard(org.apache.pivot.wtk.Keyboard) Color(java.awt.Color) Image(org.apache.pivot.wtk.media.Image) Font(java.awt.Font) Menu(org.apache.pivot.wtk.Menu)

Example 15 with Menu

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

the class MenuItemSkin method buttonPressed.

@Override
public void buttonPressed(Button button) {
    Menu.Item menuItem = (Menu.Item) getComponent();
    Menu menu = menuItem.getMenu();
    if (menu != null && !menuPopup.isOpen()) {
        // Size and position the popup
        Display display = menuItem.getDisplay();
        Dimensions displaySize = display.getSize();
        Point location = menuItem.mapPointToAncestor(display, getWidth(), 0);
        menuPopup.setLocation(location.x, location.y);
        int width = getWidth();
        // If the popup extends over the right edge of the display,
        // move it so that the right edge of the popup lines up with the
        // left edge of the menu item
        int popupWidth = menuPopup.getPreferredWidth();
        if (location.x + popupWidth > displaySize.width) {
            menuPopup.setX(location.x - width - popupWidth);
        }
        menuPopup.open(menuItem.getWindow());
        menuPopup.requestFocus();
    }
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) Menu(org.apache.pivot.wtk.Menu) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) Display(org.apache.pivot.wtk.Display)

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