Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.MenuButton$Skin


        int preferredWidth = 0;

        if (height == -1) {
            preferredWidth = getPreferredSize().width;
        } else {
            MenuButton menuButton = (MenuButton)getComponent();
            Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
            dataRenderer.render(menuButton.getButtonData(), menuButton, false);

            preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH
                + padding.left + padding.right + spacing + 2;

            // Adjust for preferred aspect ratio
View Full Code Here


        int preferredHeight = 0;

        if (width == -1) {
            preferredHeight = getPreferredSize().height;
        } else {
            MenuButton menuButton = (MenuButton)getComponent();

            Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
            dataRenderer.render(menuButton.getButtonData(), menuButton, false);

            preferredHeight = dataRenderer.getPreferredHeight(-1)
                + padding.top + padding.bottom + 2;

            // Adjust for preferred aspect ratio
View Full Code Here

        return preferredHeight;
    }

    @Override
    public Dimensions getPreferredSize() {
        MenuButton menuButton = (MenuButton)getComponent();

        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
        dataRenderer.render(menuButton.getButtonData(), menuButton, false);

        Dimensions contentSize = dataRenderer.getPreferredSize();
        int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
        int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
View Full Code Here

        return new Dimensions(preferredWidth, preferredHeight);
    }

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

        // No-op
    }

    @Override
    public void paint(Graphics2D graphics) {
        MenuButton menuButton = (MenuButton)getComponent();

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

        Color color = null;
        Color backgroundColor = null;
        Color bevelColor = null;
        Color borderColor = null;

        if (!toolbar
            || highlighted
            || menuButton.isFocused()
            || menuPopup.isOpen()) {
            if (menuButton.isEnabled()) {
                color = this.color;
                backgroundColor = this.backgroundColor;
                bevelColor = (pressed || menuPopup.isOpen()) ? pressedBevelColor : this.bevelColor;
                borderColor = this.borderColor;
            } else {
                color = disabledColor;
                backgroundColor = disabledBackgroundColor;
                bevelColor = disabledBevelColor;
                borderColor = disabledBorderColor;
            }
        }

        // Paint the background
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

        if (backgroundColor != null
            && bevelColor != null) {
            graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColor,
                width / 2f, height / 2f, backgroundColor));
            graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1,
                CORNER_RADIUS, CORNER_RADIUS));
        }

        // Paint the content
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_OFF);

        Bounds contentBounds = new Bounds(padding.left + 1, padding.top + 1,
            Math.max(width - (padding.left + padding.right + spacing + TRIGGER_WIDTH + 2), 0),
            Math.max(height - (padding.top + padding.bottom + 2), 0));
        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
        dataRenderer.render(menuButton.getButtonData(), menuButton, highlighted);
        dataRenderer.setSize(contentBounds.width, contentBounds.height);

        Graphics2D contentGraphics = (Graphics2D)graphics.create();
        contentGraphics.translate(contentBounds.x, contentBounds.y);
        contentGraphics.clipRect(0, 0, contentBounds.width, contentBounds.height);
        dataRenderer.paint(contentGraphics);
        contentGraphics.dispose();

        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

        // Paint the border
        if (borderColor != null) {
            graphics.setPaint(borderColor);
            graphics.setStroke(new BasicStroke(1));
            graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1,
                CORNER_RADIUS, CORNER_RADIUS));
        }

        // Paint the focus state
        if (menuButton.isFocused()
            && !toolbar) {
            BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND, 1.0f, new float[] {0.0f, 2.0f}, 0.0f);
            graphics.setStroke(dashStroke);
            graphics.setColor(this.borderColor);
View Full Code Here

        return true;
    }

    @Override
    public boolean isOpaque() {
        MenuButton menuButton = (MenuButton)getComponent();
        return (!toolbar
            || highlighted
            || menuButton.isFocused());
    }
View Full Code Here

    @Override
    public void buttonPressed(Button button) {
        if (menuPopup.isOpen()) {
            menuPopup.close();
        } else {
            MenuButton menuButton = (MenuButton)getComponent();

            // Determine the popup's location and preferred size, relative
            // to the button
            Window window = menuButton.getWindow();

            if (window != null) {
                int width = getWidth();
                int height = getHeight();

                Display display = menuButton.getDisplay();

                // Ensure that the popup remains within the bounds of the display
                Point buttonLocation = menuButton.mapPointToAncestor(display, 0, 0);

                Dimensions displaySize = display.getSize();
                menuPopup.setPreferredSize(-1, -1);
                Dimensions popupSize = menuPopup.getPreferredSize();
                int popupWidth = Math.max(popupSize.width, menuButton.getWidth());
                int popupHeight = popupSize.height;

                int x = buttonLocation.x;
                if (popupWidth > width
                    && x + popupWidth > displaySize.width) {
                    x = buttonLocation.x + width - popupWidth;
                }

                int y = buttonLocation.y + height - 1;
                if (y + popupSize.height > displaySize.height) {
                    if (buttonLocation.y - popupSize.height > 0) {
                        y = buttonLocation.y - popupSize.height + 1;
                    } else {
                        popupHeight = displaySize.height - y;
                    }
                } else {
                    popupHeight = -1;
                }

                menuPopup.setLocation(x, y);
                menuPopup.setPreferredSize(popupWidth, popupHeight);
                menuPopup.open(menuButton.getWindow());

                menuPopup.requestFocus();
            }
        }
    }
View Full Code Here

        int preferredWidth = 0;

        if (height == -1) {
            preferredWidth = getPreferredSize().width;
        } else {
            MenuButton menuButton = (MenuButton)getComponent();
            Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
            dataRenderer.render(menuButton.getButtonData(), menuButton, false);

            preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH
                + padding.left + padding.right + spacing + 2;

            // Adjust for preferred aspect ratio
View Full Code Here

        int preferredHeight = 0;

        if (width == -1) {
            preferredHeight = getPreferredSize().height;
        } else {
            MenuButton menuButton = (MenuButton)getComponent();

            Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
            dataRenderer.render(menuButton.getButtonData(), menuButton, false);

            preferredHeight = dataRenderer.getPreferredHeight(-1)
                + padding.top + padding.bottom + 2;

            // Adjust for preferred aspect ratio
View Full Code Here

        return preferredHeight;
    }

    @Override
    public Dimensions getPreferredSize() {
        MenuButton menuButton = (MenuButton)getComponent();

        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
        dataRenderer.render(menuButton.getButtonData(), menuButton, false);

        Dimensions contentSize = dataRenderer.getPreferredSize();
        int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
        int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.MenuButton$Skin

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.