Anonymous avatar Anonymous committed dcdc38c

scalafied loginPanel

Comments (0)

Files changed (1)

src/main/scala/login/LoginDemo.scala

 package login
 
+import org.lwjgl.opengl.Display
+import org.lwjgl.opengl.DisplayMode
+import org.lwjgl.opengl.GL11
+
+import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer
+import de.matthiasmann.twl.theme.ThemeManager
+import de.matthiasmann.twlscala.DialogLayout
 import de.matthiasmann.twl.Button
-import de.matthiasmann.twl.DialogLayout
 import de.matthiasmann.twl.EditField
 import de.matthiasmann.twl.FPSCounter
 import de.matthiasmann.twl.GUI
 import de.matthiasmann.twl.Label
-import de.matthiasmann.twl.Timer
 import de.matthiasmann.twl.Widget
-import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer
-import de.matthiasmann.twl.theme.ThemeManager
-import org.lwjgl.opengl.Display
-import org.lwjgl.opengl.DisplayMode
-import org.lwjgl.opengl.GL11
-import test.TestUtils
+import login.Implicits.fun2run
 
 object LoginDemo extends App {
   val demo = new LoginDemo
   implicit def fun2run(fun: () => Unit): Runnable = { new Runnable { def run = fun() } }
 }
 
-class LoginDemo extends Widget {
+class LoginDemo extends Widget { root =>
   import Implicits._
 
   var quit: Boolean = false
 
-  val loginPanel = new DialogLayout
-  loginPanel.setTheme("login-panel")
+  val fpsCounter = new FPSCounter
 
-  val fpsCounter = new FPSCounter
-  
-  val efName = new EditField
-  val lName = new Label("Name")
-  lName.setLabelFor(efName)
+  val loginPanel = new DialogLayout {
+    theme = "login-panel"
 
-  val efPassword = new EditField
-  efPassword.setPasswordMasking(true)
-  val lPassword = new Label("Password")
-  lPassword.setLabelFor(efPassword)
+    val efName = new EditField
+    val lName = new Label("Name")
+    lName.setLabelFor(efName)
 
-  val btnLogin = new Button("LOGIN")
-  btnLogin.addCallback(emulateLogin _)
+    val efPassword = new EditField
+    efPassword.setPasswordMasking(true)
+    val lPassword = new Label("Password")
+    lPassword.setLabelFor(efPassword)
 
-  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)
+    val btnLogin = new Button("LOGIN")
+    btnLogin.addCallback(emulateLogin _)
 
-  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))
+    horizontalGroup = ((lName || lPassword) -- (efName || efPassword)) || (Filler -- btnLogin)
+    verticalGroup = (lName || efName) -- (lPassword || efPassword) -- btnLogin
+
+    def emulateLogin() {
+      val gui = getGUI
+      if (gui != null) {
+        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()
+      }
+    }
+  }
 
   add(fpsCounter)
   add(loginPanel)
     // login panel is centered
     loginPanel.adjustSize()
     loginPanel.setPosition(
-      getInnerX + (getInnerWidth - loginPanel.getWidth) / 2,
-      getInnerY + (getInnerHeight - loginPanel.getHeight) / 2)
+      getInnerX + (root.getInnerWidth - loginPanel.getWidth) / 2,
+      getInnerY + (root.getInnerHeight - loginPanel.getHeight) / 2)
   }
 
-  def emulateLogin() {
-    val gui = getGUI
-    if (gui != null) {
-      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()
-    }
-  }
 }
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.