Anonymous avatar Anonymous committed ceac214

added some callback stuff

Comments (0)

Files changed (1)

src/main/scala/login/LoginDemo.scala

 
 class LoginDemo extends Widget { root =>
   theme = "logindemo"
-    
+
   import Implicits._
 
   var quit: Boolean = false
   val fpsCounter = new FPSCounter
 
   val loginPanel = new DialogLayout {
-    theme = "login-panel"
+    theme = "login-panel";
+
+    val lKeyVal = new Label("Key code: ")
 
     val efName = new EditField
     val lName = new Label("Name")
     lPassword.setLabelFor(efPassword)
 
     val btnLogin = new Button("LOGIN")
-    
-    horizontalGroup = ((lName || lPassword) -- (efName || efPassword)) || (Filler -- btnLogin)
-    verticalGroup = (lName || efName) -- (lPassword || efPassword) -- btnLogin
+
+    horizontalGroup = ((lName || lPassword) -- (efName || efPassword)) || (lKeyVal -- Filler -- btnLogin)
+    verticalGroup = (lName || efName) -- (lPassword || efPassword) -- (lKeyVal || btnLogin)
 
     listenTo(btnLogin)
     reactions += {
       case ButtonClicked(`btnLogin`) => emulateLogin()
     }
+
+    efName.addCallback(new EditField.Callback { 
+      def callback(key: Int) { lKeyVal.text = "Key code: " + key }})
     
     def emulateLogin() {
-      val gui = getGUI
-      if (gui != null) {
-        efName.setEnabled(false)
-        efPassword.setEnabled(false)
-        btnLogin.setEnabled(false)
+      // disable all controls while we're "logging in"
+      efName.setEnabled(false)
+      efPassword.setEnabled(false)
+      btnLogin.setEnabled(false)
 
-        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)
-        })
-
-        timer.setDelay(2500)
-        timer.start()
-      }
+      // re-enable all controls and clear password after "failure"
+      val timer = getGUI.createTimer()
+      timer.setCallback(() => {
+        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.