package org.stairwaybook.scells import swing._, event._
class Spreadsheet(val height: Int, val width: Int) extends ScrollPane {
val cellModel = new Model(height, width) import cellModel._
val table = new Table(height, width) {
... // settings as in Listing 35.1
override def rendererComponent(
isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int) =
... // as in Listing 35.3
def userData(row: Int, column: Int): String =
... // as in Listing 35.3
reactions += {
case TableUpdated(table, rows, column) => for (row <- rows)
cells(row)(column).formula = FormulaParsers.parse(userData(row, column))
case ValueChanged(cell) => updateCell(cell.row, cell.column)
}
for (row <- cells; cell <- row) listenTo(cell)
}
val rowHeader = new ListView(0 until height) { fixedCellWidth = 30
fixedCellHeight = table.rowHeight
}
viewportView = table rowHeaderView = rowHeader
}
Listing 35.9 · The finished spreadsheet component.