Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.ListView$ItemRenderer


    }

    @Override
    @SuppressWarnings("unchecked")
    public int getBaseline(int width, int height) {
        ListView listView = (ListView)getComponent();

        int baseline = -1;

        int clientWidth = width;
        if (listView.getCheckmarksEnabled()) {
            clientWidth = Math.max(clientWidth - (CHECKBOX.getWidth() + (checkboxPadding.left
                + checkboxPadding.right)), 0);
        }

        ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
        List<Object> listData = (List<Object>)listView.getListData();
        if (variableItemHeight && listData.getLength() > 0) {
            itemRenderer.render(listData.get(0), 0, listView, false, false, false, false);
            int itemHeight = itemRenderer.getPreferredHeight(clientWidth);
            if (listView.getCheckmarksEnabled()) {
                itemHeight = Math.max(CHECKBOX.getHeight() + (checkboxPadding.top
                    + checkboxPadding.bottom), itemHeight);
            }

            baseline = itemRenderer.getBaseline(clientWidth, itemHeight);
        } else {
            itemRenderer.render(null, -1, listView, false, false, false, false);

            int fixedItemHeight = itemRenderer.getPreferredHeight(-1);
            if (listView.getCheckmarksEnabled()) {
                fixedItemHeight = Math.max(CHECKBOX.getHeight() + (checkboxPadding.top
                    + checkboxPadding.bottom), fixedItemHeight);
            }

            baseline = itemRenderer.getBaseline(clientWidth, fixedItemHeight);
View Full Code Here


    }

    @Override
    @SuppressWarnings("unchecked")
    public void layout() {
        ListView listView = (ListView)getComponent();
        List<Object> listData = (List<Object>)listView.getListData();
        ListView.ItemRenderer itemRenderer = listView.getItemRenderer();

        if (variableItemHeight) {
            int width = getWidth();
            int itemEnd = listData.getLength() - 1;

            int checkboxHeight = 0;
            if (listView.getCheckmarksEnabled()) {
                checkboxHeight = CHECKBOX.getHeight() + (checkboxPadding.top
                    + checkboxPadding.bottom);
            }

            itemHeights = new ArrayList<Integer>(listData.getLength() + 1);
            int itemY = 0;

            for (int itemIndex = 0; itemIndex <= itemEnd; itemIndex++) {
                Object item = listData.get(itemIndex);
                boolean highlighted = (itemIndex == highlightedIndex
                    && listView.getSelectMode() != ListView.SelectMode.NONE);
                boolean selected = listView.isItemSelected(itemIndex);
                boolean disabled = listView.isItemDisabled(itemIndex);

                int itemWidth = width;
                int itemX = 0;

                boolean checked = false;
                if (listView.getCheckmarksEnabled()) {
                    checked = listView.isItemChecked(itemIndex);
                    itemX = CHECKBOX.getWidth() + (checkboxPadding.left
                            + checkboxPadding.right);
                    itemWidth -= itemX;
                }

                itemRenderer.render(item, itemIndex, listView, selected, checked, highlighted, disabled);
                int itemHeight = itemRenderer.getPreferredHeight(itemWidth);
                if (listView.getCheckmarksEnabled()) {
                    itemHeight = Math.max(itemHeight, checkboxHeight);
                }

                itemHeights.add(itemY);
                itemY += itemHeight;
            }

            itemHeights.add(itemY);
        } else {
            itemRenderer.render(null, -1, listView, false, false, false, false);

            fixedItemHeight = itemRenderer.getPreferredHeight(-1);
            if (listView.getCheckmarksEnabled()) {
                fixedItemHeight = Math.max(CHECKBOX.getHeight() + (checkboxPadding.top
                    + checkboxPadding.bottom), fixedItemHeight);
            }
        }
    }
View Full Code Here

    }

    @Override
    @SuppressWarnings("unchecked")
    public void paint(Graphics2D graphics) {
        ListView listView = (ListView)getComponent();
        List<Object> listData = (List<Object>)listView.getListData();
        ListView.ItemRenderer itemRenderer = listView.getItemRenderer();

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

        // Paint the background
        if (backgroundColor != null) {
            graphics.setPaint(backgroundColor);
            graphics.fillRect(0, 0, width, height);
        }

        // Paint the list contents
        int itemStart = 0;
        int itemEnd = listData.getLength() - 1;

        // Ensure that we only paint items that are visible
        Rectangle clipBounds = graphics.getClipBounds();
        if (clipBounds != null) {
            if (variableItemHeight) {
                itemStart = getItemAt(clipBounds.y);
                itemEnd = getItemAt(clipBounds.y + clipBounds.height - 1);
            } else {
                itemStart = Math.max(itemStart, (int)Math.floor(clipBounds.y
                    / (double)fixedItemHeight));
                itemEnd = Math.min(itemEnd, (int)Math.ceil((clipBounds.y
                    + clipBounds.height) / (double)fixedItemHeight) - 1);
            }
        }

        int itemY;
        if (variableItemHeight) {
            itemY = itemHeights.get(itemStart);
        } else {
            itemY = itemStart * fixedItemHeight;
        }

        for (int itemIndex = itemStart; itemIndex <= itemEnd; itemIndex++) {
            Object item = listData.get(itemIndex);
            boolean highlighted = (itemIndex == highlightedIndex
                && listView.getSelectMode() != ListView.SelectMode.NONE);
            boolean selected = listView.isItemSelected(itemIndex);
            boolean disabled = listView.isItemDisabled(itemIndex);
            int itemHeight;
            if (variableItemHeight) {
                itemHeight = itemHeights.get(itemIndex + 1) - itemHeights.get(itemIndex);
            } else {
                itemHeight = fixedItemHeight;
            }

            Color itemBackgroundColor = null;

            if (selected) {
                itemBackgroundColor = (listView.isFocused())
                    ? this.selectionBackgroundColor : inactiveSelectionBackgroundColor;
            } else {
                if (highlighted && showHighlight && !disabled) {
                    itemBackgroundColor = highlightBackgroundColor;
                }
            }

            if (itemBackgroundColor != null) {
                graphics.setPaint(itemBackgroundColor);
                graphics.fillRect(0, itemY, width, itemHeight);
            }

            int itemX = 0;
            int itemWidth = width;

            boolean checked = false;
            if (listView.getCheckmarksEnabled()) {
                checked = listView.isItemChecked(itemIndex);

                int checkboxY = (itemHeight - CHECKBOX.getHeight()) / 2;
                Graphics2D checkboxGraphics = (Graphics2D)graphics.create(checkboxPadding.left,
                    itemY + checkboxY, CHECKBOX.getWidth(), CHECKBOX.getHeight());

                CHECKBOX.setSelected(checked);
                CHECKBOX.setEnabled(!disabled && !listView.isCheckmarkDisabled(itemIndex));
                CHECKBOX.paint(checkboxGraphics);
                checkboxGraphics.dispose();

                itemX = CHECKBOX.getWidth() + (checkboxPadding.left
                    + checkboxPadding.right);
View Full Code Here

    public int getItemAt(int y) {
        if (y < 0) {
            throw new IllegalArgumentException("y is negative");
        }

        ListView listView = (ListView)getComponent();

        int index;
        if (variableItemHeight) {
            index = ArrayList.binarySearch(itemHeights, y);
            if (index < 0) {
                index = -index - 2;
            }
        } else {
            index = (y / fixedItemHeight);
        }

        List<Object> listData = (List<Object>)listView.getListData();
        if (index >= listData.getLength()) {
            index = -1;
        }

        return index;
View Full Code Here

    @Override
    public int getItemIndent() {
        int itemIndent = 0;

        ListView listView = (ListView)getComponent();
        if (listView.getCheckmarksEnabled()) {
            itemIndent = CHECKBOX.getWidth() + checkboxPadding.left + checkboxPadding.right;
        }

        return itemIndent;
    }
View Full Code Here

        return itemHeight;
    }

    @Override
    public boolean isFocusable() {
        ListView listView = (ListView)getComponent();
        return (listView.getSelectMode() != ListView.SelectMode.NONE);
    }
View Full Code Here

    @Override
    public boolean mouseMove(Component component, int x, int y) {
        boolean consumed = super.mouseMove(component, x, y);

        ListView listView = (ListView)getComponent();

        int previousHighlightedIndex = this.highlightedIndex;
        highlightedIndex = getItemAt(y);

        if (previousHighlightedIndex != highlightedIndex
            && listView.getSelectMode() != ListView.SelectMode.NONE
            && showHighlight) {
            if (previousHighlightedIndex != -1) {
                repaintComponent(getItemBounds(previousHighlightedIndex));
            }
View Full Code Here

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

        ListView listView = (ListView)getComponent();

        if (highlightedIndex != -1
            && listView.getSelectMode() != ListView.SelectMode.NONE
            && showHighlight) {
            Bounds itemBounds = getItemBounds(highlightedIndex);
            repaintComponent(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
        }
View Full Code Here

    @Override
    @SuppressWarnings("unchecked")
    public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
        boolean consumed = super.mouseDown(component, button, x, y);

        ListView listView = (ListView)getComponent();
        List<Object> listData = (List<Object>)listView.getListData();

        int itemIndex = getItemAt(y);

        if (itemIndex != -1
            && itemIndex < listData.getLength()
            && !listView.isItemDisabled(itemIndex)) {
            int itemY = getItemBounds(itemIndex).y;

            if (!(listView.getCheckmarksEnabled()
                && x > checkboxPadding.left
                && x < checkboxPadding.left + CHECKBOX.getWidth()
                && y > itemY + checkboxPadding.top
                && y < itemY + checkboxPadding.top + CHECKBOX.getHeight())) {
                ListView.SelectMode selectMode = listView.getSelectMode();

                if (button == Mouse.Button.RIGHT) {
                    if (!listView.isItemSelected(itemIndex)
                        && selectMode != ListView.SelectMode.NONE) {
                        listView.setSelectedIndex(itemIndex);
                    }
                } else {
                    Keyboard.Modifier commandModifier = Platform.getCommandModifier();

                    if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
                        && selectMode == ListView.SelectMode.MULTI) {
                        Filter<?> disabledItemFilter = listView.getDisabledItemFilter();

                        if (disabledItemFilter == null) {
                            // Select the range
                            ArrayList<Span> selectedRanges = new ArrayList<Span>();
                            int startIndex = listView.getFirstSelectedIndex();
                            int endIndex = listView.getLastSelectedIndex();

                            Span selectedRange = (itemIndex > startIndex) ?
                                new Span(startIndex, itemIndex) : new Span(itemIndex, endIndex);
                            selectedRanges.add(selectedRange);

                            listView.setSelectedRanges(selectedRanges);
                        }
                    } else if (Keyboard.isPressed(commandModifier)
                        && selectMode == ListView.SelectMode.MULTI) {
                        // Toggle the item's selection state
                        if (listView.isItemSelected(itemIndex)) {
                            listView.removeSelectedIndex(itemIndex);
                        } else {
                            listView.addSelectedIndex(itemIndex);
                        }
                    } else {
                        if (selectMode != ListView.SelectMode.NONE) {
                            if (listView.isItemSelected(itemIndex)
                                && listView.isFocused()) {
                                // Edit the item
                                editIndex = itemIndex;
                            }

                            // Select the item
                            listView.setSelectedIndex(itemIndex);
                        }
                    }
                }
            }
        }

        listView.requestFocus();

        return consumed;
    }
View Full Code Here

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

        ListView listView = (ListView)getComponent();

        List<Object> listData = (List<Object>)listView.getListData();

        int itemIndex = getItemAt(y);

        if (itemIndex < listData.getLength()
            && !listView.isItemDisabled(itemIndex)) {
            int itemY = getItemBounds(itemIndex).y;

            if (listView.getCheckmarksEnabled()
                && !listView.isCheckmarkDisabled(itemIndex)
                && x > checkboxPadding.left
                && x < checkboxPadding.left + CHECKBOX.getWidth()
                && y > itemY + checkboxPadding.top
                && y < itemY + checkboxPadding.top + CHECKBOX.getHeight()) {
                listView.setItemChecked(itemIndex, !listView.isItemChecked(itemIndex));
            } else {
                if (editIndex != -1
                    && count == 1) {
                    ListView.ItemEditor itemEditor = listView.getItemEditor();

                    if (itemEditor != null) {
                        itemEditor.editItem(listView, editIndex);
                    }
                }
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.ListView$ItemRenderer

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.