Search in sources :

Example 6 with ILayer

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

the class TextPainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    if (this.paintBg) {
        super.paintCell(cell, gc, rectangle, configRegistry);
    }
    if (this.paintFg) {
        Rectangle originalClipping = gc.getClipping();
        gc.setClipping(rectangle.intersection(originalClipping));
        IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
        setupGCFromConfig(gc, cellStyle);
        int fontHeight = gc.getFontMetrics().getHeight();
        String text = convertDataType(cell, configRegistry);
        // Draw Text
        text = getTextToDisplay(cell, gc, rectangle.width, text);
        int numberOfNewLines = getNumberOfNewLines(text);
        // if the content height is bigger than the available row height
        // we're extending the row height (only if word wrapping is enabled)
        int contentHeight = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
        int contentToCellDiff = (cell.getBounds().height - rectangle.height);
        if (performRowResize(contentHeight, rectangle)) {
            ILayer layer = cell.getLayer();
            layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff, true));
        }
        if (numberOfNewLines == 1) {
            int contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.width);
            gc.drawText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
            // start x of line = start x of text
            int x = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing;
            // y = start y of text
            int y = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
            int length = gc.textExtent(text).x;
            paintDecoration(cellStyle, gc, x, y, length, fontHeight);
        } else {
            // draw every line by itself because of the alignment, otherwise
            // the whole text is always aligned right
            int yStartPos = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight);
            // $NON-NLS-1$
            String[] lines = text.split("\n");
            for (String line : lines) {
                int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.width);
                gc.drawText(line, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + this.spacing, yStartPos + this.spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
                // start x of line = start x of text
                int x = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + this.spacing;
                // y = start y of text
                int y = yStartPos + this.spacing;
                int length = gc.textExtent(line).x;
                paintDecoration(cellStyle, gc, x, y, length, fontHeight);
                // after every line calculate the y start pos new
                yStartPos += fontHeight;
                yStartPos += this.lineSpacing;
            }
        }
        gc.setClipping(originalClipping);
        resetGC(gc);
    }
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle) RowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)

Example 7 with ILayer

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

the class VerticalTextPainter 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 8 with ILayer

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

the class VerticalTextPainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    if (this.paintBg) {
        super.paintCell(cell, gc, rectangle, configRegistry);
    }
    if (this.paintFg) {
        Rectangle originalClipping = gc.getClipping();
        gc.setClipping(rectangle.intersection(originalClipping));
        IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
        setupGCFromConfig(gc, cellStyle);
        int fontHeight = gc.getFontMetrics().getHeight();
        String text = convertDataType(cell, configRegistry);
        // Draw Text
        text = getTextToDisplay(cell, gc, rectangle.height, text);
        int numberOfNewLines = getNumberOfNewLines(text);
        // if the content height is bigger than the available column width
        // we're extending the column width (only if word wrapping is
        // enabled)
        int contentHeight = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
        int contentToCellDiff = (cell.getBounds().width - rectangle.width);
        if ((contentHeight > rectangle.width) && this.calculateByTextHeight) {
            ILayer layer = cell.getLayer();
            layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentHeight + contentToCellDiff, true));
        }
        if (text != null && text.length() > 0) {
            Transform originalTransform = new Transform(gc.getDevice());
            gc.getTransform(originalTransform);
            Transform transform = new Transform(gc.getDevice());
            gc.getTransform(transform);
            if (numberOfNewLines == 1) {
                int contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.height);
                if (!isRotateClockwise()) {
                    transform.rotate(-90f);
                    int xOffset = -rectangle.x + (-contentWidth - rectangle.y) - CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentWidth);
                    int yOffset = rectangle.x + -rectangle.y + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
                    transform.translate(xOffset, yOffset);
                } else {
                    transform.rotate(90f);
                    int horizontalPadding = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight);
                    if (horizontalPadding != 0) {
                        horizontalPadding += gc.getFontMetrics().getLeading();
                    }
                    int xOffset = rectangle.y - rectangle.x + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentWidth);
                    int yOffset = -contentHeight - rectangle.y - rectangle.x - horizontalPadding + this.spacing;
                    transform.translate(xOffset, yOffset);
                }
                gc.setTransform(transform);
                gc.drawText(text, rectangle.x, rectangle.y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
                int length = gc.textExtent(text).x;
                paintDecoration(cellStyle, gc, rectangle.x, rectangle.y, length, fontHeight);
            } else {
                // draw every line by itself because of the alignment,
                // otherwise the whole text is always aligned right
                // $NON-NLS-1$
                String[] lines = text.split("\n");
                boolean firstline = true;
                int previousXOffset = 0;
                for (String line : lines) {
                    int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.height);
                    if (!isRotateClockwise()) {
                        int xOffset = -rectangle.x + (-lineContentWidth - rectangle.y) - CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth);
                        if (firstline) {
                            transform.rotate(-90f);
                            int yOffset = rectangle.x + -rectangle.y + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
                            transform.translate(xOffset, yOffset);
                            firstline = false;
                        } else {
                            transform.translate(xOffset - previousXOffset, fontHeight + this.lineSpacing);
                        }
                        previousXOffset = xOffset;
                    } else {
                        int xOffset = rectangle.y - rectangle.x + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth);
                        if (firstline) {
                            transform.rotate(90f);
                            int horizontalPadding = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight);
                            if (horizontalPadding != 0) {
                                horizontalPadding += gc.getFontMetrics().getLeading();
                            }
                            int yOffset = -contentHeight - rectangle.y - rectangle.x - horizontalPadding + this.spacing + (fontHeight * (numberOfNewLines - 1)) + (this.lineSpacing * (numberOfNewLines - 1));
                            transform.translate(xOffset, yOffset);
                            firstline = false;
                        } else {
                            transform.translate(xOffset - previousXOffset, -fontHeight - this.lineSpacing);
                        }
                        previousXOffset = xOffset;
                    }
                    gc.setTransform(transform);
                    gc.drawText(line, rectangle.x, rectangle.y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
                    int length = gc.textExtent(line).x;
                    paintDecoration(cellStyle, gc, rectangle.x, rectangle.y, length, fontHeight);
                }
            }
            gc.setTransform(originalTransform);
            if (originalTransform != null) {
                originalTransform.dispose();
            }
            if (transform != null) {
                transform.dispose();
            }
        }
        gc.setClipping(originalClipping);
        resetGC(gc);
    }
}
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) Transform(org.eclipse.swt.graphics.Transform)

Example 9 with ILayer

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

the class ColumnReorderLayer method populateIndexOrder.

/**
 * Initialize the internal column index ordering from a clean state, which
 * means it reflects the ordering from the underlying layer.
 */
private void populateIndexOrder() {
    this.columnIndexOrder.clear();
    ILayer underlyingLayer = getUnderlyingLayer();
    for (int columnPosition = 0; columnPosition < underlyingLayer.getColumnCount(); columnPosition++) {
        int index = underlyingLayer.getColumnIndexByPosition(columnPosition);
        this.columnIndexOrder.add(index);
        this.indexPositionMapping.put(index, columnPosition);
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Example 10 with ILayer

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

the class RowReorderLayer method populateIndexOrder.

/**
 * Initially populate the index order to the local cache.
 */
private void populateIndexOrder() {
    this.rowIndexOrder.clear();
    ILayer underlyingLayer = getUnderlyingLayer();
    for (int rowPosition = 0; rowPosition < underlyingLayer.getRowCount(); rowPosition++) {
        int index = underlyingLayer.getRowIndexByPosition(rowPosition);
        this.rowIndexOrder.add(index);
        this.indexPositionMapping.put(index, rowPosition);
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

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