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);
}
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;
}
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;
}
Aggregations