| package org.eclipse.nebula.widgets.nattable.renderer.javafx.layer.cell |
| |
| import com.sun.javafx.tk.Toolkit |
| import javafx.scene.canvas.Canvas |
| import javafx.scene.shape.Rectangle |
| import org.eclipse.nebula.widgets.nattable.core.layer.cell.LayerCell |
| |
| class DefaultLayerCellRenderer implements LayerCellRenderer { |
| |
| override renderLayerCell(LayerCell cell, Canvas canvas, Rectangle clipBounds) { |
| val text = cell.dataValue.toString |
| |
| // Draw text |
| |
| val gc = canvas.graphicsContext2D |
| |
| val centerX = clipBounds.x + (clipBounds.width / 2) |
| val centerY = clipBounds.y + (clipBounds.height / 2) |
| |
| val fontMetrics = Toolkit::toolkit.fontLoader.getFontMetrics(gc.font) |
| val textWidth = fontMetrics.computeStringWidth(text) |
| |
| gc.strokeText( |
| text, |
| centerX - (textWidth / 2), |
| centerY |
| ) |
| } |
| |
| } |