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