Search in sources :

Example 6 with TableView

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

the class TerraTableViewHeaderSkin method getHeaderBounds.

@Override
public Bounds getHeaderBounds(int headerIndex) {
    Bounds headerBounds = null;
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        Utils.checkZeroBasedIndex(headerIndex, headerWidths.getLength());
        int cellX = 0;
        for (int i = 0; i < headerIndex; i++) {
            cellX += (headerWidths.get(i).intValue() + 1);
        }
        headerBounds = new Bounds(cellX, 0, headerWidths.get(headerIndex).intValue(), getHeight() - 1);
    }
    return headerBounds;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

Example 7 with TableView

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

the class TerraTableViewHeaderSkin method getHeaderAt.

@Override
public int getHeaderAt(int x) {
    Utils.checkNonNegative(x, "x");
    int headerIndex = -1;
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        int i = 0;
        int n = tableView.getColumns().getLength();
        int headerX = 0;
        while (i < n && x > headerX) {
            headerX += (headerWidths.get(i).intValue() + 1);
            i++;
        }
        if (x <= headerX) {
            headerIndex = i - 1;
        }
    }
    return headerIndex;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

Example 8 with TableView

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

the class TerraTableViewHeaderSkin method mouseMove.

@Override
public boolean mouseMove(Component component, int x, int y) {
    boolean consumed = super.mouseMove(component, x, y);
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        if (resizeHeaderIndex != -1 && Mouse.getCapturer() != tableViewHeader) {
            Mouse.capture(tableViewHeader);
        }
        if (Mouse.getCapturer() == tableViewHeader) {
            TableView.Column column = tableView.getColumns().get(resizeHeaderIndex);
            Bounds headerBounds = getHeaderBounds(resizeHeaderIndex);
            int columnWidth = Math.max(x - headerBounds.x, MINIMUM_COLUMN_WIDTH);
            column.setWidth(columnWidth, false);
        } else {
            int headerIndex = getHeaderAt(x);
            if (headerIndex != -1 && columnsResizable) {
                Bounds headerBounds = getHeaderBounds(headerIndex);
                TableView.Column column = tableView.getColumns().get(headerIndex);
                if (!column.isRelative() && column.getWidth() != -1 && x > headerBounds.x + headerBounds.width - RESIZE_HANDLE_SIZE) {
                    tableViewHeader.setCursor(Cursor.RESIZE_EAST);
                } else {
                    tableViewHeader.setCursor((Cursor) null);
                }
            } else {
                tableViewHeader.setCursor((Cursor) null);
            }
        }
    }
    return consumed;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

Example 9 with TableView

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

the class TerraTableViewHeaderSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    int width = getWidth();
    int height = getHeight();
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    Color backgroundColorLocal = null;
    Color bevelColorLocal = null;
    Color borderColorLocal = null;
    if (tableViewHeader.isEnabled()) {
        backgroundColorLocal = this.backgroundColor;
        bevelColorLocal = this.bevelColor;
        borderColorLocal = this.borderColor;
    } else {
        backgroundColorLocal = disabledBackgroundColor;
        bevelColorLocal = disabledBevelColor;
        borderColorLocal = disabledBorderColor;
    }
    // Paint the background
    if (!themeIsFlat()) {
        graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height, backgroundColorLocal));
    } else {
        graphics.setPaint(backgroundColorLocal);
    }
    graphics.fillRect(0, 0, width, height);
    // Paint the border
    if (!themeIsFlat()) {
        graphics.setPaint(borderColorLocal);
        graphics.setStroke(new BasicStroke(1));
        graphics.draw(new Line2D.Double(0.5, height - 0.5, width - 0.5, height - 0.5));
    }
    // Paint the content
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        TableView.ColumnSequence columns = tableView.getColumns();
        int headerX = 0;
        for (int columnIndex = 0, columnCount = columns.getLength(); columnIndex < columnCount; columnIndex++) {
            TableView.Column column = columns.get(columnIndex);
            int headerWidth = headerWidths.get(columnIndex).intValue();
            // Paint the pressed bevel
            if (columnIndex == pressedHeaderIndex) {
                graphics.setPaint(new GradientPaint(width / 2f, 0, pressedBevelColor, width / 2f, height, backgroundColorLocal));
                graphics.fillRect(headerX, 0, headerWidth, height - 1);
            }
            // Paint the header data
            Object headerData = column.getHeaderData();
            TableView.HeaderDataRenderer headerDataRenderer = column.getHeaderDataRenderer();
            headerDataRenderer.render(headerData, columnIndex, tableViewHeader, column.getName(), false);
            headerDataRenderer.setSize(headerWidth, height - 1);
            Graphics2D rendererGraphics = (Graphics2D) graphics.create(headerX, 0, headerWidth, height - 1);
            headerDataRenderer.paint(rendererGraphics);
            rendererGraphics.dispose();
            // Draw the sort image
            Image sortImage = null;
            String columnName = column.getName();
            SortDirection sortDirection = tableView.getSort().get(columnName);
            if (sortDirection != null) {
                switch(sortDirection) {
                    case ASCENDING:
                        {
                            sortImage = sortAscendingImage;
                            break;
                        }
                    case DESCENDING:
                        {
                            sortImage = sortDescendingImage;
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }
            if (sortImage != null) {
                int sortImageMargin = sortImage.getWidth() + SORT_INDICATOR_PADDING * 2;
                if (headerWidth >= headerDataRenderer.getPreferredWidth(-1) + sortImageMargin) {
                    Graphics2D sortImageGraphics = (Graphics2D) graphics.create();
                    sortImageGraphics.translate(headerX + headerWidth - sortImageMargin, (height - sortImage.getHeight()) / 2);
                    sortImage.paint(sortImageGraphics);
                    sortImageGraphics.dispose();
                }
            }
            // Draw the divider
            headerX += headerWidth;
            if (columnIndex < columnCount - 1 || includeTrailingVerticalGridLine) {
                if (!themeIsFlat()) {
                    graphics.setPaint(borderColorLocal);
                    graphics.draw(new Line2D.Double(headerX + 0.5, 0.5, headerX + 0.5, height - 0.5));
                }
            }
            headerX++;
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) GradientPaint(java.awt.GradientPaint) Image(org.apache.pivot.wtk.media.Image) Line2D(java.awt.geom.Line2D) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D) TableViewHeader(org.apache.pivot.wtk.TableViewHeader) SortDirection(org.apache.pivot.wtk.SortDirection) TableView(org.apache.pivot.wtk.TableView)

Example 10 with TableView

use of org.apache.pivot.wtk.TableView 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)

Aggregations

TableView (org.apache.pivot.wtk.TableView)36 ArrayList (org.apache.pivot.collections.ArrayList)12 List (org.apache.pivot.collections.List)11 TableViewHeader (org.apache.pivot.wtk.TableViewHeader)11 GradientPaint (java.awt.GradientPaint)9 Bounds (org.apache.pivot.wtk.Bounds)7 Span (org.apache.pivot.wtk.Span)6 TableViewSelectionListener (org.apache.pivot.wtk.TableViewSelectionListener)5 TableViewSortListener (org.apache.pivot.wtk.TableViewSortListener)5 IOException (java.io.IOException)4 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)4 Component (org.apache.pivot.wtk.Component)4 Keyboard (org.apache.pivot.wtk.Keyboard)4 SerializationException (org.apache.pivot.serialization.SerializationException)3 Button (org.apache.pivot.wtk.Button)3 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)3 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)3 Container (org.apache.pivot.wtk.Container)3 ListButton (org.apache.pivot.wtk.ListButton)3 ListButtonSelectionListener (org.apache.pivot.wtk.ListButtonSelectionListener)3