Skip to content

Instantly share code, notes, and snippets.

View hedefalk's full-sized avatar

Viktor Hedefalk hedefalk

View GitHub Profile
text(_ emitTo signal)
implicit def bindableText(text: Text): Target[String] = {
new Target[String] {
def bind(value: Signal[String]) = observe(value) { newValue =>
text.setText(newValue)
true // keep observing
}
}
}
implicit def textToSource(text: Text): Source[String] = {
new Source[String] {
override def emitTo(channel: Var[String]) {
text.addModifyListener(new ModifyListener() {
override def modifyText(event: ModifyEvent) = {
channel.update(text.getText)
}
})
}
}
def textbox(output: Var[String])(setups: (Text => Any)*)(parent: Composite) = {
val text = new Text(parent, SWT.BORDER)
text setText (output.now)
text emitTo output
setupAndReturn(text, setups)
}
object Temperature {
implicit def unboxText2Double(s: String) = if (s != "") java.lang.Double.parseDouble(s) else 0.0
implicit def convertDouble2String(d: Double) = d.toString
val fahrenheit = new Var[String]("0")
val celsius = new Var[String]("0")
val calcCelsius = Signal {
((5.0 / 9.0) * (fahrenheit() - 32)) toString
}
implicit def bindableText(text: Text): Target[String] = {
new Target[String] {
def bind(value: Signal[String]) = observe(value) { newValue =>
if (!text.isFocusControl) // don't update the text that's editing
text.setText(newValue)
true // keep observing
}
}
}
// outer scope
val myOutputSignal = Var[String]("")
// setup
textbox(signal)
text bind signal
@hedefalk
hedefalk / eclipse.ini
Created May 5, 2011 14:46
eclipse.ini
-startup
../../../plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
--launcher.library
../../../plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.2.R36x_v20101019_1345
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
@hedefalk
hedefalk / DateParsers.scala
Created June 21, 2011 15:57
DateParsers.scala
trait DateParsers extends RegexParsers {
def dateTime(pattern: String): Parser[DateTime] = new Parser[DateTime] {
val dateFormat = DateTimeFormat.forPattern(pattern)
val dateParser = dateFormat.getParser
def jodaParse(text: CharSequence, offset: Int) = {
val mutableDateTime = new MutableDateTime
val newPos = dateFormat.parseInto(mutableDateTime, text, offset);
(mutableDateTime.toDateTime, newPos)
}