Search in sources :

Example 11 with ListView

use of org.apache.pivot.wtk.ListView in project pivot by apache.

the class TerraListViewSkin method getItemAt.

// List view skin methods
@Override
public int getItemAt(int y) {
    Utils.checkNonNegative(y, "y");
    ListView listView = (ListView) getComponent();
    int index;
    if (variableItemHeight) {
        if (y == 0) {
            index = 0;
        } else {
            index = ArrayList.binarySearch(itemBoundaries, y);
            if (index < 0) {
                index = -(index + 1);
            }
        }
    } else {
        index = (y / fixedItemHeight);
        @SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
        if (index >= listData.getLength()) {
            index = -1;
        }
    }
    return index;
}
Also used : ListView(org.apache.pivot.wtk.ListView) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List)

Example 12 with ListView

use of org.apache.pivot.wtk.ListView in project pivot by apache.

the class TerraListViewSkin method getItemIndent.

@Override
public int getItemIndent() {
    int itemIndent = 0;
    ListView listView = (ListView) getComponent();
    if (listView.getCheckmarksEnabled()) {
        itemIndent = CHECKBOX.getWidth() + checkboxPadding.getWidth();
    }
    return itemIndent;
}
Also used : ListView(org.apache.pivot.wtk.ListView)

Example 13 with ListView

use of org.apache.pivot.wtk.ListView in project pivot by apache.

the class TerraListViewSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    ListView listView = (ListView) getComponent();
    @SuppressWarnings("unchecked") 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);
            if (itemStart == -1) {
                itemStart = listData.getLength();
            }
            if (itemEnd != -1) {
                int clipBottom = clipBounds.y + clipBounds.height - 1;
                clipBottom = Math.min(clipBottom, itemBoundaries.get(itemEnd) - 1);
                itemEnd = getItemAt(clipBottom);
            }
        } 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);
        }
    }
    // Paint the item background
    if (alternateItemBackgroundColor != null) {
        for (int itemIndex = itemStart; itemIndex <= itemEnd; itemIndex++) {
            int itemY = getItemY(itemIndex);
            int rowHeight = getItemHeight(itemIndex);
            if (itemIndex % 2 > 0) {
                graphics.setPaint(alternateItemBackgroundColor);
                graphics.fillRect(0, itemY, width, rowHeight + 1);
            }
        }
    }
    // Paint the item content
    for (int itemIndex = itemStart; itemIndex <= itemEnd; itemIndex++) {
        Object item = listData.get(itemIndex);
        boolean highlighted = (itemIndex == highlightIndex && listView.getSelectMode() != ListView.SelectMode.NONE);
        boolean selected = listView.isItemSelected(itemIndex);
        boolean disabled = listView.isItemDisabled(itemIndex);
        int itemY = getItemY(itemIndex);
        int itemHeight = getItemHeight(itemIndex);
        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;
        Button.State state = Button.State.UNSELECTED;
        if (listView.getCheckmarksEnabled()) {
            if (listView.getAllowTriStateCheckmarks()) {
                state = listView.getItemCheckmarkState(itemIndex);
            } else {
                state = listView.isItemChecked(itemIndex) ? Button.State.SELECTED : Button.State.UNSELECTED;
            }
            int checkboxY = (itemHeight - CHECKBOX.getHeight()) / 2;
            Graphics2D checkboxGraphics = (Graphics2D) graphics.create(checkboxPadding.left, itemY + checkboxY, CHECKBOX.getWidth(), CHECKBOX.getHeight());
            CHECKBOX.setEnabled(!disabled && !listView.isCheckmarkDisabled(itemIndex));
            if (listView.getAllowTriStateCheckmarks()) {
                CHECKBOX.setTriState(true);
                CHECKBOX.setState(state);
            } else {
                CHECKBOX.setTriState(false);
                CHECKBOX.setSelected(state == Button.State.SELECTED);
            }
            CHECKBOX.paint(checkboxGraphics);
            checkboxGraphics.dispose();
            itemX = CHECKBOX.getWidth() + checkboxPadding.getWidth();
            itemWidth -= itemX;
        }
        // Paint the data
        Graphics2D rendererGraphics = (Graphics2D) graphics.create(itemX, itemY, itemWidth, itemHeight);
        itemRenderer.render(item, itemIndex, listView, selected, state, highlighted, disabled);
        itemRenderer.setSize(itemWidth, itemHeight);
        itemRenderer.paint(rendererGraphics);
        rendererGraphics.dispose();
        itemY += itemHeight;
    }
}
Also used : Color(java.awt.Color) Rectangle(java.awt.Rectangle) Graphics2D(java.awt.Graphics2D) ListView(org.apache.pivot.wtk.ListView) Button(org.apache.pivot.wtk.Button) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List)

Example 14 with ListView

use of org.apache.pivot.wtk.ListView in project pivot by apache.

the class TerraListViewSkin method mouseUp.

@Override
public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
    boolean consumed = super.mouseUp(component, button, x, y);
    ListView listView = (ListView) getComponent();
    if (selectIndex != -1 && listView.getFirstSelectedIndex() != listView.getLastSelectedIndex()) {
        listView.setSelectedIndex(selectIndex);
        selectIndex = -1;
    }
    return consumed;
}
Also used : ListView(org.apache.pivot.wtk.ListView)

Example 15 with ListView

use of org.apache.pivot.wtk.ListView in project pivot by apache.

the class TerraListViewSkin method mouseOut.

@Override
public void mouseOut(Component component) {
    super.mouseOut(component);
    ListView listView = (ListView) getComponent();
    if (highlightIndex != -1 && listView.getSelectMode() != ListView.SelectMode.NONE && showHighlight) {
        Bounds itemBounds = getItemBounds(highlightIndex);
        repaintComponent(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
    }
    highlightIndex = -1;
    selectIndex = -1;
}
Also used : ListView(org.apache.pivot.wtk.ListView) Bounds(org.apache.pivot.wtk.Bounds)

Aggregations

ListView (org.apache.pivot.wtk.ListView)28 ArrayList (org.apache.pivot.collections.ArrayList)10 Button (org.apache.pivot.wtk.Button)10 List (org.apache.pivot.collections.List)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 PushButton (org.apache.pivot.wtk.PushButton)6 Span (org.apache.pivot.wtk.Span)6 ListViewSelectionListener (org.apache.pivot.wtk.ListViewSelectionListener)4 Sheet (org.apache.pivot.wtk.Sheet)4 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)4 File (java.io.File)3 Bounds (org.apache.pivot.wtk.Bounds)3 BoxPane (org.apache.pivot.wtk.BoxPane)3 Component (org.apache.pivot.wtk.Component)3 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)3 Frame (org.apache.pivot.wtk.Frame)3 Color (java.awt.Color)2 IOException (java.io.IOException)2 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 Sequence (org.apache.pivot.collections.Sequence)2