gist: 31845 Download_button fork
public
Public Clone URL: git://gist.github.com/31845.git
SWTApplication.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SWTApplication.scala
//
// Usage:
// object HelloWorld extends SWTApplication
// def createContents(parent: Shell) {
// val layout = new FillLayout(SWT.VERTICAL)
// parent.setLayout(layout)
//
// val fileLabel = new Label(parent, SWT.CENTER)
// fileLabel.setText("hello world")
// }
// }
//
// Based on code from Bruce Eckel's _Thinking in Java_.
 
import org.eclipse.swt._
import org.eclipse.swt.widgets._
import org.eclipse.swt.layout._
 
trait SWTApplication {
 
  var width: Int = 300
  var height: Int = 300
  var name: String = "Default Application Name"
 
  def createContents(parent: Shell): Unit
 
  def main(args: Array[String]) {
    val display = new Display()
    val shell = new Shell(display)
 
    shell.setText(name)
    createContents(shell)
    shell.setSize(width, height)
    shell.open()
 
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep()
    }
    display.dispose()
  }
}

Owner

crnixon

Revisions