use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraTableViewSkin method getCellBounds.
@Override
public Bounds getCellBounds(int rowIndex, int columnIndex) {
TableView tableView = (TableView) getComponent();
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
Utils.checkZeroBasedIndex(rowIndex, tableData.getLength());
int cellX = 0;
for (int i = 0; i < columnIndex; i++) {
cellX += (columnWidths.get(i).intValue() + 1);
}
int rowHeight = getRowHeight(rowIndex);
return new Bounds(cellX, rowIndex * (rowHeight + 1), columnWidths.get(columnIndex).intValue(), rowHeight);
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraTableViewSkin method layout.
@Override
public void layout() {
columnWidths = getColumnWidths((TableView) getComponent(), getWidth());
TableView tableView = (TableView) getComponent();
TableView.ColumnSequence columns = tableView.getColumns();
if (variableRowHeight) {
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
int n = tableData.getLength();
rowBoundaries = new ArrayList<>(n);
int rowY = 0;
for (int i = 0; i < n; i++) {
Object rowData = tableData.get(i);
int rowHeight = 0;
for (int columnIndex = 0, columnCount = columns.getLength(); columnIndex < columnCount; columnIndex++) {
TableView.Column column = columns.get(columnIndex);
TableView.CellRenderer cellRenderer = column.getCellRenderer();
int columnWidth = columnWidths.get(columnIndex).intValue();
cellRenderer.render(rowData, i, columnIndex, tableView, column.getName(), false, false, false);
rowHeight = Math.max(rowHeight, cellRenderer.getPreferredHeight(columnWidth));
}
rowY += rowHeight;
rowBoundaries.add(Integer.valueOf(rowY));
rowY++;
}
} else {
fixedRowHeight = calculateFixedRowHeight(tableView);
}
if (validateSelection) {
// Ensure that the selection is visible
Sequence<Span> selectedRanges = tableView.getSelectedRanges();
if (selectedRanges.getLength() > 0) {
int rangeStart = selectedRanges.get(0).start;
int rangeEnd = selectedRanges.get(selectedRanges.getLength() - 1).end;
Bounds selectionBounds = getRowBounds(rangeStart);
selectionBounds = selectionBounds.union(getRowBounds(rangeEnd));
Bounds visibleSelectionBounds = tableView.getVisibleArea(selectionBounds);
if (visibleSelectionBounds != null && visibleSelectionBounds.height < selectionBounds.height) {
tableView.scrollAreaToVisible(selectionBounds);
}
}
}
validateSelection = false;
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraTableViewSkin method selectedRangeAdded.
// Table view selection detail events
@Override
public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
if (tableView.isValid()) {
Bounds selectionBounds = getRowBounds(rangeStart);
selectionBounds = selectionBounds.union(getRowBounds(rangeEnd));
repaintComponent(selectionBounds);
// Ensure that the selection is visible
Bounds visibleSelectionBounds = tableView.getVisibleArea(selectionBounds);
if (visibleSelectionBounds.height < selectionBounds.height) {
tableView.scrollAreaToVisible(selectionBounds);
}
} else {
validateSelection = true;
}
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraTextInputSkin method scrollCharacterToVisible.
private void scrollCharacterToVisible(int offset) {
int width = getWidth();
Bounds characterBounds = getCharacterBounds(offset);
if (characterBounds != null) {
int glyphX = characterBounds.x - (padding.left + 1) + scrollLeft;
if (characterBounds.x < padding.left + 1) {
setScrollLeft(glyphX);
} else if (characterBounds.x + characterBounds.width > width - (padding.right + 1)) {
setScrollLeft(glyphX + (padding.getWidth() + 2) + characterBounds.width - width);
}
}
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraTextInputSkin method getCharacterBounds.
/**
* Determine the bounding box of the character at the given index
* in the text in coordinates relative to the entire component (that is,
* adding in the insets and padding, etc.).
*
* @param index The 0-based index of the character to inquire about.
* @return The bounding box within the component where that character
* will be displayed, or {@code null} if there is no text.
*/
@Override
public Bounds getCharacterBounds(int index) {
Bounds characterBounds = null;
if (textLayout != null) {
int x, width;
if (index < textLayout.getCharacterCount()) {
Shape glyphShape = textLayout.getLogicalHighlightShape(index, index + 1);
Rectangle2D glyphBounds2D = glyphShape.getBounds2D();
x = (int) Math.floor(glyphBounds2D.getX());
width = (int) Math.ceil(glyphBounds2D.getWidth());
} else {
// This is the terminator character
x = getTextWidth(textLayout);
width = 0;
}
characterBounds = new Bounds(x + padding.left - scrollLeft + 1 + getAlignmentDeltaX(textLayout), padding.top + 1, width, getHeight() - (padding.getHeight() + 2));
}
return characterBounds;
}
Aggregations