Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.ColorChooserButton$ColorChooserButtonBindingListenerList


        colorChooserPopup.getDecorators().add(dropShadowDecorator);
    }

    @Override
    public int getPreferredWidth(int height) {
        ColorChooserButton colorChooserButton = (ColorChooserButton)getComponent();
        Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();

        dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);

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

        return preferredWidth;
View Full Code Here


        return preferredWidth;
    }

    @Override
    public int getPreferredHeight(int width) {
        ColorChooserButton colorChooserButton = (ColorChooserButton)getComponent();
        Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();

        dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);

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

        return preferredHeight;
View Full Code Here

        return preferredHeight;
    }

    @Override
    public Dimensions getPreferredSize() {
        ColorChooserButton colorChooserButton = (ColorChooserButton)getComponent();

        Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
        dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, 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) {
        ColorChooserButton colorChooserButton = (ColorChooserButton)getComponent();

        Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
        dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, 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) {
        ColorChooserButton colorChooserButton = (ColorChooserButton)getComponent();

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

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

        if (colorChooserButton.isEnabled()) {
            backgroundColor = this.backgroundColor;
            bevelColor = (pressed || colorChooserPopup.isOpen())
                ? pressedBevelColor : this.bevelColor;
            borderColor = this.borderColor;
        } else {
            backgroundColor = disabledBackgroundColor;
            bevelColor = disabledBevelColor;
            borderColor = disabledBorderColor;
        }

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

        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(0, 0,
            Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
        Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
        dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
        dataRenderer.setSize(Math.max(contentBounds.width - (padding.left + padding.right + 2) + 1, 0),
            Math.max(contentBounds.height - (padding.top + padding.bottom + 2) + 1, 0));

        Graphics2D contentGraphics = (Graphics2D)graphics.create();
        contentGraphics.translate(padding.left + 1, padding.top + 1);
        contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
        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 (colorChooserButton.isFocused()) {
            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);
            graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(width - 5, 0),
                Math.max(height - 5, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
        }

        // Paint the focus state
        if (colorChooserButton.isFocused()) {
            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);
            graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(width - 5, 0),
View Full Code Here

    // ButtonPressListener methods

    @Override
    public void buttonPressed(Button button) {
        ColorChooserButton colorChooserButton = (ColorChooserButton)button;

        if (colorChooserPopup.isOpen()) {
            colorChooserPopup.close();

            Color color = colorChooser.getSelectedColor();
            colorChooserButton.setSelectedColor(color);
        } else {
                // Determine the popup's location and preferred size, relative
                // to the button
                Display display = colorChooserButton.getDisplay();

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

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

                    Dimensions displaySize = display.getSize();

                    colorChooserPopup.setPreferredSize(-1, -1);
                    Dimensions popupSize = colorChooserPopup.getPreferredSize();
                    int popupWidth = Math.max(popupSize.width,
                        colorChooserButton.getWidth() - TRIGGER_WIDTH - 1);
                    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) {
                        y = buttonLocation.y - popupSize.height + 1;
                    }

                    colorChooser.setSelectedColor(colorChooserButton.getSelectedColor());

                    colorChooserPopup.setLocation(x, y);
                    colorChooserPopup.setPreferredSize(popupWidth, popupHeight);
                    colorChooserPopup.open(colorChooserButton.getWindow());
                    colorChooserPopup.requestFocus();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.ColorChooserButton$ColorChooserButtonBindingListenerList

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.