Package org.apache.pivot.wtk

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


        // No-op
    }

    @Override
    public void paint(Graphics2D graphics) {
        ListButton listButton = (ListButton)getComponent();

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

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

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

        graphics.setStroke(new BasicStroke());

        // 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 = listButton.getDataRenderer();
        dataRenderer.render(listButton.getButtonData(), listButton, 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
        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));
        graphics.draw(new Line2D.Double(contentBounds.x + contentBounds.width, 0.5,
            contentBounds.x + contentBounds.width, contentBounds.height));

        // Paint the focus state
        if (listButton.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 (listViewPopup.isOpen()) {
            listViewPopup.close();
        } else {
            ListButton listButton = (ListButton)button;

            if (listButton.getListData().getLength() > 0) {
                // Determine the popup's location and preferred size, relative
                // to the button
                Display display = listButton.getDisplay();

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

                    // Adjust for list size
                    int listSize = listButton.getListSize();
                    if (listSize == -1) {
                        listViewBorder.setPreferredHeight(-1);
                    } else {
                        if (!listViewBorder.isPreferredHeightSet()) {
                            ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
                            int borderHeight = itemRenderer.getPreferredHeight(-1) * listSize + 2;

                            if (listViewBorder.getPreferredHeight() > borderHeight) {
                                listViewBorder.setPreferredHeight(borderHeight);
                            } else {
                                listViewBorder.setPreferredHeight(-1);
                            }
                        }
                    }

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

                    Dimensions displaySize = display.getSize();

                    listViewPopup.setPreferredSize(-1, -1);
                    Dimensions popupSize = listViewPopup.getPreferredSize();
                    int popupWidth = Math.max(popupSize.width, listButton.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) {
                        if (buttonLocation.y - popupSize.height > 0) {
                            y = buttonLocation.y - popupSize.height + 1;
                        } else {
                            popupHeight = displaySize.height - y;
                        }
                    } else {
                        popupHeight = -1;
                    }

                    listViewPopup.setLocation(x, y);
                    listViewPopup.setPreferredSize(popupWidth, popupHeight);
                    listViewPopup.open(listButton.getWindow());

                    ApplicationContext.queueCallback(new Runnable() {
                        @Override
                        public void run() {
                            int selectedIndex = listView.getSelectedIndex();
View Full Code Here

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

        ListButton listButton = (ListButton)component;
        listButton.getListButtonListeners().add(this);
        listButton.getListButtonSelectionListeners().add(this);

        listView.setListData(listButton.getListData());
        listView.setItemRenderer(listButton.getItemRenderer());
    }
View Full Code Here

        boolean consumed = super.mouseDown(component, button, x, y);

        pressed = true;
        repaintComponent();

        ListButton listButton = (ListButton)component;

        if (listViewPopup.isOpen()) {
            listViewPopup.close();
        } else if (listButton.isRepeatable() && !getTriggerBounds().contains(x, y)) {
            listButton.requestFocus();
        } else {
            listViewPopup.open(component.getWindow());
        }

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

        ListButton listButton = (ListButton)getComponent();
        if (listButton.isRepeatable() && !getTriggerBounds().contains(x, y)) {
            listButton.press();
        }

        return consumed;
    }
View Full Code Here

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

        ListButton listButton = (ListButton)getComponent();

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

            if (listViewPopup.isOpen()) {
                listViewPopup.close();
            } else if (!listButton.isRepeatable()){
                listViewPopup.open(component.getWindow());
            }
        } else if (keyCode == Keyboard.KeyCode.UP) {
            int index = listButton.getSelectedIndex();

            do {
                index--;
            } while (index >= 0
                && listButton.isItemDisabled(index));

            if (index >= 0) {
                listButton.setSelectedIndex(index);
                consumed = true;
            }
        } else if (keyCode == Keyboard.KeyCode.DOWN) {
            if (Keyboard.isPressed(Keyboard.Modifier.ALT)) {
                listViewPopup.open(component.getWindow());

                consumed = true;
            } else {
                int index = listButton.getSelectedIndex();
                int count = listButton.getListData().getLength();

                do {
                    index++;
                } while (index < count
                    && listView.isItemDisabled(index));

                if (index < count) {
                    listButton.setSelectedIndex(index);
                    consumed = true;
                }
            }
        } else {
            consumed = super.keyPressed(component, keyCode, keyLocation);
View Full Code Here

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

        ListButton listButton = (ListButton)getComponent();

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

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

View Full Code Here

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

        ListButton listButton = (ListButton)getComponent();

        List<?> listData = listButton.getListData();
        ListView.ItemRenderer itemRenderer = listButton.getItemRenderer();

        character = Character.toUpperCase(character);

        for (int i = listButton.getSelectedIndex() + 1, n = listData.getLength(); i < n; i++) {
            if (!listButton.isItemDisabled(i)) {
                String string = itemRenderer.toString(listData.get(i));

                if (string != null
                    && string.length() > 0) {
                    char first = Character.toUpperCase(string.charAt(0));

                    if (first == character) {
                        listButton.setSelectedIndex(i);
                        consumed = true;
                        break;
                    }
                }
            }
View Full Code Here

        Enum<?>[] enumConstants = type.getEnumConstants();
        for (int i = 0; i < enumConstants.length; i++) {
            listData.add(enumConstants[i]);
        }

        ListButton listButton = new ListButton();
        listButton.setListData(listData);
        listButton.setSelectedItem(value);
        section.add(listButton);
        Form.setLabel(listButton, key);

        listButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
            private boolean updating = false;

            @Override
            public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
                if (!updating) {
                    updating = true;
                    try {
                        dictionary.put(key, listButton.getSelectedItem());
                    } catch (Exception exception) {
                        displayErrorMessage(exception, listButton.getWindow());
                        listButton.setSelectedIndex(previousSelectedIndex);
                    } finally {
                        updating = false;
                    }
                }
            }
View Full Code Here

        return listButton;
    }

    private void updateEnumControl(Dictionary<String, Object> dictionary, String key) {
        ListButton listButton = (ListButton)controls.get(key);

        if (listButton != null) {
            Enum<?> value = (Enum<?>)dictionary.get(key);
            listButton.setSelectedItem(value);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.ListButton$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.