added JFXOkayCancelAlert

This commit is contained in:
Jannik 2019-06-06 14:41:30 +02:00
parent 90b21ca3d1
commit 594f083a8d
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
4 changed files with 79 additions and 15 deletions

View File

@ -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<ActionEvent>? = null
var cancelAction: EventHandler<ActionEvent>? = 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<Void>(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()
}
}

View File

@ -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()
}
}

View File

@ -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()

View File

@ -26,6 +26,7 @@ class MainViewController : Controller() {
}
fun addAllElements(elementList: ArrayList<GUIModel>) {
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)