Skip to content

Instantly share code, notes, and snippets.

@hedefalk
Created February 25, 2011 09:33
Show Gist options
  • Save hedefalk/843581 to your computer and use it in GitHub Desktop.
Save hedefalk/843581 to your computer and use it in GitHub Desktop.
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
}
val calcFahrenheit = Signal {
((9.0 / 5.0) * celsius() + 32) toString
}
def main(args: Array[String]): Unit = {
val window = shell("Temperature converter take 4",
group("Temperature converter",
layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false),
layout = new GridLayout(2, false),
label("Fahrenheit"),
textbox(fahrenheit)(_ bind calcFahrenheit, layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false)),
label("Celsius"),
textbox(celsius)(_ bind calcCelsius, layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false))))
window.setMinimumSize(300, 50)
window.pack
runEventLoop(window)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment