Search in sources :

Example 86 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class TableCellPainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
    if (this.paintBg) {
        super.paintCell(cell, gc, bounds, configRegistry);
    }
    Object[] cellDataArray = getDataAsArray(cell);
    if (cellDataArray != null) {
        // iterate over all values in the collection and render them
        // separately by creating temporary sub cells
        // and adding grid lines for the sub cells
        int subGridY = bounds.y;
        if (cellDataArray != null) {
            Color originalColor = gc.getForeground();
            for (int i = 0; i < cellDataArray.length; i++) {
                ILayerCell subCell = createSubLayerCell(cell, cellDataArray[i]);
                int subCellHeight = getSubCellHeight(subCell, gc, configRegistry);
                Rectangle subCellBounds = new Rectangle(bounds.x, subGridY, bounds.width, subCellHeight);
                this.getInternalPainter().paintCell(subCell, gc, subCellBounds, configRegistry);
                // render sub grid line
                // update subGridY for calculated height
                subGridY += subCellHeight + 1;
                gc.setForeground(cell.getDisplayMode().equals(DisplayMode.SELECT) ? getSelectedGridColor() : getGridColor());
                gc.drawLine(bounds.x, subGridY, bounds.x + bounds.width, subGridY);
                gc.setForeground(originalColor);
                // increase subGridY by 1 so the next sub cell renders below
                subGridY += 1;
            }
            // perform resize if necessary
            int neededHeight = subGridY - bounds.y;
            if (isCalculateParentCellHeight() && (neededHeight > cell.getBounds().height)) {
                ILayer layer = cell.getLayer();
                layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), neededHeight, true));
            }
        }
    } else {
        this.getInternalPainter().paintCell(cell, gc, bounds, configRegistry);
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) RowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)

Example 87 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class TextPainter method setNewMinLength.

@Override
protected void setNewMinLength(ILayerCell cell, int contentWidth) {
    int cellLength = cell.getBounds().width;
    if (cellLength < contentWidth) {
        // execute ColumnResizeCommand
        ILayer layer = cell.getLayer();
        layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth, true));
    }
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Example 88 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class VerticalTextImagePainter method setNewMinLength.

@Override
protected void setNewMinLength(ILayerCell cell, int contentHeight) {
    int cellLength = cell.getBounds().height;
    if (cellLength < contentHeight) {
        ILayer layer = cell.getLayer();
        layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight, true));
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) RowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)

Example 89 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class VerticalTextImagePainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    if (this.paintBg) {
        super.paintCell(cell, gc, rectangle, configRegistry);
    }
    Rectangle originalClipping = gc.getClipping();
    gc.setClipping(rectangle.intersection(originalClipping));
    IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
    setupGCFromConfig(gc, cellStyle);
    boolean underline = renderUnderlined(cellStyle);
    boolean strikethrough = renderStrikethrough(cellStyle);
    String text = convertDataType(cell, configRegistry);
    // calculate the text to display, adds dots if the text is longer than
    // the available row height and adds new lines instead of spaces if word
    // wrapping is enabled
    text = getTextToDisplay(cell, gc, rectangle.height, text);
    int numberOfNewLines = getNumberOfNewLines(text);
    // if the content width is bigger than the available column width
    // we're extending the column width (only if word wrapping is enabled)
    int fontHeight = gc.getFontMetrics().getHeight();
    int contentWidth = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
    int contentToCellDiff = (cell.getBounds().width - rectangle.width);
    if ((contentWidth > rectangle.width) && this.calculateByTextHeight) {
        ILayer layer = cell.getLayer();
        layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
    }
    if (text != null && text.length() > 0) {
        if (numberOfNewLines == 1) {
            int contentHeight = Math.min(getLengthFromCache(gc, text), rectangle.height);
            GraphicsUtils.drawVerticalText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight + this.spacing), underline, strikethrough, this.paintBg, gc, SWT.UP);
        } else {
            // draw every line by itself because of the alignment, otherwise
            // the whole text is always aligned right
            int xStartPos = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth);
            // $NON-NLS-1$
            String[] lines = text.split("\n");
            for (String line : lines) {
                int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.height);
                GraphicsUtils.drawVerticalText(line, xStartPos + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth + this.spacing), underline, strikethrough, this.paintBg, gc, SWT.UP);
                // after every line calculate the x start pos new
                xStartPos += fontHeight;
                xStartPos += this.lineSpacing;
            }
        }
    }
    gc.setClipping(originalClipping);
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 90 with ILayer

use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.

the class CellLayerPainter method paintCell.

protected void paintCell(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
    ILayer layer = cell.getLayer();
    int columnPosition = cell.getColumnPosition();
    int rowPosition = cell.getRowPosition();
    ICellPainter cellPainter = layer.getCellPainter(columnPosition, rowPosition, cell, configRegistry);
    Rectangle adjustedCellBounds = layer.getLayerPainter().adjustCellBounds(columnPosition, rowPosition, cell.getBounds());
    if (cellPainter != null) {
        Rectangle originalClipping = gc.getClipping();
        int startX = getStartXOfColumnPosition(columnPosition);
        int startY = getStartYOfRowPosition(rowPosition);
        int endX = getStartXOfColumnPosition(cell.getOriginColumnPosition() + cell.getColumnSpan());
        int endY = getStartYOfRowPosition(cell.getOriginRowPosition() + cell.getRowSpan());
        Rectangle cellClipBounds = originalClipping.intersection(new Rectangle(startX, startY, endX - startX, endY - startY));
        gc.setClipping(cellClipBounds.intersection(adjustedCellBounds));
        cellPainter.paintCell(cell, gc, adjustedCellBounds, configRegistry);
        gc.setClipping(originalClipping);
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Aggregations

ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)127 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)91 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)90 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)82 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)73 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)71 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)68 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)68 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)67 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)67 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)64 HashMap (java.util.HashMap)62 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)60 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)58 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)58 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)53 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)48 GridLayout (org.eclipse.swt.layout.GridLayout)35 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)34 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)33