Search in sources :

Example 21 with Bounds

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);
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) TableView(org.apache.pivot.wtk.TableView)

Example 22 with Bounds

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;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Span(org.apache.pivot.wtk.Span) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) TableView(org.apache.pivot.wtk.TableView)

Example 23 with Bounds

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;
    }
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 24 with Bounds

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);
        }
    }
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 25 with Bounds

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;
}
Also used : Shape(java.awt.Shape) Bounds(org.apache.pivot.wtk.Bounds) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

Bounds (org.apache.pivot.wtk.Bounds)77 Point (org.apache.pivot.wtk.Point)21 GradientPaint (java.awt.GradientPaint)15 Color (java.awt.Color)10 Graphics2D (java.awt.Graphics2D)9 Rectangle (java.awt.Rectangle)7 TableView (org.apache.pivot.wtk.TableView)7 BasicStroke (java.awt.BasicStroke)6 GeneralPath (java.awt.geom.GeneralPath)5 Button (org.apache.pivot.wtk.Button)5 Component (org.apache.pivot.wtk.Component)5 Span (org.apache.pivot.wtk.Span)5 TextArea (org.apache.pivot.wtk.TextArea)5 TextPane (org.apache.pivot.wtk.TextPane)5 FontRenderContext (java.awt.font.FontRenderContext)4 LineMetrics (java.awt.font.LineMetrics)4 Area (java.awt.geom.Area)4 RoundRectangle2D (java.awt.geom.RoundRectangle2D)4 ArrayList (org.apache.pivot.collections.ArrayList)4 ScrollPane (org.apache.pivot.wtk.ScrollPane)4