| package org.eclipse.nebula.widgets.nattable.core.layer.impl |
| |
| import org.eclipse.nebula.widgets.nattable.core.geometry.PixelRectangle |
| import org.eclipse.nebula.widgets.nattable.core.graphics.Color |
| import org.eclipse.nebula.widgets.nattable.core.graphics.GraphicsContext |
| import org.eclipse.nebula.widgets.nattable.core.layer.Layer |
| import org.eclipse.nebula.widgets.nattable.core.layer.cell.Cell |
| |
| import static java.lang.Math.* |
| |
| import static extension org.eclipse.nebula.widgets.nattable.core.layer.LayerInvariants.* |
| |
| class GridLineCellLayerPainter extends CellLayerPainter { |
| |
| // LayerPainter interface |
| |
| override paintLayer(Layer layer, PixelRectangle layerPaintBounds, GraphicsContext gc) { |
| // Draw cells |
| super.paintLayer(layer, layerPaintBounds, gc) |
| |
| // Draw grid lines |
| drawGridLines(layer, gc) |
| } |
| |
| // CellLayerPainter methods |
| |
| override protected getAdjustedPixelBounds(Cell cell) { |
| val pixelBounds = super.getAdjustedPixelBounds(cell) |
| |
| new PixelRectangle( |
| pixelBounds.x, |
| pixelBounds.y, |
| pixelBounds.width - 1, |
| pixelBounds.height - 1 |
| ) |
| } |
| |
| // |
| |
| def drawGridLines(Layer layer, GraphicsContext gc) { |
| gc.pushState |
| |
| gc.foregroundColor = new Color(0, 0, 255) |
| |
| // Draw |
| val clipBounds = gc.clipBounds |
| |
| val pixelWidth = layer.getPixelWidth |
| val pixelHeight = layer.getPixelHeight |
| |
| // Draw horizontal grid lines |
| val fromRowPosition = max(layer.getRowPositionOfYPixel(clipBounds.y) + 1, 1) |
| val toRowPosition = min(layer.getRowPositionOfYPixel(clipBounds.y + clipBounds.height), layer.rowCount) |
| if (fromRowPosition <= toRowPosition) |
| for (rowPosition : fromRowPosition .. toRowPosition) { |
| val y = layer.getStartYPixelOfRowPosition(rowPosition) - 1 |
| gc.drawLine( |
| 0, y, |
| pixelWidth, y |
| ) |
| } |
| |
| // Draw vertical grid lines |
| val fromColumnPosition = max(layer.getColumnPositionOfXPixel(clipBounds.x) + 1, 1) |
| val toColumnPosition = min(layer.getColumnPositionOfXPixel(clipBounds.x + clipBounds.width), layer.columnCount) |
| if (fromColumnPosition <= toColumnPosition) |
| for (columnPosition : fromColumnPosition .. toColumnPosition) { |
| val x = layer.getStartXPixelOfColumnPosition(columnPosition) - 1 |
| gc.drawLine( |
| x, 0, |
| x, pixelHeight |
| ) |
| } |
| |
| gc.popState |
| } |
| |
| } |