blob: ef5226529633911a449b252e149e8cf8dd509419 [file] [log] [blame]
package org.eclipse.nebula.widgets.nattable.core.layer.cell.impl
import org.eclipse.nebula.widgets.nattable.core.geometry.PixelArea
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.cell.Cell
import org.eclipse.nebula.widgets.nattable.core.layer.cell.CellPainter
class TextCellPainter implements CellPainter {
override paintCell(Cell cell, PixelArea cellPaintArea, GraphicsContext gc) {
gc.backgroundColor = new Color(255, 0, 0)
gc.fillRectangle(new PixelRectangle(1, 1, cellPaintArea.width - 2, cellPaintArea.height - 2))
val text = cell.dataValue.toString
val centerX = cellPaintArea.width / 2
val centerY = cellPaintArea.height / 2
val textWidth = gc.calculateTextWidth(text)
gc.drawText(
text,
centerX - (textWidth / 2) as int,
centerY - (gc.fontHeight / 2) as int
)
}
}