| package org.eclipse.nebula.widgets.nattable.renderer.javafx.layer |
| |
| import javafx.scene.canvas.Canvas |
| import javafx.scene.paint.Color |
| import javafx.scene.shape.Rectangle |
| import org.eclipse.nebula.widgets.nattable.core.layer.Layer |
| import org.eclipse.nebula.widgets.nattable.core.layer.cell.LayerCell |
| |
| import static extension org.eclipse.nebula.widgets.nattable.core.layer.LayerInvariants.* |
| |
| class GridLineCellLayerRenderer extends CellLayerRenderer { |
| |
| override renderLayer(Layer layer, Canvas canvas) { |
| // Draw grid lines |
| drawGridLines(canvas, layer) |
| |
| // Draw cells |
| super.renderLayer(layer, canvas) |
| } |
| |
| def drawGridLines(Canvas canvas, Layer layer) { |
| val gc = canvas.graphicsContext2D |
| gc.stroke = Color::BLUE |
| |
| val pixelWidth = layer.pixelWidth |
| val pixelHeight = layer.pixelHeight |
| |
| for (columnPosition : 0 .. layer.columnCount) |
| for (rowPosition : 0 .. layer.rowCount) { |
| val startX = layer.getStartXPixelOfColumnPosition(columnPosition) |
| val startY = layer.getStartYPixelOfRowPosition(rowPosition) |
| |
| // Draw horizontal grid lines |
| gc.strokeLine( |
| 0, startY, |
| pixelWidth, startY |
| ) |
| |
| // Draw vertical grid lines |
| gc.strokeLine( |
| startX, 0, |
| startX, pixelHeight |
| ) |
| } |
| } |
| |
| override protected getClipBounds(LayerCell cell) { |
| val cellBounds = super.getClipBounds(cell) |
| |
| new Rectangle( |
| cellBounds.x + 10, |
| cellBounds.y + 10, |
| cellBounds.width - 10, |
| cellBounds.height - 10 |
| ) |
| } |
| |
| } |