Search in sources :

Example 26 with ListView

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

the class TerraListViewSkin method mouseWheel.

@Override
public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount, int wheelRotation, int x, int y) {
    ListView listView = (ListView) getComponent();
    if (highlightIndex != -1) {
        Bounds itemBounds = getItemBounds(highlightIndex);
        highlightIndex = -1;
        if (listView.getSelectMode() != ListView.SelectMode.NONE && showHighlight) {
            repaintComponent(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height, true);
        }
    }
    return super.mouseWheel(component, scrollType, scrollAmount, wheelRotation, x, y);
}
Also used : ListView(org.apache.pivot.wtk.ListView) Bounds(org.apache.pivot.wtk.Bounds)

Example 27 with ListView

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

the class TerraListViewSkin method layout.

@Override
public void layout() {
    ListView listView = (ListView) getComponent();
    @SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
    ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
    if (variableItemHeight) {
        int width = getWidth();
        int checkboxHeight = 0;
        if (listView.getCheckmarksEnabled()) {
            checkboxHeight = CHECKBOX.getHeight() + checkboxPadding.getHeight();
        }
        int n = listData.getLength();
        itemBoundaries = new ArrayList<>(n);
        int itemY = 0;
        for (int i = 0; i < n; i++) {
            Object item = listData.get(i);
            int itemWidth = width;
            int itemX = 0;
            Button.State state = Button.State.UNSELECTED;
            if (listView.getCheckmarksEnabled()) {
                if (listView.getAllowTriStateCheckmarks()) {
                    state = listView.getItemCheckmarkState(i);
                } else {
                    state = listView.isItemChecked(i) ? Button.State.SELECTED : Button.State.UNSELECTED;
                }
                itemX = CHECKBOX.getWidth() + checkboxPadding.getWidth();
                itemWidth -= itemX;
            }
            itemRenderer.render(item, i, listView, false, state, false, false);
            int itemHeight = itemRenderer.getPreferredHeight(itemWidth);
            if (listView.getCheckmarksEnabled()) {
                itemHeight = Math.max(itemHeight, checkboxHeight);
            }
            itemY += itemHeight;
            itemBoundaries.add(itemY);
        }
    } else {
        itemRenderer.render(null, -1, listView, false, Button.State.UNSELECTED, false, false);
        fixedItemHeight = itemRenderer.getPreferredHeight(-1);
        if (listView.getCheckmarksEnabled()) {
            fixedItemHeight = Math.max(CHECKBOX.getHeight() + checkboxPadding.getHeight(), fixedItemHeight);
        }
    }
    if (validateSelection) {
        // Ensure that the selection is visible
        Sequence<Span> selectedRanges = listView.getSelectedRanges();
        if (selectedRanges.getLength() > 0) {
            int rangeStart = selectedRanges.get(0).start;
            int rangeEnd = selectedRanges.get(selectedRanges.getLength() - 1).end;
            Bounds selectionBounds = getItemBounds(rangeStart);
            selectionBounds = selectionBounds.union(getItemBounds(rangeEnd));
            Bounds visibleSelectionBounds = listView.getVisibleArea(selectionBounds);
            if (visibleSelectionBounds != null && visibleSelectionBounds.height < selectionBounds.height) {
                listView.scrollAreaToVisible(selectionBounds);
            }
        }
    }
    validateSelection = false;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Span(org.apache.pivot.wtk.Span) 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 28 with ListView

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

the class TerraListViewSkin method getBaseline.

@Override
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.getWidth()), 0);
    }
    ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
    @SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
    if (variableItemHeight && listData.getLength() > 0) {
        itemRenderer.render(listData.get(0), 0, listView, false, Button.State.UNSELECTED, false, false);
        int itemHeight = itemRenderer.getPreferredHeight(clientWidth);
        if (listView.getCheckmarksEnabled()) {
            itemHeight = Math.max(CHECKBOX.getHeight() + checkboxPadding.getHeight(), itemHeight);
        }
        baseline = itemRenderer.getBaseline(clientWidth, itemHeight);
    } else {
        itemRenderer.render(null, -1, listView, false, Button.State.UNSELECTED, false, false);
        int fixedItemHeightLocal = itemRenderer.getPreferredHeight(-1);
        if (listView.getCheckmarksEnabled()) {
            fixedItemHeightLocal = Math.max(CHECKBOX.getHeight() + checkboxPadding.getHeight(), fixedItemHeightLocal);
        }
        baseline = itemRenderer.getBaseline(clientWidth, fixedItemHeightLocal);
    }
    return baseline;
}
Also used : ListView(org.apache.pivot.wtk.ListView) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List)

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