WIP desktop client for Chatto reimplemented in ScalaFX and Sapphire Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

124 lines
3.8 KiB

package wow.doge.chatto.controller
import javafx.fxml.FXML
import javafx.scene.control.Label
import javafx.scene.control.Button
import javafx.scene.layout.FlowPane
import javafx.scene.control.TextArea
import javafx.scene.control.ListView
import javafx.scene.layout.HBox
import javafx.scene.layout.VBox
import scalafx.Includes._
import wow.doge.chatto.control.UserBox
import javafx.application.Platform
import javax.inject.Inject
import org.scalafx.extras._
import wow.doge.chatto.messagebuble.BubbledMDFXNode
import wow.doge.chatto.service.UserService
import scala.concurrent.ExecutionContext
import scala.concurrent.ExecutionContext.Implicits.global
import com.typesafe.scalalogging.LazyLogging
// import wow.doge.chatto.controller.LoginController.Person
import com.sfxcode.sapphire.core.value.FXBean
import wow.doge.chatto.AppDataHandler
import com.jfoenix.controls.JFXListView
import scala.async.Async.{async, await}
import javafx.scene.paint.Color
class ChatController @Inject() (
userService: UserService,
appDataHandler: AppDataHandler
) extends AbstractViewController
with LazyLogging {
@FXML private var label: Label = _
@FXML private var flowPane: FlowPane = _
@FXML private var submitButton: Button = _
@FXML private var logoutButton: Button = _
// @FXML private var chatTextArea: TextArea = _
@FXML private var chatInput: TextArea = _
@FXML private var usersVBox: VBox = _
@FXML var usersListView: JFXListView[Any] = _
@FXML private var chatListView: JFXListView[HBox] = _
// applicationController.show
override def didGainVisibilityFirstTime(): Unit = {
super.didGainVisibilityFirstTime()
val ub = new UserBox()
this.stage.resizable = true
ub.messageLabel.text = "Hi there"
// ub.messageLabel.id =
ub.userRadioButton.text = "User 1"
// usersVBox.children.clear()
// usersVBox.children += ub
println("test")
println(s"Result = ${func()}")
offFX(println("hello from new thread"))
// chatTextArea.visible <== !chatInput.text.isEmpty
// chatTextArea.text <== chatInput.text
for (r <- userService.func2()) yield (logger.info(s"${r.body}"))
val person = Person(0, 10, "Billy")
val bean = FXBean[Person](person)
ub.messageLabel.text <== bean.getStringProperty("name")
// bean.getStringProperty("name") <== chatInput.text
// bean.getStringProperty("name")() = "Lester"
println(bean.getValue("name"))
println(bean.getStringProperty("name")())
// bean.
bean.updateValue("name", "Lester")
println(bean.bean)
logoutButton.onAction = (e) => {
applicationController.logout()
println(appDataHandler.appData)
}
}
override def didGainVisibility(): Unit = {
super.didGainVisibility()
chatInput.requestFocus()
async {
val willBeUsers = userService
.getUsers(appDataHandler.appData.credentials)
.map(_.body)
val maybeUsers = await(willBeUsers)
val maybeUsersBoxes = maybeUsers.map(users => {
users.map(user => {
// val ub = new UserBox()
// ub.messageLabel.text = "Hi there"
// ub.userRadioButton.text = user
// ub
// new Rectangle {
// fill <== when(hover) choose (Color.Red)
// }
val hb = new HBox
new HBox {
this.children += new Label {
textProperty() = user
// textFillProperty <== when(this.hover) choose (Color.RED) otherwise (Color.BLUE)
}
// fill <== when(this.hover) choose (Color.RED) otherwise (Color.BLUE)
}
})
})
onFX {
maybeUsersBoxes.map(userBoxes => {
usersListView.items() ++= userBoxes
})
}
}
}
def func() = {
val x = offFXAndWait {
2 + 3
}
x
}
}
final case class Person(id: Int, age: Int, name: String)