| 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 extension org.eclipse.nebula.widgets.nattable.core.layer.LayerInvariants.* |
| |
| class GridLineCellLayerPainter extends CellLayerPainter { |
| |
| // LayerPainter interface |
| |
| override paintLayer(Layer layer, GraphicsContext gc) { |
| // Draw cells |
| super.paintLayer(layer, gc) |
| |
| // Draw grid lines |
| drawGridLines(layer, gc) |
| } |
| |
| // CellLayerPainter methods |
| |
| override protected getPaintRegion(Cell cell) { |
| val cellBounds = super.getPaintRegion(cell) |
| |
| new PixelRectangle( |
| cellBounds.x + 1, |
| cellBounds.y + 1, |
| cellBounds.width - 1, |
| cellBounds.height - 1 |
| ) |
| } |
| |
| // |
| |
| def drawGridLines(Layer layer, GraphicsContext gc) { |
| gc.pushState |
| |
| gc.foregroundColor = new Color(0, 0, 255, 0) |
| |
| // Draw |
| val pixelWidth = layer.getPixelWidth |
| val pixelHeight = layer.getPixelHeight |
| |
| for (columnPosition : 0 .. layer.getColumnCount) { |
| val startX = layer.getStartXPixelOfColumnPosition(columnPosition) |
| for (rowPosition : 0 .. layer.getRowCount) { |
| val startY = layer.getStartYPixelOfRowPosition(rowPosition) |
| |
| // Draw horizontal grid lines |
| gc.drawLine( |
| 0, startY, |
| pixelWidth, startY |
| ) |
| |
| // Draw vertical grid lines |
| gc.drawLine( |
| startX, 0, |
| startX, pixelHeight |
| ) |
| } |
| } |
| |
| gc.popState |
| } |
| |
| } |