Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.Menu$Item$ItemListenerList


    @Override
    public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
        boolean consumed = super.keyPressed(component, keyCode, keyLocation);

        Menu menu = (Menu)component;

        if (keyCode == Keyboard.KeyCode.UP) {
            Menu.SectionSequence sections = menu.getSections();
            int sectionCount = sections.getLength();

            Menu.Item activeItem = menu.getActiveItem();
            int sectionIndex;
            int itemIndex;
            if (activeItem == null) {
                sectionIndex = sectionCount - 1;
                itemIndex = -1;
            } else {
                Menu.Section section = activeItem.getSection();
                sectionIndex = sections.indexOf(section);
                itemIndex = section.indexOf(activeItem) - 1;

                if (itemIndex == -1) {
                    sectionIndex--;
                }
            }

            while (sectionIndex >= 0) {
                Section section = sections.get(sectionIndex);
                if (itemIndex == -1) {
                    int sectionLength = section.getLength();
                    itemIndex = sectionLength - 1;
                }

                while (itemIndex >= 0) {
                    Item item = section.get(itemIndex);

                    if (item.isEnabled()) {
                        item.setActive(true);
                        break;
                    }

                    itemIndex--;
                }

                if (itemIndex >= 0) {
                    break;
                }

                sectionIndex--;
            }

            consumed = true;
        } else if (keyCode == Keyboard.KeyCode.DOWN) {
            Menu.SectionSequence sections = menu.getSections();
            int sectionCount = sections.getLength();

            Menu.Item activeItem = menu.getActiveItem();
            int sectionIndex;
            int itemIndex;
            if (activeItem == null) {
                sectionIndex = 0;
                itemIndex = 0;
            } else {
                Menu.Section section = activeItem.getSection();
                sectionIndex = sections.indexOf(section);
                itemIndex = section.indexOf(activeItem) + 1;
            }

            while (sectionIndex < sectionCount) {
                Section section = sections.get(sectionIndex);
                int sectionLength = section.getLength();

                while (itemIndex < sectionLength) {
                    Item item = section.get(itemIndex);

                    if (item.isEnabled()) {
                        item.setActive(true);
                        break;
                    }

                    itemIndex++;
                }

                if (itemIndex < sectionLength) {
                    break;
                }

                sectionIndex++;
                itemIndex = 0;
            }

            consumed = true;
        } else if (keyCode == Keyboard.KeyCode.LEFT) {
            // Close the window if this is not a top-level menu
            if (menu.getItem() != null) {
                Window window = menu.getWindow();
                window.close();
                consumed = true;
            }
        } else if (keyCode == Keyboard.KeyCode.RIGHT) {
            Menu.Item activeItem = menu.getActiveItem();

            // Press if the item has a sub-menu
            if (activeItem != null
                && activeItem.getMenu() != null) {
                activeItem.press();
                consumed = true;
            }
        } else if (keyCode == Keyboard.KeyCode.ENTER) {
            Menu.Item activeItem = menu.getActiveItem();

            // Press if the item does not have a sub-menu
            if (activeItem != null
                && activeItem.getMenu() == null) {
                activeItem.press();
View Full Code Here


    @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();
View Full Code Here

    @Override
    public boolean keyTyped(Component component, char character) {
        boolean consumed = super.keyTyped(component, character);

        Menu menu = (Menu)component;
        Menu.SectionSequence sections = menu.getSections();
        int sectionCount = sections.getLength();

        Menu.Item activeItem = menu.getActiveItem();

        int sectionIndex;
        int itemIndex;
        if (activeItem == null) {
            sectionIndex = 0;
View Full Code Here

        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);
View Full Code Here

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

        if (menuPopup.isContextMenu()) {
View Full Code Here

    public void menuChanged(MenuPopup menuPopup, Menu previousMenu) {
        if (previousMenu != null) {
            previousMenu.getMenuItemSelectionListeners().remove(menuItemSelectionListener);
        }

        Menu menu = menuPopup.getMenu();
        if (menu != null) {
            menu.getMenuItemSelectionListeners().add(menuItemSelectionListener);
        }

        panorama.setView(menu);
    }
View Full Code Here

    }

    @Override
    public void buttonPressed(Button button) {
        Menu.Item menuItem = (Menu.Item)getComponent();
        Menu menu = menuItem.getMenu();

        if (menu != null
            && !menuPopup.isOpen()) {
            Display display = menuItem.getDisplay();
            Point location = menuItem.mapPointToAncestor(display, getWidth(), 0);
View Full Code Here

    }

    @Override
    public void paint(Graphics2D graphics) {
        Menu.Item menuItem = (Menu.Item)getComponent();
        Menu menu = menuItem.getSection().getMenu();

        int width = getWidth();
        int height = getHeight();

        boolean highlight = menuItem.isActive();

        // Paint highlight state
        if (highlight) {
            Color activeBackgroundColor = (Color)menu.getStyles().get("activeBackgroundColor");
            graphics.setPaint(new GradientPaint(width / 2, 0, TerraTheme.brighten(activeBackgroundColor),
                width / 2, height, activeBackgroundColor));
            graphics.fillRect(0, 0, width, height);
        }

        // Paint the content
        Button.DataRenderer dataRenderer = menuItem.getDataRenderer();
        dataRenderer.render(menuItem.getButtonData(), menuItem, highlight);
        dataRenderer.setSize(Math.max(width - EXPANDER_SIZE, 0), height);

        dataRenderer.paint(graphics);

        // Paint the expander
        if (menuItem.getMenu() != null) {
            Color color = (Color)(highlight ?
                menu.getStyles().get("activeColor") : menu.getStyles().get("color"));
            graphics.setColor(color);
            graphics.setStroke(new BasicStroke(0));

            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
View Full Code Here

        boolean opaque = false;

        Menu.Item menuItem = (Menu.Item)getComponent();

        if (menuItem.isActive()) {
            Menu menu = menuItem.getSection().getMenu();
            Color activeBackgroundColor = (Color)menu.getStyles().get("activeBackgroundColor");
            opaque = (activeBackgroundColor.getTransparency() == Transparency.OPAQUE);
        }

        return opaque;
    }
View Full Code Here

        }

        @Override
        public void paint(Graphics2D graphics) {
            Menu.Item menuItem = (Menu.Item)getComponent();
            Menu menu = menuItem.getSection().getMenu();

            Color color = (Color)menu.getStyles().get("color");
            graphics.setColor(color);
            graphics.setStroke(new BasicStroke(2.5f));

            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.Menu$Item$ItemListenerList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.