blob: aaae36d9a7967745acec2364dcc9a9674950267d [file] [log] [blame]
package org.eclipse.nebula.widgets.nattable.renderer.javafx.graphics
import com.sun.javafx.tk.Toolkit
import org.eclipse.nebula.widgets.nattable.core.graphics.Color
import org.eclipse.nebula.widgets.nattable.core.graphics.GraphicsContext
class JavaFXGraphicsContext implements GraphicsContext {
val javafx.scene.canvas.GraphicsContext gc
new(javafx.scene.canvas.GraphicsContext gc) {
this.gc = gc
}
override pushState() {
gc.save
}
override popState() {
gc.restore
}
override setForegroundColor(Color foregroundColor) {
gc.stroke = new javafx.scene.paint.Color(
foregroundColor.red as double / 255,
foregroundColor.green as double / 255,
foregroundColor.blue as double / 255,
foregroundColor.alpha as double / 255
)
}
override drawLine(int x1, int y1, int x2, int y2) {
gc.strokeLine(x1, y1, x2, y2)
}
override drawText(String text, int x, int y) {
gc.strokeText(text, x, y)
}
override calculateTextWidth(String text) {
val fontMetrics = Toolkit::toolkit.fontLoader.getFontMetrics(gc.font)
fontMetrics.computeStringWidth(text)
}
}