Does anybody know some well-written sample projects showing how to achieve MVP architecture in Scala+Swing?
I found only this topics about MVP in Scala + Swing:
Unfortunately, Scala Swing abandons quite a bit of the underlying Java Swing MVC. To give some examples: ComboBox
has no direct access to the model (unlike JComboBox
), neither does ListView
, Button
, etc. Only Table
has the model, but not Scala'fied, so untyped.
So if you want to use the existing Java models, you need to go into the peer
fields of the Scala Swing widgets. If you want MVC with your own models, well, then you'll have to do the wiring by hand.
import scala.swing._
import Swing._
val m = new javax.swing.DefaultButtonModel
val cb = new CheckBox ("Check" ) { peer.setModel(m) }
val tb = new ToggleButton("Toggle") { peer.setModel(m) }
val f = new Frame {
contents = new FlowPanel(cb, tb)
pack().centerOnScreen()
open()
}
m addChangeListener ChangeListener { _ =>
println(s"Selected? ${m.isSelected}")
}
m.setSelected(true)
This is a tiny library to create models in Scala.
This is a small bit of example of controllers in Scala, but might not be exactly what you're looking for:
https://github.com/lrytz/pacman/tree/master/src/main/scala/epfl/pacman