Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.CalendarButton$CalendarButtonBindingListenerList


    @Override
    public void install(Component component) {
        super.install(component);

        CalendarButton calendarButton = (CalendarButton)component;
        calendarButton.getCalendarButtonListeners().add(this);
        calendarButton.getCalendarButtonSelectionListeners().add(this);

        calendar.setLocale(calendarButton.getLocale());
    }
View Full Code Here


    @Override
    public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
        boolean consumed = super.mouseClick(component, button, x, y, count);

        CalendarButton calendarButton = (CalendarButton)getComponent();

        calendarButton.requestFocus();
        calendarButton.press();

        return consumed;
    }
View Full Code Here

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

        CalendarButton calendarButton = (CalendarButton)getComponent();

        if (keyCode == Keyboard.KeyCode.SPACE) {
            pressed = false;
            repaintComponent();

            calendarButton.press();
        } else {
            consumed = super.keyReleased(component, keyCode, keyLocation);
        }

        return consumed;
View Full Code Here

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

    @Override
    public int getPreferredWidth(int height) {
        CalendarButton calendarButton = (CalendarButton) getComponent();

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

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

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

        return preferredHeight;
View Full Code Here

        return preferredHeight;
    }

    @Override
    public Dimensions getPreferredSize() {
        CalendarButton calendarButton = (CalendarButton) getComponent();

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

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

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

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

        if (calendarButton.isEnabled()) {
            backgroundColor = this.backgroundColor;
            bevelColor = (pressed
                || (calendarPopup.isOpen() && closeTransition == null)) ? pressedBevelColor : this.bevelColor;
            borderColor = this.borderColor;
        } else {
            backgroundColor = disabledBackgroundColor;
            bevelColor = disabledBevelColor;
            borderColor = disabledBorderColor;
        }

        graphics.setStroke(new BasicStroke());

        // Paint the background
        graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColor,
            width / 2f, height / 2f, backgroundColor));
        graphics.fillRect(0, 0, width, height);

        // Paint the border
        graphics.setPaint(borderColor);

        Bounds contentBounds = new Bounds(0, 0,
            Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
        GraphicsUtilities.drawRect(graphics, contentBounds.x, contentBounds.y,
            contentBounds.width + 1, contentBounds.height + 1);

        Bounds triggerBounds = new Bounds(Math.max(width - TRIGGER_WIDTH - 1, 0), 0, TRIGGER_WIDTH,
            Math.max(height - 1, 0));
        GraphicsUtilities.drawRect(graphics, triggerBounds.x, triggerBounds.y,
            triggerBounds.width + 1, triggerBounds.height + 1);

        // Paint the content
        Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
        dataRenderer.render(calendarButton.getButtonData(), calendarButton, 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();

        // Paint the focus state
        if (calendarButton.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(borderColor);
View Full Code Here

    @Override
    public void buttonPressed(Button button) {
        if (calendarPopup.isOpen()) {
            calendarPopup.close();
        } else {
            CalendarButton calendarButton = (CalendarButton) button;

            // Determine the popup's location and preferred size, relative
            // to the button
            Display display = calendarButton.getDisplay();

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

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

                Dimensions displaySize = display.getSize();

                calendarPopup.setPreferredSize(-1, -1);
                Dimensions popupSize = calendarPopup.getPreferredSize();
                int popupWidth = Math.max(popupSize.width, calendarButton.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;
                }

                calendarPopup.setLocation(x, y);
                calendarPopup.setPreferredSize(popupWidth, popupHeight);
                calendarPopup.open(calendarButton.getWindow());

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

    private Component addCalendarDateControl(final Dictionary<String, Object> dictionary,
        final String key, Form.Section section) {
        CalendarDate calendarDate = (CalendarDate)dictionary.get(key);

        CalendarButton calendarButton = new CalendarButton();
        calendarButton.setMinimumPreferredWidth(75);
        calendarButton.setSelectedDate(calendarDate);
        section.add(calendarButton);
        Form.setLabel(calendarButton, key);

        calendarButton.getCalendarButtonSelectionListeners().add
            (new CalendarButtonSelectionListener() {
            @Override
            public void selectedDateChanged(CalendarButton calendarButton,
                CalendarDate previousSelectedDate) {
                try {
                    dictionary.put(key, calendarButton.getSelectedDate());
                } catch (Exception exception) {
                    displayErrorMessage(exception, calendarButton.getWindow());
                    dictionary.put(key, previousSelectedDate);
                }
            }
        });
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.CalendarButton$CalendarButtonBindingListenerList

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.