Search in sources :

Example 6 with TableViewHeader

use of org.apache.pivot.wtk.TableViewHeader 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 7 with TableViewHeader

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

the class TerraTableViewHeaderSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    int baseline = -1;
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        ArrayList<Integer> headerWidthsLocal = TerraTableViewSkin.getColumnWidths(tableView, width);
        int rowHeight = getPreferredHeight(width) - 1;
        TableView.ColumnSequence columns = tableView.getColumns();
        for (int i = 0, n = columns.getLength(); i < n; i++) {
            TableView.Column column = columns.get(i);
            TableView.HeaderDataRenderer headerDataRenderer = column.getHeaderDataRenderer();
            headerDataRenderer.render(column.getHeaderData(), i, tableViewHeader, column.getName(), false);
            baseline = Math.max(baseline, headerDataRenderer.getBaseline(headerWidthsLocal.get(i).intValue(), rowHeight));
        }
    }
    return baseline;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

Example 8 with TableViewHeader

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

the class TerraTableViewHeaderSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        preferredWidth = TerraTableViewSkin.getPreferredWidth(tableView, includeTrailingVerticalGridLine);
    }
    return preferredWidth;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

Example 9 with TableViewHeader

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

the class TerraTableViewHeaderSkin method mouseClick.

@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
    boolean consumed = super.mouseClick(component, button, x, y, count);
    if (button == Mouse.Button.LEFT) {
        TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
        TableView tableView = tableViewHeader.getTableView();
        if (resizeHeaderIndex != -1) {
            TableView.Column column = tableView.getColumns().get(resizeHeaderIndex);
            if (count == 2 && !column.isRelative() && column.getWidth() != -1) {
                // Size the column to fit its contents
                int columnWidth = 0;
                TableView.CellRenderer cellRenderer = column.getCellRenderer();
                List<?> tableData = tableView.getTableData();
                int rowIndex = 0;
                for (Object rowData : tableData) {
                    cellRenderer.render(rowData, rowIndex++, resizeHeaderIndex, tableView, column.getName(), false, false, false);
                    columnWidth = Math.max(cellRenderer.getPreferredWidth(-1), columnWidth);
                }
                column.setWidth(columnWidth);
            }
        } else if (pressedHeaderIndex != -1) {
            // Press the header
            tableViewHeader.pressHeader(pressedHeaderIndex);
            // Update the sort
            TableViewHeader.SortMode sortMode = tableViewHeader.getSortMode();
            if (sortMode != TableViewHeader.SortMode.NONE) {
                TableView.Column column = tableView.getColumns().get(pressedHeaderIndex);
                String columnName = column.getName();
                SortDirection sortDirection = tableView.getSort().get(columnName);
                if (sortDirection == null) {
                    sortDirection = SortDirection.ASCENDING;
                } else if (sortDirection == SortDirection.ASCENDING) {
                    sortDirection = SortDirection.DESCENDING;
                } else {
                    sortDirection = SortDirection.ASCENDING;
                }
                if (sortMode == TableViewHeader.SortMode.MULTI_COLUMN && Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
                    tableView.getSort().put(columnName, sortDirection);
                } else {
                    tableView.setSort(columnName, sortDirection);
                }
                consumed = true;
            }
        }
        resizeHeaderIndex = -1;
        pressedHeaderIndex = -1;
    }
    return consumed;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) SortDirection(org.apache.pivot.wtk.SortDirection) SortMode(org.apache.pivot.wtk.TableViewHeader.SortMode) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

Example 10 with TableViewHeader

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

the class TerraTableViewHeaderSkin method layout.

@Override
public void layout() {
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        headerWidths = TerraTableViewSkin.getColumnWidths(tableView, getWidth());
    } else {
        headerWidths = null;
    }
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) TableView(org.apache.pivot.wtk.TableView)

Aggregations

TableView (org.apache.pivot.wtk.TableView)11 TableViewHeader (org.apache.pivot.wtk.TableViewHeader)11 GradientPaint (java.awt.GradientPaint)9 Bounds (org.apache.pivot.wtk.Bounds)3 SortDirection (org.apache.pivot.wtk.SortDirection)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Line2D (java.awt.geom.Line2D)1 SortMode (org.apache.pivot.wtk.TableViewHeader.SortMode)1 Image (org.apache.pivot.wtk.media.Image)1