Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
clarifies visually what happens during login phase
Browse files Browse the repository at this point in the history
(cursor, disable frame)
+ exit application when landing frame is disposed
  • Loading branch information
tyrcho committed Apr 4, 2015
1 parent bfe749c commit c708ee8
Showing 1 changed file with 47 additions and 23 deletions.
70 changes: 47 additions & 23 deletions companion/src/main/scala/net/hearthstats/ui/LandingFrame.scala
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package net.hearthstats.ui

import java.awt.{ Color, Cursor, Dimension }
import javax.imageio.ImageIO
import javax.swing._
import java.awt.{Color, Cursor, Dimension}

import scala.concurrent.{Future, Promise}
import scala.swing.{Component, Container, Frame, Label, Point}
import scala.swing.event.ButtonClicked
import scala.util.control.NonFatal

import grizzled.slf4j.Logging
import net.hearthstats.config.{ Environment, UserConfig }
import javax.imageio.ImageIO
import javax.swing.{ImageIcon, JOptionPane}
import net.hearthstats.config.{Environment, UserConfig}
import net.hearthstats.hstatsapi.API
import net.hearthstats.ui.log.Log
import net.hearthstats.ui.notification.NotificationQueue
import net.hearthstats.ui.util._
import net.hearthstats.util.{ Browse, Translation }
import scala.swing.event.ButtonClicked
import scala.swing.{ Frame, Label, Point }
import scala.concurrent.Future
import scala.concurrent.Promise
import net.hearthstats.ui.util.{FontHelper, MigPanel, PasswordOptionTextField, StringOptionTextField}
import net.hearthstats.util.{Browse, Translation}

class LandingFrame(translation: Translation,
uilog: Log,
config: UserConfig,
api: API,
val notificationQueue: NotificationQueue,
val environment: Environment) extends Frame with Logging {
notificationQueue: NotificationQueue,
environment: Environment) extends Frame with Logging {
import config._
import translation.t

Expand Down Expand Up @@ -51,6 +53,10 @@ class LandingFrame(translation: Translation,

var connected = Promise[Unit]()

override def closeOperation(): Unit = {
System.exit(0)
}

def createLandingPage(): Future[Unit] = {

val icon = new ImageIcon(getClass.getResource("/images/icon.png")).getImage
Expand Down Expand Up @@ -123,11 +129,10 @@ class LandingFrame(translation: Translation,

contents = panel
background = Color.WHITE

if(config.lastLoginOK){
new Thread{
override def run():Unit={
Thread.sleep(200)

if (config.lastLoginOK) {
new Thread {
override def run(): Unit = {
checkForPassword()
}
}.start()
Expand All @@ -140,21 +145,40 @@ class LandingFrame(translation: Translation,
title = "HearthStats Companion Login Page"
}

def login(): Boolean = try {
setEnabled(false)
cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)
api.login(config.email.get, config.password.get)
} finally {
setEnabled(true)
cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)
}

def setEnabled(e: Boolean): Unit = {
def enable(c: Component): Unit = {
c.enabled = e
if (c.isInstanceOf[Container]) {
for (i <- c.asInstanceOf[Container].contents) enable(i)
}
}
for (c <- contents) enable(c)
repaint()
}

//check if password and email matched
def checkForPassword() {
def checkForPassword(): Unit =
try {
if (api.login(config.email.get, config.password.get)) {
if (login()) {
connected.success(())
config.lastLoginOK.set(true)
info("Password correct")
dispose()
} else {
JOptionPane.showMessageDialog(null, "Invalid Email or Password")
JOptionPane.showMessageDialog(peer, "Invalid Email or Password")
config.lastLoginOK.set(false)
info("Invalid email or password")
}
} catch {
case e: Throwable => throw new Exception("entered nothing", e)
case NonFatal(e) => throw new Exception("entered nothing", e)
}

}
}

0 comments on commit c708ee8

Please sign in to comment.