Search in sources :

Example 1 with BorderCell

use of org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.BorderCell in project nebula.widgets.nattable by eclipse.

the class FillHandleLayerPainter method paintLayer.

@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
    Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
    int columnPositionOffset = positionRectangle.x;
    int rowPositionOffset = positionRectangle.y;
    super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
    ILayerCell fillHandleCell = null;
    BorderCell[][] borderCells = new BorderCell[positionRectangle.height][positionRectangle.width];
    boolean atLeastOne = false;
    for (int columnPosition = columnPositionOffset, ix = 0; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++, ix++) {
        for (int rowPosition = rowPositionOffset, iy = 0; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++, iy++) {
            boolean insideBorder = false;
            Rectangle cellBounds = null;
            ILayerCell currentCell = natLayer.getCellByPosition(columnPosition, rowPosition);
            if (currentCell != null) {
                cellBounds = currentCell.getBounds();
                if (isFillHandleRegion(currentCell)) {
                    insideBorder = true;
                    atLeastOne = true;
                }
                if (fillHandleCell == null && isFillHandleCell(currentCell)) {
                    fillHandleCell = currentCell;
                }
            }
            Rectangle fixedBounds = fixBoundsInGridLines(cellBounds, xOffset, yOffset);
            BorderCell borderCell = new BorderCell(fixedBounds, insideBorder);
            borderCells[iy][ix] = borderCell;
        }
    }
    if (atLeastOne) {
        // Save gc settings
        int originalLineStyle = gc.getLineStyle();
        int originalLineWidth = gc.getLineWidth();
        Color originalForeground = gc.getForeground();
        BorderStyle fillHandleRegionBorderStyle = getHandleRegionBorderStyle(configRegistry);
        BorderPainter borderPainter = new BorderPainter(borderCells, fillHandleRegionBorderStyle);
        borderPainter.paintBorder(gc);
        // Restore original gc settings
        gc.setLineStyle(originalLineStyle);
        gc.setLineWidth(originalLineWidth);
        gc.setForeground(originalForeground);
    }
    // paint the border around the copied cells if a clipboard is set
    if (this.clipboard != null && this.clipboard.getCopiedCells() != null) {
        paintCopyBorder(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
    }
    // to find it and eventually repaint it
    if (fillHandleCell == null && positionRectangle.width <= 2 && positionRectangle.height <= 2) {
        for (int columnPosition = columnPositionOffset - 1; columnPosition < columnPositionOffset + positionRectangle.width + 1 && fillHandleCell == null; columnPosition++) {
            for (int rowPosition = rowPositionOffset - 1; rowPosition < rowPositionOffset + positionRectangle.height + 1 && fillHandleCell == null; rowPosition++) {
                ILayerCell currentCell = natLayer.getCellByPosition(columnPosition, rowPosition);
                if (currentCell != null) {
                    if (isFillHandleCell(currentCell)) {
                        fillHandleCell = currentCell;
                    }
                }
            }
        }
    }
    if (fillHandleCell != null) {
        paintFillHandle(fillHandleCell, gc, xOffset, yOffset, configRegistry);
    } else {
        // set the local stored bounds to null as no handle is rendered and
        // therefore event matchers shouldn't react anymore
        this.handleBounds = null;
    }
}
Also used : BorderPainter(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) BorderCell(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.BorderCell)

Example 2 with BorderCell

use of org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.BorderCell in project nebula.widgets.nattable by eclipse.

the class SelectionLayerPainter method paintLayer.

@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
    super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
    Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
    int columnPositionOffset = positionRectangle.x;
    int rowPositionOffset = positionRectangle.y;
    // nothing to draw, we exit
    if (positionRectangle.width <= 0 || positionRectangle.height <= 0) {
        return;
    }
    BorderCell[][] borderCells;
    boolean atLeastOne = false;
    PaintModeEnum paintMode;
    // tentative way to know that this is a single cell update
    if (positionRectangle.width <= 2 && positionRectangle.height <= 2) {
        // In order to correctly paint the selection borders in case of
        // single cell updates we need to consider also the adjacent cells.
        // Therefore we try to retrieve also cells that are outside the
        // pixelRectangle but still inside our layer.
        // +2 because we are going to read also adjacent cells in the
        // extremities
        borderCells = new BorderCell[positionRectangle.height + 2][positionRectangle.width + 2];
        // we need to repaint only the internal borders of the external
        // cells
        paintMode = PaintModeEnum.NO_EXTERNAL_BORDERS;
        // extremities
        for (int columnPosition = columnPositionOffset - 1, ix = 0; columnPosition < columnPositionOffset + positionRectangle.width + 1; columnPosition++, ix++) {
            for (int rowPosition = rowPositionOffset - 1, iy = 0; rowPosition < rowPositionOffset + positionRectangle.height + 1; rowPosition++, iy++) {
                boolean insideBorder = false;
                Rectangle cellBounds = null;
                ILayerCell currentCell = natLayer.getCellByPosition(columnPosition, rowPosition);
                if (currentCell != null) {
                    cellBounds = currentCell.getBounds();
                    // the cell should be considered only if it is in our
                    // layer
                    boolean toBeConsidered = isInCurrentLayer(ix, iy, xOffset, yOffset, cellBounds, borderCells);
                    if (toBeConsidered && isSelected(currentCell)) {
                        insideBorder = true;
                        atLeastOne = true;
                    }
                }
                Rectangle fixedBounds = fixBoundsInGridLines(cellBounds, xOffset, yOffset);
                BorderCell borderCell = new BorderCell(fixedBounds, insideBorder);
                borderCells[iy][ix] = borderCell;
            }
        }
    } else {
        borderCells = new BorderCell[positionRectangle.height][positionRectangle.width];
        paintMode = PaintModeEnum.ALL;
        for (int columnPosition = columnPositionOffset, ix = 0; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++, ix++) {
            for (int rowPosition = rowPositionOffset, iy = 0; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++, iy++) {
                boolean insideBorder = false;
                Rectangle cellBounds = null;
                ILayerCell currentCell = natLayer.getCellByPosition(columnPosition, rowPosition);
                if (currentCell != null) {
                    // In case of spanned cells the border painter needs to
                    // know the bounds of adjacent cells even if they are
                    // not selected. This is the reason why we get the
                    // bounds also for non selected cells.
                    cellBounds = currentCell.getBounds();
                    if (isSelected(currentCell)) {
                        insideBorder = true;
                        atLeastOne = true;
                    }
                }
                Rectangle fixedBounds = fixBoundsInGridLines(cellBounds, xOffset, yOffset);
                BorderCell borderCell = new BorderCell(fixedBounds, insideBorder);
                borderCells[iy][ix] = borderCell;
            }
        }
    }
    if (atLeastOne) {
        // Save gc settings
        int originalLineStyle = gc.getLineStyle();
        int originalLineWidth = gc.getLineWidth();
        Color originalForeground = gc.getForeground();
        BorderStyle borderStyle = getBorderStyle(configRegistry);
        BorderPainter borderPainter = new BorderPainter(borderCells, borderStyle, paintMode);
        borderPainter.paintBorder(gc);
        // Restore original gc settings
        gc.setLineStyle(originalLineStyle);
        gc.setLineWidth(originalLineWidth);
        gc.setForeground(originalForeground);
    }
}
Also used : BorderPainter(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter) PaintModeEnum(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.PaintModeEnum) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) BorderCell(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.BorderCell)

Aggregations

ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)2 BorderPainter (org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter)2 BorderCell (org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.BorderCell)2 BorderStyle (org.eclipse.nebula.widgets.nattable.style.BorderStyle)2 Color (org.eclipse.swt.graphics.Color)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 PaintModeEnum (org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.PaintModeEnum)1