From 594f083a8dc0cdd580c3e95ab9b0c85f07869fb3 Mon Sep 17 00:00:00 2001 From: Seil0 Date: Thu, 6 Jun 2019 14:41:30 +0200 Subject: [PATCH] added JFXOkayCancelAlert --- .../alerts/JFXOkayCancelAlert.kt | 59 +++++++++++++++++++ .../controller/Controller.kt | 29 +++++---- .../hso/texturesyncclient/model/GUIModel.kt | 2 +- .../view/mainView/MainViewController.kt | 4 +- 4 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 client/src/main/kotlin/org/hso/texturesyncclient/alerts/JFXOkayCancelAlert.kt diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/alerts/JFXOkayCancelAlert.kt b/client/src/main/kotlin/org/hso/texturesyncclient/alerts/JFXOkayCancelAlert.kt new file mode 100644 index 0000000..8bbc64a --- /dev/null +++ b/client/src/main/kotlin/org/hso/texturesyncclient/alerts/JFXOkayCancelAlert.kt @@ -0,0 +1,59 @@ +package org.hso.texturesyncclient.alerts + +import com.jfoenix.controls.JFXAlert +import com.jfoenix.controls.JFXButton +import com.jfoenix.controls.JFXDialogLayout + +import javafx.event.ActionEvent +import javafx.event.EventHandler +import javafx.scene.text.Text +import tornadofx.FX + +/** + * + * @param heading Heading text of the alert + * @param body Content text of the alert + * @param btnStyle Style of the buttons + */ +class JFXOkayCancelAlert(heading: String, body: String, private var btnStyle: String) { + + var okayAction: EventHandler? = null + var cancelAction: EventHandler? = null + + private var okayText = "Okay" + private var cancelText = "Cancel" + private var headingText = Text(heading) + private var bodyText = Text(body) + + init { + //headingText.style = "-fx-font: 14px Verdana; -fx-text-fill: #2b7bbb;" + //bodyText.style = "-fx-font: 14px Verdana; -fx-text-fill: #2b7bbb;" + } + + fun showAndWait() { + val alert = JFXAlert(FX.primaryStage) + + val okayBtn = JFXButton(okayText) + okayBtn.addEventHandler(ActionEvent.ACTION) { alert.close() } + okayBtn.addEventHandler(ActionEvent.ACTION, okayAction!!) + okayBtn.buttonType = JFXButton.ButtonType.RAISED + okayBtn.prefHeight = 32.0 + okayBtn.style = btnStyle + + val cancelBtn = JFXButton(cancelText) + cancelBtn.addEventHandler(ActionEvent.ACTION) { alert.close() } + cancelBtn.addEventHandler(ActionEvent.ACTION, cancelAction!!) + cancelBtn.buttonType = JFXButton.ButtonType.RAISED + cancelBtn.prefHeight = 32.0 + cancelBtn.style = btnStyle + + val content = JFXDialogLayout() + //content.background = Background(BackgroundFill(Paint.valueOf("#2b2b2b"), CornerRadii.EMPTY, Insets.EMPTY)) + content.setActions(cancelBtn, okayBtn) + content.setHeading(headingText) + content.setBody(bodyText) + alert.setContent(content) + alert.showAndWait() + } + +} diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt index 54664a1..ec02dca 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt @@ -2,7 +2,9 @@ package org.hso.texturesyncclient.controller import javafx.application.Platform import javafx.collections.ObservableList +import javafx.event.EventHandler import javafx.stage.DirectoryChooser +import org.hso.texturesyncclient.alerts.JFXOkayCancelAlert import org.hso.texturesyncclient.controller.net.Connection import org.hso.texturesyncclient.model.GUIModel import org.hso.texturesyncclient.model.Sha256 @@ -22,7 +24,6 @@ import java.io.File import javax.imageio.ImageIO import java.util.UUID import java.nio.file.Files -import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.close import java.io.FileOutputStream @@ -160,18 +161,22 @@ class RootController : Controller() { } fun deleteTexture(data: Texture) { + val dialogDelete = JFXOkayCancelAlert( + "Löschen", + "Wirklich löschen?", + "-fx-button-type: RAISED; -fx-background-color: #2b7bbb; -fx-text-fill: #000000;" + ) + dialogDelete.okayAction = EventHandler { + println("Okay") + con.deleteTexture(data) -//display "confirm delete" dialog and delete texture when needed - - //if yes : - - con.deleteTexture(data) - - //TODO delete texture from ui - - mvc.removeTextureFromView(data) - - + //TODO delete texture from ui + mvc.removeTextureFromView(data) + } + dialogDelete.cancelAction = EventHandler { + println("Cancel") + } + dialogDelete.showAndWait() } } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt index 1e53ccb..3a81d8f 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt @@ -16,7 +16,7 @@ import org.hso.texturesyncclient.controller.RootController import org.hso.texturesyncclient.view.mainView.MainViewController import tornadofx.* -class GUIModel constructor(data: Texture, img: Image) : VBox(){ +class GUIModel constructor(var data: Texture, img: Image) : VBox(){ private var image = ImageView() private var label = Label() diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt index 62779d6..36d226b 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt @@ -26,6 +26,7 @@ class MainViewController : Controller() { } fun addAllElements(elementList: ArrayList) { + elementList.get(0).data folderView.children.addAll(elementList) } @@ -80,8 +81,7 @@ class MainViewController : Controller() { //TODO delete guimodel from view //var previewList = folderView.children - - //previewList.s + //previewList.stream().filter { x:GUIModel -> x.data.id == data.id }.findAny().e //folderView.children.remove(data)