Anonymous avatar Anonymous committed 04913ba

reorganizing

Comments (0)

Files changed (1)

src/main/scala/login/LoginDemo.scala

 
 object LoginDemo extends App {
   val demo = new LoginDemo
-  demo.construct()
   demo.runMain()
 }
 
+object Implicits {
+  implicit def fun2run(fun: () => Unit): Runnable = { new Runnable { def run = fun() } }
+}
+
 class LoginDemo extends Widget {
+  import Implicits._
+
+  var quit: Boolean = false
+
+  val loginPanel = new DialogLayout
+  loginPanel.setTheme("login-panel")
+
+  val fpsCounter = new FPSCounter
+  
+  val efName = new EditField
+  val lName = new Label("Name")
+  lName.setLabelFor(efName)
+
+  val efPassword = new EditField
+  efPassword.setPasswordMasking(true)
+  val lPassword = new Label("Password")
+  lPassword.setLabelFor(efPassword)
+
+  val btnLogin = new Button("LOGIN")
+  btnLogin.addCallback(emulateLogin _)
+
+  val hLabels = loginPanel.createParallelGroup(lName, lPassword)
+  val hFields = loginPanel.createParallelGroup(efName, efPassword)
+  val hBtn = loginPanel.createSequentialGroup()
+    .addGap() // right align the button by using a variable gap
+    .addWidget(btnLogin)
+
+  loginPanel.setHorizontalGroup(loginPanel.createParallelGroup()
+    .addGroup(loginPanel.createSequentialGroup(hLabels, hFields))
+    .addGroup(hBtn))
+  loginPanel.setVerticalGroup(loginPanel.createSequentialGroup()
+    .addGroup(loginPanel.createParallelGroup(lName, efName))
+    .addGroup(loginPanel.createParallelGroup(lPassword, efPassword))
+    .addWidget(btnLogin))
+
+  add(fpsCounter)
+  add(loginPanel)
 
   def runMain() {
     Display.setDisplayMode(new DisplayMode(800, 600))
     Display.setTitle("TWL Login Panel Demo")
     Display.setVSyncEnabled(true)
 
-    val demo = this
-
     val renderer = new LWJGLRenderer()
-    val gui = new GUI(demo, renderer)
+    val gui = new GUI(this, renderer)
 
     val theme = ThemeManager.createThemeManager(getClass.getResource("/login.xml"), renderer)
     gui.applyTheme(theme)
 
-    while (!Display.isCloseRequested() && !demo.quit) {
+    while (!(quit || Display.isCloseRequested)) {
       GL11.glClear(GL11.GL_COLOR_BUFFER_BIT)
-
       gui.update()
       Display.update()
     }
     Display.destroy()
   }
 
-  var fpsCounter: FPSCounter = null
-  var loginPanel: DialogLayout = null
-  var efName: EditField = null
-  var efPassword: EditField = null
-  var btnLogin: Button = null
-
-  var quit: Boolean = false
-
-  implicit def fun2run(fun: () => Unit) : Runnable = { new Runnable { def run = fun() } }
-
-  def construct() {
-    fpsCounter = new FPSCounter
-
-    loginPanel = new DialogLayout
-    loginPanel.setTheme("login-panel")
-
-    efName = new EditField
-
-    efPassword = new EditField
-    efPassword.setPasswordMasking(true)
-
-    val lName = new Label("Name")
-    lName.setLabelFor(efName)
-
-    val lPassword = new Label("Password")
-    lPassword.setLabelFor(efPassword)
-
-    btnLogin = new Button("LOGIN")
-    btnLogin.addCallback(emulateLogin _)
-
-    val hLabels = loginPanel.createParallelGroup(lName, lPassword)
-    val hFields = loginPanel.createParallelGroup(efName, efPassword)
-    val hBtn = loginPanel.createSequentialGroup()
-      .addGap() // right align the button by using a variable gap
-      .addWidget(btnLogin)
-
-    loginPanel.setHorizontalGroup(loginPanel.createParallelGroup()
-      .addGroup(loginPanel.createSequentialGroup(hLabels, hFields))
-      .addGroup(hBtn))
-    loginPanel.setVerticalGroup(loginPanel.createSequentialGroup()
-      .addGroup(loginPanel.createParallelGroup(lName, efName))
-      .addGroup(loginPanel.createParallelGroup(lPassword, efPassword))
-      .addWidget(btnLogin))
-
-    add(fpsCounter)
-    add(loginPanel)
-  }
-
   override def layout() {
     // fpsCounter is bottom right
     fpsCounter.adjustSize()
     fpsCounter.setPosition(
-        getInnerRight - fpsCounter.getWidth, 
-        getInnerBottom - fpsCounter.getHeight)
+      getInnerRight - fpsCounter.getWidth,
+      getInnerBottom - fpsCounter.getHeight)
 
     // login panel is centered
     loginPanel.adjustSize()
 
       val timer = gui.createTimer()
       timer.setCallback(() => {
-          // once the timer fired re-enable the controls and clear the password
-          efName.setEnabled(true)
-          efPassword.setEnabled(true)
-          efPassword.setText("")
-          btnLogin.setEnabled(true)
-        }
-      )
+        // once the timer fired re-enable the controls and clear the password
+        efName.setEnabled(true)
+        efPassword.setEnabled(true)
+        efPassword.setText("")
+        btnLogin.setEnabled(true)
+      })
 
       timer.setDelay(2500)
       timer.start()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.