From 0f3361017d64920027594c9b6b0ec6569d851b98 Mon Sep 17 00:00:00 2001 From: Sarah Gerweck Date: Sat, 4 Jun 2016 00:34:06 -0700 Subject: [PATCH] A couple of classes for making custom table cells --- .../util/control/CenteredTextCell.scala | 8 +++++++ .../scalafx/util/control/GenericCell.scala | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/main/scala/org/gerweck/scalafx/util/control/CenteredTextCell.scala create mode 100644 src/main/scala/org/gerweck/scalafx/util/control/GenericCell.scala diff --git a/src/main/scala/org/gerweck/scalafx/util/control/CenteredTextCell.scala b/src/main/scala/org/gerweck/scalafx/util/control/CenteredTextCell.scala new file mode 100644 index 0000000..608651b --- /dev/null +++ b/src/main/scala/org/gerweck/scalafx/util/control/CenteredTextCell.scala @@ -0,0 +1,8 @@ +package org.gerweck.scalafx.util.control + +import scalafx.geometry.Pos +import scalafx.scene.control.TableCell + +class CenteredTextCell[A, B] extends TableCell[A, B](new GenericCell[A, B]) { + alignment = Pos.Center +} diff --git a/src/main/scala/org/gerweck/scalafx/util/control/GenericCell.scala b/src/main/scala/org/gerweck/scalafx/util/control/GenericCell.scala new file mode 100644 index 0000000..d30fd27 --- /dev/null +++ b/src/main/scala/org/gerweck/scalafx/util/control/GenericCell.scala @@ -0,0 +1,22 @@ +package org.gerweck.scalafx.util.control + +class GenericCell[A, B] extends javafx.scene.control.TableCell[A, B] { + def handleItemUpdate(item: B) = { + text = item.toString + } + + override def updateItem(item: B, empty: Boolean) = { + super.updateItem(item, empty) + if (empty || item == null) { + text = null + graphic = null + } else { + handleItemUpdate(item) + } + } + + final def text = getText() + final def text_=(s: String) = setText(s) + final def graphic = getGraphic() + final def graphic_=(g: javafx.scene.Node) = setGraphic(g) +}