Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package space.smena.app.controller
- import javafx.scene.control.Button
- import javafx.scene.control.ComboBox
- import javafx.scene.control.TableCell
- import javafx.scene.image.ImageView
- import javafx.scene.layout.BorderPane
- import space.smena.app.model.Printer
- import tornadofx.*
- class HomeView : View("Home") {
- private val commonController: CommonController by inject()
- private val homeController: HomeController by inject()
- override val root = BorderPane()
- private val printers = homeController.loadPrintersAndUpdateStatus().observable()
- private val devices = homeController.loadDevices()
- var printingIsRunning = false
- var updateStatusIsRunning = false
- val model = PrinterModel(Printer())
- init {
- with(root) {
- top {}
- center {
- tableview(printers) {
- column("Printer", Printer::deviceNameProperty).setCellFactory {
- object : TableCell<Printer, String>() {
- val cmb = ComboBox<String>(devices)
- override fun updateItem(item: String?, empty: Boolean) {
- super.updateItem(item, empty)
- if (item == null) {
- graphic = null
- return
- }
- graphic = cmb
- cmb.value = item
- }
- }
- }
- column("Account", Printer::printerNameProperty)
- column("Connection", Printer::isOnlineProperty).cellFormat {
- graphic = if (rowItem.connectStatus) {
- ImageView("connection-ok.png")
- } else {
- ImageView("connection-off.png")
- }
- graphic.resize(22.5, 22.5)
- }
- column("Status", Printer::genericStatusProperty).apply {
- remainingWidth()
- cellFormat {
- graphic = if (rowItem.genericStatus) {
- ImageView("connection-ok.png")
- } else {
- ImageView("connection-off.png")
- }
- graphic.resize(20.5, 22.5)
- }
- }
- column("Start print", Printer::printingStatusProperty).apply {
- setCellFactory {
- object : TableCell<Printer, Boolean>() {
- val btn = Button()
- override fun updateItem(item: Boolean?, empty: Boolean) {
- super.updateItem(item, empty)
- if (item == null) {
- graphic = null
- return
- }
- graphic = if (rowItem.printingStatus) {
- btn.apply {
- graphic = ImageView("pause.png")
- }
- } else {
- btn.apply {
- graphic = ImageView("play.png")
- }
- }
- graphic = btn
- btn.setOnAction {
- // todo: event на остановку/включенеи
- event ->
- println("Проверка печати у ${rowItem.deviceName}")
- }
- }
- }
- }
- }
- column("Test print", Printer::deviceNameProperty).setCellFactory {
- object : TableCell<Printer, String>() {
- val btn = Button("Тест")
- override fun updateItem(item: String?, empty: Boolean) {
- super.updateItem(item, empty)
- if (item == null) {
- graphic = null
- return
- }
- graphic = btn
- btn.setOnAction {
- // todo: event на проверку
- event -> println("Проверка печати у $item ($event)")
- }
- }
- }
- }
- model.rebindOnChange(this) { selectedPrinter ->
- printer = selectedPrinter ?: Printer()
- }
- smartResize()
- }
- }
- bottom {}
- }
- }
- }
- class PrinterModel(var printer: Printer) : ViewModel() {
- val printerId = bind { printer.idProperty }
- val device = bind { printer.deviceNameProperty }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement