Anonymous avatar Anonymous committed 5e0cdbc

prettification

Comments (0)

Files changed (1)

src/main/scala/login/LoginDemo.scala

 
 object LoginDemo extends App {
   val demo = new LoginDemo
-  demo.construct
+  demo.construct()
   demo.runMain()
 }
 
 class LoginDemo extends Widget {
 
   def runMain() {
-    Display.setDisplayMode(new DisplayMode(800, 600));
-    Display.create();
-    Display.setTitle("TWL Login Panel Demo");
-    Display.setVSyncEnabled(true);
+    Display.setDisplayMode(new DisplayMode(800, 600))
+    Display.create()
+    Display.setTitle("TWL Login Panel Demo")
+    Display.setVSyncEnabled(true)
 
     val demo = this
 
-    val renderer = new LWJGLRenderer();
-    val gui = new GUI(demo, renderer);
+    val renderer = new LWJGLRenderer()
+    val gui = new GUI(demo, renderer)
 
-    val theme = ThemeManager.createThemeManager(getClass.getResource("/login.xml"), renderer);
-    gui.applyTheme(theme);
+    val theme = ThemeManager.createThemeManager(getClass.getResource("/login.xml"), renderer)
+    gui.applyTheme(theme)
 
     while (!Display.isCloseRequested() && !demo.quit) {
-      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
+      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT)
 
-      gui.update();
-      Display.update();
+      gui.update()
+      Display.update()
     }
 
-    gui.destroy();
-    theme.destroy();
-    Display.destroy();
+    gui.destroy()
+    theme.destroy()
+    Display.destroy()
   }
 
   var fpsCounter: FPSCounter = null
 
   var quit: Boolean = false
 
-  // implicit def fun2run(fun: () => Unit) : Runnable = { new Runnable { def run = fun } }
+  implicit def fun2run(fun: () => Unit) : Runnable = { new Runnable { def run = fun() } }
 
   def construct() {
-    fpsCounter = new FPSCounter();
+    fpsCounter = new FPSCounter
 
-    loginPanel = new DialogLayout();
-    loginPanel.setTheme("login-panel");
+    loginPanel = new DialogLayout
+    loginPanel.setTheme("login-panel")
 
-    efName = new EditField();
+    efName = new EditField
 
-    efPassword = new EditField();
-    efPassword.setPasswordMasking(true);
+    efPassword = new EditField
+    efPassword.setPasswordMasking(true)
 
-    val lName = new Label("Name");
-    lName.setLabelFor(efName);
+    val lName = new Label("Name")
+    lName.setLabelFor(efName)
 
-    val lPassword = new Label("Password");
-    lPassword.setLabelFor(efPassword);
+    val lPassword = new Label("Password")
+    lPassword.setLabelFor(efPassword)
 
-    btnLogin = new Button("LOGIN");
-    btnLogin.addCallback(new Runnable() {
-      def run() {
-        emulateLogin();
-      }
-    });
+    btnLogin = new Button("LOGIN")
+    btnLogin.addCallback(emulateLogin _)
 
-    val hLabels = loginPanel.createParallelGroup(lName, lPassword);
-    val hFields = loginPanel.createParallelGroup(efName, 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);
+      .addWidget(btnLogin)
 
     loginPanel.setHorizontalGroup(loginPanel.createParallelGroup()
       .addGroup(loginPanel.createSequentialGroup(hLabels, hFields))
-      .addGroup(hBtn));
+      .addGroup(hBtn))
     loginPanel.setVerticalGroup(loginPanel.createSequentialGroup()
       .addGroup(loginPanel.createParallelGroup(lName, efName))
       .addGroup(loginPanel.createParallelGroup(lPassword, efPassword))
-      .addWidget(btnLogin));
+      .addWidget(btnLogin))
 
-    add(fpsCounter);
-    add(loginPanel);
+    add(fpsCounter)
+    add(loginPanel)
   }
 
   override def layout() {
     // fpsCounter is bottom right
-    fpsCounter.adjustSize();
+    fpsCounter.adjustSize()
     fpsCounter.setPosition(
-      getInnerRight() - fpsCounter.getWidth(),
-      getInnerBottom() - fpsCounter.getHeight());
+        getInnerRight - fpsCounter.getWidth, 
+        getInnerBottom - fpsCounter.getHeight)
 
     // login panel is centered
-    loginPanel.adjustSize();
+    loginPanel.adjustSize()
     loginPanel.setPosition(
-      getInnerX() + (getInnerWidth() - loginPanel.getWidth()) / 2,
-      getInnerY() + (getInnerHeight() - loginPanel.getHeight()) / 2);
+      getInnerX + (getInnerWidth - loginPanel.getWidth) / 2,
+      getInnerY + (getInnerHeight - loginPanel.getHeight) / 2)
   }
 
   def emulateLogin() {
-    val gui = getGUI();
+    val gui = getGUI
     if (gui != null) {
-      // step 1: disable all controls
-      efName.setEnabled(false);
-      efPassword.setEnabled(false);
-      btnLogin.setEnabled(false);
+      efName.setEnabled(false)
+      efPassword.setEnabled(false)
+      btnLogin.setEnabled(false)
 
-      // step 2: start a timer to simulate the process of talking to a remote server
-      val timer = gui.createTimer();
-      timer.setCallback(new Runnable() {
-        def run() {
+      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);
+          efName.setEnabled(true)
+          efPassword.setEnabled(true)
+          efPassword.setText("")
+          btnLogin.setEnabled(true)
         }
-      });
-      timer.setDelay(2500);
-      timer.start();
+      )
 
-      /* NOTE: in a real app you would need to keep a reference to the timer object
-             * to cancel it if the user closes the dialog which uses the timer.
-             * @see Widget#beforeRemoveFromGUI(de.matthiasmann.twl.GUI)
-             */
+      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.