Skip to content

Instantly share code, notes, and snippets.

@fnumatic
Created November 23, 2012 11:28
Show Gist options
  • Save fnumatic/4135213 to your computer and use it in GitHub Desktop.
Save fnumatic/4135213 to your computer and use it in GitHub Desktop.
Simple Swing Application with scala.react * github.com/ingoem/scala-react
This is based on the scala.react library.
There should be an output on the console on every button click.
But nothing happens. Any clue?
import MySwingDomain._
object Gui extends ReactiveSwingApp {
val button = new MyButton("test")
def top = new MainFrame {
contents = new FlowPanel {
contents += button
}
}
schedule { ConsoleObserver().obs }
}
case class ConsoleObserver() extends Observing {
def obs {
observe(Gui.button.actionPerformed)(_ => println("click"))
}
}
import MySwingDomain._
class MyButton(text: String) extends Button(text) with HasAction
trait HasAction extends Observing {
this: AbstractButton =>
def getAction() = peer.getAction
def addActionListener(a: ActionListener) = peer.addActionListener(a)
def removeActionListener(a: ActionListener) = peer.removeActionListener(a)
val actionPerformed: Events[Action] =
new EventSource[Action](MySwingDomain.owner) {
source =>
addActionListener(new ActionListener {
def actionPerformed(e: ActionEvent) = { source emit getAction }
})
}
}
object MySwingDomain extends SwingDomain {
self:Domain =>
val scheduler = new SwingScheduler()
val engine = new Engine
}
abstract class SwingDomain extends Domain {
trait ReactiveSwingApp extends SimpleSwingApplication {
override def main(args: Array[String]) {
schedule { startup(args) }
start()
}
}
}
@nightscape
Copy link

Hi again,

after digging and debugging through the code I found the culprit (see my fork of your gist)

source emit getAction

needs to be a

source << getAction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment