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