blob: bf4b5c0720651908019b087fc483998408da7bf4 [file] [log] [blame]
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, PixelRectangle paintBounds, GraphicsContext gc) {
// Draw cells
super.paintLayer(layer, paintBounds, gc)
// Draw grid lines
drawGridLines(layer, gc)
}
// CellLayerPainter methods
override protected getPaintBounds(Cell cell) {
val cellBounds = super.getPaintBounds(cell)
new PixelRectangle(
cellBounds.x,
cellBounds.y,
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
// Draw horizontal grid lines
for (rowPosition : 1 .. layer.getRowCount) {
val startY = layer.getStartYPixelOfRowPosition(rowPosition) - 1
gc.drawLine(
0, startY,
pixelWidth, startY
)
}
// Draw vertical grid lines
for (columnPosition : 1 .. layer.getColumnCount) {
val startX = layer.getStartXPixelOfColumnPosition(columnPosition) - 1
gc.drawLine(
startX, 0,
startX, pixelHeight
)
}
gc.popState
}
}